Qt 4.8
qt-4.8.6
src
gui
widgets
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
50
QT_BEGIN_HEADER
51
52
QT_BEGIN_NAMESPACE
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
{
68
Invalid
,
69
Intermediate
,
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
:
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
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
132
class
QDoubleValidatorPrivate
;
133
134
class
Q_GUI_EXPORT
QDoubleValidator
:
public
QValidator
135
{
136
Q_OBJECT
137
double
bottom
;
138
double
top
;
139
int
decimals
;
140
Q_ENUMS
(
Notation
)
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
{
149
StandardNotation
,
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
182
class
Q_GUI_EXPORT
QRegExpValidator
: public
QValidator
183
{
184
Q_OBJECT
185
QRegExp
regExp
;
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
206
QRegExp
r;
207
};
208
209
#endif // QT_NO_REGEXP
210
211
#endif // QT_NO_VALIDATOR
212
213
QT_END_NAMESPACE
214
215
QT_END_HEADER
216
217
#endif // QVALIDATOR_H
QValidator::Invalid
Definition:
qvalidator.h:68
d
double d
Definition:
qnumeric_p.h:62
QDoubleValidator::Notation
Notation
This enum defines the allowed notations for entering a double.
Definition:
qvalidator.h:148
QRegExpValidator
The QRegExpValidator class is used to check a string against a regular expression.
Definition:
qvalidator.h:182
QT_END_NAMESPACE
#define QT_END_NAMESPACE
This macro expands to.
Definition:
qglobal.h:90
QRegExpValidator::regExp
QRegExp regExp
the regular expression used for validation
Definition:
qvalidator.h:185
QT_MODULE
#define QT_MODULE(x)
Definition:
qglobal.h:2783
QRegExp
The QRegExp class provides pattern matching using regular expressions.
Definition:
qregexp.h:61
QT_BEGIN_HEADER
#define QT_BEGIN_HEADER
Definition:
qglobal.h:136
Q_GUI_EXPORT
#define Q_GUI_EXPORT
Definition:
qglobal.h:1450
QValidator::fixup
virtual void fixup(QString &) const
This function attempts to change input to be valid according to this validator's rules.
Definition:
qvalidator.cpp:246
Q_DISABLE_COPY
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition:
qglobal.h:2523
QString
The QString class provides a Unicode character string.
Definition:
qstring.h:83
QObject
The QObject class is the base class of all Qt objects.
Definition:
qobject.h:111
QIntValidator
The QIntValidator class provides a validator that ensures a string contains a valid integer within a ...
Definition:
qvalidator.h:96
dec
Q_CORE_EXPORT QTextStream & dec(QTextStream &s)
Q_ENUMS
#define Q_ENUMS(x)
Definition:
qobjectdefs.h:84
QDoubleValidator::bottom
double bottom
the validator's minimum acceptable value
Definition:
qvalidator.h:137
QDoubleValidator::decimals
int decimals() const
Definition:
qvalidator.h:163
QIntValidator::bottom
int bottom
the validator's lowest acceptable value
Definition:
qvalidator.h:99
QT_BEGIN_NAMESPACE
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition:
qglobal.h:89
QValidator
The QValidator class provides validation of input text.
Definition:
qvalidator.h:60
QLocale
Definition:
qlocale.h:133
QDoubleValidator::top
double top
the validator's maximum acceptable value
Definition:
qvalidator.h:138
name
const char * name
Definition:
qkeysequence.cpp:396
QValidator::validate
virtual State validate(QString &, int &) const =0
This virtual function returns Invalid if input is invalid according to this validator's rules...
State
The State element defines configurations of objects and properties.
QDoubleValidator::top
double top() const
Definition:
qvalidator.h:162
Q_OBJECT
#define Q_OBJECT
Definition:
qobjectdefs.h:157
QIntValidator::bottom
int bottom() const
Definition:
qvalidator.h:114
QIntValidator::top
int top() const
Definition:
qvalidator.h:115
QDoubleValidator::StandardNotation
Definition:
qvalidator.h:149
QRegExpValidator::regExp
const QRegExp & regExp() const
Definition:
qvalidator.h:195
QValidator::State
State
This enum type defines the states in which a validated string can exist.
Definition:
qvalidator.h:67
QValidatorPrivate
Definition:
qvalidator.cpp:135
QValidator::Intermediate
Definition:
qvalidator.h:69
QIntValidator::top
int top
the validator's highest acceptable value
Definition:
qvalidator.h:100
QObjectPrivate
Definition:
qobject_p.h:98
Q_DECLARE_PRIVATE
#define Q_DECLARE_PRIVATE(Class)
Definition:
qglobal.h:2467
QDoubleValidatorPrivate
Definition:
qvalidator.cpp:520
QDoubleValidator::bottom
double bottom() const
Definition:
qvalidator.h:161
class
#define class
Definition:
qapplication_x11.cpp:92
QT_END_HEADER
#define QT_END_HEADER
Definition:
qglobal.h:137
QDoubleValidator::decimals
int decimals
the validator's maximum number of digits after the decimal point
Definition:
qvalidator.h:139
QDoubleValidator
The QDoubleValidator class provides range checking of floating-point numbers.
Definition:
qvalidator.h:134
Qt 4.8 Source Code Browser