Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
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// Qt-Security score:significant reason:default
5
6#ifndef QVALIDATOR_H
7#define QVALIDATOR_H
8
9#include <QtGui/qtguiglobal.h>
10#include <QtCore/qobject.h>
11#include <QtCore/qstring.h>
12#if QT_CONFIG(regularexpression)
13# include <QtCore/qregularexpression.h>
14#endif
15#include <QtCore/qlocale.h>
16
18
19
20#ifndef QT_NO_VALIDATOR
21
22class QValidatorPrivate;
23
24class Q_GUI_EXPORT QValidator : public QObject
25{
26 Q_OBJECT
27public:
28 explicit QValidator(QObject * parent = nullptr);
29 ~QValidator();
30
31 enum State {
32 Invalid,
33 Intermediate,
34 Acceptable
35 };
36 Q_ENUM(State)
37
38 void setLocale(const QLocale &locale);
39 QLocale locale() const;
40
41 virtual State validate(QString &, int &) const = 0;
42 virtual void fixup(QString &) const;
43
44Q_SIGNALS:
45 void changed();
46
47protected:
48 QValidator(QObjectPrivate &d, QObject *parent);
49 QValidator(QValidatorPrivate &d, QObject *parent);
50
51private:
52 Q_DISABLE_COPY(QValidator)
53 Q_DECLARE_PRIVATE(QValidator)
54};
55
56class Q_GUI_EXPORT QIntValidator : public QValidator
57{
58 Q_OBJECT
59 Q_PROPERTY(int bottom READ bottom WRITE setBottom NOTIFY bottomChanged)
60 Q_PROPERTY(int top READ top WRITE setTop NOTIFY topChanged)
61
62public:
63 explicit QIntValidator(QObject * parent = nullptr);
64 QIntValidator(int bottom, int top, QObject *parent = nullptr);
65 ~QIntValidator();
66
67 QValidator::State validate(QString &, int &) const override;
68 void fixup(QString &input) const override;
69
70 void setBottom(int);
71 void setTop(int);
72 void setRange(int bottom, int top);
73
74 int bottom() const { return b; }
75 int top() const { return t; }
76Q_SIGNALS:
77 void bottomChanged(int bottom);
78 void topChanged(int top);
79
80private:
81 Q_DISABLE_COPY(QIntValidator)
82
83 int b;
84 int t;
85};
86
88
89class Q_GUI_EXPORT QDoubleValidator : public QValidator
90{
91 Q_OBJECT
92 Q_PROPERTY(double bottom READ bottom WRITE setBottom NOTIFY bottomChanged)
93 Q_PROPERTY(double top READ top WRITE setTop NOTIFY topChanged)
94 Q_PROPERTY(int decimals READ decimals WRITE setDecimals NOTIFY decimalsChanged)
95 Q_PROPERTY(Notation notation READ notation WRITE setNotation NOTIFY notationChanged)
96
97public:
98 explicit QDoubleValidator(QObject * parent = nullptr);
99 QDoubleValidator(double bottom, double top, int decimals, QObject *parent = nullptr);
100 ~QDoubleValidator();
101
102 enum Notation {
103 StandardNotation,
104 ScientificNotation
105 };
106 Q_ENUM(Notation)
107 QValidator::State validate(QString &, int &) const override;
108 void fixup(QString &input) const override;
109
110 void setRange(double bottom, double top, int decimals);
111 void setRange(double bottom, double top);
112 void setBottom(double);
113 void setTop(double);
114 void setDecimals(int);
115 void setNotation(Notation);
116
117 double bottom() const { return b; }
118 double top() const { return t; }
119 int decimals() const { return dec; }
120 Notation notation() const;
121
122Q_SIGNALS:
123 void bottomChanged(double bottom);
124 void topChanged(double top);
125 void decimalsChanged(int decimals);
126 void notationChanged(QDoubleValidator::Notation notation);
127
128private:
129 Q_DECLARE_PRIVATE(QDoubleValidator)
130 Q_DISABLE_COPY(QDoubleValidator)
131
132 double b;
133 double t;
134 int dec;
135};
136
137#if QT_CONFIG(regularexpression)
138
139class QRegularExpressionValidatorPrivate;
140
141class Q_GUI_EXPORT QRegularExpressionValidator : public QValidator
142{
143 Q_OBJECT
144 Q_PROPERTY(QRegularExpression regularExpression READ regularExpression WRITE setRegularExpression NOTIFY regularExpressionChanged)
145
146public:
147 explicit QRegularExpressionValidator(QObject *parent = nullptr);
148 explicit QRegularExpressionValidator(const QRegularExpression &re, QObject *parent = nullptr);
149 ~QRegularExpressionValidator();
150
151 QValidator::State validate(QString &input, int &pos) const override;
152
153 QRegularExpression regularExpression() const;
154
155public Q_SLOTS:
156 void setRegularExpression(const QRegularExpression &re);
157
158Q_SIGNALS:
159 void regularExpressionChanged(const QRegularExpression &re);
160
161private:
162 Q_DISABLE_COPY(QRegularExpressionValidator)
163 Q_DECLARE_PRIVATE(QRegularExpressionValidator)
164};
165
166#endif // QT_CONFIG(regularexpression)
167
168#endif // QT_NO_VALIDATOR
169
170QT_END_NAMESPACE
171
172#endif // QVALIDATOR_H
void fixupWithLocale(QString &input, QLocaleData::NumberMode numMode, const QLocale &locale) const
The QDoubleValidator class provides range checking of floating-point numbers.
Definition qvalidator.h:90
The QIntValidator class provides a validator that ensures a string contains a valid integer within a ...
Definition qvalidator.h:57
The QValidator class provides validation of input text.
Definition qvalidator.h:25
#define LLONG_MAX
static qlonglong pow10(int exp)
static std::optional< QValidator::State > initialResultCheck(T min, T max, const QLocaleData::ParsingResult &result)
static int numDigits(qlonglong n)