diff options
-rw-r--r-- | examples/quick/localstorage/localstorage/Header.qml | 10 | ||||
-rw-r--r-- | src/quick/doc/snippets/qml/regularexpression.qml | 56 | ||||
-rw-r--r-- | src/quick/doc/snippets/qml/texthandling.qml | 4 | ||||
-rw-r--r-- | src/quick/items/qquicktextinput.cpp | 7 | ||||
-rw-r--r-- | src/quick/util/qquickutilmodule.cpp | 3 | ||||
-rw-r--r-- | src/quick/util/qquickvalidator.cpp | 46 | ||||
-rw-r--r-- | src/quick/util/qquickvalidator_p.h | 3 |
7 files changed, 119 insertions, 10 deletions
diff --git a/examples/quick/localstorage/localstorage/Header.qml b/examples/quick/localstorage/localstorage/Header.qml index 18f51c1b6e..b3807f6e40 100644 --- a/examples/quick/localstorage/localstorage/Header.qml +++ b/examples/quick/localstorage/localstorage/Header.qml @@ -48,7 +48,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ -import QtQuick 2.7 +import QtQuick 2.14 import QtQuick.Window 2.0 import QtQuick.LocalStorage 2.0 import "Database.js" as JS @@ -143,8 +143,8 @@ Item { font.pixelSize: 22 activeFocusOnPress: true activeFocusOnTab: true - validator: RegExpValidator { - regExp: /[0-9/,:.]+/ + validator: RegularExpressionValidator { + regularExpression: /[0-9/,:.]+/ } onEditingFinished: { if (dateInput.text == "") { @@ -174,8 +174,8 @@ Item { font.pixelSize: 22 activeFocusOnPress: true activeFocusOnTab: true - validator: RegExpValidator { - regExp: /\d{1,3}/ + validator: RegularExpressionValidator { + regularExpression: /\d{1,3}/ } onEditingFinished: { if (distInput.text == "") { diff --git a/src/quick/doc/snippets/qml/regularexpression.qml b/src/quick/doc/snippets/qml/regularexpression.qml new file mode 100644 index 0000000000..f6f4a4171a --- /dev/null +++ b/src/quick/doc/snippets/qml/regularexpression.qml @@ -0,0 +1,56 @@ +/**************************************************************************** +** +** Copyright (C) 2019 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:BSD$ +** 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. +** +** BSD License Usage +** Alternatively, you may use this file under the terms of the BSD license +** as follows: +** +** "Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are +** met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in +** the documentation and/or other materials provided with the +** distribution. +** * Neither the name of The Qt Company Ltd nor the names of its +** contributors may be used to endorse or promote products derived +** from this software without specific prior written permission. +** +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +import QtQuick 2.14 +//![0] +TextInput { + id: hexNumber + validator: RegularExpressionValidator { regularExpression: /[0-9A-F]+/ } +} +//![0] diff --git a/src/quick/doc/snippets/qml/texthandling.qml b/src/quick/doc/snippets/qml/texthandling.qml index 0fb5fc130f..6c086f8501 100644 --- a/src/quick/doc/snippets/qml/texthandling.qml +++ b/src/quick/doc/snippets/qml/texthandling.qml @@ -48,7 +48,7 @@ ** ****************************************************************************/ //! [document] -import QtQuick 2.0 +import QtQuick 2.14 //! [parent begin] @@ -83,7 +83,7 @@ Column { } TextInput { focus: true - validator: RegExpValidator { regExp: /fruit basket/ } + validator: RegularExpressionValidator { regularExpression: /fruit basket/ } } } //! [regexp validator] diff --git a/src/quick/items/qquicktextinput.cpp b/src/quick/items/qquicktextinput.cpp index 5f6fd8f50f..598ebb7a68 100644 --- a/src/quick/items/qquicktextinput.cpp +++ b/src/quick/items/qquicktextinput.cpp @@ -1009,9 +1009,10 @@ void QQuickTextInput::setAutoScroll(bool b) an acceptable or intermediate state. The accepted signal will only be sent if the text is in an acceptable state when enter is pressed. - Currently supported validators are IntValidator, DoubleValidator and - RegExpValidator. An example of using validators is shown below, which allows - input of integers between 11 and 31 into the text input: + Currently supported validators are IntValidator, DoubleValidator, + RegExpValidator and RegularExpressionValidator. An example of using + validators is shown below, which allows input of integers between 11 and 31 + into the text input: \code import QtQuick 2.0 diff --git a/src/quick/util/qquickutilmodule.cpp b/src/quick/util/qquickutilmodule.cpp index 5147ebc6f6..d222a0c0be 100644 --- a/src/quick/util/qquickutilmodule.cpp +++ b/src/quick/util/qquickutilmodule.cpp @@ -103,6 +103,9 @@ void QQuickUtilModule::defineModule() qmlRegisterType<QQuickIntValidator>("QtQuick",2,0,"IntValidator"); qmlRegisterType<QQuickDoubleValidator>("QtQuick",2,0,"DoubleValidator"); qmlRegisterType<QRegExpValidator>("QtQuick",2,0,"RegExpValidator"); +#if QT_CONFIG(regularexpression) + qmlRegisterType<QRegularExpressionValidator>("QtQuick", 2, 14, "RegularExpressionValidator"); +#endif #endif qmlRegisterUncreatableType<QQuickAnimator>("QtQuick", 2, 2, "Animator", QQuickAbstractAnimation::tr("Animator is an abstract class")); diff --git a/src/quick/util/qquickvalidator.cpp b/src/quick/util/qquickvalidator.cpp index b2b773cd94..4709b3dda3 100644 --- a/src/quick/util/qquickvalidator.cpp +++ b/src/quick/util/qquickvalidator.cpp @@ -206,9 +206,13 @@ void QQuickDoubleValidator::resetLocaleName() \inqmlmodule QtQuick \ingroup qtquick-text-utility \brief Provides a string validator. + \deprecated The RegExpValidator type provides a validator, which counts as valid any string which matches a specified regular expression. + + RegExpValidator is deprecated since it is based on the deprecated \l {QRegExp}. Use + \l RegularExpressionValidator instead. */ /*! \qmlproperty regExp QtQuick::RegExpValidator::regExp @@ -239,6 +243,48 @@ void QQuickDoubleValidator::resetLocaleName() \endcode \endlist */ +/*! + \qmltype RegularExpressionValidator + \instantiates QRegularExpressionValidator + \inqmlmodule QtQuick + \ingroup qtquick-text-utility + \brief Provides a string validator. + \since 5.14 + + The RegularExpressionValidator type provides a validator, that counts as valid any string which + matches a specified regular expression. +*/ +/*! + \qmlproperty regularExpression QtQuick::RegularExpressionValidator::regularExpression + + This property holds the regular expression used for validation. + + Note that this property should be a regular expression in JS syntax, e.g /a/ for the regular + expression matching "a". + + By default, this property contains a regular expression with the pattern \c{.*} that matches any + string. + + Below you can find an example of a \l TextInput object with a RegularExpressionValidator + specified: + + \snippet qml/regularexpression.qml 0 + + Some more examples of regular expressions: + + \list + \li A list of numbers with one to three positions separated by a comma: + \badcode + /\d{1,3}(?:,\d{1,3})+$/ + \endcode + + \li An amount consisting of up to 3 numbers before the decimal point, and + 1 to 2 after the decimal point: + \badcode + /(\d{1,3})([.,]\d{1,2})?$/ + \endcode + \endlist +*/ #endif // validator diff --git a/src/quick/util/qquickvalidator_p.h b/src/quick/util/qquickvalidator_p.h index 812e552d8e..9212efa044 100644 --- a/src/quick/util/qquickvalidator_p.h +++ b/src/quick/util/qquickvalidator_p.h @@ -95,6 +95,9 @@ QML_DECLARE_TYPE(QValidator) QML_DECLARE_TYPE(QQuickIntValidator) QML_DECLARE_TYPE(QQuickDoubleValidator) QML_DECLARE_TYPE(QRegExpValidator) +#if QT_CONFIG(regularexpression) +QML_DECLARE_TYPE(QRegularExpressionValidator) +#endif #endif #endif // QQUICKVALIDATOR_P_H |