qvalidator.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/util/qvalidator.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6class QValidatorPrivate : public QObjectPrivate{-
7 inline QValidator* q_func() { return static_cast<QValidator *>(q_ptr); } inline const QValidator* q_func() const { return static_cast<const QValidator *>(q_ptr); } friend class QValidator;-
8public:-
9 QValidatorPrivate() : QObjectPrivate()-
10 {-
11 }
never executed: end of block
0
12-
13 QLocale locale;-
14};-
15-
16-
17-
18-
19-
20-
21-
22QValidator::QValidator(QObject * parent)-
23 : QObject(*new QValidatorPrivate, parent)-
24{-
25}
never executed: end of block
0
26-
27-
28-
29-
30-
31-
32QValidator::~QValidator()-
33{-
34}-
35-
36-
37-
38-
39-
40-
41-
42QLocale QValidator::locale() const-
43{-
44 const QValidatorPrivate * const d = d_func();-
45 return
never executed: return d->locale;
d->locale;
never executed: return d->locale;
0
46}-
47void QValidator::setLocale(const QLocale &locale)-
48{-
49 QValidatorPrivate * const d = d_func();-
50 if (d->locale != locale
d->locale != localeDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
51 d->locale = locale;-
52 changed();-
53 }
never executed: end of block
0
54}
never executed: end of block
0
55void QValidator::fixup(QString &) const-
56{-
57}-
58QIntValidator::QIntValidator(QObject * parent)-
59 : QValidator(parent)-
60{-
61 b = (-2147483647 - 1);-
62 t = 2147483647;-
63}
never executed: end of block
0
64-
65-
66-
67-
68-
69-
70-
71QIntValidator::QIntValidator(int minimum, int maximum,-
72 QObject * parent)-
73 : QValidator(parent)-
74{-
75 b = minimum;-
76 t = maximum;-
77}
never executed: end of block
0
78-
79-
80-
81-
82-
83-
84QIntValidator::~QIntValidator()-
85{-
86-
87}-
88static int numDigits(qlonglong n)-
89{-
90 if (n == 0
n == 0Description
TRUEnever evaluated
FALSEnever evaluated
)
0
91 return
never executed: return 1;
1;
never executed: return 1;
0
92 return
never executed: return (int)std::log10(double(n)) + 1;
(int)std::log10(double(n)) + 1;
never executed: return (int)std::log10(double(n)) + 1;
0
93}-
94-
95static qlonglong pow10(int exp)-
96{-
97 qlonglong result = 1;-
98 for (int i = 0; i < exp
i < expDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i)
0
99 result *= 10;
never executed: result *= 10;
0
100 return
never executed: return result;
result;
never executed: return result;
0
101}-
102-
103QValidator::State QIntValidator::validate(QString & input, int&) const-
104{-
105 QByteArray buff;-
106 if (!locale().d->m_data->validateChars(input, QLocaleData::IntegerMode, &buff, -1,
!locale().d->m...mberOptions())Description
TRUEnever evaluated
FALSEnever evaluated
0
107 locale().numberOptions())
!locale().d->m...mberOptions())Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
108 return
never executed: return Invalid;
Invalid;
never executed: return Invalid;
0
109 }-
110-
111 if (buff.isEmpty()
buff.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
112 return
never executed: return Intermediate;
Intermediate;
never executed: return Intermediate;
0
113-
114 if (b >= 0
b >= 0Description
TRUEnever evaluated
FALSEnever evaluated
&& buff.startsWith('-')
buff.startsWith('-')Description
TRUEnever evaluated
FALSEnever evaluated
)
0
115 return
never executed: return Invalid;
Invalid;
never executed: return Invalid;
0
116-
117 if (t < 0
t < 0Description
TRUEnever evaluated
FALSEnever evaluated
&& buff.startsWith('+')
buff.startsWith('+')Description
TRUEnever evaluated
FALSEnever evaluated
)
0
118 return
never executed: return Invalid;
Invalid;
never executed: return Invalid;
0
119-
120 if (buff.size() == 1
buff.size() == 1Description
TRUEnever evaluated
FALSEnever evaluated
&& (buff.at(0) == '+'
buff.at(0) == '+'Description
TRUEnever evaluated
FALSEnever evaluated
|| buff.at(0) == '-'
buff.at(0) == '-'Description
TRUEnever evaluated
FALSEnever evaluated
))
0
121 return
never executed: return Intermediate;
Intermediate;
never executed: return Intermediate;
0
122-
123 bool ok, overflow;-
124 qlonglong entered = QLocaleData::bytearrayToLongLong(buff.constData(), 10, &ok, &overflow);-
125 if (overflow
overflowDescription
TRUEnever evaluated
FALSEnever evaluated
|| !ok
!okDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
126 return
never executed: return Invalid;
Invalid;
never executed: return Invalid;
0
127-
128 if (entered >= b
entered >= bDescription
TRUEnever evaluated
FALSEnever evaluated
&& entered <= t
entered <= tDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
129 locale().toInt(input, &ok);-
130 return
never executed: return ok ? Acceptable : Intermediate;
ok ? Acceptable : Intermediate;
never executed: return ok ? Acceptable : Intermediate;
0
131 }-
132-
133 if (entered >= 0
entered >= 0Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
134-
135-
136 return
never executed: return (entered > t && -entered < b) ? Invalid : Intermediate;
(entered > t && -entered < b) ? Invalid : Intermediate;
never executed: return (entered > t && -entered < b) ? Invalid : Intermediate;
0
137 } else {-
138 return
never executed: return (entered < b) ? Invalid : Intermediate;
(entered < b) ? Invalid : Intermediate;
never executed: return (entered < b) ? Invalid : Intermediate;
0
139 }-
140}-
141-
142-
143void QIntValidator::fixup(QString &input) const-
144{-
145 QByteArray buff;-
146 if (!locale().d->m_data->validateChars(input, QLocaleData::IntegerMode, &buff, -1,
!locale().d->m...mberOptions())Description
TRUEnever evaluated
FALSEnever evaluated
0
147 locale().numberOptions())
!locale().d->m...mberOptions())Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
148 return;
never executed: return;
0
149 }-
150 bool ok, overflow;-
151 qlonglong entered = QLocaleData::bytearrayToLongLong(buff.constData(), 10, &ok, &overflow);-
152 if (ok
okDescription
TRUEnever evaluated
FALSEnever evaluated
&& !overflow
!overflowDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
153 input = locale().toString(entered);
never executed: input = locale().toString(entered);
0
154}
never executed: end of block
0
155void QIntValidator::setRange(int bottom, int top)-
156{-
157 bool rangeChanged = false;-
158 if (b != bottom
b != bottomDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
159 b = bottom;-
160 rangeChanged = true;-
161 bottomChanged(b);-
162 }
never executed: end of block
0
163-
164 if (t != top
t != topDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
165 t = top;-
166 rangeChanged = true;-
167 topChanged(t);-
168 }
never executed: end of block
0
169-
170 if (rangeChanged
rangeChangedDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
171 changed();
never executed: changed();
0
172}
never executed: end of block
0
173void QIntValidator::setBottom(int bottom)-
174{-
175 setRange(bottom, top());-
176}
never executed: end of block
0
177void QIntValidator::setTop(int top)-
178{-
179 setRange(bottom(), top);-
180}
never executed: end of block
0
181-
182-
183-
184-
185QValidator::QValidator(QObjectPrivate &d, QObject *parent)-
186 : QObject(d, parent)-
187{-
188}
never executed: end of block
0
189-
190-
191-
192-
193QValidator::QValidator(QValidatorPrivate &d, QObject *parent)-
194 : QObject(d, parent)-
195{-
196}
never executed: end of block
0
197-
198-
199-
200class QDoubleValidatorPrivate : public QValidatorPrivate-
201{-
202 inline QDoubleValidator* q_func() { return static_cast<QDoubleValidator *>(q_ptr); } inline const QDoubleValidator* q_func() const { return static_cast<const QDoubleValidator *>(q_ptr); } friend class QDoubleValidator;-
203public:-
204 QDoubleValidatorPrivate()-
205 : QValidatorPrivate()-
206 , notation(QDoubleValidator::ScientificNotation)-
207 {-
208 }
never executed: end of block
0
209-
210 QDoubleValidator::Notation notation;-
211-
212 QValidator::State validateWithLocale(QString & input, QLocaleData::NumberMode numMode, const QLocale &locale) const;-
213};-
214QDoubleValidator::QDoubleValidator(QObject * parent)-
215 : QValidator(*new QDoubleValidatorPrivate , parent)-
216{-
217 b = -(__builtin_huge_val());-
218 t = (__builtin_huge_val());-
219 dec = 1000;-
220}
never executed: end of block
0
221QDoubleValidator::QDoubleValidator(double bottom, double top, int decimals,-
222 QObject * parent)-
223 : QValidator(*new QDoubleValidatorPrivate , parent)-
224{-
225 b = bottom;-
226 t = top;-
227 dec = decimals;-
228}
never executed: end of block
0
229-
230-
231-
232-
233-
234-
235QDoubleValidator::~QDoubleValidator()-
236{-
237}-
238QValidator::State QDoubleValidator::validate(QString & input, int &) const-
239{-
240 const QDoubleValidatorPrivate * const d = d_func();-
241-
242 QLocaleData::NumberMode numMode = QLocaleData::DoubleStandardMode;-
243 switch (d->notation) {-
244 case
never executed: case StandardNotation:
StandardNotation:
never executed: case StandardNotation:
0
245 numMode = QLocaleData::DoubleStandardMode;-
246 break;
never executed: break;
0
247 case
never executed: case ScientificNotation:
ScientificNotation:
never executed: case ScientificNotation:
0
248 numMode = QLocaleData::DoubleScientificMode;-
249 break;
never executed: break;
0
250 }-
251-
252 return
never executed: return d->validateWithLocale(input, numMode, locale());
d->validateWithLocale(input, numMode, locale());
never executed: return d->validateWithLocale(input, numMode, locale());
0
253}-
254-
255QValidator::State QDoubleValidatorPrivate::validateWithLocale(QString &input, QLocaleData::NumberMode numMode, const QLocale &locale) const-
256{-
257 const QDoubleValidator * const q = q_func();-
258 QByteArray buff;-
259 if (!locale.d->m_data->validateChars(input, numMode, &buff, q->dec, locale.numberOptions())
!locale.d->m_d...mberOptions())Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
260 return
never executed: return QValidator::Invalid;
QValidator::Invalid;
never executed: return QValidator::Invalid;
0
261 }-
262-
263 if (buff.isEmpty()
buff.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
264 return
never executed: return QValidator::Intermediate;
QValidator::Intermediate;
never executed: return QValidator::Intermediate;
0
265-
266 if (q->b >= 0
q->b >= 0Description
TRUEnever evaluated
FALSEnever evaluated
&& buff.startsWith('-')
buff.startsWith('-')Description
TRUEnever evaluated
FALSEnever evaluated
)
0
267 return
never executed: return QValidator::Invalid;
QValidator::Invalid;
never executed: return QValidator::Invalid;
0
268-
269 if (q->t < 0
q->t < 0Description
TRUEnever evaluated
FALSEnever evaluated
&& buff.startsWith('+')
buff.startsWith('+')Description
TRUEnever evaluated
FALSEnever evaluated
)
0
270 return
never executed: return QValidator::Invalid;
QValidator::Invalid;
never executed: return QValidator::Invalid;
0
271-
272 bool ok = false;-
273 double i = buff.toDouble(&ok);-
274 if (i == qt_qnan()
i == qt_qnan()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
275 return
never executed: return QValidator::Invalid;
QValidator::Invalid;
never executed: return QValidator::Invalid;
0
276 if (!ok
!okDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
277 return
never executed: return QValidator::Intermediate;
QValidator::Intermediate;
never executed: return QValidator::Intermediate;
0
278-
279 if (i >= q->b
i >= q->bDescription
TRUEnever evaluated
FALSEnever evaluated
&& i <= q->t
i <= q->tDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
280 return
never executed: return QValidator::Acceptable;
QValidator::Acceptable;
never executed: return QValidator::Acceptable;
0
281-
282 if (notation == QDoubleValidator::StandardNotation
notation == QD...andardNotationDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
283 double max = qMax(qAbs(q->b), qAbs(q->t));-
284 if (max < 9223372036854775807LL
max < 9223372036854775807LLDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
285 qlonglong n = pow10(numDigits(qlonglong(max))) - 1;-
286 if (qAbs(i) > n
qAbs(i) > nDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
287 return
never executed: return QValidator::Invalid;
QValidator::Invalid;
never executed: return QValidator::Invalid;
0
288 }
never executed: end of block
0
289 }
never executed: end of block
0
290-
291 return
never executed: return QValidator::Intermediate;
QValidator::Intermediate;
never executed: return QValidator::Intermediate;
0
292}-
293void QDoubleValidator::setRange(double minimum, double maximum, int decimals)-
294{-
295 bool rangeChanged = false;-
296 if (b != minimum
b != minimumDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
297 b = minimum;-
298 rangeChanged = true;-
299 bottomChanged(b);-
300 }
never executed: end of block
0
301-
302 if (t != maximum
t != maximumDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
303 t = maximum;-
304 rangeChanged = true;-
305 topChanged(t);-
306 }
never executed: end of block
0
307-
308 if (dec != decimals
dec != decimalsDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
309 dec = decimals;-
310 rangeChanged = true;-
311 decimalsChanged(dec);-
312 }
never executed: end of block
0
313 if (rangeChanged
rangeChangedDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
314 changed();
never executed: changed();
0
315}
never executed: end of block
0
316void QDoubleValidator::setBottom(double bottom)-
317{-
318 setRange(bottom, top(), decimals());-
319}
never executed: end of block
0
320void QDoubleValidator::setTop(double top)-
321{-
322 setRange(bottom(), top, decimals());-
323}
never executed: end of block
0
324void QDoubleValidator::setDecimals(int decimals)-
325{-
326 setRange(bottom(), top(), decimals);-
327}
never executed: end of block
0
328void QDoubleValidator::setNotation(Notation newNotation)-
329{-
330 QDoubleValidatorPrivate * const d = d_func();-
331 if (d->notation != newNotation
d->notation != newNotationDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
332 d->notation = newNotation;-
333 notationChanged(d->notation);-
334 changed();-
335 }
never executed: end of block
0
336}
never executed: end of block
0
337-
338QDoubleValidator::Notation QDoubleValidator::notation() const-
339{-
340 const QDoubleValidatorPrivate * const d = d_func();-
341 return
never executed: return d->notation;
d->notation;
never executed: return d->notation;
0
342}-
343QRegExpValidator::QRegExpValidator(QObject *parent)-
344 : QValidator(parent), r(QString::fromLatin1(".*"))-
345{-
346}
never executed: end of block
0
347QRegExpValidator::QRegExpValidator(const QRegExp& rx, QObject *parent)-
348 : QValidator(parent), r(rx)-
349{-
350}
never executed: end of block
0
351-
352-
353-
354-
355-
356-
357QRegExpValidator::~QRegExpValidator()-
358{-
359}-
360QValidator::State QRegExpValidator::validate(QString &input, int& pos) const-
361{-
362 QRegExp copy = r;-
363 if (copy.exactMatch(input)
copy.exactMatch(input)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
364 return
never executed: return Acceptable;
Acceptable;
never executed: return Acceptable;
0
365 } else {-
366 if (copy.matchedLength() == input.size()
copy.matchedLe...= input.size()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
367 return
never executed: return Intermediate;
Intermediate;
never executed: return Intermediate;
0
368 } else {-
369 pos = input.size();-
370 return
never executed: return Invalid;
Invalid;
never executed: return Invalid;
0
371 }-
372 }-
373}-
374void QRegExpValidator::setRegExp(const QRegExp& rx)-
375{-
376 if (r != rx
r != rxDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
377 r = rx;-
378 regExpChanged(r);-
379 changed();-
380 }
never executed: end of block
0
381}
never executed: end of block
0
382class QRegularExpressionValidatorPrivate : public QValidatorPrivate-
383{-
384 inline QRegularExpressionValidator* q_func() { return static_cast<QRegularExpressionValidator *>(q_ptr); } inline const QRegularExpressionValidator* q_func() const { return static_cast<const QRegularExpressionValidator *>(q_ptr); } friend class QRegularExpressionValidator;-
385-
386public:-
387 QRegularExpression origRe;-
388 QRegularExpression usedRe;-
389 void setRegularExpression(const QRegularExpression &re);-
390};-
391-
392-
393-
394-
395-
396-
397QRegularExpressionValidator::QRegularExpressionValidator(QObject *parent)-
398 : QValidator(*new QRegularExpressionValidatorPrivate, parent)-
399{-
400-
401-
402}
never executed: end of block
0
403-
404-
405-
406-
407-
408-
409QRegularExpressionValidator::QRegularExpressionValidator(const QRegularExpression &re, QObject *parent)-
410 : QValidator(*new QRegularExpressionValidatorPrivate, parent)-
411{-
412 QRegularExpressionValidatorPrivate * const d = d_func();-
413 d->setRegularExpression(re);-
414}
never executed: end of block
0
415-
416-
417-
418-
419-
420-
421QRegularExpressionValidator::~QRegularExpressionValidator()-
422{-
423}-
424QValidator::State QRegularExpressionValidator::validate(QString &input, int &pos) const-
425{-
426 const QRegularExpressionValidatorPrivate * const d = d_func();-
427-
428-
429-
430-
431 if (d->origRe.pattern().isEmpty()
d->origRe.pattern().isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
432 return
never executed: return Acceptable;
Acceptable;
never executed: return Acceptable;
0
433-
434 const QRegularExpressionMatch m = d->usedRe.match(input, 0, QRegularExpression::PartialPreferCompleteMatch);-
435 if (m.hasMatch()
m.hasMatch()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
436 return
never executed: return Acceptable;
Acceptable;
never executed: return Acceptable;
0
437 } else if (input.isEmpty()
input.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
|| m.hasPartialMatch()
m.hasPartialMatch()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
438 return
never executed: return Intermediate;
Intermediate;
never executed: return Intermediate;
0
439 } else {-
440 pos = input.size();-
441 return
never executed: return Invalid;
Invalid;
never executed: return Invalid;
0
442 }-
443}-
444QRegularExpression QRegularExpressionValidator::regularExpression() const-
445{-
446 const QRegularExpressionValidatorPrivate * const d = d_func();-
447 return
never executed: return d->origRe;
d->origRe;
never executed: return d->origRe;
0
448}-
449-
450void QRegularExpressionValidator::setRegularExpression(const QRegularExpression &re)-
451{-
452 QRegularExpressionValidatorPrivate * const d = d_func();-
453 d->setRegularExpression(re);-
454}
never executed: end of block
0
455-
456-
457-
458-
459-
460-
461-
462void QRegularExpressionValidatorPrivate::setRegularExpression(const QRegularExpression &re)-
463{-
464 QRegularExpressionValidator * const q = q_func();-
465-
466 if (origRe != re
origRe != reDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
467 usedRe = origRe = re;-
468 usedRe.setPattern(QLatin1String("\\A(?:") + re.pattern() + QLatin1String(")\\z"));-
469 q->regularExpressionChanged(re);-
470 q->changed();-
471 }
never executed: end of block
0
472}
never executed: end of block
0
473-
474-
475-
476-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9