QtBase  v6.3.1
qvalidator.h
Go to the documentation of this file.
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 
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 {
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:
85 
86 private:
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:
113  void topChanged(int top);
114 
115 private:
117 
118  int b;
119  int t;
120 };
121 
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 {
139  ScientificNotation
140  };
141  Q_ENUM(Notation)
142  QValidator::State validate(QString &, int &) const override;
143  void fixup(QString &input) const override;
144 
145  void setRange(double bottom, double top, int decimals);
146  void setRange(double bottom, double top);
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 
157 Q_SIGNALS:
158  void bottomChanged(double bottom);
159  void topChanged(double top);
160  void decimalsChanged(int decimals);
162 
163 private:
164  Q_DECLARE_PRIVATE(QDoubleValidator)
166 
167  double b;
168  double t;
169  int dec;
170 };
171 
172 #if QT_CONFIG(regularexpression)
173 
174 class QRegularExpressionValidatorPrivate;
175 
176 class Q_GUI_EXPORT QRegularExpressionValidator : public QValidator
177 {
178  Q_OBJECT
179  Q_PROPERTY(QRegularExpression regularExpression READ regularExpression WRITE setRegularExpression NOTIFY regularExpressionChanged)
180 
181 public:
182  explicit QRegularExpressionValidator(QObject *parent = nullptr);
183  explicit QRegularExpressionValidator(const QRegularExpression &re, QObject *parent = nullptr);
184  ~QRegularExpressionValidator();
185 
186  QValidator::State validate(QString &input, int &pos) const override;
187 
188  QRegularExpression regularExpression() const;
189 
190 public Q_SLOTS:
191  void setRegularExpression(const QRegularExpression &re);
192 
193 Q_SIGNALS:
194  void regularExpressionChanged(const QRegularExpression &re);
195 
196 private:
197  Q_DISABLE_COPY(QRegularExpressionValidator)
198  Q_DECLARE_PRIVATE(QRegularExpressionValidator)
199 };
200 
201 #endif // QT_CONFIG(regularexpression)
202 
203 #endif // QT_NO_VALIDATOR
204 
206 
207 #endif // QVALIDATOR_H
The QDoubleValidator class provides range checking of floating-point numbers. \inmodule QtGui.
Definition: qvalidator.h:125
void bottomChanged(double bottom)
int decimals() const
Definition: qvalidator.h:154
void decimalsChanged(int decimals)
void notationChanged(QDoubleValidator::Notation notation)
void topChanged(double top)
double top() const
Definition: qvalidator.h:153
double bottom() const
Definition: qvalidator.h:152
The QIntValidator class provides a validator that ensures a string contains a valid integer within a ...
Definition: qvalidator.h:92
void topChanged(int top)
int top() const
Definition: qvalidator.h:110
int bottom() const
Definition: qvalidator.h:109
void bottomChanged(int bottom)
The QObject class is the base class of all Qt objects.
Definition: qobject.h:125
The QRegularExpression class provides pattern matching using regular expressions.
The QString class provides a Unicode character string.
Definition: qstring.h:388
The QValidator class provides validation of input text. \inmodule QtGui.
Definition: qvalidator.h:60
@ Intermediate
Definition: qvalidator.h:68
virtual State validate(QString &, int &) const =0
void changed()
#define Q_DISABLE_COPY(Class)
Definition: qglobal.h:515
GLboolean GLboolean GLboolean b
GLdouble GLdouble GLdouble GLdouble top
GLint GLint bottom
GLdouble GLdouble t
[9]
Definition: qopenglext.h:243
GLenum GLenum GLenum input
Definition: qopenglext.h:10816
#define Q_ENUM(x)
Definition: qtmetamacros.h:104
#define Q_PROPERTY(...)
Definition: qtmetamacros.h:92
#define Q_OBJECT
Definition: qtmetamacros.h:158
#define Q_SLOTS
Definition: qtmetamacros.h:80
#define Q_SIGNALS
Definition: qtmetamacros.h:81
progressBar setRange(0, 100)
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent