QtGui/qvalidator.h Source File

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 
60 class Q_GUI_EXPORT QValidator : public QObject
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 #ifdef QT3_SUPPORT
84 public:
85  QT3_SUPPORT_CONSTRUCTOR QValidator(QObject * parent, const char *name);
86 #endif
87 protected:
88  QValidator(QObjectPrivate &d, QObject *parent);
89  QValidator(QValidatorPrivate &d, QObject *parent);
90 
91 private:
92  Q_DISABLE_COPY(QValidator)
93  Q_DECLARE_PRIVATE(QValidator)
94 };
95 
96 class 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 
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 #ifdef QT3_SUPPORT
118 public:
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 
132 class QDoubleValidatorPrivate;
133 
134 class 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)
141  Q_PROPERTY(Notation notation READ notation WRITE setNotation)
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 #ifdef QT3_SUPPORT
167 public:
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 
182 class Q_GUI_EXPORT QRegExpValidator : public QValidator
183 {
184  Q_OBJECT
185  Q_PROPERTY(QRegExp regExp READ regExp WRITE setRegExp)
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 #ifdef QT3_SUPPORT
198 public:
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 
206  QRegExp r;
207 };
208 
209 #endif // QT_NO_REGEXP
210 
211 #endif // QT_NO_VALIDATOR
212 
214 
216 
217 #endif // QVALIDATOR_H
GLdouble GLdouble GLdouble r
Definition: GLee.h:1189
unsigned int(APIENTRYP PFNGLXGETAGPOFFSETMESAPROC)(const void *pointer)
Definition: GLee.h:10762
GLenum GLenum GLenum input
Definition: GLee.h:5776
#define QT_END_NAMESPACE
Definition: qglobal.h:128
#define Q_PROPERTY(text)
Definition: qobjectdefs.h:80
#define QT_BEGIN_HEADER
Definition: qglobal.h:141
State
The state the media producing object is in at the moment.
double top() const
Definition: qvalidator.h:162
double bottom() const
Definition: qvalidator.h:161
int decimals() const
Definition: qvalidator.h:163
Q_CORE_EXPORT QTextStream & dec(QTextStream &s)
#define Q_ENUMS(x)
Definition: qobjectdefs.h:84
int top() const
Definition: qvalidator.h:115
#define QT_BEGIN_NAMESPACE
Definition: qglobal.h:127
const QRegExp & regExp() const
Definition: qvalidator.h:195
virtual State validate(QString &, int &) const =0
#define Q_OBJECT
Definition: qobjectdefs.h:157
GLubyte GLubyte b
Definition: GLee.h:5404
GLuint const GLchar * name
Definition: GLee.h:1704
GLdouble GLdouble t
Definition: GLee.h:1181
#define QT_END_HEADER
Definition: qglobal.h:142