source: trunk/src/gui/widgets/qvalidator.h

Last change on this file was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

File size: 6.0 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the QtGui module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
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** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
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
50QT_BEGIN_HEADER
51
52QT_BEGIN_NAMESPACE
53
54QT_MODULE(Gui)
55
56#ifndef QT_NO_VALIDATOR
57
58class QValidatorPrivate;
59
60class Q_GUI_EXPORT QValidator : public QObject
61{
62 Q_OBJECT
63public:
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
84public:
85 QT3_SUPPORT_CONSTRUCTOR QValidator(QObject * parent, const char *name);
86#endif
87protected:
88 QValidator(QObjectPrivate &d, QObject *parent);
89 QValidator(QValidatorPrivate &d, QObject *parent);
90
91private:
92 Q_DISABLE_COPY(QValidator)
93 Q_DECLARE_PRIVATE(QValidator)
94};
95
96class 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
102public:
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 void fixup(QString &input) const;
109
110 void setBottom(int);
111 void setTop(int);
112 virtual void setRange(int bottom, int top);
113
114 int bottom() const { return b; }
115 int top() const { return t; }
116
117#ifdef QT3_SUPPORT
118public:
119 QT3_SUPPORT_CONSTRUCTOR QIntValidator(QObject * parent, const char *name);
120 QT3_SUPPORT_CONSTRUCTOR QIntValidator(int bottom, int top, QObject * parent, const char *name);
121#endif
122
123private:
124 Q_DISABLE_COPY(QIntValidator)
125
126 int b;
127 int t;
128};
129
130#ifndef QT_NO_REGEXP
131
132class QDoubleValidatorPrivate;
133
134class Q_GUI_EXPORT QDoubleValidator : public QValidator
135{
136 Q_OBJECT
137 Q_PROPERTY(double bottom READ bottom WRITE setBottom)
138 Q_PROPERTY(double top READ top WRITE setTop)
139 Q_PROPERTY(int decimals READ decimals WRITE setDecimals)
140 Q_ENUMS(Notation)
141 Q_PROPERTY(Notation notation READ notation WRITE setNotation)
142
143public:
144 explicit QDoubleValidator(QObject * parent = 0);
145 QDoubleValidator(double bottom, double top, int decimals, QObject * parent);
146 ~QDoubleValidator();
147
148 enum Notation {
149 StandardNotation,
150 ScientificNotation
151 };
152
153 QValidator::State validate(QString &, int &) const;
154
155 virtual void setRange(double bottom, double top, int decimals = 0);
156 void setBottom(double);
157 void setTop(double);
158 void setDecimals(int);
159 void setNotation(Notation);
160
161 double bottom() const { return b; }
162 double top() const { return t; }
163 int decimals() const { return dec; }
164 Notation notation() const;
165
166#ifdef QT3_SUPPORT
167public:
168 QT3_SUPPORT_CONSTRUCTOR QDoubleValidator(QObject * parent, const char *name);
169 QT3_SUPPORT_CONSTRUCTOR QDoubleValidator(double bottom, double top, int decimals,
170 QObject * parent, const char *name);
171#endif
172private:
173 Q_DECLARE_PRIVATE(QDoubleValidator)
174 Q_DISABLE_COPY(QDoubleValidator)
175
176 double b;
177 double t;
178 int dec;
179};
180
181
182class Q_GUI_EXPORT QRegExpValidator : public QValidator
183{
184 Q_OBJECT
185 Q_PROPERTY(QRegExp regExp READ regExp WRITE setRegExp)
186
187public:
188 explicit QRegExpValidator(QObject *parent = 0);
189 QRegExpValidator(const QRegExp& rx, QObject *parent);
190 ~QRegExpValidator();
191
192 virtual QValidator::State validate(QString& input, int& pos) const;
193
194 void setRegExp(const QRegExp& rx);
195 const QRegExp& regExp() const { return r; } // ### make inline for 5.0
196
197#ifdef QT3_SUPPORT
198public:
199 QT3_SUPPORT_CONSTRUCTOR QRegExpValidator(QObject *parent, const char *name);
200 QT3_SUPPORT_CONSTRUCTOR QRegExpValidator(const QRegExp& rx, QObject *parent, const char *name);
201#endif
202
203private:
204 Q_DISABLE_COPY(QRegExpValidator)
205
206 QRegExp r;
207};
208
209#endif // QT_NO_REGEXP
210
211#endif // QT_NO_VALIDATOR
212
213QT_END_NAMESPACE
214
215QT_END_HEADER
216
217#endif // QVALIDATOR_H
Note: See TracBrowser for help on using the repository browser.