Qt 4.8
qvalidator.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
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 
51 
53 
54 QT_MODULE(Gui)
55 
56 #ifndef QT_NO_VALIDATOR
57 
58 class QValidatorPrivate;
59 
61 {
62  Q_OBJECT
63 public:
64  explicit QValidator(QObject * parent = 0);
65  ~QValidator();
66 
67  enum State {
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 public:
84 #ifdef QT3_SUPPORT
85  QT3_SUPPORT_CONSTRUCTOR QValidator(QObject * parent, const char *name);
86 #endif
87 protected:
90 
91 private:
94 };
95 
97 {
98  Q_OBJECT
99  int bottom;
100  int top;
101 
102 public:
103  explicit QIntValidator(QObject * parent = 0);
104  QIntValidator(int bottom, int top, QObject *parent = 0);
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 public:
118 #ifdef QT3_SUPPORT
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 
123 private:
124  Q_DISABLE_COPY(QIntValidator)
125 
126  int b;
127  int t;
128 };
129 
130 #ifndef QT_NO_REGEXP
131 
133 
135 {
136  Q_OBJECT
137  double bottom;
138  double top;
139  int decimals;
141  Notation notation;
142 
143 public:
144  explicit QDoubleValidator(QObject * parent = 0);
145  QDoubleValidator(double bottom, double top, int decimals, QObject *parent = 0);
146  ~QDoubleValidator();
147 
148  enum Notation {
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 public:
167 #ifdef QT3_SUPPORT
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
172 private:
173  Q_DECLARE_PRIVATE(QDoubleValidator)
174  Q_DISABLE_COPY(QDoubleValidator)
175 
176  double b;
177  double t;
178  int dec;
179 };
180 
181 
183 {
184  Q_OBJECT
186 
187 public:
188  explicit QRegExpValidator(QObject *parent = 0);
189  QRegExpValidator(const QRegExp& rx, QObject *parent = 0);
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 public:
198 #ifdef QT3_SUPPORT
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 
203 private:
204  Q_DISABLE_COPY(QRegExpValidator)
205 
207 };
208 
209 #endif // QT_NO_REGEXP
210 
211 #endif // QT_NO_VALIDATOR
212 
214 
216 
217 #endif // QVALIDATOR_H
double d
Definition: qnumeric_p.h:62
Notation
This enum defines the allowed notations for entering a double.
Definition: qvalidator.h:148
The QRegExpValidator class is used to check a string against a regular expression.
Definition: qvalidator.h:182
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QRegExp regExp
the regular expression used for validation
Definition: qvalidator.h:185
#define QT_MODULE(x)
Definition: qglobal.h:2783
The QRegExp class provides pattern matching using regular expressions.
Definition: qregexp.h:61
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
virtual void fixup(QString &) const
This function attempts to change input to be valid according to this validator&#39;s rules.
Definition: qvalidator.cpp:246
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
The QIntValidator class provides a validator that ensures a string contains a valid integer within a ...
Definition: qvalidator.h:96
Q_CORE_EXPORT QTextStream & dec(QTextStream &s)
#define Q_ENUMS(x)
Definition: qobjectdefs.h:84
double bottom
the validator&#39;s minimum acceptable value
Definition: qvalidator.h:137
int decimals() const
Definition: qvalidator.h:163
int bottom
the validator&#39;s lowest acceptable value
Definition: qvalidator.h:99
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
The QValidator class provides validation of input text.
Definition: qvalidator.h:60
double top
the validator&#39;s maximum acceptable value
Definition: qvalidator.h:138
const char * name
virtual State validate(QString &, int &) const =0
This virtual function returns Invalid if input is invalid according to this validator&#39;s rules...
The State element defines configurations of objects and properties.
double top() const
Definition: qvalidator.h:162
#define Q_OBJECT
Definition: qobjectdefs.h:157
int bottom() const
Definition: qvalidator.h:114
int top() const
Definition: qvalidator.h:115
const QRegExp & regExp() const
Definition: qvalidator.h:195
State
This enum type defines the states in which a validated string can exist.
Definition: qvalidator.h:67
int top
the validator&#39;s highest acceptable value
Definition: qvalidator.h:100
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
double bottom() const
Definition: qvalidator.h:161
#define class
#define QT_END_HEADER
Definition: qglobal.h:137
int decimals
the validator&#39;s maximum number of digits after the decimal point
Definition: qvalidator.h:139
The QDoubleValidator class provides range checking of floating-point numbers.
Definition: qvalidator.h:134