File indexing completed on 2026-05-05 08:48:18
0001
0002
0003
0004
0005
0006 #ifndef QVALIDATOR_H
0007 #define QVALIDATOR_H
0008
0009 #include <QtGui/qtguiglobal.h>
0010 #include <QtCore/qobject.h>
0011 #include <QtCore/qstring.h>
0012 #if QT_CONFIG(regularexpression)
0013 # include <QtCore/qregularexpression.h>
0014 #endif
0015 #include <QtCore/qlocale.h>
0016
0017 QT_BEGIN_NAMESPACE
0018
0019
0020 #ifndef QT_NO_VALIDATOR
0021
0022 class QValidatorPrivate;
0023
0024 class Q_GUI_EXPORT QValidator : public QObject
0025 {
0026 Q_OBJECT
0027 public:
0028 explicit QValidator(QObject * parent = nullptr);
0029 ~QValidator();
0030
0031 enum State {
0032 Invalid,
0033 Intermediate,
0034 Acceptable
0035 };
0036 Q_ENUM(State)
0037
0038 void setLocale(const QLocale &locale);
0039 QLocale locale() const;
0040
0041 virtual State validate(QString &, int &) const = 0;
0042 virtual void fixup(QString &) const;
0043
0044 Q_SIGNALS:
0045 void changed();
0046
0047 protected:
0048 QValidator(QObjectPrivate &d, QObject *parent);
0049 QValidator(QValidatorPrivate &d, QObject *parent);
0050
0051 private:
0052 Q_DISABLE_COPY(QValidator)
0053 Q_DECLARE_PRIVATE(QValidator)
0054 };
0055
0056 class Q_GUI_EXPORT QIntValidator : public QValidator
0057 {
0058 Q_OBJECT
0059 Q_PROPERTY(int bottom READ bottom WRITE setBottom NOTIFY bottomChanged)
0060 Q_PROPERTY(int top READ top WRITE setTop NOTIFY topChanged)
0061
0062 public:
0063 explicit QIntValidator(QObject * parent = nullptr);
0064 QIntValidator(int bottom, int top, QObject *parent = nullptr);
0065 ~QIntValidator();
0066
0067 QValidator::State validate(QString &, int &) const override;
0068 void fixup(QString &input) const override;
0069
0070 void setBottom(int);
0071 void setTop(int);
0072 void setRange(int bottom, int top);
0073
0074 int bottom() const { return b; }
0075 int top() const { return t; }
0076 Q_SIGNALS:
0077 void bottomChanged(int bottom);
0078 void topChanged(int top);
0079
0080 private:
0081 Q_DISABLE_COPY(QIntValidator)
0082
0083 int b;
0084 int t;
0085 };
0086
0087 class QDoubleValidatorPrivate;
0088
0089 class Q_GUI_EXPORT QDoubleValidator : public QValidator
0090 {
0091 Q_OBJECT
0092 Q_PROPERTY(double bottom READ bottom WRITE setBottom NOTIFY bottomChanged)
0093 Q_PROPERTY(double top READ top WRITE setTop NOTIFY topChanged)
0094 Q_PROPERTY(int decimals READ decimals WRITE setDecimals NOTIFY decimalsChanged)
0095 Q_PROPERTY(Notation notation READ notation WRITE setNotation NOTIFY notationChanged)
0096
0097 public:
0098 explicit QDoubleValidator(QObject * parent = nullptr);
0099 QDoubleValidator(double bottom, double top, int decimals, QObject *parent = nullptr);
0100 ~QDoubleValidator();
0101
0102 enum Notation {
0103 StandardNotation,
0104 ScientificNotation
0105 };
0106 Q_ENUM(Notation)
0107 QValidator::State validate(QString &, int &) const override;
0108 void fixup(QString &input) const override;
0109
0110 void setRange(double bottom, double top, int decimals);
0111 void setRange(double bottom, double top);
0112 void setBottom(double);
0113 void setTop(double);
0114 void setDecimals(int);
0115 void setNotation(Notation);
0116
0117 double bottom() const { return b; }
0118 double top() const { return t; }
0119 int decimals() const { return dec; }
0120 Notation notation() const;
0121
0122 Q_SIGNALS:
0123 void bottomChanged(double bottom);
0124 void topChanged(double top);
0125 void decimalsChanged(int decimals);
0126 void notationChanged(QDoubleValidator::Notation notation);
0127
0128 private:
0129 Q_DECLARE_PRIVATE(QDoubleValidator)
0130 Q_DISABLE_COPY(QDoubleValidator)
0131
0132 double b;
0133 double t;
0134 int dec;
0135 };
0136
0137 #if QT_CONFIG(regularexpression)
0138
0139 class QRegularExpressionValidatorPrivate;
0140
0141 class Q_GUI_EXPORT QRegularExpressionValidator : public QValidator
0142 {
0143 Q_OBJECT
0144 Q_PROPERTY(QRegularExpression regularExpression READ regularExpression WRITE setRegularExpression NOTIFY regularExpressionChanged)
0145
0146 public:
0147 explicit QRegularExpressionValidator(QObject *parent = nullptr);
0148 explicit QRegularExpressionValidator(const QRegularExpression &re, QObject *parent = nullptr);
0149 ~QRegularExpressionValidator();
0150
0151 QValidator::State validate(QString &input, int &pos) const override;
0152
0153 QRegularExpression regularExpression() const;
0154
0155 public Q_SLOTS:
0156 void setRegularExpression(const QRegularExpression &re);
0157
0158 Q_SIGNALS:
0159 void regularExpressionChanged(const QRegularExpression &re);
0160
0161 private:
0162 Q_DISABLE_COPY(QRegularExpressionValidator)
0163 Q_DECLARE_PRIVATE(QRegularExpressionValidator)
0164 };
0165
0166 #endif
0167
0168 #endif
0169
0170 QT_END_NAMESPACE
0171
0172 #endif