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 | } |
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(); |
77 | } |
78 | |
79 | void QQuickIntValidator::setLocaleName(const QString &name) |
80 | { |
81 | if (locale().name() != name) { |
82 | setLocale(QLocale(name)); |
83 | emit localeNameChanged(); |
84 | } |
85 | } |
86 | |
87 | void QQuickIntValidator::resetLocaleName() |
88 | { |
89 | QLocale defaultLocale; |
90 | if (locale() != defaultLocale) { |
91 | setLocale(defaultLocale); |
92 | emit localeNameChanged(); |
93 | } |
94 | } |
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 | } |
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(); |
152 | } |
153 | |
154 | void QQuickDoubleValidator::setLocaleName(const QString &name) |
155 | { |
156 | if (locale().name() != name) { |
157 | setLocale(QLocale(name)); |
158 | emit localeNameChanged(); |
159 | } |
160 | } |
161 | |
162 | void QQuickDoubleValidator::resetLocaleName() |
163 | { |
164 | QLocale defaultLocale; |
165 | if (locale() != defaultLocale) { |
166 | setLocale(defaultLocale); |
167 | emit localeNameChanged(); |
168 | } |
169 | } |
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 | \deprecated |
210 | |
211 | The RegExpValidator type provides a validator, which counts as valid any string which |
212 | matches a specified regular expression. |
213 | |
214 | RegExpValidator is deprecated since it is based on the deprecated \l {QRegExp}. Use |
215 | \l RegularExpressionValidator instead. |
216 | */ |
217 | /*! |
218 | \qmlproperty regExp QtQuick::RegExpValidator::regExp |
219 | |
220 | This property holds the regular expression used for validation. |
221 | |
222 | Note that this property should be a regular expression in JS syntax, e.g /a/ for the regular expression |
223 | matching "a". |
224 | |
225 | By default, this property contains a regular expression with the pattern .* that matches any string. |
226 | |
227 | Below you can find an example of a \l TextInput object with a RegExpValidator specified: |
228 | |
229 | \snippet qml/regexp.qml 0 |
230 | |
231 | Some more examples of regular expressions: |
232 | |
233 | \list |
234 | \li A list of numbers with one to three positions separated by a comma: |
235 | \badcode |
236 | /\d{1,3}(?:,\d{1,3})+$/ |
237 | \endcode |
238 | |
239 | \li An amount consisting of up to 3 numbers before the decimal point, and |
240 | 1 to 2 after the decimal point: |
241 | \badcode |
242 | /(\d{1,3})([.,]\d{1,2})?$/ |
243 | \endcode |
244 | \endlist |
245 | */ |
246 | /*! |
247 | \qmltype RegularExpressionValidator |
248 | \instantiates QRegularExpressionValidator |
249 | \inqmlmodule QtQuick |
250 | \ingroup qtquick-text-utility |
251 | \brief Provides a string validator. |
252 | \since 5.14 |
253 | |
254 | The RegularExpressionValidator type provides a validator, that counts as valid any string which |
255 | matches a specified regular expression. |
256 | */ |
257 | /*! |
258 | \qmlproperty regularExpression QtQuick::RegularExpressionValidator::regularExpression |
259 | |
260 | This property holds the regular expression used for validation. |
261 | |
262 | Note that this property should be a regular expression in JS syntax, e.g /a/ for the regular |
263 | expression matching "a". |
264 | |
265 | By default, this property contains a regular expression with the pattern \c{.*} that matches any |
266 | string. |
267 | |
268 | Below you can find an example of a \l TextInput object with a RegularExpressionValidator |
269 | specified: |
270 | |
271 | \snippet qml/regularexpression.qml 0 |
272 | |
273 | Some more examples of regular expressions: |
274 | |
275 | \list |
276 | \li A list of numbers with one to three positions separated by a comma: |
277 | \badcode |
278 | /\d{1,3}(?:,\d{1,3})+$/ |
279 | \endcode |
280 | |
281 | \li An amount consisting of up to 3 numbers before the decimal point, and |
282 | 1 to 2 after the decimal point: |
283 | \badcode |
284 | /(\d{1,3})([.,]\d{1,2})?$/ |
285 | \endcode |
286 | \endlist |
287 | */ |
288 | |
289 | #endif // validator |
290 | |
291 | QT_END_NAMESPACE |
292 | |
293 | #include "moc_qquickvalidator_p.cpp" |
294 | |