1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2016 The Qt Company Ltd. |
4 | ** Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> |
5 | ** Contact: https://www.qt.io/licensing/ |
6 | ** |
7 | ** This file is part of the QtGui module of the Qt Toolkit. |
8 | ** |
9 | ** $QT_BEGIN_LICENSE:LGPL$ |
10 | ** Commercial License Usage |
11 | ** Licensees holding valid commercial Qt licenses may use this file in |
12 | ** accordance with the commercial license agreement provided with the |
13 | ** Software or, alternatively, in accordance with the terms contained in |
14 | ** a written agreement between you and The Qt Company. For licensing terms |
15 | ** and conditions see https://www.qt.io/terms-conditions. For further |
16 | ** information use the contact form at https://www.qt.io/contact-us. |
17 | ** |
18 | ** GNU Lesser General Public License Usage |
19 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
20 | ** General Public License version 3 as published by the Free Software |
21 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
22 | ** packaging of this file. Please review the following information to |
23 | ** ensure the GNU Lesser General Public License version 3 requirements |
24 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
25 | ** |
26 | ** GNU General Public License Usage |
27 | ** Alternatively, this file may be used under the terms of the GNU |
28 | ** General Public License version 2.0 or (at your option) the GNU General |
29 | ** Public license version 3 or any later version approved by the KDE Free |
30 | ** Qt Foundation. The licenses are as published by the Free Software |
31 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
32 | ** included in the packaging of this file. Please review the following |
33 | ** information to ensure the GNU General Public License requirements will |
34 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
35 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
36 | ** |
37 | ** $QT_END_LICENSE$ |
38 | ** |
39 | ****************************************************************************/ |
40 | |
41 | #ifndef QVALIDATOR_H |
42 | #define QVALIDATOR_H |
43 | |
44 | #include <QtGui/qtguiglobal.h> |
45 | #include <QtCore/qobject.h> |
46 | #include <QtCore/qstring.h> |
47 | #if QT_CONFIG(regularexpression) |
48 | # include <QtCore/qregularexpression.h> |
49 | #endif |
50 | #include <QtCore/qlocale.h> |
51 | |
52 | QT_BEGIN_NAMESPACE |
53 | |
54 | |
55 | #ifndef QT_NO_VALIDATOR |
56 | |
57 | class QValidatorPrivate; |
58 | |
59 | class Q_GUI_EXPORT QValidator : public QObject |
60 | { |
61 | Q_OBJECT |
62 | public: |
63 | explicit QValidator(QObject * parent = nullptr); |
64 | ~QValidator(); |
65 | |
66 | enum State { |
67 | Invalid, |
68 | Intermediate, |
69 | Acceptable |
70 | }; |
71 | Q_ENUM(State) |
72 | |
73 | void setLocale(const QLocale &locale); |
74 | QLocale locale() const; |
75 | |
76 | virtual State validate(QString &, int &) const = 0; |
77 | virtual void fixup(QString &) const; |
78 | |
79 | Q_SIGNALS: |
80 | void changed(); |
81 | |
82 | protected: |
83 | QValidator(QObjectPrivate &d, QObject *parent); |
84 | QValidator(QValidatorPrivate &d, QObject *parent); |
85 | |
86 | private: |
87 | Q_DISABLE_COPY(QValidator) |
88 | Q_DECLARE_PRIVATE(QValidator) |
89 | }; |
90 | |
91 | class Q_GUI_EXPORT QIntValidator : public QValidator |
92 | { |
93 | Q_OBJECT |
94 | Q_PROPERTY(int bottom READ bottom WRITE setBottom NOTIFY bottomChanged) |
95 | Q_PROPERTY(int top READ top WRITE setTop NOTIFY topChanged) |
96 | |
97 | public: |
98 | explicit QIntValidator(QObject * parent = nullptr); |
99 | QIntValidator(int bottom, int top, QObject *parent = nullptr); |
100 | ~QIntValidator(); |
101 | |
102 | QValidator::State validate(QString &, int &) const override; |
103 | void fixup(QString &input) const override; |
104 | |
105 | void setBottom(int); |
106 | void setTop(int); |
107 | void setRange(int bottom, int top); |
108 | |
109 | int bottom() const { return b; } |
110 | int top() const { return t; } |
111 | Q_SIGNALS: |
112 | void bottomChanged(int bottom); |
113 | void topChanged(int top); |
114 | |
115 | private: |
116 | Q_DISABLE_COPY(QIntValidator) |
117 | |
118 | int b; |
119 | int t; |
120 | }; |
121 | |
122 | class QDoubleValidatorPrivate; |
123 | |
124 | class Q_GUI_EXPORT QDoubleValidator : public QValidator |
125 | { |
126 | Q_OBJECT |
127 | Q_PROPERTY(double bottom READ bottom WRITE setBottom NOTIFY bottomChanged) |
128 | Q_PROPERTY(double top READ top WRITE setTop NOTIFY topChanged) |
129 | Q_PROPERTY(int decimals READ decimals WRITE setDecimals NOTIFY decimalsChanged) |
130 | Q_PROPERTY(Notation notation READ notation WRITE setNotation NOTIFY notationChanged) |
131 | |
132 | public: |
133 | explicit QDoubleValidator(QObject * parent = nullptr); |
134 | QDoubleValidator(double bottom, double top, int decimals, QObject *parent = nullptr); |
135 | ~QDoubleValidator(); |
136 | |
137 | enum Notation { |
138 | StandardNotation, |
139 | ScientificNotation |
140 | }; |
141 | Q_ENUM(Notation) |
142 | QValidator::State validate(QString &, int &) const override; |
143 | |
144 | void setRange(double bottom, double top, int decimals = 0); |
145 | void setBottom(double); |
146 | void setTop(double); |
147 | void setDecimals(int); |
148 | void setNotation(Notation); |
149 | |
150 | double bottom() const { return b; } |
151 | double top() const { return t; } |
152 | int decimals() const { return dec; } |
153 | Notation notation() const; |
154 | |
155 | Q_SIGNALS: |
156 | void bottomChanged(double bottom); |
157 | void topChanged(double top); |
158 | void decimalsChanged(int decimals); |
159 | void notationChanged(QDoubleValidator::Notation notation); |
160 | |
161 | private: |
162 | Q_DECLARE_PRIVATE(QDoubleValidator) |
163 | Q_DISABLE_COPY(QDoubleValidator) |
164 | |
165 | double b; |
166 | double t; |
167 | int dec; |
168 | }; |
169 | |
170 | #if QT_CONFIG(regularexpression) |
171 | |
172 | class QRegularExpressionValidatorPrivate; |
173 | |
174 | class Q_GUI_EXPORT QRegularExpressionValidator : public QValidator |
175 | { |
176 | Q_OBJECT |
177 | Q_PROPERTY(QRegularExpression regularExpression READ regularExpression WRITE setRegularExpression NOTIFY regularExpressionChanged) |
178 | |
179 | public: |
180 | explicit QRegularExpressionValidator(QObject *parent = nullptr); |
181 | explicit QRegularExpressionValidator(const QRegularExpression &re, QObject *parent = nullptr); |
182 | ~QRegularExpressionValidator(); |
183 | |
184 | QValidator::State validate(QString &input, int &pos) const override; |
185 | |
186 | QRegularExpression regularExpression() const; |
187 | |
188 | public Q_SLOTS: |
189 | void setRegularExpression(const QRegularExpression &re); |
190 | |
191 | Q_SIGNALS: |
192 | void regularExpressionChanged(const QRegularExpression &re); |
193 | |
194 | private: |
195 | Q_DISABLE_COPY(QRegularExpressionValidator) |
196 | Q_DECLARE_PRIVATE(QRegularExpressionValidator) |
197 | }; |
198 | |
199 | #endif // QT_CONFIG(regularexpression) |
200 | |
201 | #endif // QT_NO_VALIDATOR |
202 | |
203 | QT_END_NAMESPACE |
204 | |
205 | #endif // QVALIDATOR_H |
206 | |