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#include <QtCore/qregexp.h>
48#if QT_CONFIG(regularexpression)
49# include <QtCore/qregularexpression.h>
50#endif
51#include <QtCore/qlocale.h>
52
53QT_BEGIN_NAMESPACE
54
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 = nullptr);
65 ~QValidator();
66
67 enum State {
68 Invalid,
69 Intermediate,
70 Acceptable
71 };
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
79Q_SIGNALS:
80 void changed();
81
82protected:
83 QValidator(QObjectPrivate &d, QObject *parent);
84 QValidator(QValidatorPrivate &d, QObject *parent);
85
86private:
87 Q_DISABLE_COPY(QValidator)
88 Q_DECLARE_PRIVATE(QValidator)
89};
90
91class 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
97public:
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 virtual void setRange(int bottom, int top);
108
109 int bottom() const { return b; }
110 int top() const { return t; }
111Q_SIGNALS:
112 void bottomChanged(int bottom);
113 void topChanged(int top);
114
115private:
116 Q_DISABLE_COPY(QIntValidator)
117
118 int b;
119 int t;
120};
121
122#ifndef QT_NO_REGEXP
123
124class QDoubleValidatorPrivate;
125
126class Q_GUI_EXPORT QDoubleValidator : public QValidator
127{
128 Q_OBJECT
129 Q_PROPERTY(double bottom READ bottom WRITE setBottom NOTIFY bottomChanged)
130 Q_PROPERTY(double top READ top WRITE setTop NOTIFY topChanged)
131 Q_PROPERTY(int decimals READ decimals WRITE setDecimals NOTIFY decimalsChanged)
132 Q_PROPERTY(Notation notation READ notation WRITE setNotation NOTIFY notationChanged)
133
134public:
135 explicit QDoubleValidator(QObject * parent = nullptr);
136 QDoubleValidator(double bottom, double top, int decimals, QObject *parent = nullptr);
137 ~QDoubleValidator();
138
139 enum Notation {
140 StandardNotation,
141 ScientificNotation
142 };
143 Q_ENUM(Notation)
144 QValidator::State validate(QString &, int &) const override;
145
146 virtual void setRange(double bottom, double top, int decimals = 0);
147 void setBottom(double);
148 void setTop(double);
149 void setDecimals(int);
150 void setNotation(Notation);
151
152 double bottom() const { return b; }
153 double top() const { return t; }
154 int decimals() const { return dec; }
155 Notation notation() const;
156
157Q_SIGNALS:
158 void bottomChanged(double bottom);
159 void topChanged(double top);
160 void decimalsChanged(int decimals);
161 void notationChanged(QDoubleValidator::Notation notation);
162
163private:
164 Q_DECLARE_PRIVATE(QDoubleValidator)
165 Q_DISABLE_COPY(QDoubleValidator)
166
167 double b;
168 double t;
169 int dec;
170};
171
172
173class Q_GUI_EXPORT QRegExpValidator : public QValidator
174{
175 Q_OBJECT
176 Q_PROPERTY(QRegExp regExp READ regExp WRITE setRegExp NOTIFY regExpChanged)
177
178public:
179 explicit QRegExpValidator(QObject *parent = nullptr);
180 explicit QRegExpValidator(const QRegExp& rx, QObject *parent = nullptr);
181 ~QRegExpValidator();
182
183 virtual QValidator::State validate(QString& input, int& pos) const override;
184
185 void setRegExp(const QRegExp& rx);
186 const QRegExp& regExp() const { return r; }
187
188Q_SIGNALS:
189 void regExpChanged(const QRegExp& regExp);
190
191private:
192 Q_DISABLE_COPY(QRegExpValidator)
193
194 QRegExp r;
195};
196
197#endif // QT_NO_REGEXP
198
199#if QT_CONFIG(regularexpression)
200
201class QRegularExpressionValidatorPrivate;
202
203class Q_GUI_EXPORT QRegularExpressionValidator : public QValidator
204{
205 Q_OBJECT
206 Q_PROPERTY(QRegularExpression regularExpression READ regularExpression WRITE setRegularExpression NOTIFY regularExpressionChanged)
207
208public:
209 explicit QRegularExpressionValidator(QObject *parent = nullptr);
210 explicit QRegularExpressionValidator(const QRegularExpression &re, QObject *parent = nullptr);
211 ~QRegularExpressionValidator();
212
213 virtual QValidator::State validate(QString &input, int &pos) const override;
214
215 QRegularExpression regularExpression() const;
216
217public Q_SLOTS:
218 void setRegularExpression(const QRegularExpression &re);
219
220Q_SIGNALS:
221 void regularExpressionChanged(const QRegularExpression &re);
222
223private:
224 Q_DISABLE_COPY(QRegularExpressionValidator)
225 Q_DECLARE_PRIVATE(QRegularExpressionValidator)
226};
227
228#endif // QT_CONFIG(regularexpression)
229
230#endif // QT_NO_VALIDATOR
231
232QT_END_NAMESPACE
233
234#endif // QVALIDATOR_H
235