Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qvalidator.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
3// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
4
5#ifndef QVALIDATOR_H
6#define QVALIDATOR_H
7
8#include <QtGui/qtguiglobal.h>
9#include <QtCore/qobject.h>
10#include <QtCore/qstring.h>
11#if QT_CONFIG(regularexpression)
12# include <QtCore/qregularexpression.h>
13#endif
14#include <QtCore/qlocale.h>
15
17
18
19#ifndef QT_NO_VALIDATOR
20
22
23class Q_GUI_EXPORT QValidator : public QObject
24{
26public:
27 explicit QValidator(QObject * parent = nullptr);
29
30 enum State {
33 Acceptable
34 };
36
37 void setLocale(const QLocale &locale);
38 QLocale locale() const;
39
40 virtual State validate(QString &, int &) const = 0;
41 virtual void fixup(QString &) const;
42
44 void changed();
45
46protected:
49
50private:
51 Q_DISABLE_COPY(QValidator)
52 Q_DECLARE_PRIVATE(QValidator)
53};
54
55class Q_GUI_EXPORT QIntValidator : public QValidator
56{
58 Q_PROPERTY(int bottom READ bottom WRITE setBottom NOTIFY bottomChanged)
59 Q_PROPERTY(int top READ top WRITE setTop NOTIFY topChanged)
60
61public:
62 explicit QIntValidator(QObject * parent = nullptr);
63 QIntValidator(int bottom, int top, QObject *parent = nullptr);
65
66 QValidator::State validate(QString &, int &) const override;
67 void fixup(QString &input) const override;
68
69 void setBottom(int);
70 void setTop(int);
71 void setRange(int bottom, int top);
72
73 int bottom() const { return b; }
74 int top() const { return t; }
77 void topChanged(int top);
78
79private:
80 Q_DISABLE_COPY(QIntValidator)
81
82 int b;
83 int t;
84};
85
87
88class Q_GUI_EXPORT QDoubleValidator : public QValidator
89{
91 Q_PROPERTY(double bottom READ bottom WRITE setBottom NOTIFY bottomChanged)
92 Q_PROPERTY(double top READ top WRITE setTop NOTIFY topChanged)
93 Q_PROPERTY(int decimals READ decimals WRITE setDecimals NOTIFY decimalsChanged)
94 Q_PROPERTY(Notation notation READ notation WRITE setNotation NOTIFY notationChanged)
95
96public:
97 explicit QDoubleValidator(QObject * parent = nullptr);
98 QDoubleValidator(double bottom, double top, int decimals, QObject *parent = nullptr);
100
101 enum Notation {
103 ScientificNotation
104 };
105 Q_ENUM(Notation)
106 QValidator::State validate(QString &, int &) const override;
107 void fixup(QString &input) const override;
108
109 void setRange(double bottom, double top, int decimals);
110 void setRange(double bottom, double top);
111 void setBottom(double);
112 void setTop(double);
113 void setDecimals(int);
114 void setNotation(Notation);
115
116 double bottom() const { return b; }
117 double top() const { return t; }
118 int decimals() const { return dec; }
119 Notation notation() const;
120
122 void bottomChanged(double bottom);
123 void topChanged(double top);
124 void decimalsChanged(int decimals);
126
127private:
128 Q_DECLARE_PRIVATE(QDoubleValidator)
129 Q_DISABLE_COPY(QDoubleValidator)
130
131 double b;
132 double t;
133 int dec;
134};
135
136#if QT_CONFIG(regularexpression)
137
138class QRegularExpressionValidatorPrivate;
139
140class Q_GUI_EXPORT QRegularExpressionValidator : public QValidator
141{
143 Q_PROPERTY(QRegularExpression regularExpression READ regularExpression WRITE setRegularExpression NOTIFY regularExpressionChanged)
144
145public:
146 explicit QRegularExpressionValidator(QObject *parent = nullptr);
147 explicit QRegularExpressionValidator(const QRegularExpression &re, QObject *parent = nullptr);
148 ~QRegularExpressionValidator();
149
150 QValidator::State validate(QString &input, int &pos) const override;
151
152 QRegularExpression regularExpression() const;
153
154public Q_SLOTS:
155 void setRegularExpression(const QRegularExpression &re);
156
158 void regularExpressionChanged(const QRegularExpression &re);
159
160private:
161 Q_DISABLE_COPY(QRegularExpressionValidator)
162 Q_DECLARE_PRIVATE(QRegularExpressionValidator)
163};
164
165#endif // QT_CONFIG(regularexpression)
166
167#endif // QT_NO_VALIDATOR
168
170
171#endif // QVALIDATOR_H
The QDoubleValidator class provides range checking of floating-point numbers.
Definition qvalidator.h:89
void bottomChanged(double bottom)
This signal is emitted after the bottom property changed.
int decimals() const
Definition qvalidator.h:118
void decimalsChanged(int decimals)
This signal is emitted after the decimals property changed.
void notationChanged(QDoubleValidator::Notation notation)
This signal is emitted after the notation property changed.
void topChanged(double top)
This signal is emitted after the top property changed.
double top() const
Definition qvalidator.h:117
double bottom() const
Definition qvalidator.h:116
The QIntValidator class provides a validator that ensures a string contains a valid integer within a ...
Definition qvalidator.h:56
void topChanged(int top)
This signal is emitted after the top property changed.
int top() const
Definition qvalidator.h:74
void bottomChanged(int bottom)
This signal is emitted after the bottom property changed.
\inmodule QtCore
Definition qobject.h:103
\inmodule QtCore \reentrant
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
The QValidator class provides validation of input text.
Definition qvalidator.h:24
State
This enum type defines the states in which a validated string can exist.
Definition qvalidator.h:30
virtual State validate(QString &, int &) const =0
This virtual function returns \l Invalid if input is invalid according to this validator's rules,...
void changed()
This signal is emitted when any property that may affect the validity of a string has changed.
Combined button and popup list for selecting options.
GLboolean GLboolean GLboolean b
GLdouble GLdouble GLdouble GLdouble top
GLint GLint bottom
GLdouble GLdouble t
Definition qopenglext.h:243
GLenum GLenum GLenum input
#define Q_ENUM(x)
#define Q_PROPERTY(...)
#define Q_OBJECT
#define Q_SLOTS
#define Q_SIGNALS
#define explicit
progressBar setRange(0, 100)