OpenCoverage

qspinbox.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qspinbox.cpp
Source codeSwitch to Preprocessed file
LineSourceCount
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 QtWidgets 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 <private/qabstractspinbox_p.h>-
41#include <qspinbox.h>-
42-
43#ifndef QT_NO_SPINBOX-
44-
45#include <qlineedit.h>-
46#include <qlocale.h>-
47#include <qvalidator.h>-
48#include <qdebug.h>-
49-
50#include <float.h>-
51-
52QT_BEGIN_NAMESPACE-
53-
54//#define QSPINBOX_QSBDEBUG-
55#ifdef QSPINBOX_QSBDEBUG-
56# define QSBDEBUG qDebug-
57#else-
58# define QSBDEBUG if (false) qDebug-
59#endif-
60-
61class QSpinBoxPrivate : public QAbstractSpinBoxPrivate-
62{-
63 Q_DECLARE_PUBLIC(QSpinBox)-
64public:-
65 QSpinBoxPrivate();-
66 void emitSignals(EmitPolicy ep, const QVariant &) Q_DECL_OVERRIDE;-
67-
68 virtual QVariant valueFromText(const QString &n) const Q_DECL_OVERRIDE;-
69 virtual QString textFromValue(const QVariant &n) const Q_DECL_OVERRIDE;-
70 QVariant validateAndInterpret(QString &input, int &pos,-
71 QValidator::State &state) const;-
72-
73 inline void init() {-
74 Q_Q(QSpinBox);-
75 q->setInputMethodHints(Qt::ImhDigitsOnly);-
76 setLayoutItemMargins(QStyle::SE_SpinBoxLayoutItem);-
77 }
never executed: end of block
0
78-
79 int displayIntegerBase;-
80};-
81-
82class QDoubleSpinBoxPrivate : public QAbstractSpinBoxPrivate-
83{-
84 Q_DECLARE_PUBLIC(QDoubleSpinBox)-
85public:-
86 QDoubleSpinBoxPrivate();-
87 void emitSignals(EmitPolicy ep, const QVariant &) Q_DECL_OVERRIDE;-
88-
89 virtual QVariant valueFromText(const QString &n) const Q_DECL_OVERRIDE;-
90 virtual QString textFromValue(const QVariant &n) const Q_DECL_OVERRIDE;-
91 QVariant validateAndInterpret(QString &input, int &pos,-
92 QValidator::State &state) const;-
93 double round(double input) const;-
94 // variables-
95 int decimals;-
96-
97 inline void init() {-
98 Q_Q(QDoubleSpinBox);-
99 q->setInputMethodHints(Qt::ImhFormattedNumbersOnly);-
100 }
never executed: end of block
0
101-
102 // When fiddling with the decimals property, we may lose precision in these properties.-
103 double actualMin;-
104 double actualMax;-
105};-
106-
107-
108/*!-
109 \class QSpinBox-
110 \brief The QSpinBox class provides a spin box widget.-
111-
112 \ingroup basicwidgets-
113 \inmodule QtWidgets-
114-
115 QSpinBox is designed to handle integers and discrete sets of-
116 values (e.g., month names); use QDoubleSpinBox for floating point-
117 values.-
118-
119 QSpinBox allows the user to choose a value by clicking the up/down-
120 buttons or pressing up/down on the keyboard to increase/decrease-
121 the value currently displayed. The user can also type the value in-
122 manually. The spin box supports integer values but can be extended to-
123 use different strings with validate(), textFromValue() and valueFromText().-
124-
125 Every time the value changes QSpinBox emits two valueChanged() signals,-
126 one providing an int and the other a QString. The QString overload-
127 provides the value with both prefix() and suffix().-
128 The current value can be fetched with value() and set with setValue().-
129-
130 Clicking the up/down buttons or using the keyboard accelerator's-
131 up and down arrows will increase or decrease the current value in-
132 steps of size singleStep(). If you want to change this behaviour you-
133 can reimplement the virtual function stepBy(). The minimum and-
134 maximum value and the step size can be set using one of the-
135 constructors, and can be changed later with setMinimum(),-
136 setMaximum() and setSingleStep().-
137-
138 Most spin boxes are directional, but QSpinBox can also operate as-
139 a circular spin box, i.e. if the range is 0-99 and the current-
140 value is 99, clicking "up" will give 0 if wrapping() is set to-
141 true. Use setWrapping() if you want circular behavior.-
142-
143 The displayed value can be prepended and appended with arbitrary-
144 strings indicating, for example, currency or the unit of-
145 measurement. See setPrefix() and setSuffix(). The text in the spin-
146 box is retrieved with text() (which includes any prefix() and-
147 suffix()), or with cleanText() (which has no prefix(), no suffix()-
148 and no leading or trailing whitespace).-
149-
150 It is often desirable to give the user a special (often default)-
151 choice in addition to the range of numeric values. See-
152 setSpecialValueText() for how to do this with QSpinBox.-
153-
154 \table 100%-
155 \row \li \inlineimage windowsvista-spinbox.png Screenshot of a Windows Vista spin box-
156 \li A spin box shown in the \l{Windows Vista Style Widget Gallery}{Windows Vista widget style}.-
157 \row \li \inlineimage fusion-spinbox.png Screenshot of a Fusion spin box-
158 \li A spin box shown in the \l{Fusion Style Widget Gallery}{Fusion widget style}.-
159 \row \li \inlineimage macintosh-spinbox.png Screenshot of a Macintosh spin box-
160 \li A spin box shown in the \l{Macintosh Style Widget Gallery}{Macintosh widget style}.-
161 \endtable-
162-
163 \section1 Subclassing QSpinBox-
164-
165 If using prefix(), suffix(), and specialValueText() don't provide-
166 enough control, you subclass QSpinBox and reimplement-
167 valueFromText() and textFromValue(). For example, here's the code-
168 for a custom spin box that allows the user to enter icon sizes-
169 (e.g., "32 x 32"):-
170-
171 \snippet widgets/icons/iconsizespinbox.cpp 1-
172 \codeline-
173 \snippet widgets/icons/iconsizespinbox.cpp 2-
174-
175 See the \l{widgets/icons}{Icons} example for the full source-
176 code.-
177-
178 \sa QDoubleSpinBox, QDateTimeEdit, QSlider, {Spin Boxes Example}-
179*/-
180-
181/*!-
182 \fn void QSpinBox::valueChanged(int i)-
183-
184 This signal is emitted whenever the spin box's value is changed.-
185 The new value's integer value is passed in \a i.-
186*/-
187-
188/*!-
189 \fn void QSpinBox::valueChanged(const QString &text)-
190-
191 \overload-
192-
193 The new value is passed in \a text with prefix() and suffix().-
194*/-
195-
196/*!-
197 Constructs a spin box with 0 as minimum value and 99 as maximum value, a-
198 step value of 1. The value is initially set to 0. It is parented to \a-
199 parent.-
200-
201 \sa setMinimum(), setMaximum(), setSingleStep()-
202*/-
203-
204QSpinBox::QSpinBox(QWidget *parent)-
205 : QAbstractSpinBox(*new QSpinBoxPrivate, parent)-
206{-
207 Q_D(QSpinBox);-
208 d->init();-
209}
never executed: end of block
0
210-
211/*!-
212 Destructor.-
213*/-
214QSpinBox::~QSpinBox() {}-
215-
216/*!-
217 \property QSpinBox::value-
218 \brief the value of the spin box-
219-
220 setValue() will emit valueChanged() if the new value is different-
221 from the old one. The value property has a second notifier-
222 signal which includes the spin box's prefix and suffix.-
223*/-
224-
225int QSpinBox::value() const-
226{-
227 Q_D(const QSpinBox);-
228 return d->value.toInt();
never executed: return d->value.toInt();
0
229}-
230-
231void QSpinBox::setValue(int value)-
232{-
233 Q_D(QSpinBox);-
234 d->setValue(QVariant(value), EmitIfChanged);-
235}
never executed: end of block
0
236-
237/*!-
238 \property QSpinBox::prefix-
239 \brief the spin box's prefix-
240-
241 The prefix is prepended to the start of the displayed value.-
242 Typical use is to display a unit of measurement or a currency-
243 symbol. For example:-
244-
245 \snippet code/src_gui_widgets_qspinbox.cpp 0-
246-
247 To turn off the prefix display, set this property to an empty-
248 string. The default is no prefix. The prefix is not displayed when-
249 value() == minimum() and specialValueText() is set.-
250-
251 If no prefix is set, prefix() returns an empty string.-
252-
253 \sa suffix(), setSuffix(), specialValueText(), setSpecialValueText()-
254*/-
255-
256QString QSpinBox::prefix() const-
257{-
258 Q_D(const QSpinBox);-
259 return d->prefix;
never executed: return d->prefix;
0
260}-
261-
262void QSpinBox::setPrefix(const QString &prefix)-
263{-
264 Q_D(QSpinBox);-
265-
266 d->prefix = prefix;-
267 d->updateEdit();-
268-
269 d->cachedSizeHint = QSize();-
270 d->cachedMinimumSizeHint = QSize(); // minimumSizeHint cares about the prefix-
271 updateGeometry();-
272}
never executed: end of block
0
273-
274/*!-
275 \property QSpinBox::suffix-
276 \brief the suffix of the spin box-
277-
278 The suffix is appended to the end of the displayed value. Typical-
279 use is to display a unit of measurement or a currency symbol. For-
280 example:-
281-
282 \snippet code/src_gui_widgets_qspinbox.cpp 1-
283-
284 To turn off the suffix display, set this property to an empty-
285 string. The default is no suffix. The suffix is not displayed for-
286 the minimum() if specialValueText() is set.-
287-
288 If no suffix is set, suffix() returns an empty string.-
289-
290 \sa prefix(), setPrefix(), specialValueText(), setSpecialValueText()-
291*/-
292-
293QString QSpinBox::suffix() const-
294{-
295 Q_D(const QSpinBox);-
296-
297 return d->suffix;
never executed: return d->suffix;
0
298}-
299-
300void QSpinBox::setSuffix(const QString &suffix)-
301{-
302 Q_D(QSpinBox);-
303-
304 d->suffix = suffix;-
305 d->updateEdit();-
306-
307 d->cachedSizeHint = QSize();-
308 updateGeometry();-
309}
never executed: end of block
0
310-
311/*!-
312 \property QSpinBox::cleanText-
313-
314 \brief the text of the spin box excluding any prefix, suffix,-
315 or leading or trailing whitespace.-
316-
317 \sa text, QSpinBox::prefix, QSpinBox::suffix-
318*/-
319-
320QString QSpinBox::cleanText() const-
321{-
322 Q_D(const QSpinBox);-
323-
324 return d->stripped(d->edit->displayText());
never executed: return d->stripped(d->edit->displayText());
0
325}-
326-
327-
328/*!-
329 \property QSpinBox::singleStep-
330 \brief the step value-
331-
332 When the user uses the arrows to change the spin box's value the-
333 value will be incremented/decremented by the amount of the-
334 singleStep. The default value is 1. Setting a singleStep value of-
335 less than 0 does nothing.-
336*/-
337-
338int QSpinBox::singleStep() const-
339{-
340 Q_D(const QSpinBox);-
341-
342 return d->singleStep.toInt();
never executed: return d->singleStep.toInt();
0
343}-
344-
345void QSpinBox::setSingleStep(int value)-
346{-
347 Q_D(QSpinBox);-
348 if (value >= 0) {
value >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
349 d->singleStep = QVariant(value);-
350 d->updateEdit();-
351 }
never executed: end of block
0
352}
never executed: end of block
0
353-
354/*!-
355 \property QSpinBox::minimum-
356-
357 \brief the minimum value of the spin box-
358-
359 When setting this property the \l maximum is adjusted-
360 if necessary to ensure that the range remains valid.-
361-
362 The default minimum value is 0.-
363-
364 \sa setRange(), specialValueText-
365*/-
366-
367int QSpinBox::minimum() const-
368{-
369 Q_D(const QSpinBox);-
370-
371 return d->minimum.toInt();
never executed: return d->minimum.toInt();
0
372}-
373-
374void QSpinBox::setMinimum(int minimum)-
375{-
376 Q_D(QSpinBox);-
377 const QVariant m(minimum);-
378 d->setRange(m, (d->variantCompare(d->maximum, m) > 0 ? d->maximum : m));-
379}
never executed: end of block
0
380-
381/*!-
382 \property QSpinBox::maximum-
383-
384 \brief the maximum value of the spin box-
385-
386 When setting this property the minimum is adjusted-
387 if necessary, to ensure that the range remains valid.-
388-
389 The default maximum value is 99.-
390-
391 \sa setRange(), specialValueText-
392-
393*/-
394-
395int QSpinBox::maximum() const-
396{-
397 Q_D(const QSpinBox);-
398-
399 return d->maximum.toInt();
never executed: return d->maximum.toInt();
0
400}-
401-
402void QSpinBox::setMaximum(int maximum)-
403{-
404 Q_D(QSpinBox);-
405 const QVariant m(maximum);-
406 d->setRange((d->variantCompare(d->minimum, m) < 0 ? d->minimum : m), m);-
407}
never executed: end of block
0
408-
409/*!-
410 Convenience function to set the \a minimum, and \a maximum values-
411 with a single function call.-
412-
413 \snippet code/src_gui_widgets_qspinbox.cpp 2-
414 is equivalent to:-
415 \snippet code/src_gui_widgets_qspinbox.cpp 3-
416-
417 \sa minimum, maximum-
418*/-
419-
420void QSpinBox::setRange(int minimum, int maximum)-
421{-
422 Q_D(QSpinBox);-
423 d->setRange(QVariant(minimum), QVariant(maximum));-
424}
never executed: end of block
0
425-
426/*!-
427 \property QSpinBox::displayIntegerBase-
428-
429 \brief the base used to display the value of the spin box-
430-
431 The default displayIntegerBase value is 10.-
432-
433 \sa textFromValue(), valueFromText()-
434 \since 5.2-
435*/-
436-
437int QSpinBox::displayIntegerBase() const-
438{-
439 Q_D(const QSpinBox);-
440 return d->displayIntegerBase;
never executed: return d->displayIntegerBase;
0
441}-
442-
443void QSpinBox::setDisplayIntegerBase(int base)-
444{-
445 Q_D(QSpinBox);-
446 // Falls back to base 10 on invalid bases (like QString)-
447 if (Q_UNLIKELY(base < 2 || base > 36)) {
__builtin_expe... > 36), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
448 qWarning("QSpinBox::setDisplayIntegerBase: Invalid base (%d)", base);-
449 base = 10;-
450 }
never executed: end of block
0
451-
452 if (base != d->displayIntegerBase) {
base != d->displayIntegerBaseDescription
TRUEnever evaluated
FALSEnever evaluated
0
453 d->displayIntegerBase = base;-
454 d->updateEdit();-
455 }
never executed: end of block
0
456}
never executed: end of block
0
457-
458/*!-
459 This virtual function is used by the spin box whenever it needs to-
460 display the given \a value. The default implementation returns a-
461 string containing \a value printed in the standard way using-
462 QWidget::locale().toString(), but with the thousand separator-
463 removed unless setGroupSeparatorShown() is set. Reimplementations may-
464 return anything. (See the example in the detailed description.)-
465-
466 Note: QSpinBox does not call this function for specialValueText()-
467 and that neither prefix() nor suffix() should be included in the-
468 return value.-
469-
470 If you reimplement this, you may also need to reimplement-
471 valueFromText() and validate()-
472-
473 \sa valueFromText(), validate(), QLocale::groupSeparator()-
474*/-
475-
476QString QSpinBox::textFromValue(int value) const-
477{-
478 Q_D(const QSpinBox);-
479 QString str;-
480-
481 if (d->displayIntegerBase != 10) {
d->displayIntegerBase != 10Description
TRUEnever evaluated
FALSEnever evaluated
0
482 const QLatin1String prefix = value < 0 ? QLatin1String("-") : QLatin1String();
value < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
483 str = prefix + QString::number(qAbs(value), d->displayIntegerBase);-
484 } else {
never executed: end of block
0
485 str = locale().toString(value);-
486 if (!d->showGroupSeparator && (qAbs(value) >= 1000 || value == INT_MIN)) {
!d->showGroupSeparatorDescription
TRUEnever evaluated
FALSEnever evaluated
qAbs(value) >= 1000Description
TRUEnever evaluated
FALSEnever evaluated
value == (-2147483647 - 1)Description
TRUEnever evaluated
FALSEnever evaluated
0
487 str.remove(locale().groupSeparator());-
488 }
never executed: end of block
0
489 }
never executed: end of block
0
490-
491 return str;
never executed: return str;
0
492}-
493-
494/*!-
495 \fn int QSpinBox::valueFromText(const QString &text) const-
496-
497 This virtual function is used by the spin box whenever it needs to-
498 interpret \a text entered by the user as a value.-
499-
500 Subclasses that need to display spin box values in a non-numeric-
501 way need to reimplement this function.-
502-
503 Note: QSpinBox handles specialValueText() separately; this-
504 function is only concerned with the other values.-
505-
506 \sa textFromValue(), validate()-
507*/-
508-
509int QSpinBox::valueFromText(const QString &text) const-
510{-
511 Q_D(const QSpinBox);-
512-
513 QString copy = text;-
514 int pos = d->edit->cursorPosition();-
515 QValidator::State state = QValidator::Acceptable;-
516 return d->validateAndInterpret(copy, pos, state).toInt();
never executed: return d->validateAndInterpret(copy, pos, state).toInt();
0
517}-
518-
519/*!-
520 \reimp-
521*/-
522QValidator::State QSpinBox::validate(QString &text, int &pos) const-
523{-
524 Q_D(const QSpinBox);-
525-
526 QValidator::State state;-
527 d->validateAndInterpret(text, pos, state);-
528 return state;
never executed: return state;
0
529}-
530-
531-
532/*!-
533 \reimp-
534*/-
535void QSpinBox::fixup(QString &input) const-
536{-
537 if (!isGroupSeparatorShown())
!isGroupSeparatorShown()Description
TRUEnever evaluated
FALSEnever evaluated
0
538 input.remove(locale().groupSeparator());
never executed: input.remove(locale().groupSeparator());
0
539}
never executed: end of block
0
540-
541-
542// --- QDoubleSpinBox ----
543-
544/*!-
545 \class QDoubleSpinBox-
546 \brief The QDoubleSpinBox class provides a spin box widget that-
547 takes doubles.-
548-
549 \ingroup basicwidgets-
550 \inmodule QtWidgets-
551-
552 QDoubleSpinBox allows the user to choose a value by clicking the-
553 up and down buttons or by pressing Up or Down on the keyboard to-
554 increase or decrease the value currently displayed. The user can-
555 also type the value in manually. The spin box supports double-
556 values but can be extended to use different strings with-
557 validate(), textFromValue() and valueFromText().-
558-
559 Every time the value changes QDoubleSpinBox emits two-
560 valueChanged() signals, one taking providing a double and the other-
561 a QString. The QString overload provides the value with both-
562 prefix() and suffix(). The current value can be fetched with-
563 value() and set with setValue().-
564-
565 Note: QDoubleSpinBox will round numbers so they can be displayed-
566 with the current precision. In a QDoubleSpinBox with decimals set-
567 to 2, calling setValue(2.555) will cause value() to return 2.56.-
568-
569 Clicking the up and down buttons or using the keyboard accelerator's-
570 Up and Down arrows will increase or decrease the current value in-
571 steps of size singleStep(). If you want to change this behavior you-
572 can reimplement the virtual function stepBy(). The minimum and-
573 maximum value and the step size can be set using one of the-
574 constructors, and can be changed later with setMinimum(),-
575 setMaximum() and setSingleStep(). The spinbox has a default-
576 precision of 2 decimal places but this can be changed using-
577 setDecimals().-
578-
579 Most spin boxes are directional, but QDoubleSpinBox can also-
580 operate as a circular spin box, i.e. if the range is 0.0-99.9 and-
581 the current value is 99.9, clicking "up" will give 0 if wrapping()-
582 is set to true. Use setWrapping() if you want circular behavior.-
583-
584 The displayed value can be prepended and appended with arbitrary-
585 strings indicating, for example, currency or the unit of-
586 measurement. See setPrefix() and setSuffix(). The text in the spin-
587 box is retrieved with text() (which includes any prefix() and-
588 suffix()), or with cleanText() (which has no prefix(), no suffix()-
589 and no leading or trailing whitespace).-
590-
591 It is often desirable to give the user a special (often default)-
592 choice in addition to the range of numeric values. See-
593 setSpecialValueText() for how to do this with QDoubleSpinBox.-
594-
595 \note The displayed value of the QDoubleSpinBox is limited to 18 characters-
596 in addition to eventual prefix and suffix content. This limitation is used-
597 to keep the double spin box usable even with extremely large values.-
598 \sa QSpinBox, QDateTimeEdit, QSlider, {Spin Boxes Example}-
599*/-
600-
601/*!-
602 \fn void QDoubleSpinBox::valueChanged(double d);-
603-
604 This signal is emitted whenever the spin box's value is changed.-
605 The new value is passed in \a d.-
606*/-
607-
608/*!-
609 \fn void QDoubleSpinBox::valueChanged(const QString &text);-
610-
611 \overload-
612-
613 The new value is passed in \a text with prefix() and suffix().-
614*/-
615-
616/*!-
617 Constructs a spin box with 0.0 as minimum value and 99.99 as maximum value,-
618 a step value of 1.0 and a precision of 2 decimal places. The value is-
619 initially set to 0.00. The spin box has the given \a parent.-
620-
621 \sa setMinimum(), setMaximum(), setSingleStep()-
622*/-
623QDoubleSpinBox::QDoubleSpinBox(QWidget *parent)-
624 : QAbstractSpinBox(*new QDoubleSpinBoxPrivate, parent)-
625{-
626 Q_D(QDoubleSpinBox);-
627 d->init();-
628}
never executed: end of block
0
629-
630/*!-
631 Destructor.-
632*/-
633QDoubleSpinBox::~QDoubleSpinBox() {}-
634-
635/*!-
636 \property QDoubleSpinBox::value-
637 \brief the value of the spin box-
638-
639 setValue() will emit valueChanged() if the new value is different-
640 from the old one. The value property has a second notifier-
641 signal which includes the spin box's prefix and suffix.-
642-
643 Note: The value will be rounded so it can be displayed with the-
644 current setting of decimals.-
645-
646 \sa decimals-
647*/-
648double QDoubleSpinBox::value() const-
649{-
650 Q_D(const QDoubleSpinBox);-
651-
652 return d->value.toDouble();
never executed: return d->value.toDouble();
0
653}-
654-
655void QDoubleSpinBox::setValue(double value)-
656{-
657 Q_D(QDoubleSpinBox);-
658 QVariant v(d->round(value));-
659 d->setValue(v, EmitIfChanged);-
660}
never executed: end of block
0
661/*!-
662 \property QDoubleSpinBox::prefix-
663 \brief the spin box's prefix-
664-
665 The prefix is prepended to the start of the displayed value.-
666 Typical use is to display a unit of measurement or a currency-
667 symbol. For example:-
668-
669 \snippet code/src_gui_widgets_qspinbox.cpp 4-
670-
671 To turn off the prefix display, set this property to an empty-
672 string. The default is no prefix. The prefix is not displayed when-
673 value() == minimum() and specialValueText() is set.-
674-
675 If no prefix is set, prefix() returns an empty string.-
676-
677 \sa suffix(), setSuffix(), specialValueText(), setSpecialValueText()-
678*/-
679-
680QString QDoubleSpinBox::prefix() const-
681{-
682 Q_D(const QDoubleSpinBox);-
683-
684 return d->prefix;
never executed: return d->prefix;
0
685}-
686-
687void QDoubleSpinBox::setPrefix(const QString &prefix)-
688{-
689 Q_D(QDoubleSpinBox);-
690-
691 d->prefix = prefix;-
692 d->updateEdit();-
693}
never executed: end of block
0
694-
695/*!-
696 \property QDoubleSpinBox::suffix-
697 \brief the suffix of the spin box-
698-
699 The suffix is appended to the end of the displayed value. Typical-
700 use is to display a unit of measurement or a currency symbol. For-
701 example:-
702-
703 \snippet code/src_gui_widgets_qspinbox.cpp 5-
704-
705 To turn off the suffix display, set this property to an empty-
706 string. The default is no suffix. The suffix is not displayed for-
707 the minimum() if specialValueText() is set.-
708-
709 If no suffix is set, suffix() returns an empty string.-
710-
711 \sa prefix(), setPrefix(), specialValueText(), setSpecialValueText()-
712*/-
713-
714QString QDoubleSpinBox::suffix() const-
715{-
716 Q_D(const QDoubleSpinBox);-
717-
718 return d->suffix;
never executed: return d->suffix;
0
719}-
720-
721void QDoubleSpinBox::setSuffix(const QString &suffix)-
722{-
723 Q_D(QDoubleSpinBox);-
724-
725 d->suffix = suffix;-
726 d->updateEdit();-
727-
728 d->cachedSizeHint = QSize();-
729 updateGeometry();-
730}
never executed: end of block
0
731-
732/*!-
733 \property QDoubleSpinBox::cleanText-
734-
735 \brief the text of the spin box excluding any prefix, suffix,-
736 or leading or trailing whitespace.-
737-
738 \sa text, QDoubleSpinBox::prefix, QDoubleSpinBox::suffix-
739*/-
740-
741QString QDoubleSpinBox::cleanText() const-
742{-
743 Q_D(const QDoubleSpinBox);-
744-
745 return d->stripped(d->edit->displayText());
never executed: return d->stripped(d->edit->displayText());
0
746}-
747-
748/*!-
749 \property QDoubleSpinBox::singleStep-
750 \brief the step value-
751-
752 When the user uses the arrows to change the spin box's value the-
753 value will be incremented/decremented by the amount of the-
754 singleStep. The default value is 1.0. Setting a singleStep value-
755 of less than 0 does nothing.-
756*/-
757double QDoubleSpinBox::singleStep() const-
758{-
759 Q_D(const QDoubleSpinBox);-
760-
761 return d->singleStep.toDouble();
never executed: return d->singleStep.toDouble();
0
762}-
763-
764void QDoubleSpinBox::setSingleStep(double value)-
765{-
766 Q_D(QDoubleSpinBox);-
767-
768 if (value >= 0) {
value >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
769 d->singleStep = value;-
770 d->updateEdit();-
771 }
never executed: end of block
0
772}
never executed: end of block
0
773-
774/*!-
775 \property QDoubleSpinBox::minimum-
776-
777 \brief the minimum value of the spin box-
778-
779 When setting this property the \l maximum is adjusted-
780 if necessary to ensure that the range remains valid.-
781-
782 The default minimum value is 0.0.-
783-
784 Note: The minimum value will be rounded to match the decimals-
785 property.-
786-
787 \sa decimals, setRange(), specialValueText-
788*/-
789-
790double QDoubleSpinBox::minimum() const-
791{-
792 Q_D(const QDoubleSpinBox);-
793-
794 return d->minimum.toDouble();
never executed: return d->minimum.toDouble();
0
795}-
796-
797void QDoubleSpinBox::setMinimum(double minimum)-
798{-
799 Q_D(QDoubleSpinBox);-
800 d->actualMin = minimum;-
801 const QVariant m(d->round(minimum));-
802 d->setRange(m, (d->variantCompare(d->maximum, m) > 0 ? d->maximum : m));-
803}
never executed: end of block
0
804-
805/*!-
806 \property QDoubleSpinBox::maximum-
807-
808 \brief the maximum value of the spin box-
809-
810 When setting this property the \l minimum is adjusted-
811 if necessary, to ensure that the range remains valid.-
812-
813 The default maximum value is 99.99.-
814-
815 Note: The maximum value will be rounded to match the decimals-
816 property.-
817-
818 \sa decimals, setRange()-
819*/-
820-
821double QDoubleSpinBox::maximum() const-
822{-
823 Q_D(const QDoubleSpinBox);-
824-
825 return d->maximum.toDouble();
never executed: return d->maximum.toDouble();
0
826}-
827-
828void QDoubleSpinBox::setMaximum(double maximum)-
829{-
830 Q_D(QDoubleSpinBox);-
831 d->actualMax = maximum;-
832 const QVariant m(d->round(maximum));-
833 d->setRange((d->variantCompare(d->minimum, m) < 0 ? d->minimum : m), m);-
834}
never executed: end of block
0
835-
836/*!-
837 Convenience function to set the \a minimum and \a maximum values-
838 with a single function call.-
839-
840 Note: The maximum and minimum values will be rounded to match the-
841 decimals property.-
842-
843 \snippet code/src_gui_widgets_qspinbox.cpp 6-
844 is equivalent to:-
845 \snippet code/src_gui_widgets_qspinbox.cpp 7-
846-
847 \sa minimum, maximum-
848*/-
849-
850void QDoubleSpinBox::setRange(double minimum, double maximum)-
851{-
852 Q_D(QDoubleSpinBox);-
853 d->actualMin = minimum;-
854 d->actualMax = maximum;-
855 d->setRange(QVariant(d->round(minimum)), QVariant(d->round(maximum)));-
856}
never executed: end of block
0
857-
858/*!-
859 \property QDoubleSpinBox::decimals-
860-
861 \brief the precision of the spin box, in decimals-
862-
863 Sets how many decimals the spinbox will use for displaying and-
864 interpreting doubles.-
865-
866 \warning The maximum value for \a decimals is DBL_MAX_10_EXP +-
867 DBL_DIG (ie. 323) because of the limitations of the double type.-
868-
869 Note: The maximum, minimum and value might change as a result of-
870 changing this property.-
871*/-
872-
873int QDoubleSpinBox::decimals() const-
874{-
875 Q_D(const QDoubleSpinBox);-
876-
877 return d->decimals;
never executed: return d->decimals;
0
878}-
879-
880void QDoubleSpinBox::setDecimals(int decimals)-
881{-
882 Q_D(QDoubleSpinBox);-
883 d->decimals = qBound(0, decimals, DBL_MAX_10_EXP + DBL_DIG);-
884-
885 setRange(d->actualMin, d->actualMax); // make sure values are rounded-
886 setValue(value());-
887}
never executed: end of block
0
888-
889/*!-
890 This virtual function is used by the spin box whenever it needs to-
891 display the given \a value. The default implementation returns a string-
892 containing \a value printed using QWidget::locale().toString(\a value,-
893 QLatin1Char('f'), decimals()) and will remove the thousand-
894 separator unless setGroupSeparatorShown() is set. Reimplementations may-
895 return anything.-
896-
897 Note: QDoubleSpinBox does not call this function for-
898 specialValueText() and that neither prefix() nor suffix() should-
899 be included in the return value.-
900-
901 If you reimplement this, you may also need to reimplement-
902 valueFromText().-
903-
904 \sa valueFromText(), QLocale::groupSeparator()-
905*/-
906-
907-
908QString QDoubleSpinBox::textFromValue(double value) const-
909{-
910 Q_D(const QDoubleSpinBox);-
911 QString str = locale().toString(value, 'f', d->decimals);-
912 if (!d->showGroupSeparator && qAbs(value) >= 1000.0)
!d->showGroupSeparatorDescription
TRUEnever evaluated
FALSEnever evaluated
qAbs(value) >= 1000.0Description
TRUEnever evaluated
FALSEnever evaluated
0
913 str.remove(locale().groupSeparator());
never executed: str.remove(locale().groupSeparator());
0
914-
915 return str;
never executed: return str;
0
916}-
917-
918/*!-
919 This virtual function is used by the spin box whenever it needs to-
920 interpret \a text entered by the user as a value.-
921-
922 Subclasses that need to display spin box values in a non-numeric-
923 way need to reimplement this function.-
924-
925 Note: QDoubleSpinBox handles specialValueText() separately; this-
926 function is only concerned with the other values.-
927-
928 \sa textFromValue(), validate()-
929*/-
930double QDoubleSpinBox::valueFromText(const QString &text) const-
931{-
932 Q_D(const QDoubleSpinBox);-
933-
934 QString copy = text;-
935 int pos = d->edit->cursorPosition();-
936 QValidator::State state = QValidator::Acceptable;-
937 return d->validateAndInterpret(copy, pos, state).toDouble();
never executed: return d->validateAndInterpret(copy, pos, state).toDouble();
0
938}-
939-
940/*!-
941 \reimp-
942*/-
943QValidator::State QDoubleSpinBox::validate(QString &text, int &pos) const-
944{-
945 Q_D(const QDoubleSpinBox);-
946-
947 QValidator::State state;-
948 d->validateAndInterpret(text, pos, state);-
949 return state;
never executed: return state;
0
950}-
951-
952-
953/*!-
954 \reimp-
955*/-
956void QDoubleSpinBox::fixup(QString &input) const-
957{-
958 input.remove(locale().groupSeparator());-
959}
never executed: end of block
0
960-
961// --- QSpinBoxPrivate ----
962-
963/*!-
964 \internal-
965 Constructs a QSpinBoxPrivate object-
966*/-
967-
968QSpinBoxPrivate::QSpinBoxPrivate()-
969{-
970 minimum = QVariant((int)0);-
971 maximum = QVariant((int)99);-
972 value = minimum;-
973 displayIntegerBase = 10;-
974 singleStep = QVariant((int)1);-
975 type = QVariant::Int;-
976}
never executed: end of block
0
977-
978/*!-
979 \internal-
980 \reimp-
981*/-
982-
983void QSpinBoxPrivate::emitSignals(EmitPolicy ep, const QVariant &old)-
984{-
985 Q_Q(QSpinBox);-
986 if (ep != NeverEmit) {
ep != NeverEmitDescription
TRUEnever evaluated
FALSEnever evaluated
0
987 pendingEmit = false;-
988 if (ep == AlwaysEmit || value != old) {
ep == AlwaysEmitDescription
TRUEnever evaluated
FALSEnever evaluated
value != oldDescription
TRUEnever evaluated
FALSEnever evaluated
0
989 emit q->valueChanged(edit->displayText());-
990 emit q->valueChanged(value.toInt());-
991 }
never executed: end of block
0
992 }
never executed: end of block
0
993}
never executed: end of block
0
994-
995/*!-
996 \internal-
997 \reimp-
998*/-
999-
1000QString QSpinBoxPrivate::textFromValue(const QVariant &value) const-
1001{-
1002 Q_Q(const QSpinBox);-
1003 return q->textFromValue(value.toInt());
never executed: return q->textFromValue(value.toInt());
0
1004}-
1005/*!-
1006 \internal-
1007 \reimp-
1008*/-
1009-
1010QVariant QSpinBoxPrivate::valueFromText(const QString &text) const-
1011{-
1012 Q_Q(const QSpinBox);-
1013-
1014 return QVariant(q->valueFromText(text));
never executed: return QVariant(q->valueFromText(text));
0
1015}-
1016-
1017-
1018/*!-
1019 \internal Multi purpose function that parses input, sets state to-
1020 the appropriate state and returns the value it will be interpreted-
1021 as.-
1022*/-
1023-
1024QVariant QSpinBoxPrivate::validateAndInterpret(QString &input, int &pos,-
1025 QValidator::State &state) const-
1026{-
1027 if (cachedText == input && !input.isEmpty()) {
cachedText == inputDescription
TRUEnever evaluated
FALSEnever evaluated
!input.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
1028 state = cachedState;-
1029 QSBDEBUG() << "cachedText was '" << cachedText << "' state was "
dead code: QMessageLogger(__FILE__, 1029, __PRETTY_FUNCTION__).debug() << "cachedText was '" << cachedText << "' state was " << state << " and value was " << cachedValue;
-
1030 << state << " and value was " << cachedValue;
dead code: QMessageLogger(__FILE__, 1029, __PRETTY_FUNCTION__).debug() << "cachedText was '" << cachedText << "' state was " << state << " and value was " << cachedValue;
-
1031-
1032 return cachedValue;
never executed: return cachedValue;
0
1033 }-
1034 const int max = maximum.toInt();-
1035 const int min = minimum.toInt();-
1036-
1037 QString copy = stripped(input, &pos);-
1038 QSBDEBUG() << "input" << input << "copy" << copy;
dead code: QMessageLogger(__FILE__, 1038, __PRETTY_FUNCTION__).debug() << "input" << input << "copy" << copy;
-
1039 state = QValidator::Acceptable;-
1040 int num = min;-
1041-
1042 if (max != min && (copy.isEmpty()
max != minDescription
TRUEnever evaluated
FALSEnever evaluated
copy.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
1043 || (min < 0 && copy == QLatin1String("-"))
min < 0Description
TRUEnever evaluated
FALSEnever evaluated
copy == QLatin1String("-")Description
TRUEnever evaluated
FALSEnever evaluated
0
1044 || (max >= 0 && copy == QLatin1String("+")))) {
max >= 0Description
TRUEnever evaluated
FALSEnever evaluated
copy == QLatin1String("+")Description
TRUEnever evaluated
FALSEnever evaluated
0
1045 state = QValidator::Intermediate;-
1046 QSBDEBUG() << __FILE__ << __LINE__<< "num is set to" << num;
dead code: QMessageLogger(__FILE__, 1046, __PRETTY_FUNCTION__).debug() << __FILE__ << 1046<< "num is set to" << num;
-
1047 } else if (copy.startsWith(QLatin1Char('-')) && min >= 0) {
never executed: end of block
copy.startsWit...tin1Char('-'))Description
TRUEnever evaluated
FALSEnever evaluated
min >= 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1048 state = QValidator::Invalid; // special-case -0 will be interpreted as 0 and thus not be invalid with a range from 0-100-
1049 } else {
never executed: end of block
0
1050 bool ok = false;-
1051 if (displayIntegerBase != 10) {
displayIntegerBase != 10Description
TRUEnever evaluated
FALSEnever evaluated
0
1052 num = copy.toInt(&ok, displayIntegerBase);-
1053 } else {
never executed: end of block
0
1054 num = locale.toInt(copy, &ok);-
1055 if (!ok && copy.contains(locale.groupSeparator()) && (max >= 1000 || min <= -1000)) {
!okDescription
TRUEnever evaluated
FALSEnever evaluated
copy.contains(...upSeparator())Description
TRUEnever evaluated
FALSEnever evaluated
max >= 1000Description
TRUEnever evaluated
FALSEnever evaluated
min <= -1000Description
TRUEnever evaluated
FALSEnever evaluated
0
1056 QString copy2 = copy;-
1057 copy2.remove(locale.groupSeparator());-
1058 num = locale.toInt(copy2, &ok);-
1059 }
never executed: end of block
0
1060 }
never executed: end of block
0
1061 QSBDEBUG() << __FILE__ << __LINE__<< "num is set to" << num;
dead code: QMessageLogger(__FILE__, 1061, __PRETTY_FUNCTION__).debug() << __FILE__ << 1061<< "num is set to" << num;
-
1062 if (!ok) {
!okDescription
TRUEnever evaluated
FALSEnever evaluated
0
1063 state = QValidator::Invalid;-
1064 } else if (num >= min && num <= max) {
never executed: end of block
num >= minDescription
TRUEnever evaluated
FALSEnever evaluated
num <= maxDescription
TRUEnever evaluated
FALSEnever evaluated
0
1065 state = QValidator::Acceptable;-
1066 } else if (max == min) {
never executed: end of block
max == minDescription
TRUEnever evaluated
FALSEnever evaluated
0
1067 state = QValidator::Invalid;-
1068 } else {
never executed: end of block
0
1069 if ((num >= 0 && num > max) || (num < 0 && num < min)) {
num >= 0Description
TRUEnever evaluated
FALSEnever evaluated
num > maxDescription
TRUEnever evaluated
FALSEnever evaluated
num < 0Description
TRUEnever evaluated
FALSEnever evaluated
num < minDescription
TRUEnever evaluated
FALSEnever evaluated
0
1070 state = QValidator::Invalid;-
1071 QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Invalid";
dead code: QMessageLogger(__FILE__, 1071, __PRETTY_FUNCTION__).debug() << __FILE__ << 1071<< "state is set to Invalid";
-
1072 } else {
never executed: end of block
0
1073 state = QValidator::Intermediate;-
1074 QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Intermediate";
dead code: QMessageLogger(__FILE__, 1074, __PRETTY_FUNCTION__).debug() << __FILE__ << 1074<< "state is set to Intermediate";
-
1075 }
never executed: end of block
0
1076 }-
1077 }-
1078 if (state != QValidator::Acceptable)
state != QVali...or::AcceptableDescription
TRUEnever evaluated
FALSEnever evaluated
0
1079 num = max > 0 ? min : max;
never executed: num = max > 0 ? min : max;
max > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1080 input = prefix + copy + suffix;-
1081 cachedText = input;-
1082 cachedState = state;-
1083 cachedValue = QVariant((int)num);-
1084-
1085 QSBDEBUG() << "cachedText is set to '" << cachedText << "' state is set to "
dead code: QMessageLogger(__FILE__, 1085, __PRETTY_FUNCTION__).debug() << "cachedText is set to '" << cachedText << "' state is set to " << state << " and value is set to " << cachedValue;
-
1086 << state << " and value is set to " << cachedValue;
dead code: QMessageLogger(__FILE__, 1085, __PRETTY_FUNCTION__).debug() << "cachedText is set to '" << cachedText << "' state is set to " << state << " and value is set to " << cachedValue;
-
1087 return cachedValue;
never executed: return cachedValue;
0
1088}-
1089-
1090// --- QDoubleSpinBoxPrivate ----
1091-
1092/*!-
1093 \internal-
1094 Constructs a QSpinBoxPrivate object-
1095*/-
1096-
1097QDoubleSpinBoxPrivate::QDoubleSpinBoxPrivate()-
1098{-
1099 actualMin = 0.0;-
1100 actualMax = 99.99;-
1101 minimum = QVariant(actualMin);-
1102 maximum = QVariant(actualMax);-
1103 value = minimum;-
1104 singleStep = QVariant(1.0);-
1105 decimals = 2;-
1106 type = QVariant::Double;-
1107}
never executed: end of block
0
1108-
1109/*!-
1110 \internal-
1111 \reimp-
1112*/-
1113-
1114void QDoubleSpinBoxPrivate::emitSignals(EmitPolicy ep, const QVariant &old)-
1115{-
1116 Q_Q(QDoubleSpinBox);-
1117 if (ep != NeverEmit) {
ep != NeverEmitDescription
TRUEnever evaluated
FALSEnever evaluated
0
1118 pendingEmit = false;-
1119 if (ep == AlwaysEmit || value != old) {
ep == AlwaysEmitDescription
TRUEnever evaluated
FALSEnever evaluated
value != oldDescription
TRUEnever evaluated
FALSEnever evaluated
0
1120 emit q->valueChanged(edit->displayText());-
1121 emit q->valueChanged(value.toDouble());-
1122 }
never executed: end of block
0
1123 }
never executed: end of block
0
1124}
never executed: end of block
0
1125-
1126-
1127/*!-
1128 \internal-
1129 \reimp-
1130*/-
1131QVariant QDoubleSpinBoxPrivate::valueFromText(const QString &f) const-
1132{-
1133 Q_Q(const QDoubleSpinBox);-
1134 return QVariant(q->valueFromText(f));
never executed: return QVariant(q->valueFromText(f));
0
1135}-
1136-
1137/*!-
1138 \internal-
1139 Rounds to a double value that is restricted to decimals.-
1140 E.g. // decimals = 2-
1141-
1142 round(5.555) => 5.56-
1143 */-
1144-
1145double QDoubleSpinBoxPrivate::round(double value) const-
1146{-
1147 return QString::number(value, 'f', decimals).toDouble();
never executed: return QString::number(value, 'f', decimals).toDouble();
0
1148}-
1149-
1150-
1151/*!-
1152 \internal Multi purpose function that parses input, sets state to-
1153 the appropriate state and returns the value it will be interpreted-
1154 as.-
1155*/-
1156-
1157QVariant QDoubleSpinBoxPrivate::validateAndInterpret(QString &input, int &pos,-
1158 QValidator::State &state) const-
1159{-
1160 if (cachedText == input && !input.isEmpty()) {
cachedText == inputDescription
TRUEnever evaluated
FALSEnever evaluated
!input.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
1161 state = cachedState;-
1162 QSBDEBUG() << "cachedText was '" << cachedText << "' state was "
dead code: QMessageLogger(__FILE__, 1162, __PRETTY_FUNCTION__).debug() << "cachedText was '" << cachedText << "' state was " << state << " and value was " << cachedValue;
-
1163 << state << " and value was " << cachedValue;
dead code: QMessageLogger(__FILE__, 1162, __PRETTY_FUNCTION__).debug() << "cachedText was '" << cachedText << "' state was " << state << " and value was " << cachedValue;
-
1164 return cachedValue;
never executed: return cachedValue;
0
1165 }-
1166 const double max = maximum.toDouble();-
1167 const double min = minimum.toDouble();-
1168-
1169 QString copy = stripped(input, &pos);-
1170 QSBDEBUG() << "input" << input << "copy" << copy;
dead code: QMessageLogger(__FILE__, 1170, __PRETTY_FUNCTION__).debug() << "input" << input << "copy" << copy;
-
1171 int len = copy.size();-
1172 double num = min;-
1173 const bool plus = max >= 0;-
1174 const bool minus = min <= 0;-
1175-
1176 switch (len) {-
1177 case 0:
never executed: case 0:
0
1178 state = max != min ? QValidator::Intermediate : QValidator::Invalid;
max != minDescription
TRUEnever evaluated
FALSEnever evaluated
0
1179 goto end;
never executed: goto end;
0
1180 case 1:
never executed: case 1:
0
1181 if (copy.at(0) == locale.decimalPoint()
copy.at(0) == ...decimalPoint()Description
TRUEnever evaluated
FALSEnever evaluated
0
1182 || (plus && copy.at(0) == QLatin1Char('+'))
plusDescription
TRUEnever evaluated
FALSEnever evaluated
copy.at(0) == QLatin1Char('+')Description
TRUEnever evaluated
FALSEnever evaluated
0
1183 || (minus && copy.at(0) == QLatin1Char('-'))) {
minusDescription
TRUEnever evaluated
FALSEnever evaluated
copy.at(0) == QLatin1Char('-')Description
TRUEnever evaluated
FALSEnever evaluated
0
1184 state = QValidator::Intermediate;-
1185 goto end;
never executed: goto end;
0
1186 }-
1187 break;
never executed: break;
0
1188 case 2:
never executed: case 2:
0
1189 if (copy.at(1) == locale.decimalPoint()
copy.at(1) == ...decimalPoint()Description
TRUEnever evaluated
FALSEnever evaluated
0
1190 && ((plus && copy.at(0) == QLatin1Char('+')) || (minus && copy.at(0) == QLatin1Char('-')))) {
plusDescription
TRUEnever evaluated
FALSEnever evaluated
copy.at(0) == QLatin1Char('+')Description
TRUEnever evaluated
FALSEnever evaluated
minusDescription
TRUEnever evaluated
FALSEnever evaluated
copy.at(0) == QLatin1Char('-')Description
TRUEnever evaluated
FALSEnever evaluated
0
1191 state = QValidator::Intermediate;-
1192 goto end;
never executed: goto end;
0
1193 }-
1194 break;
never executed: break;
0
1195 default: break;
never executed: break;
never executed: default:
0
1196 }-
1197-
1198 if (copy.at(0) == locale.groupSeparator()) {
copy.at(0) == ...oupSeparator()Description
TRUEnever evaluated
FALSEnever evaluated
0
1199 QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Invalid";
dead code: QMessageLogger(__FILE__, 1199, __PRETTY_FUNCTION__).debug() << __FILE__ << 1199<< "state is set to Invalid";
-
1200 state = QValidator::Invalid;-
1201 goto end;
never executed: goto end;
0
1202 } else if (len > 1) {
len > 1Description
TRUEnever evaluated
FALSEnever evaluated
0
1203 const int dec = copy.indexOf(locale.decimalPoint());-
1204 if (dec != -1) {
dec != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1205 if (dec + 1 < copy.size() && copy.at(dec + 1) == locale.decimalPoint() && pos == dec + 1) {
dec + 1 < copy.size()Description
TRUEnever evaluated
FALSEnever evaluated
copy.at(dec + ...decimalPoint()Description
TRUEnever evaluated
FALSEnever evaluated
pos == dec + 1Description
TRUEnever evaluated
FALSEnever evaluated
0
1206 copy.remove(dec + 1, 1); // typing a delimiter when you are on the delimiter-
1207 } // should be treated as typing right arrow
never executed: end of block
0
1208-
1209 if (copy.size() - dec > decimals + 1) {
copy.size() - ...> decimals + 1Description
TRUEnever evaluated
FALSEnever evaluated
0
1210 QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Invalid";
dead code: QMessageLogger(__FILE__, 1210, __PRETTY_FUNCTION__).debug() << __FILE__ << 1210<< "state is set to Invalid";
-
1211 state = QValidator::Invalid;-
1212 goto end;
never executed: goto end;
0
1213 }-
1214 for (int i=dec + 1; i<copy.size(); ++i) {
i<copy.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
1215 if (copy.at(i).isSpace() || copy.at(i) == locale.groupSeparator()) {
copy.at(i).isSpace()Description
TRUEnever evaluated
FALSEnever evaluated
copy.at(i) == ...oupSeparator()Description
TRUEnever evaluated
FALSEnever evaluated
0
1216 QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Invalid";
dead code: QMessageLogger(__FILE__, 1216, __PRETTY_FUNCTION__).debug() << __FILE__ << 1216<< "state is set to Invalid";
-
1217 state = QValidator::Invalid;-
1218 goto end;
never executed: goto end;
0
1219 }-
1220 }
never executed: end of block
0
1221 } else {
never executed: end of block
0
1222 const QChar last = copy.at(len - 1);-
1223 const QChar secondLast = copy.at(len - 2);-
1224 if ((last == locale.groupSeparator() || last.isSpace())
last == locale...oupSeparator()Description
TRUEnever evaluated
FALSEnever evaluated
last.isSpace()Description
TRUEnever evaluated
FALSEnever evaluated
0
1225 && (secondLast == locale.groupSeparator() || secondLast.isSpace())) {
secondLast == ...oupSeparator()Description
TRUEnever evaluated
FALSEnever evaluated
secondLast.isSpace()Description
TRUEnever evaluated
FALSEnever evaluated
0
1226 state = QValidator::Invalid;-
1227 QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Invalid";
dead code: QMessageLogger(__FILE__, 1227, __PRETTY_FUNCTION__).debug() << __FILE__ << 1227<< "state is set to Invalid";
-
1228 goto end;
never executed: goto end;
0
1229 } else if (last.isSpace() && (!locale.groupSeparator().isSpace() || secondLast.isSpace())) {
last.isSpace()Description
TRUEnever evaluated
FALSEnever evaluated
!locale.groupS...or().isSpace()Description
TRUEnever evaluated
FALSEnever evaluated
secondLast.isSpace()Description
TRUEnever evaluated
FALSEnever evaluated
0
1230 state = QValidator::Invalid;-
1231 QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Invalid";
dead code: QMessageLogger(__FILE__, 1231, __PRETTY_FUNCTION__).debug() << __FILE__ << 1231<< "state is set to Invalid";
-
1232 goto end;
never executed: goto end;
0
1233 }-
1234 }
never executed: end of block
0
1235 }-
1236-
1237 {-
1238 bool ok = false;-
1239 num = locale.toDouble(copy, &ok);-
1240 QSBDEBUG() << __FILE__ << __LINE__ << locale << copy << num << ok;
dead code: QMessageLogger(__FILE__, 1240, __PRETTY_FUNCTION__).debug() << __FILE__ << 1240 << locale << copy << num << ok;
-
1241-
1242 if (!ok) {
!okDescription
TRUEnever evaluated
FALSEnever evaluated
0
1243 if (locale.groupSeparator().isPrint()) {
locale.groupSe...or().isPrint()Description
TRUEnever evaluated
FALSEnever evaluated
0
1244 if (max < 1000 && min > -1000 && copy.contains(locale.groupSeparator())) {
max < 1000Description
TRUEnever evaluated
FALSEnever evaluated
min > -1000Description
TRUEnever evaluated
FALSEnever evaluated
copy.contains(...upSeparator())Description
TRUEnever evaluated
FALSEnever evaluated
0
1245 state = QValidator::Invalid;-
1246 QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Invalid";
dead code: QMessageLogger(__FILE__, 1246, __PRETTY_FUNCTION__).debug() << __FILE__ << 1246<< "state is set to Invalid";
-
1247 goto end;
never executed: goto end;
0
1248 }-
1249-
1250 const int len = copy.size();-
1251 for (int i=0; i<len- 1; ++i) {
i<len- 1Description
TRUEnever evaluated
FALSEnever evaluated
0
1252 if (copy.at(i) == locale.groupSeparator() && copy.at(i + 1) == locale.groupSeparator()) {
copy.at(i) == ...oupSeparator()Description
TRUEnever evaluated
FALSEnever evaluated
copy.at(i + 1)...oupSeparator()Description
TRUEnever evaluated
FALSEnever evaluated
0
1253 QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Invalid";
dead code: QMessageLogger(__FILE__, 1253, __PRETTY_FUNCTION__).debug() << __FILE__ << 1253<< "state is set to Invalid";
-
1254 state = QValidator::Invalid;-
1255 goto end;
never executed: goto end;
0
1256 }-
1257 }
never executed: end of block
0
1258-
1259 QString copy2 = copy;-
1260 copy2.remove(locale.groupSeparator());-
1261 num = locale.toDouble(copy2, &ok);-
1262 QSBDEBUG() << locale.groupSeparator() << num << copy2 << ok;
dead code: QMessageLogger(__FILE__, 1262, __PRETTY_FUNCTION__).debug() << locale.groupSeparator() << num << copy2 << ok;
-
1263-
1264 if (!ok) {
!okDescription
TRUEnever evaluated
FALSEnever evaluated
0
1265 state = QValidator::Invalid;-
1266 QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Invalid";
dead code: QMessageLogger(__FILE__, 1266, __PRETTY_FUNCTION__).debug() << __FILE__ << 1266<< "state is set to Invalid";
-
1267 goto end;
never executed: goto end;
0
1268 }-
1269 }
never executed: end of block
0
1270 }
never executed: end of block
0
1271-
1272 if (!ok) {
!okDescription
TRUEnever evaluated
FALSEnever evaluated
0
1273 state = QValidator::Invalid;-
1274 QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Invalid";
dead code: QMessageLogger(__FILE__, 1274, __PRETTY_FUNCTION__).debug() << __FILE__ << 1274<< "state is set to Invalid";
-
1275 } else if (num >= min && num <= max) {
never executed: end of block
num >= minDescription
TRUEnever evaluated
FALSEnever evaluated
num <= maxDescription
TRUEnever evaluated
FALSEnever evaluated
0
1276 state = QValidator::Acceptable;-
1277 QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Acceptable";
dead code: QMessageLogger(__FILE__, 1277, __PRETTY_FUNCTION__).debug() << __FILE__ << 1277<< "state is set to Acceptable";
-
1278 } else if (max == min) { // when max and min is the same the only non-Invalid input is max (or min)
never executed: end of block
max == minDescription
TRUEnever evaluated
FALSEnever evaluated
0
1279 state = QValidator::Invalid;-
1280 QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Invalid";
dead code: QMessageLogger(__FILE__, 1280, __PRETTY_FUNCTION__).debug() << __FILE__ << 1280<< "state is set to Invalid";
-
1281 } else {
never executed: end of block
0
1282 if ((num >= 0 && num > max) || (num < 0 && num < min)) {
num >= 0Description
TRUEnever evaluated
FALSEnever evaluated
num > maxDescription
TRUEnever evaluated
FALSEnever evaluated
num < 0Description
TRUEnever evaluated
FALSEnever evaluated
num < minDescription
TRUEnever evaluated
FALSEnever evaluated
0
1283 state = QValidator::Invalid;-
1284 QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Invalid";
dead code: QMessageLogger(__FILE__, 1284, __PRETTY_FUNCTION__).debug() << __FILE__ << 1284<< "state is set to Invalid";
-
1285 } else {
never executed: end of block
0
1286 state = QValidator::Intermediate;-
1287 QSBDEBUG() << __FILE__ << __LINE__<< "state is set to Intermediate";
dead code: QMessageLogger(__FILE__, 1287, __PRETTY_FUNCTION__).debug() << __FILE__ << 1287<< "state is set to Intermediate";
-
1288 }
never executed: end of block
0
1289 }-
1290 }-
1291-
1292end:
code before this statement never executed: end:
0
1293 if (state != QValidator::Acceptable) {
state != QVali...or::AcceptableDescription
TRUEnever evaluated
FALSEnever evaluated
0
1294 num = max > 0 ? min : max;
max > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1295 }
never executed: end of block
0
1296-
1297 input = prefix + copy + suffix;-
1298 cachedText = input;-
1299 cachedState = state;-
1300 cachedValue = QVariant(num);-
1301 return QVariant(num);
never executed: return QVariant(num);
0
1302}-
1303-
1304/*-
1305 \internal-
1306 \reimp-
1307*/-
1308-
1309QString QDoubleSpinBoxPrivate::textFromValue(const QVariant &f) const-
1310{-
1311 Q_Q(const QDoubleSpinBox);-
1312 return q->textFromValue(f.toDouble());
never executed: return q->textFromValue(f.toDouble());
0
1313}-
1314-
1315/*! \reimp */-
1316bool QSpinBox::event(QEvent *event)-
1317{-
1318 Q_D(QSpinBox);-
1319 if (event->type() == QEvent::StyleChange
event->type() ...t::StyleChangeDescription
TRUEnever evaluated
FALSEnever evaluated
0
1320#ifdef Q_OS_MAC-
1321 || event->type() == QEvent::MacSizeChange-
1322#endif-
1323 )-
1324 d->setLayoutItemMargins(QStyle::SE_SpinBoxLayoutItem);
never executed: d->setLayoutItemMargins(QStyle::SE_SpinBoxLayoutItem);
0
1325 return QAbstractSpinBox::event(event);
never executed: return QAbstractSpinBox::event(event);
0
1326}-
1327-
1328QT_END_NAMESPACE-
1329-
1330#include "moc_qspinbox.cpp"-
1331-
1332#endif // QT_NO_SPINBOX-
Source codeSwitch to Preprocessed file

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