| Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/qtdeclarative/src/qtdeclarative/src/quick/util/qquickvalidator.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||
| 2 | ** | - | ||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||
| 5 | ** | - | ||||||
| 6 | ** This file is part of the QtQuick module of the Qt Toolkit. | - | ||||||
| 7 | ** | - | ||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||
| 9 | ** Commercial License Usage | - | ||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||
| 14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||
| 15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||
| 16 | ** | - | ||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||
| 19 | ** General Public License version 3 as published by the Free Software | - | ||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||
| 24 | ** | - | ||||||
| 25 | ** GNU General Public License Usage | - | ||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||
| 35 | ** | - | ||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||
| 37 | ** | - | ||||||
| 38 | ****************************************************************************/ | - | ||||||
| 39 | - | |||||||
| 40 | #include "qquickvalidator_p.h" | - | ||||||
| 41 | - | |||||||
| 42 | QT_BEGIN_NAMESPACE | - | ||||||
| 43 | - | |||||||
| 44 | #if QT_CONFIG(validator) | - | ||||||
| 45 | - | |||||||
| 46 | /*! | - | ||||||
| 47 | \qmltype IntValidator | - | ||||||
| 48 | \instantiates QIntValidator | - | ||||||
| 49 | \inqmlmodule QtQuick | - | ||||||
| 50 | \ingroup qtquick-text-utility | - | ||||||
| 51 | \brief Defines a validator for integer values. | - | ||||||
| 52 | - | |||||||
| 53 | The IntValidator type provides a validator for integer values. | - | ||||||
| 54 | - | |||||||
| 55 | If no \l locale is set IntValidator uses the \l {QLocale::setDefault()}{default locale} to | - | ||||||
| 56 | interpret the number and will accept locale specific digits, group separators, and positive | - | ||||||
| 57 | and negative signs. In addition, IntValidator is always guaranteed to accept a number | - | ||||||
| 58 | formatted according to the "C" locale. | - | ||||||
| 59 | */ | - | ||||||
| 60 | - | |||||||
| 61 | QQuickIntValidator::QQuickIntValidator(QObject *parent) | - | ||||||
| 62 | : QIntValidator(parent) | - | ||||||
| 63 | { | - | ||||||
| 64 | } executed 8 times by 2 tests: end of blockExecuted by:
| 8 | ||||||
| 65 | - | |||||||
| 66 | /*! | - | ||||||
| 67 | \qmlproperty string QtQuick::IntValidator::locale | - | ||||||
| 68 | - | |||||||
| 69 | This property holds the name of the locale used to interpret the number. | - | ||||||
| 70 | - | |||||||
| 71 | \sa {QtQml::Qt::locale()}{Qt.locale()} | - | ||||||
| 72 | */ | - | ||||||
| 73 | - | |||||||
| 74 | QString QQuickIntValidator::localeName() const | - | ||||||
| 75 | { | - | ||||||
| 76 | return locale().name(); executed 6 times by 1 test: return locale().name();Executed by:
| 6 | ||||||
| 77 | } | - | ||||||
| 78 | - | |||||||
| 79 | void QQuickIntValidator::setLocaleName(const QString &name) | - | ||||||
| 80 | { | - | ||||||
| 81 | if (locale().name() != name) {
| 0-4 | ||||||
| 82 | setLocale(QLocale(name)); | - | ||||||
| 83 | emit localeNameChanged(); | - | ||||||
| 84 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||
| 85 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||
| 86 | - | |||||||
| 87 | void QQuickIntValidator::resetLocaleName() | - | ||||||
| 88 | { | - | ||||||
| 89 | QLocale defaultLocale; | - | ||||||
| 90 | if (locale() != defaultLocale) {
| 0-4 | ||||||
| 91 | setLocale(defaultLocale); | - | ||||||
| 92 | emit localeNameChanged(); | - | ||||||
| 93 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||
| 94 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||
| 95 | - | |||||||
| 96 | /*! | - | ||||||
| 97 | \qmlproperty int QtQuick::IntValidator::top | - | ||||||
| 98 | - | |||||||
| 99 | This property holds the validator's highest acceptable value. | - | ||||||
| 100 | By default, this property's value is derived from the highest signed integer available (typically 2147483647). | - | ||||||
| 101 | */ | - | ||||||
| 102 | /*! | - | ||||||
| 103 | \qmlproperty int QtQuick::IntValidator::bottom | - | ||||||
| 104 | - | |||||||
| 105 | This property holds the validator's lowest acceptable value. | - | ||||||
| 106 | By default, this property's value is derived from the lowest signed integer available (typically -2147483647). | - | ||||||
| 107 | */ | - | ||||||
| 108 | - | |||||||
| 109 | /*! | - | ||||||
| 110 | \qmltype DoubleValidator | - | ||||||
| 111 | \instantiates QDoubleValidator | - | ||||||
| 112 | \inqmlmodule QtQuick | - | ||||||
| 113 | \ingroup qtquick-text-utility | - | ||||||
| 114 | \brief Defines a validator for non-integer numbers. | - | ||||||
| 115 | - | |||||||
| 116 | The DoubleValidator type provides a validator for non-integer numbers. | - | ||||||
| 117 | - | |||||||
| 118 | Input is accepted if it contains a double that is within the valid range | - | ||||||
| 119 | and is in the correct format. | - | ||||||
| 120 | - | |||||||
| 121 | Input is accepected but invalid if it contains a double that is outside | - | ||||||
| 122 | the range or is in the wrong format; e.g. with too many digits after the | - | ||||||
| 123 | decimal point or is empty. | - | ||||||
| 124 | - | |||||||
| 125 | Input is rejected if it is not a double. | - | ||||||
| 126 | - | |||||||
| 127 | Note: If the valid range consists of just positive doubles (e.g. 0.0 to | - | ||||||
| 128 | 100.0) and input is a negative double then it is rejected. If \l notation | - | ||||||
| 129 | is set to DoubleValidator.StandardNotation, and the input contains more | - | ||||||
| 130 | digits before the decimal point than a double in the valid range may have, | - | ||||||
| 131 | it is also rejected. If \l notation is DoubleValidator.ScientificNotation, | - | ||||||
| 132 | and the input is not in the valid range, it is accecpted but invalid. The | - | ||||||
| 133 | value may yet become valid by changing the exponent. | - | ||||||
| 134 | */ | - | ||||||
| 135 | - | |||||||
| 136 | QQuickDoubleValidator::QQuickDoubleValidator(QObject *parent) | - | ||||||
| 137 | : QDoubleValidator(parent) | - | ||||||
| 138 | { | - | ||||||
| 139 | } executed 6 times by 1 test: end of blockExecuted by:
| 6 | ||||||
| 140 | - | |||||||
| 141 | /*! | - | ||||||
| 142 | \qmlproperty string QtQuick::DoubleValidator::locale | - | ||||||
| 143 | - | |||||||
| 144 | This property holds the name of the locale used to interpret the number. | - | ||||||
| 145 | - | |||||||
| 146 | \sa {QtQml::Qt::locale()}{Qt.locale()} | - | ||||||
| 147 | */ | - | ||||||
| 148 | - | |||||||
| 149 | QString QQuickDoubleValidator::localeName() const | - | ||||||
| 150 | { | - | ||||||
| 151 | return locale().name(); executed 6 times by 1 test: return locale().name();Executed by:
| 6 | ||||||
| 152 | } | - | ||||||
| 153 | - | |||||||
| 154 | void QQuickDoubleValidator::setLocaleName(const QString &name) | - | ||||||
| 155 | { | - | ||||||
| 156 | if (locale().name() != name) {
| 0-4 | ||||||
| 157 | setLocale(QLocale(name)); | - | ||||||
| 158 | emit localeNameChanged(); | - | ||||||
| 159 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||
| 160 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||
| 161 | - | |||||||
| 162 | void QQuickDoubleValidator::resetLocaleName() | - | ||||||
| 163 | { | - | ||||||
| 164 | QLocale defaultLocale; | - | ||||||
| 165 | if (locale() != defaultLocale) {
| 0-4 | ||||||
| 166 | setLocale(defaultLocale); | - | ||||||
| 167 | emit localeNameChanged(); | - | ||||||
| 168 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||
| 169 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||
| 170 | - | |||||||
| 171 | /*! | - | ||||||
| 172 | \qmlproperty real QtQuick::DoubleValidator::top | - | ||||||
| 173 | - | |||||||
| 174 | This property holds the validator's maximum acceptable value. | - | ||||||
| 175 | By default, this property contains a value of infinity. | - | ||||||
| 176 | */ | - | ||||||
| 177 | /*! | - | ||||||
| 178 | \qmlproperty real QtQuick::DoubleValidator::bottom | - | ||||||
| 179 | - | |||||||
| 180 | This property holds the validator's minimum acceptable value. | - | ||||||
| 181 | By default, this property contains a value of -infinity. | - | ||||||
| 182 | */ | - | ||||||
| 183 | /*! | - | ||||||
| 184 | \qmlproperty int QtQuick::DoubleValidator::decimals | - | ||||||
| 185 | - | |||||||
| 186 | This property holds the validator's maximum number of digits after the decimal point. | - | ||||||
| 187 | By default, this property contains a value of 1000. | - | ||||||
| 188 | */ | - | ||||||
| 189 | /*! | - | ||||||
| 190 | \qmlproperty enumeration QtQuick::DoubleValidator::notation | - | ||||||
| 191 | This property holds the notation of how a string can describe a number. | - | ||||||
| 192 | - | |||||||
| 193 | The possible values for this property are: | - | ||||||
| 194 | - | |||||||
| 195 | \list | - | ||||||
| 196 | \li DoubleValidator.StandardNotation | - | ||||||
| 197 | \li DoubleValidator.ScientificNotation (default) | - | ||||||
| 198 | \endlist | - | ||||||
| 199 | - | |||||||
| 200 | If this property is set to DoubleValidator.ScientificNotation, the written number may have an exponent part (e.g. 1.5E-2). | - | ||||||
| 201 | */ | - | ||||||
| 202 | - | |||||||
| 203 | /*! | - | ||||||
| 204 | \qmltype RegExpValidator | - | ||||||
| 205 | \instantiates QRegExpValidator | - | ||||||
| 206 | \inqmlmodule QtQuick | - | ||||||
| 207 | \ingroup qtquick-text-utility | - | ||||||
| 208 | \brief Provides a string validator. | - | ||||||
| 209 | - | |||||||
| 210 | The RegExpValidator type provides a validator, which counts as valid any string which | - | ||||||
| 211 | matches a specified regular expression. | - | ||||||
| 212 | */ | - | ||||||
| 213 | /*! | - | ||||||
| 214 | \qmlproperty regExp QtQuick::RegExpValidator::regExp | - | ||||||
| 215 | - | |||||||
| 216 | This property holds the regular expression used for validation. | - | ||||||
| 217 | - | |||||||
| 218 | Note that this property should be a regular expression in JS syntax, e.g /a/ for the regular expression | - | ||||||
| 219 | matching "a". | - | ||||||
| 220 | - | |||||||
| 221 | By default, this property contains a regular expression with the pattern .* that matches any string. | - | ||||||
| 222 | - | |||||||
| 223 | Below you can find an example of a \l TextInput object with a RegExpValidator specified: | - | ||||||
| 224 | - | |||||||
| 225 | \snippet qml/regexp.qml 0 | - | ||||||
| 226 | - | |||||||
| 227 | Some more examples of regular expressions: | - | ||||||
| 228 | - | |||||||
| 229 | \list | - | ||||||
| 230 | \li A list of numbers with one to three positions separated by a comma: | - | ||||||
| 231 | \badcode | - | ||||||
| 232 | /\d{1,3}(?:,\d{1,3})+$/ | - | ||||||
| 233 | \endcode | - | ||||||
| 234 | - | |||||||
| 235 | \li An amount consisting of up to 3 numbers before the decimal point, and | - | ||||||
| 236 | 1 to 2 after the decimal point: | - | ||||||
| 237 | \badcode | - | ||||||
| 238 | /(\d{1,3})([.,]\d{1,2})?$/ | - | ||||||
| 239 | \endcode | - | ||||||
| 240 | \endlist | - | ||||||
| 241 | */ | - | ||||||
| 242 | - | |||||||
| 243 | #endif // validator | - | ||||||
| 244 | - | |||||||
| 245 | QT_END_NAMESPACE | - | ||||||
| 246 | - | |||||||
| 247 | #include "moc_qquickvalidator_p.cpp" | - | ||||||
| Source code | Switch to Preprocessed file |