From dee55af0a5359bb3b57a89cf3065ffca9d8506da Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Sun, 15 Mar 2020 18:12:39 +0100 Subject: Remove QRegExpValidator As QRegExp will be moved to a compat library in Qt 6. Change-Id: I181aec45bd798f49d2c50a0e7fb64782e004b854 Reviewed-by: Samuel Gaist --- .../doc/snippets/code/src_gui_util_qvalidator.cpp | 45 ------- src/gui/util/qvalidator.cpp | 135 +-------------------- src/gui/util/qvalidator.h | 30 ----- 3 files changed, 5 insertions(+), 205 deletions(-) (limited to 'src/gui') diff --git a/src/gui/doc/snippets/code/src_gui_util_qvalidator.cpp b/src/gui/doc/snippets/code/src_gui_util_qvalidator.cpp index cc73ad9a19..1297ad8afe 100644 --- a/src/gui/doc/snippets/code/src_gui_util_qvalidator.cpp +++ b/src/gui/doc/snippets/code/src_gui_util_qvalidator.cpp @@ -99,51 +99,6 @@ s = "50"; v.validate(s, pos); // returns Acceptable //! [2] - -//! [3] -// regexp: optional '-' followed by between 1 and 3 digits -QRegExp rx("-?\\d{1,3}"); -QValidator *validator = new QRegExpValidator(rx, this); - -QLineEdit *edit = new QLineEdit(this); -edit->setValidator(validator); -//! [3] - - -//! [4] -// integers 1 to 9999 -QRegExp rx("[1-9]\\d{0,3}"); -// the validator treats the regexp as "^[1-9]\\d{0,3}$" -QRegExpValidator v(rx, 0); -QString s; -int pos = 0; - -s = "0"; v.validate(s, pos); // returns Invalid -s = "12345"; v.validate(s, pos); // returns Invalid -s = "1"; v.validate(s, pos); // returns Acceptable - -rx.setPattern("\\S+"); // one or more non-whitespace characters -v.setRegExp(rx); -s = "myfile.txt"; v.validate(s, pos); // Returns Acceptable -s = "my file.txt"; v.validate(s, pos); // Returns Invalid - -// A, B or C followed by exactly five digits followed by W, X, Y or Z -rx.setPattern("[A-C]\\d{5}[W-Z]"); -v.setRegExp(rx); -s = "a12345Z"; v.validate(s, pos); // Returns Invalid -s = "A12345Z"; v.validate(s, pos); // Returns Acceptable -s = "B12"; v.validate(s, pos); // Returns Intermediate - -// match most 'readme' files -rx.setPattern("read\\S?me(\.(txt|asc|1st))?"); -rx.setCaseSensitive(false); -v.setRegExp(rx); -s = "readme"; v.validate(s, pos); // Returns Acceptable -s = "README.1ST"; v.validate(s, pos); // Returns Acceptable -s = "read me.txt"; v.validate(s, pos); // Returns Invalid -s = "readm"; v.validate(s, pos); // Returns Intermediate -//! [4] - //! [5] // regexp: optional '-' followed by between 1 and 3 digits QRegularExpression rx("-?\\d{1,3}"); diff --git a/src/gui/util/qvalidator.cpp b/src/gui/util/qvalidator.cpp index 54cbb28ffa..b01b09c0f9 100644 --- a/src/gui/util/qvalidator.cpp +++ b/src/gui/util/qvalidator.cpp @@ -58,7 +58,7 @@ QT_BEGIN_NAMESPACE The class itself is abstract. Two subclasses, \l QIntValidator and \l QDoubleValidator, provide basic numeric-range checking, and \l - QRegExpValidator provides general checking using a custom regular + QRegularExpressionValidator provides general checking using a custom regular expression. If the built-in validators aren't sufficient, you can subclass @@ -114,7 +114,7 @@ QT_BEGIN_NAMESPACE QValidator is typically used with QLineEdit, QSpinBox and QComboBox. - \sa QIntValidator, QDoubleValidator, QRegExpValidator, {Line Edits Example} + \sa QIntValidator, QDoubleValidator, QRegularExpressionValidator, {Line Edits Example} */ @@ -192,13 +192,6 @@ QT_BEGIN_NAMESPACE \internal */ -/*! - \fn void QRegExpValidator::regExpChanged(const QRegExp ®Exp) - - This signal is emitted after the regExp property changed. - \internal -*/ - class QValidatorPrivate : public QObjectPrivate{ Q_DECLARE_PUBLIC(QValidator) public: @@ -328,7 +321,7 @@ void QValidator::fixup(QString &) const is not set by default, the validator will accept group separators. It is thus recommended to use QLocale::toInt() to obtain the numeric value. - \sa QDoubleValidator, QRegExpValidator, QLocale::toInt(), {Line Edits Example} + \sa QDoubleValidator, QRegularExpressionValidator, QLocale::toInt(), {Line Edits Example} */ /*! @@ -534,8 +527,6 @@ QValidator::QValidator(QValidatorPrivate &d, QObject *parent) { } -#ifndef QT_NO_REGEXP - class QDoubleValidatorPrivate : public QValidatorPrivate { Q_DECLARE_PUBLIC(QDoubleValidator) @@ -577,7 +568,7 @@ public: is not set by default, the validator will accept group separators. It is thus recommended to use QLocale::toDouble() to obtain the numeric value. - \sa QIntValidator, QRegExpValidator, QLocale::toDouble(), {Line Edits Example} + \sa QIntValidator, QRegularExpressionValidator, QLocale::toDouble(), {Line Edits Example} */ /*! @@ -818,122 +809,6 @@ QDoubleValidator::Notation QDoubleValidator::notation() const return d->notation; } -/*! - \class QRegExpValidator - \brief The QRegExpValidator class is used to check a string - against a regular expression. - \inmodule QtGui - - QRegExpValidator uses a regular expression (regexp) to - determine whether an input string is \l Acceptable, \l - Intermediate, or \l Invalid. The regexp can either be supplied - when the QRegExpValidator is constructed, or at a later time. - - When QRegExpValidator determines whether a string is \l Acceptable - or not, the regexp is treated as if it begins with the start of string - assertion (\b{^}) and ends with the end of string assertion - (\b{$}); the match is against the entire input string, or from - the given position if a start position greater than zero is given. - - If a string is a prefix of an \l Acceptable string, it is considered - \l Intermediate. For example, "" and "A" are \l Intermediate for the - regexp \b{[A-Z][0-9]} (whereas "_" would be \l Invalid). - - For a brief introduction to Qt's regexp engine, see \l QRegExp. - - Example of use: - \snippet code/src_gui_util_qvalidator.cpp 3 - - Below we present some examples of validators. In practice they would - normally be associated with a widget as in the example above. - - \snippet code/src_gui_util_qvalidator.cpp 4 - - \sa QRegExp, QIntValidator, QDoubleValidator, {Settings Editor Example} -*/ - -/*! - Constructs a validator with a \a parent object that accepts - any string (including an empty one) as valid. -*/ - -QRegExpValidator::QRegExpValidator(QObject *parent) - : QRegExpValidator(QRegExp(QString::fromLatin1(".*")), parent) -{ -} - -/*! - Constructs a validator with a \a parent object that - accepts all strings that match the regular expression \a rx. - - The match is made against the entire string; e.g. if the regexp is - \b{[A-Fa-f0-9]+} it will be treated as \b{^[A-Fa-f0-9]+$}. -*/ - -QRegExpValidator::QRegExpValidator(const QRegExp& rx, QObject *parent) - : QValidator(parent), r(rx) -{ -} - - -/*! - Destroys the validator. -*/ - -QRegExpValidator::~QRegExpValidator() -{ -} - -/*! - Returns \l Acceptable if \a input is matched by the regular - expression for this validator, \l Intermediate if it has matched - partially (i.e. could be a valid match if additional valid - characters are added), and \l Invalid if \a input is not matched. - - Additionally, if \a input is not matched, the \a pos parameter is set to - the length of the \a input parameter. - - For example, if the regular expression is \b{\\w\\d\\d} - (word-character, digit, digit) then "A57" is \l Acceptable, - "E5" is \l Intermediate, and "+9" is \l Invalid. - - \sa QRegExp::exactMatch() -*/ - -QValidator::State QRegExpValidator::validate(QString &input, int& pos) const -{ - QRegExp copy = r; - if (copy.exactMatch(input)) { - return Acceptable; - } else { - if (copy.matchedLength() == input.size()) { - return Intermediate; - } else { - pos = input.size(); - return Invalid; - } - } -} - -/*! - \property QRegExpValidator::regExp - \brief the regular expression used for validation - - By default, this property contains a regular expression with the pattern \c{.*} - that matches any string. -*/ - -void QRegExpValidator::setRegExp(const QRegExp& rx) -{ - if (r != rx) { - r = rx; - emit regExpChanged(r); - emit changed(); - } -} - -#endif - #if QT_CONFIG(regularexpression) /*! @@ -964,7 +839,7 @@ void QRegExpValidator::setRegExp(const QRegExp& rx) \snippet code/src_gui_util_qvalidator.cpp 6 - \sa QRegularExpression, QIntValidator, QDoubleValidator, QRegExpValidator + \sa QRegularExpression, QIntValidator, QDoubleValidator */ class QRegularExpressionValidatorPrivate : public QValidatorPrivate diff --git a/src/gui/util/qvalidator.h b/src/gui/util/qvalidator.h index f0e72e3814..38e2e6c130 100644 --- a/src/gui/util/qvalidator.h +++ b/src/gui/util/qvalidator.h @@ -44,7 +44,6 @@ #include #include #include -#include #if QT_CONFIG(regularexpression) # include #endif @@ -120,8 +119,6 @@ private: int t; }; -#ifndef QT_NO_REGEXP - class QDoubleValidatorPrivate; class Q_GUI_EXPORT QDoubleValidator : public QValidator @@ -170,33 +167,6 @@ private: int dec; }; - -class Q_GUI_EXPORT QRegExpValidator : public QValidator -{ - Q_OBJECT - Q_PROPERTY(QRegExp regExp READ regExp WRITE setRegExp NOTIFY regExpChanged) - -public: - explicit QRegExpValidator(QObject *parent = nullptr); - explicit QRegExpValidator(const QRegExp& rx, QObject *parent = nullptr); - ~QRegExpValidator(); - - virtual QValidator::State validate(QString& input, int& pos) const override; - - void setRegExp(const QRegExp& rx); - const QRegExp& regExp() const { return r; } - -Q_SIGNALS: - void regExpChanged(const QRegExp& regExp); - -private: - Q_DISABLE_COPY(QRegExpValidator) - - QRegExp r; -}; - -#endif // QT_NO_REGEXP - #if QT_CONFIG(regularexpression) class QRegularExpressionValidatorPrivate; -- cgit v1.2.3