|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtGui module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
15 ** |
|
16 ** GNU Lesser General Public License Usage |
|
17 ** Alternatively, this file may be used under the terms of the GNU Lesser |
|
18 ** General Public License version 2.1 as published by the Free Software |
|
19 ** Foundation and appearing in the file LICENSE.LGPL included in the |
|
20 ** packaging of this file. Please review the following information to |
|
21 ** ensure the GNU Lesser General Public License version 2.1 requirements |
|
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. |
|
23 ** |
|
24 ** In addition, as a special exception, Nokia gives you certain additional |
|
25 ** rights. These rights are described in the Nokia Qt LGPL Exception |
|
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. |
|
27 ** |
|
28 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
37 ** |
|
38 ** $QT_END_LICENSE$ |
|
39 ** |
|
40 ****************************************************************************/ |
|
41 |
|
42 #ifndef QVALIDATOR_H |
|
43 #define QVALIDATOR_H |
|
44 |
|
45 #include <QtCore/qobject.h> |
|
46 #include <QtCore/qstring.h> |
|
47 #include <QtCore/qregexp.h> |
|
48 #include <QtCore/qlocale.h> |
|
49 |
|
50 QT_BEGIN_HEADER |
|
51 |
|
52 QT_BEGIN_NAMESPACE |
|
53 |
|
54 QT_MODULE(Gui) |
|
55 |
|
56 #ifndef QT_NO_VALIDATOR |
|
57 |
|
58 class QValidatorPrivate; |
|
59 |
|
60 class Q_GUI_EXPORT QValidator : public QObject |
|
61 { |
|
62 Q_OBJECT |
|
63 public: |
|
64 explicit QValidator(QObject * parent = 0); |
|
65 ~QValidator(); |
|
66 |
|
67 enum State { |
|
68 Invalid, |
|
69 Intermediate, |
|
70 Acceptable |
|
71 |
|
72 #if defined(QT3_SUPPORT) && !defined(Q_MOC_RUN) |
|
73 , Valid = Intermediate |
|
74 #endif |
|
75 }; |
|
76 |
|
77 void setLocale(const QLocale &locale); |
|
78 QLocale locale() const; |
|
79 |
|
80 virtual State validate(QString &, int &) const = 0; |
|
81 virtual void fixup(QString &) const; |
|
82 |
|
83 #ifdef QT3_SUPPORT |
|
84 public: |
|
85 QT3_SUPPORT_CONSTRUCTOR QValidator(QObject * parent, const char *name); |
|
86 #endif |
|
87 protected: |
|
88 QValidator(QObjectPrivate &d, QObject *parent); |
|
89 QValidator(QValidatorPrivate &d, QObject *parent); |
|
90 |
|
91 private: |
|
92 Q_DISABLE_COPY(QValidator) |
|
93 Q_DECLARE_PRIVATE(QValidator) |
|
94 }; |
|
95 |
|
96 class Q_GUI_EXPORT QIntValidator : public QValidator |
|
97 { |
|
98 Q_OBJECT |
|
99 Q_PROPERTY(int bottom READ bottom WRITE setBottom) |
|
100 Q_PROPERTY(int top READ top WRITE setTop) |
|
101 |
|
102 public: |
|
103 explicit QIntValidator(QObject * parent = 0); |
|
104 QIntValidator(int bottom, int top, QObject * parent); |
|
105 ~QIntValidator(); |
|
106 |
|
107 QValidator::State validate(QString &, int &) const; |
|
108 |
|
109 void setBottom(int); |
|
110 void setTop(int); |
|
111 virtual void setRange(int bottom, int top); |
|
112 |
|
113 int bottom() const { return b; } |
|
114 int top() const { return t; } |
|
115 |
|
116 #ifdef QT3_SUPPORT |
|
117 public: |
|
118 QT3_SUPPORT_CONSTRUCTOR QIntValidator(QObject * parent, const char *name); |
|
119 QT3_SUPPORT_CONSTRUCTOR QIntValidator(int bottom, int top, QObject * parent, const char *name); |
|
120 #endif |
|
121 |
|
122 private: |
|
123 Q_DISABLE_COPY(QIntValidator) |
|
124 |
|
125 int b; |
|
126 int t; |
|
127 }; |
|
128 |
|
129 #ifndef QT_NO_REGEXP |
|
130 |
|
131 class QDoubleValidatorPrivate; |
|
132 |
|
133 class Q_GUI_EXPORT QDoubleValidator : public QValidator |
|
134 { |
|
135 Q_OBJECT |
|
136 Q_PROPERTY(double bottom READ bottom WRITE setBottom) |
|
137 Q_PROPERTY(double top READ top WRITE setTop) |
|
138 Q_PROPERTY(int decimals READ decimals WRITE setDecimals) |
|
139 Q_PROPERTY(Notation notation READ notation WRITE setNotation) |
|
140 |
|
141 public: |
|
142 explicit QDoubleValidator(QObject * parent); |
|
143 QDoubleValidator(double bottom, double top, int decimals, QObject * parent); |
|
144 ~QDoubleValidator(); |
|
145 |
|
146 enum Notation { |
|
147 StandardNotation, |
|
148 ScientificNotation |
|
149 }; |
|
150 |
|
151 QValidator::State validate(QString &, int &) const; |
|
152 |
|
153 virtual void setRange(double bottom, double top, int decimals = 0); |
|
154 void setBottom(double); |
|
155 void setTop(double); |
|
156 void setDecimals(int); |
|
157 void setNotation(Notation); |
|
158 |
|
159 double bottom() const { return b; } |
|
160 double top() const { return t; } |
|
161 int decimals() const { return dec; } |
|
162 Notation notation() const; |
|
163 |
|
164 #ifdef QT3_SUPPORT |
|
165 public: |
|
166 QT3_SUPPORT_CONSTRUCTOR QDoubleValidator(QObject * parent, const char *name); |
|
167 QT3_SUPPORT_CONSTRUCTOR QDoubleValidator(double bottom, double top, int decimals, |
|
168 QObject * parent, const char *name); |
|
169 #endif |
|
170 private: |
|
171 Q_DECLARE_PRIVATE(QDoubleValidator) |
|
172 Q_DISABLE_COPY(QDoubleValidator) |
|
173 |
|
174 double b; |
|
175 double t; |
|
176 int dec; |
|
177 }; |
|
178 |
|
179 |
|
180 class Q_GUI_EXPORT QRegExpValidator : public QValidator |
|
181 { |
|
182 Q_OBJECT |
|
183 Q_PROPERTY(QRegExp regExp READ regExp WRITE setRegExp) |
|
184 |
|
185 public: |
|
186 explicit QRegExpValidator(QObject *parent); |
|
187 QRegExpValidator(const QRegExp& rx, QObject *parent); |
|
188 ~QRegExpValidator(); |
|
189 |
|
190 virtual QValidator::State validate(QString& input, int& pos) const; |
|
191 |
|
192 void setRegExp(const QRegExp& rx); |
|
193 const QRegExp& regExp() const { return r; } // ### make inline for 5.0 |
|
194 |
|
195 #ifdef QT3_SUPPORT |
|
196 public: |
|
197 QT3_SUPPORT_CONSTRUCTOR QRegExpValidator(QObject *parent, const char *name); |
|
198 QT3_SUPPORT_CONSTRUCTOR QRegExpValidator(const QRegExp& rx, QObject *parent, const char *name); |
|
199 #endif |
|
200 |
|
201 private: |
|
202 Q_DISABLE_COPY(QRegExpValidator) |
|
203 |
|
204 QRegExp r; |
|
205 }; |
|
206 |
|
207 #endif // QT_NO_REGEXP |
|
208 |
|
209 #endif // QT_NO_VALIDATOR |
|
210 |
|
211 QT_END_NAMESPACE |
|
212 |
|
213 QT_END_HEADER |
|
214 |
|
215 #endif // QVALIDATOR_H |