| 1 | /**************************************************************************** |
| 2 | ** |
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. |
| 4 | ** Copyright (C) 2012 Klarälvdalens Datakonsult AB, a KDAB Group company, [email protected], author Giuseppe D'Angelo <[email protected]> |
| 5 | ** Contact: https://www.qt.io/licensing/ |
| 6 | ** |
| 7 | ** This file is part of the QtGui module of the Qt Toolkit. |
| 8 | ** |
| 9 | ** $QT_BEGIN_LICENSE:LGPL$ |
| 10 | ** Commercial License Usage |
| 11 | ** Licensees holding valid commercial Qt licenses may use this file in |
| 12 | ** accordance with the commercial license agreement provided with the |
| 13 | ** Software or, alternatively, in accordance with the terms contained in |
| 14 | ** a written agreement between you and The Qt Company. For licensing terms |
| 15 | ** and conditions see https://www.qt.io/terms-conditions. For further |
| 16 | ** information use the contact form at https://www.qt.io/contact-us. |
| 17 | ** |
| 18 | ** GNU Lesser General Public License Usage |
| 19 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
| 20 | ** General Public License version 3 as published by the Free Software |
| 21 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
| 22 | ** packaging of this file. Please review the following information to |
| 23 | ** ensure the GNU Lesser General Public License version 3 requirements |
| 24 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
| 25 | ** |
| 26 | ** GNU General Public License Usage |
| 27 | ** Alternatively, this file may be used under the terms of the GNU |
| 28 | ** General Public License version 2.0 or (at your option) the GNU General |
| 29 | ** Public license version 3 or any later version approved by the KDE Free |
| 30 | ** Qt Foundation. The licenses are as published by the Free Software |
| 31 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
| 32 | ** included in the packaging of this file. Please review the following |
| 33 | ** information to ensure the GNU General Public License requirements will |
| 34 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
| 35 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
| 36 | ** |
| 37 | ** $QT_END_LICENSE$ |
| 38 | ** |
| 39 | ****************************************************************************/ |
| 40 | |
| 41 | #ifndef QVALIDATOR_H |
| 42 | #define QVALIDATOR_H |
| 43 | |
| 44 | #include <QtGui/qtguiglobal.h> |
| 45 | #include <QtCore/qobject.h> |
| 46 | #include <QtCore/qstring.h> |
| 47 | #include <QtCore/qregexp.h> |
| 48 | #if QT_CONFIG(regularexpression) |
| 49 | # include <QtCore/qregularexpression.h> |
| 50 | #endif |
| 51 | #include <QtCore/qlocale.h> |
| 52 | |
| 53 | QT_BEGIN_NAMESPACE |
| 54 | |
| 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 = nullptr); |
| 65 | ~QValidator(); |
| 66 | |
| 67 | enum State { |
| 68 | Invalid, |
| 69 | Intermediate, |
| 70 | Acceptable |
| 71 | }; |
| 72 | Q_ENUM(State) |
| 73 | |
| 74 | void setLocale(const QLocale &locale); |
| 75 | QLocale locale() const; |
| 76 | |
| 77 | virtual State validate(QString &, int &) const = 0; |
| 78 | virtual void fixup(QString &) const; |
| 79 | |
| 80 | Q_SIGNALS: |
| 81 | void changed(); |
| 82 | |
| 83 | protected: |
| 84 | QValidator(QObjectPrivate &d, QObject *parent); |
| 85 | QValidator(QValidatorPrivate &d, QObject *parent); |
| 86 | |
| 87 | private: |
| 88 | Q_DISABLE_COPY(QValidator) |
| 89 | Q_DECLARE_PRIVATE(QValidator) |
| 90 | }; |
| 91 | |
| 92 | class Q_GUI_EXPORT QIntValidator : public QValidator |
| 93 | { |
| 94 | Q_OBJECT |
| 95 | Q_PROPERTY(int bottom READ bottom WRITE setBottom NOTIFY bottomChanged) |
| 96 | Q_PROPERTY(int top READ top WRITE setTop NOTIFY topChanged) |
| 97 | |
| 98 | public: |
| 99 | explicit QIntValidator(QObject * parent = nullptr); |
| 100 | QIntValidator(int bottom, int top, QObject *parent = nullptr); |
| 101 | ~QIntValidator(); |
| 102 | |
| 103 | QValidator::State validate(QString &, int &) const override; |
| 104 | void fixup(QString &input) const override; |
| 105 | |
| 106 | void setBottom(int); |
| 107 | void setTop(int); |
| 108 | virtual void setRange(int bottom, int top); |
| 109 | |
| 110 | int bottom() const { return b; } |
| 111 | int top() const { return t; } |
| 112 | Q_SIGNALS: |
| 113 | void bottomChanged(int bottom); |
| 114 | void topChanged(int top); |
| 115 | |
| 116 | private: |
| 117 | Q_DISABLE_COPY(QIntValidator) |
| 118 | |
| 119 | int b; |
| 120 | int t; |
| 121 | }; |
| 122 | |
| 123 | #ifndef QT_NO_REGEXP |
| 124 | |
| 125 | class QDoubleValidatorPrivate; |
| 126 | |
| 127 | class Q_GUI_EXPORT QDoubleValidator : public QValidator |
| 128 | { |
| 129 | Q_OBJECT |
| 130 | Q_PROPERTY(double bottom READ bottom WRITE setBottom NOTIFY bottomChanged) |
| 131 | Q_PROPERTY(double top READ top WRITE setTop NOTIFY topChanged) |
| 132 | Q_PROPERTY(int decimals READ decimals WRITE setDecimals NOTIFY decimalsChanged) |
| 133 | Q_PROPERTY(Notation notation READ notation WRITE setNotation NOTIFY notationChanged) |
| 134 | |
| 135 | public: |
| 136 | explicit QDoubleValidator(QObject * parent = nullptr); |
| 137 | QDoubleValidator(double bottom, double top, int decimals, QObject *parent = nullptr); |
| 138 | ~QDoubleValidator(); |
| 139 | |
| 140 | enum Notation { |
| 141 | StandardNotation, |
| 142 | ScientificNotation |
| 143 | }; |
| 144 | Q_ENUM(Notation) |
| 145 | QValidator::State validate(QString &, int &) const override; |
| 146 | |
| 147 | virtual void setRange(double bottom, double top, int decimals = 0); |
| 148 | void setBottom(double); |
| 149 | void setTop(double); |
| 150 | void setDecimals(int); |
| 151 | void setNotation(Notation); |
| 152 | |
| 153 | double bottom() const { return b; } |
| 154 | double top() const { return t; } |
| 155 | int decimals() const { return dec; } |
| 156 | Notation notation() const; |
| 157 | |
| 158 | Q_SIGNALS: |
| 159 | void bottomChanged(double bottom); |
| 160 | void topChanged(double top); |
| 161 | void decimalsChanged(int decimals); |
| 162 | void notationChanged(QDoubleValidator::Notation notation); |
| 163 | |
| 164 | private: |
| 165 | Q_DECLARE_PRIVATE(QDoubleValidator) |
| 166 | Q_DISABLE_COPY(QDoubleValidator) |
| 167 | |
| 168 | double b; |
| 169 | double t; |
| 170 | int dec; |
| 171 | }; |
| 172 | |
| 173 | |
| 174 | class Q_GUI_EXPORT QRegExpValidator : public QValidator |
| 175 | { |
| 176 | Q_OBJECT |
| 177 | Q_PROPERTY(QRegExp regExp READ regExp WRITE setRegExp NOTIFY regExpChanged) |
| 178 | |
| 179 | public: |
| 180 | explicit QRegExpValidator(QObject *parent = nullptr); |
| 181 | explicit QRegExpValidator(const QRegExp& rx, QObject *parent = nullptr); |
| 182 | ~QRegExpValidator(); |
| 183 | |
| 184 | virtual QValidator::State validate(QString& input, int& pos) const override; |
| 185 | |
| 186 | void setRegExp(const QRegExp& rx); |
| 187 | const QRegExp& regExp() const { return r; } |
| 188 | |
| 189 | Q_SIGNALS: |
| 190 | void regExpChanged(const QRegExp& regExp); |
| 191 | |
| 192 | private: |
| 193 | Q_DISABLE_COPY(QRegExpValidator) |
| 194 | |
| 195 | QRegExp r; |
| 196 | }; |
| 197 | |
| 198 | #endif // QT_NO_REGEXP |
| 199 | |
| 200 | #if QT_CONFIG(regularexpression) |
| 201 | |
| 202 | class QRegularExpressionValidatorPrivate; |
| 203 | |
| 204 | class Q_GUI_EXPORT QRegularExpressionValidator : public QValidator |
| 205 | { |
| 206 | Q_OBJECT |
| 207 | Q_PROPERTY(QRegularExpression regularExpression READ regularExpression WRITE setRegularExpression NOTIFY regularExpressionChanged) |
| 208 | |
| 209 | public: |
| 210 | explicit QRegularExpressionValidator(QObject *parent = nullptr); |
| 211 | explicit QRegularExpressionValidator(const QRegularExpression &re, QObject *parent = nullptr); |
| 212 | ~QRegularExpressionValidator(); |
| 213 | |
| 214 | virtual QValidator::State validate(QString &input, int &pos) const override; |
| 215 | |
| 216 | QRegularExpression regularExpression() const; |
| 217 | |
| 218 | public Q_SLOTS: |
| 219 | void setRegularExpression(const QRegularExpression &re); |
| 220 | |
| 221 | Q_SIGNALS: |
| 222 | void regularExpressionChanged(const QRegularExpression &re); |
| 223 | |
| 224 | private: |
| 225 | Q_DISABLE_COPY(QRegularExpressionValidator) |
| 226 | Q_DECLARE_PRIVATE(QRegularExpressionValidator) |
| 227 | }; |
| 228 | |
| 229 | #endif // QT_CONFIG(regularexpression) |
| 230 | |
| 231 | #endif // QT_NO_VALIDATOR |
| 232 | |
| 233 | QT_END_NAMESPACE |
| 234 | |
| 235 | #endif // QVALIDATOR_H |
| 236 | |