Remove QRegExpValidator

As QRegExp will be moved to a compat library in Qt 6.

Change-Id: I181aec45bd798f49d2c50a0e7fb64782e004b854
Reviewed-by: Samuel Gaist <samuel.gaist@idiap.ch>
This commit is contained in:
Lars Knoll 2020-03-15 18:12:39 +01:00
parent befd198c15
commit dee55af0a5
11 changed files with 7 additions and 319 deletions

View File

@ -686,7 +686,7 @@ QT_BEGIN_NAMESPACE
the position in the string where the match was made (or -1 if
there was no match).
\sa QString, QStringList, QRegExpValidator, QSortFilterProxyModel,
\sa QString, QStringList, QSortFilterProxyModel,
{tools/regexp}{Regular Expression Example}
*/

View File

@ -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}");

View File

@ -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 &regExp)
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

View File

@ -44,7 +44,6 @@
#include <QtGui/qtguiglobal.h>
#include <QtCore/qobject.h>
#include <QtCore/qstring.h>
#include <QtCore/qregexp.h>
#if QT_CONFIG(regularexpression)
# include <QtCore/qregularexpression.h>
#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;

View File

@ -941,7 +941,7 @@ QT_CLASS_LIB(QToolButton, QtWidgets, qtoolbutton.h)
QT_CLASS_LIB(QValidator, QtGui, qvalidator.h)
QT_CLASS_LIB(QIntValidator, QtGui, qvalidator.h)
QT_CLASS_LIB(QDoubleValidator, QtGui, qvalidator.h)
QT_CLASS_LIB(QRegExpValidator, QtGui, qvalidator.h)
QT_CLASS_LIB(QRegularExpressionValidator, QtGui, qvalidator.h)
QT_CLASS_LIB(QScriptEngineDebugger, QtScriptTools, qscriptenginedebugger.h)
QT_CLASS_LIB(QDesignerComponents, QtDesigner, qdesigner_components.h)
QT_CLASS_LIB(QExtensionFactory, QtDesigner, default_extensionfactory.h)

View File

@ -3,7 +3,6 @@
add_subdirectory(qdesktopservices)
add_subdirectory(qdoublevalidator)
add_subdirectory(qintvalidator)
add_subdirectory(qregexpvalidator)
add_subdirectory(qregularexpressionvalidator)
add_subdirectory(qshadergenerator)
add_subdirectory(qshadergraph)

View File

@ -1 +0,0 @@
tst_qregexpvalidator

View File

@ -1,12 +0,0 @@
# Generated from qregexpvalidator.pro.
#####################################################################
## tst_qregexpvalidator Test:
#####################################################################
add_qt_test(tst_qregexpvalidator
SOURCES
tst_qregexpvalidator.cpp
PUBLIC_LIBRARIES
Qt::Gui
)

View File

@ -1,4 +0,0 @@
CONFIG += testcase
TARGET = tst_qregexpvalidator
SOURCES += tst_qregexpvalidator.cpp
QT += testlib

View File

@ -1,93 +0,0 @@
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3 as published by the Free Software
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include <QtTest/QtTest>
#include <qregexp.h>
#include <qvalidator.h>
class tst_QRegExpValidator : public QObject
{
Q_OBJECT
private slots:
void validate_data();
void validate();
};
void tst_QRegExpValidator::validate_data()
{
QTest::addColumn<QString>("rx");
QTest::addColumn<QString>("value");
QTest::addColumn<int>("state");
QTest::newRow( "data0" ) << QString("[1-9]\\d{0,3}") << QString("0") << 0;
QTest::newRow( "data1" ) << QString("[1-9]\\d{0,3}") << QString("12345") << 0;
QTest::newRow( "data2" ) << QString("[1-9]\\d{0,3}") << QString("1") << 2;
QTest::newRow( "data3" ) << QString("\\S+") << QString("myfile.txt") << 2;
QTest::newRow( "data4" ) << QString("\\S+") << QString("my file.txt") << 0;
QTest::newRow( "data5" ) << QString("[A-C]\\d{5}[W-Z]") << QString("a12345Z") << 0;
QTest::newRow( "data6" ) << QString("[A-C]\\d{5}[W-Z]") << QString("A12345Z") << 2;
QTest::newRow( "data7" ) << QString("[A-C]\\d{5}[W-Z]") << QString("B12") << 1;
QTest::newRow( "data8" ) << QString("read\\S?me(\\.(txt|asc|1st))?") << QString("readme") << 2;
QTest::newRow( "data9" ) << QString("read\\S?me(\\.(txt|asc|1st))?") << QString("read me.txt") << 0;
QTest::newRow( "data10" ) << QString("read\\S?me(\\.(txt|asc|1st))?") << QString("readm") << 1;
}
void tst_QRegExpValidator::validate()
{
QFETCH( QString, rx );
QFETCH( QString, value );
QFETCH( int, state );
QRegExpValidator rv( 0 );
QSignalSpy spy(&rv, SIGNAL(regExpChanged(QRegExp)));
QSignalSpy changedSpy(&rv, SIGNAL(changed()));
rv.setRegExp( QRegExp( rx ) );
int pos = -1;
QCOMPARE( (int)rv.validate( value, pos ), state );
if (state == QValidator::Invalid)
QCOMPARE(pos, value.length());
else
QCOMPARE(pos, -1); // untouched on Acceptable or Intermediate
QCOMPARE(spy.count(), 1);
QCOMPARE(changedSpy.count(), 1);
}
QTEST_APPLESS_MAIN(tst_QRegExpValidator)
#include "tst_qregexpvalidator.moc"

View File

@ -3,7 +3,6 @@ SUBDIRS= \
qdesktopservices \
qdoublevalidator \
qintvalidator \
qregexpvalidator \
qregularexpressionvalidator \
qshadergenerator \
qshadergraph \