1 | // Copyright (C) 2016 The Qt Company Ltd. |
2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
3 | |
4 | #include "qquickvalidator_p.h" |
5 | |
6 | QT_BEGIN_NAMESPACE |
7 | |
8 | #if QT_CONFIG(validator) |
9 | |
10 | /*! |
11 | \qmltype IntValidator |
12 | \instantiates QIntValidator |
13 | \inqmlmodule QtQuick |
14 | \ingroup qtquick-text-utility |
15 | \ingroup qtquick-text-validators |
16 | \brief Defines a validator for integer values. |
17 | |
18 | The IntValidator type provides a validator for integer values. |
19 | |
20 | If no \l locale is set IntValidator uses the \l {QLocale::setDefault()}{default locale} to |
21 | interpret the number and will accept locale specific digits, group separators, and positive |
22 | and negative signs. In addition, IntValidator is always guaranteed to accept a number |
23 | formatted according to the "C" locale. |
24 | |
25 | \sa DoubleValidator, RegularExpressionValidator, {Validating Input Text} |
26 | */ |
27 | |
28 | QQuickIntValidator::QQuickIntValidator(QObject *parent) |
29 | : QIntValidator(parent) |
30 | { |
31 | } |
32 | |
33 | /*! |
34 | \qmlproperty string QtQuick::IntValidator::locale |
35 | |
36 | This property holds the name of the locale used to interpret the number. |
37 | |
38 | \sa {QtQml::Qt::locale()}{Qt.locale()} |
39 | */ |
40 | |
41 | QString QQuickIntValidator::localeName() const |
42 | { |
43 | return locale().name(); |
44 | } |
45 | |
46 | void QQuickIntValidator::setLocaleName(const QString &name) |
47 | { |
48 | if (locale().name() != name) { |
49 | setLocale(QLocale(name)); |
50 | emit localeNameChanged(); |
51 | } |
52 | } |
53 | |
54 | void QQuickIntValidator::resetLocaleName() |
55 | { |
56 | QLocale defaultLocale; |
57 | if (locale() != defaultLocale) { |
58 | setLocale(defaultLocale); |
59 | emit localeNameChanged(); |
60 | } |
61 | } |
62 | |
63 | /*! |
64 | \qmlproperty int QtQuick::IntValidator::top |
65 | |
66 | This property holds the validator's highest acceptable value. |
67 | By default, this property's value is derived from the highest signed integer available (typically 2147483647). |
68 | */ |
69 | /*! |
70 | \qmlproperty int QtQuick::IntValidator::bottom |
71 | |
72 | This property holds the validator's lowest acceptable value. |
73 | By default, this property's value is derived from the lowest signed integer available (typically -2147483647). |
74 | */ |
75 | |
76 | /*! |
77 | \qmltype DoubleValidator |
78 | \instantiates QDoubleValidator |
79 | \inqmlmodule QtQuick |
80 | \ingroup qtquick-text-utility |
81 | \ingroup qtquick-text-validators |
82 | \brief Defines a validator for non-integer numbers. |
83 | |
84 | The DoubleValidator type provides a validator for non-integer numbers. |
85 | |
86 | Input is accepted if it contains a double that is within the valid range |
87 | and is in the correct format. |
88 | |
89 | Input is accepected but invalid if it contains a double that is outside |
90 | the range or is in the wrong format; e.g. with too many digits after the |
91 | decimal point or is empty. |
92 | |
93 | Input is rejected if it is not a double. |
94 | |
95 | Note: If the valid range consists of just positive doubles (e.g. 0.0 to |
96 | 100.0) and input is a negative double then it is rejected. If \l notation |
97 | is set to DoubleValidator.StandardNotation, and the input contains more |
98 | digits before the decimal point than a double in the valid range may have, |
99 | it is also rejected. If \l notation is DoubleValidator.ScientificNotation, |
100 | and the input is not in the valid range, it is accecpted but invalid. The |
101 | value may yet become valid by changing the exponent. |
102 | |
103 | \sa IntValidator, RegularExpressionValidator, {Validating Input Text} |
104 | */ |
105 | |
106 | QQuickDoubleValidator::QQuickDoubleValidator(QObject *parent) |
107 | : QDoubleValidator(parent) |
108 | { |
109 | } |
110 | |
111 | /*! |
112 | \qmlproperty string QtQuick::DoubleValidator::locale |
113 | |
114 | This property holds the name of the locale used to interpret the number. |
115 | |
116 | \sa {QtQml::Qt::locale()}{Qt.locale()} |
117 | */ |
118 | |
119 | QString QQuickDoubleValidator::localeName() const |
120 | { |
121 | return locale().name(); |
122 | } |
123 | |
124 | void QQuickDoubleValidator::setLocaleName(const QString &name) |
125 | { |
126 | if (locale().name() != name) { |
127 | setLocale(QLocale(name)); |
128 | emit localeNameChanged(); |
129 | } |
130 | } |
131 | |
132 | void QQuickDoubleValidator::resetLocaleName() |
133 | { |
134 | QLocale defaultLocale; |
135 | if (locale() != defaultLocale) { |
136 | setLocale(defaultLocale); |
137 | emit localeNameChanged(); |
138 | } |
139 | } |
140 | |
141 | /*! |
142 | \qmlproperty real QtQuick::DoubleValidator::top |
143 | |
144 | This property holds the validator's maximum acceptable value. |
145 | By default, this property contains a value of infinity. |
146 | */ |
147 | /*! |
148 | \qmlproperty real QtQuick::DoubleValidator::bottom |
149 | |
150 | This property holds the validator's minimum acceptable value. |
151 | By default, this property contains a value of -infinity. |
152 | */ |
153 | /*! |
154 | \qmlproperty int QtQuick::DoubleValidator::decimals |
155 | |
156 | This property holds the validator's maximum number of digits after the decimal point. |
157 | By default, this property contains a value of 1000. |
158 | */ |
159 | /*! |
160 | \qmlproperty enumeration QtQuick::DoubleValidator::notation |
161 | This property holds the notation of how a string can describe a number. |
162 | |
163 | The possible values for this property are: |
164 | |
165 | \value DoubleValidator.StandardNotation only decimal numbers with optional sign (e.g. \c -0.015) |
166 | \value DoubleValidator.ScientificNotation (default) the written number may have an exponent part (e.g. \c 1.5E-2) |
167 | */ |
168 | |
169 | /*! |
170 | \qmltype RegularExpressionValidator |
171 | \instantiates QRegularExpressionValidator |
172 | \inqmlmodule QtQuick |
173 | \ingroup qtquick-text-utility |
174 | \ingroup qtquick-text-validators |
175 | \brief Provides a string validator. |
176 | \since 5.14 |
177 | |
178 | The RegularExpressionValidator type provides a validator, that counts as valid any string which |
179 | matches a specified regular expression. |
180 | |
181 | \sa IntValidator, DoubleValidator, {Validating Input Text} |
182 | */ |
183 | /*! |
184 | \qmlproperty regularExpression QtQuick::RegularExpressionValidator::regularExpression |
185 | |
186 | This property holds the regular expression used for validation. |
187 | |
188 | Note that this property should be a regular expression in JS syntax, e.g /a/ for the regular |
189 | expression matching "a". |
190 | |
191 | By default, this property contains a regular expression with the pattern \c{.*} that matches any |
192 | string. |
193 | |
194 | Below you can find an example of a \l TextInput object with a RegularExpressionValidator |
195 | specified: |
196 | |
197 | \snippet qml/regularexpression.qml 0 |
198 | |
199 | Some more examples of regular expressions: |
200 | |
201 | \list |
202 | \li A list of numbers with one to three positions separated by a comma: |
203 | \badcode |
204 | /\d{1,3}(?:,\d{1,3})+$/ |
205 | \endcode |
206 | |
207 | \li An amount consisting of up to 3 numbers before the decimal point, and |
208 | 1 to 2 after the decimal point: |
209 | \badcode |
210 | /(\d{1,3})([.,]\d{1,2})?$/ |
211 | \endcode |
212 | \endlist |
213 | */ |
214 | |
215 | #endif // validator |
216 | |
217 | QT_END_NAMESPACE |
218 | |
219 | #include "moc_qquickvalidator_p.cpp" |
220 | |