1 /**************************************************************************** 2 ** $Id: qt/qvalidator.h 3.3.8 edited Jan 11 14:39 $ 3 ** 4 ** Definition of validator classes 5 ** 6 ** Created : 970610 7 ** 8 ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved. 9 ** 10 ** This file is part of the widgets module of the Qt GUI Toolkit. 11 ** 12 ** This file may be distributed under the terms of the Q Public License 13 ** as defined by Trolltech ASA of Norway and appearing in the file 14 ** LICENSE.QPL included in the packaging of this file. 15 ** 16 ** This file may be distributed and/or modified under the terms of the 17 ** GNU General Public License version 2 as published by the Free Software 18 ** Foundation and appearing in the file LICENSE.GPL included in the 19 ** packaging of this file. 20 ** 21 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition 22 ** licenses may use this file in accordance with the Qt Commercial License 23 ** Agreement provided with the Software. 24 ** 25 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 26 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 27 ** 28 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 29 ** information about Qt Commercial License Agreements. 30 ** See http://www.trolltech.com/qpl/ for QPL licensing information. 31 ** See http://www.trolltech.com/gpl/ for GPL licensing information. 32 ** 33 ** Contact info@trolltech.com if any conditions of this licensing are 34 ** not clear to you. 35 ** 36 **********************************************************************/ 37 38 #ifndef QVALIDATOR_H 39 #define QVALIDATOR_H 40 41 #ifndef QT_H 42 #include "qobject.h" 43 #include "qstring.h" // char*->QString conversion 44 #include "qregexp.h" // QString->QRegExp conversion 45 #endif // QT_H 46 47 #ifndef QT_NO_VALIDATOR 48 49 50 class Q_EXPORT QValidator : public QObject 51 { 52 Q_OBJECT 53 public: 54 QValidator( QObject * parent, const char *name = 0 ); 55 ~QValidator(); 56 57 enum State { Invalid, Intermediate, Valid=Intermediate, Acceptable }; 58 59 virtual State validate( QString &, int & ) const = 0; 60 virtual void fixup( QString & ) const; 61 62 private: 63 #if defined(Q_DISABLE_COPY) 64 QValidator( const QValidator & ); 65 QValidator& operator=( const QValidator & ); 66 #endif 67 }; 68 69 70 class Q_EXPORT QIntValidator : public QValidator 71 { 72 Q_OBJECT 73 Q_PROPERTY( int bottom READ bottom WRITE setBottom ) 74 Q_PROPERTY( int top READ top WRITE setTop ) 75 76 public: 77 QIntValidator( QObject * parent, const char *name = 0 ); 78 QIntValidator( int bottom, int top, 79 QObject * parent, const char *name = 0 ); 80 ~QIntValidator(); 81 82 QValidator::State validate( QString &, int & ) const; 83 84 void setBottom( int ); 85 void setTop( int ); 86 virtual void setRange( int bottom, int top ); 87 bottom()88 int bottom() const { return b; } top()89 int top() const { return t; } 90 91 private: 92 #if defined(Q_DISABLE_COPY) 93 QIntValidator( const QIntValidator & ); 94 QIntValidator& operator=( const QIntValidator & ); 95 #endif 96 97 int b, t; 98 }; 99 100 #ifndef QT_NO_REGEXP 101 102 class Q_EXPORT QDoubleValidator : public QValidator 103 { 104 Q_OBJECT 105 Q_PROPERTY( double bottom READ bottom WRITE setBottom ) 106 Q_PROPERTY( double top READ top WRITE setTop ) 107 Q_PROPERTY( int decimals READ decimals WRITE setDecimals ) 108 109 public: 110 QDoubleValidator( QObject * parent, const char *name = 0 ); 111 QDoubleValidator( double bottom, double top, int decimals, 112 QObject * parent, const char *name = 0 ); 113 ~QDoubleValidator(); 114 115 QValidator::State validate( QString &, int & ) const; 116 117 virtual void setRange( double bottom, double top, int decimals = 0 ); 118 void setBottom( double ); 119 void setTop( double ); 120 void setDecimals( int ); 121 bottom()122 double bottom() const { return b; } top()123 double top() const { return t; } decimals()124 int decimals() const { return d; } 125 126 private: 127 #if defined(Q_DISABLE_COPY) 128 QDoubleValidator( const QDoubleValidator & ); 129 QDoubleValidator& operator=( const QDoubleValidator & ); 130 #endif 131 132 double b, t; 133 int d; 134 }; 135 136 137 class Q_EXPORT QRegExpValidator : public QValidator 138 { 139 Q_OBJECT 140 // Q_PROPERTY( QRegExp regExp READ regExp WRITE setRegExp ) 141 142 public: 143 QRegExpValidator( QObject *parent, const char *name = 0 ); 144 QRegExpValidator( const QRegExp& rx, QObject *parent, 145 const char *name = 0 ); 146 ~QRegExpValidator(); 147 148 virtual QValidator::State validate( QString& input, int& pos ) const; 149 150 void setRegExp( const QRegExp& rx ); regExp()151 const QRegExp& regExp() const { return r; } 152 153 private: 154 #if defined(Q_DISABLE_COPY) 155 QRegExpValidator( const QRegExpValidator& ); 156 QRegExpValidator& operator=( const QRegExpValidator& ); 157 #endif 158 159 QRegExp r; 160 }; 161 #endif // QT_NO_REGEXP 162 163 164 #endif // QT_NO_VALIDATOR 165 166 #endif // QVALIDATOR_H 167