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