OpenCoverage

qabstractspinbox.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/widgets/widgets/qabstractspinbox.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 <qplatformdefs.h>-
41#include <private/qabstractspinbox_p.h>-
42#include <private/qdatetimeparser_p.h>-
43#include <private/qlineedit_p.h>-
44#include <qabstractspinbox.h>-
45-
46#ifndef QT_NO_SPINBOX-
47-
48#include <qapplication.h>-
49#include <qstylehints.h>-
50#include <qclipboard.h>-
51#include <qdatetime.h>-
52#include <qdatetimeedit.h>-
53#include <qevent.h>-
54#include <qmenu.h>-
55#include <qpainter.h>-
56#include <qpalette.h>-
57#include <qstylepainter.h>-
58#include <qdebug.h>-
59#ifndef QT_NO_ACCESSIBILITY-
60# include <qaccessible.h>-
61#endif-
62-
63-
64//#define QABSTRACTSPINBOX_QSBDEBUG-
65#ifdef QABSTRACTSPINBOX_QSBDEBUG-
66# define QASBDEBUG qDebug-
67#else-
68# define QASBDEBUG if (false) qDebug-
69#endif-
70-
71QT_BEGIN_NAMESPACE-
72-
73/*!-
74 \class QAbstractSpinBox-
75 \brief The QAbstractSpinBox class provides a spinbox and a line edit to-
76 display values.-
77-
78 \ingroup abstractwidgets-
79 \inmodule QtWidgets-
80-
81 The class is designed as a common super class for widgets like-
82 QSpinBox, QDoubleSpinBox and QDateTimeEdit-
83-
84 Here are the main properties of the class:-
85-
86 \list 1-
87-
88 \li \l text: The text that is displayed in the QAbstractSpinBox.-
89-
90 \li \l alignment: The alignment of the text in the QAbstractSpinBox.-
91-
92 \li \l wrapping: Whether the QAbstractSpinBox wraps from the-
93 minimum value to the maximum value and vica versa.-
94-
95 \endlist-
96-
97 QAbstractSpinBox provides a virtual stepBy() function that is-
98 called whenever the user triggers a step. This function takes an-
99 integer value to signify how many steps were taken. E.g. Pressing-
100 Qt::Key_Down will trigger a call to stepBy(-1).-
101-
102 QAbstractSpinBox also provide a virtual function stepEnabled() to-
103 determine whether stepping up/down is allowed at any point. This-
104 function returns a bitset of StepEnabled.-
105-
106 \sa QAbstractSlider, QSpinBox, QDoubleSpinBox, QDateTimeEdit,-
107 {Spin Boxes Example}-
108*/-
109-
110/*!-
111 \enum QAbstractSpinBox::StepEnabledFlag-
112-
113 \value StepNone-
114 \value StepUpEnabled-
115 \value StepDownEnabled-
116*/-
117-
118/*!-
119 \fn void QAbstractSpinBox::editingFinished()-
120-
121 This signal is emitted editing is finished. This happens when the-
122 spinbox loses focus and when enter is pressed.-
123*/-
124-
125/*!-
126 Constructs an abstract spinbox with the given \a parent with default-
127 \l wrapping, and \l alignment properties.-
128*/-
129-
130QAbstractSpinBox::QAbstractSpinBox(QWidget *parent)-
131 : QWidget(*new QAbstractSpinBoxPrivate, parent, 0)-
132{-
133 Q_D(QAbstractSpinBox);-
134 d->init();-
135}
never executed: end of block
0
136-
137/*!-
138 \internal-
139*/-
140QAbstractSpinBox::QAbstractSpinBox(QAbstractSpinBoxPrivate &dd, QWidget *parent)-
141 : QWidget(dd, parent, 0)-
142{-
143 Q_D(QAbstractSpinBox);-
144 d->init();-
145}
never executed: end of block
0
146-
147/*!-
148 Called when the QAbstractSpinBox is destroyed.-
149*/-
150-
151QAbstractSpinBox::~QAbstractSpinBox()-
152{-
153}-
154-
155/*!-
156 \enum QAbstractSpinBox::ButtonSymbols-
157-
158 This enum type describes the symbols that can be displayed on the buttons-
159 in a spin box.-
160-
161 \inlineimage qspinbox-updown.png-
162 \inlineimage qspinbox-plusminus.png-
163-
164 \value UpDownArrows Little arrows in the classic style.-
165 \value PlusMinus \b{+} and \b{-} symbols.-
166 \value NoButtons Don't display buttons.-
167-
168 \sa QAbstractSpinBox::buttonSymbols-
169*/-
170-
171/*!-
172 \property QAbstractSpinBox::buttonSymbols-
173-
174 \brief the current button symbol mode-
175-
176 The possible values can be either \c UpDownArrows or \c PlusMinus.-
177 The default is \c UpDownArrows.-
178-
179 Note that some styles might render PlusMinus and UpDownArrows-
180 identically.-
181-
182 \sa ButtonSymbols-
183*/-
184-
185QAbstractSpinBox::ButtonSymbols QAbstractSpinBox::buttonSymbols() const-
186{-
187 Q_D(const QAbstractSpinBox);-
188 return d->buttonSymbols;
never executed: return d->buttonSymbols;
0
189}-
190-
191void QAbstractSpinBox::setButtonSymbols(ButtonSymbols buttonSymbols)-
192{-
193 Q_D(QAbstractSpinBox);-
194 if (d->buttonSymbols != buttonSymbols) {
d->buttonSymbo... buttonSymbolsDescription
TRUEnever evaluated
FALSEnever evaluated
0
195 d->buttonSymbols = buttonSymbols;-
196 d->updateEditFieldGeometry();-
197 update();-
198 }
never executed: end of block
0
199}
never executed: end of block
0
200-
201/*!-
202 \property QAbstractSpinBox::text-
203-
204 \brief the spin box's text, including any prefix and suffix-
205-
206 There is no default text.-
207*/-
208-
209QString QAbstractSpinBox::text() const-
210{-
211 return lineEdit()->displayText();
never executed: return lineEdit()->displayText();
0
212}-
213-
214-
215/*!-
216 \property QAbstractSpinBox::specialValueText-
217 \brief the special-value text-
218-
219 If set, the spin box will display this text instead of a numeric-
220 value whenever the current value is equal to minimum(). Typical use-
221 is to indicate that this choice has a special (default) meaning.-
222-
223 For example, if your spin box allows the user to choose a scale factor-
224 (or zoom level) for displaying an image, and your application is able-
225 to automatically choose one that will enable the image to fit completely-
226 within the display window, you can set up the spin box like this:-
227-
228 \snippet widgets/spinboxes/window.cpp 3-
229-
230 The user will then be able to choose a scale from 1% to 1000%-
231 or select "Auto" to leave it up to the application to choose. Your code-
232 must then interpret the spin box value of 0 as a request from the user-
233 to scale the image to fit inside the window.-
234-
235 All values are displayed with the prefix and suffix (if set), \e-
236 except for the special value, which only shows the special value-
237 text. This special text is passed in the QSpinBox::valueChanged()-
238 signal that passes a QString.-
239-
240 To turn off the special-value text display, call this function-
241 with an empty string. The default is no special-value text, i.e.-
242 the numeric value is shown as usual.-
243-
244 If no special-value text is set, specialValueText() returns an-
245 empty string.-
246*/-
247-
248QString QAbstractSpinBox::specialValueText() const-
249{-
250 Q_D(const QAbstractSpinBox);-
251 return d->specialValueText;
never executed: return d->specialValueText;
0
252}-
253-
254void QAbstractSpinBox::setSpecialValueText(const QString &specialValueText)-
255{-
256 Q_D(QAbstractSpinBox);-
257-
258 d->specialValueText = specialValueText;-
259 d->cachedSizeHint = QSize(); // minimumSizeHint doesn't care about specialValueText-
260 d->clearCache();-
261 d->updateEdit();-
262}
never executed: end of block
0
263-
264/*!-
265 \property QAbstractSpinBox::wrapping-
266-
267 \brief whether the spin box is circular.-
268-
269 If wrapping is true stepping up from maximum() value will take you-
270 to the minimum() value and vica versa. Wrapping only make sense if-
271 you have minimum() and maximum() values set.-
272-
273 \snippet code/src_gui_widgets_qabstractspinbox.cpp 0-
274-
275 \sa QSpinBox::minimum(), QSpinBox::maximum()-
276*/-
277-
278bool QAbstractSpinBox::wrapping() const-
279{-
280 Q_D(const QAbstractSpinBox);-
281 return d->wrapping;
never executed: return d->wrapping;
0
282}-
283-
284void QAbstractSpinBox::setWrapping(bool wrapping)-
285{-
286 Q_D(QAbstractSpinBox);-
287 d->wrapping = wrapping;-
288}
never executed: end of block
0
289-
290-
291/*!-
292 \property QAbstractSpinBox::readOnly-
293 \brief whether the spin box is read only.-
294-
295 In read-only mode, the user can still copy the text to the-
296 clipboard, or drag and drop the text;-
297 but cannot edit it.-
298-
299 The QLineEdit in the QAbstractSpinBox does not show a cursor in-
300 read-only mode.-
301-
302 \sa QLineEdit::readOnly-
303*/-
304-
305bool QAbstractSpinBox::isReadOnly() const-
306{-
307 Q_D(const QAbstractSpinBox);-
308 return d->readOnly;
never executed: return d->readOnly;
0
309}-
310-
311void QAbstractSpinBox::setReadOnly(bool enable)-
312{-
313 Q_D(QAbstractSpinBox);-
314 d->readOnly = enable;-
315 d->edit->setReadOnly(enable);-
316 QEvent event(QEvent::ReadOnlyChange);-
317 QApplication::sendEvent(this, &event);-
318 update();-
319}
never executed: end of block
0
320-
321/*!-
322 \property QAbstractSpinBox::keyboardTracking-
323 \brief whether keyboard tracking is enabled for the spinbox.-
324 \since 4.3-
325-
326 If keyboard tracking is enabled (the default), the spinbox-
327 emits the valueChanged() signal while the new value is being-
328 entered from the keyboard.-
329-
330 E.g. when the user enters the value 600 by typing 6, 0, and 0,-
331 the spinbox emits 3 signals with the values 6, 60, and 600-
332 respectively.-
333-
334 If keyboard tracking is disabled, the spinbox doesn't emit the-
335 valueChanged() signal while typing. It emits the signal later,-
336 when the return key is pressed, when keyboard focus is lost, or-
337 when other spinbox functionality is used, e.g. pressing an arrow-
338 key.-
339*/-
340-
341bool QAbstractSpinBox::keyboardTracking() const-
342{-
343 Q_D(const QAbstractSpinBox);-
344 return d->keyboardTracking;
never executed: return d->keyboardTracking;
0
345}-
346-
347void QAbstractSpinBox::setKeyboardTracking(bool enable)-
348{-
349 Q_D(QAbstractSpinBox);-
350 d->keyboardTracking = enable;-
351}
never executed: end of block
0
352-
353/*!-
354 \property QAbstractSpinBox::frame-
355 \brief whether the spin box draws itself with a frame-
356-
357 If enabled (the default) the spin box draws itself inside a frame,-
358 otherwise the spin box draws itself without any frame.-
359*/-
360-
361bool QAbstractSpinBox::hasFrame() const-
362{-
363 Q_D(const QAbstractSpinBox);-
364 return d->frame;
never executed: return d->frame;
0
365}-
366-
367-
368void QAbstractSpinBox::setFrame(bool enable)-
369{-
370 Q_D(QAbstractSpinBox);-
371 d->frame = enable;-
372 update();-
373 d->updateEditFieldGeometry();-
374}
never executed: end of block
0
375-
376/*!-
377 \property QAbstractSpinBox::accelerated-
378 \brief whether the spin box will accelerate the frequency of the steps when-
379 pressing the step Up/Down buttons.-
380 \since 4.2-
381-
382 If enabled the spin box will increase/decrease the value faster-
383 the longer you hold the button down.-
384*/-
385-
386void QAbstractSpinBox::setAccelerated(bool accelerate)-
387{-
388 Q_D(QAbstractSpinBox);-
389 d->accelerate = accelerate;-
390-
391}
never executed: end of block
0
392bool QAbstractSpinBox::isAccelerated() const-
393{-
394 Q_D(const QAbstractSpinBox);-
395 return d->accelerate;
never executed: return d->accelerate;
0
396}-
397-
398/*!-
399 \property QAbstractSpinBox::showGroupSeparator-
400 \since 5.3-
401-
402-
403 This property holds whether a thousands separator is enabled. By default this-
404 property is false.-
405*/-
406bool QAbstractSpinBox::isGroupSeparatorShown() const-
407{-
408 Q_D(const QAbstractSpinBox);-
409 return d->showGroupSeparator;
never executed: return d->showGroupSeparator;
0
410}-
411-
412void QAbstractSpinBox::setGroupSeparatorShown(bool shown)-
413{-
414 Q_D(QAbstractSpinBox);-
415 if (d->showGroupSeparator == shown)
d->showGroupSeparator == shownDescription
TRUEnever evaluated
FALSEnever evaluated
0
416 return;
never executed: return;
0
417 d->showGroupSeparator = shown;-
418 d->setValue(d->value, EmitIfChanged);-
419 updateGeometry();-
420}
never executed: end of block
0
421-
422/*!-
423 \enum QAbstractSpinBox::CorrectionMode-
424-
425 This enum type describes the mode the spinbox will use to correct-
426 an \l{QValidator::}{Intermediate} value if editing finishes.-
427-
428 \value CorrectToPreviousValue The spinbox will revert to the last-
429 valid value.-
430-
431 \value CorrectToNearestValue The spinbox will revert to the nearest-
432 valid value.-
433-
434 \sa correctionMode-
435*/-
436-
437/*!-
438 \property QAbstractSpinBox::correctionMode-
439 \brief the mode to correct an \l{QValidator::}{Intermediate}-
440 value if editing finishes-
441 \since 4.2-
442-
443 The default mode is QAbstractSpinBox::CorrectToPreviousValue.-
444-
445 \sa acceptableInput, validate(), fixup()-
446*/-
447void QAbstractSpinBox::setCorrectionMode(CorrectionMode correctionMode)-
448{-
449 Q_D(QAbstractSpinBox);-
450 d->correctionMode = correctionMode;-
451-
452}
never executed: end of block
0
453QAbstractSpinBox::CorrectionMode QAbstractSpinBox::correctionMode() const-
454{-
455 Q_D(const QAbstractSpinBox);-
456 return d->correctionMode;
never executed: return d->correctionMode;
0
457}-
458-
459-
460/*!-
461 \property QAbstractSpinBox::acceptableInput-
462 \brief whether the input satisfies the current validation-
463 \since 4.2-
464-
465 \sa validate(), fixup(), correctionMode-
466*/-
467-
468bool QAbstractSpinBox::hasAcceptableInput() const-
469{-
470 Q_D(const QAbstractSpinBox);-
471 return d->edit->hasAcceptableInput();
never executed: return d->edit->hasAcceptableInput();
0
472}-
473-
474/*!-
475 \property QAbstractSpinBox::alignment-
476 \brief the alignment of the spin box-
477-
478 Possible Values are Qt::AlignLeft, Qt::AlignRight, and Qt::AlignHCenter.-
479-
480 By default, the alignment is Qt::AlignLeft-
481-
482 Attempting to set the alignment to an illegal flag combination-
483 does nothing.-
484-
485 \sa Qt::Alignment-
486*/-
487-
488Qt::Alignment QAbstractSpinBox::alignment() const-
489{-
490 Q_D(const QAbstractSpinBox);-
491-
492 return (Qt::Alignment)d->edit->alignment();
never executed: return (Qt::Alignment)d->edit->alignment();
0
493}-
494-
495void QAbstractSpinBox::setAlignment(Qt::Alignment flag)-
496{-
497 Q_D(QAbstractSpinBox);-
498-
499 d->edit->setAlignment(flag);-
500}
never executed: end of block
0
501-
502/*!-
503 Selects all the text in the spinbox except the prefix and suffix.-
504*/-
505-
506void QAbstractSpinBox::selectAll()-
507{-
508 Q_D(QAbstractSpinBox);-
509-
510-
511 if (!d->specialValue()) {
!d->specialValue()Description
TRUEnever evaluated
FALSEnever evaluated
0
512 const int tmp = d->edit->displayText().size() - d->suffix.size();-
513 d->edit->setSelection(tmp, -(tmp - d->prefix.size()));-
514 } else {
never executed: end of block
0
515 d->edit->selectAll();-
516 }
never executed: end of block
0
517}-
518-
519/*!-
520 Clears the lineedit of all text but prefix and suffix.-
521*/-
522-
523void QAbstractSpinBox::clear()-
524{-
525 Q_D(QAbstractSpinBox);-
526-
527 d->edit->setText(d->prefix + d->suffix);-
528 d->edit->setCursorPosition(d->prefix.size());-
529 d->cleared = true;-
530}
never executed: end of block
0
531-
532/*!-
533 Virtual function that determines whether stepping up and down is-
534 legal at any given time.-
535-
536 The up arrow will be painted as disabled unless (stepEnabled() &-
537 StepUpEnabled) != 0.-
538-
539 The default implementation will return (StepUpEnabled|-
540 StepDownEnabled) if wrapping is turned on. Else it will return-
541 StepDownEnabled if value is > minimum() or'ed with StepUpEnabled if-
542 value < maximum().-
543-
544 If you subclass QAbstractSpinBox you will need to reimplement this function.-
545-
546 \sa QSpinBox::minimum(), QSpinBox::maximum(), wrapping()-
547*/-
548-
549-
550QAbstractSpinBox::StepEnabled QAbstractSpinBox::stepEnabled() const-
551{-
552 Q_D(const QAbstractSpinBox);-
553 if (d->readOnly || d->type == QVariant::Invalid)
d->readOnlyDescription
TRUEnever evaluated
FALSEnever evaluated
d->type == QVariant::InvalidDescription
TRUEnever evaluated
FALSEnever evaluated
0
554 return StepNone;
never executed: return StepNone;
0
555 if (d->wrapping)
d->wrappingDescription
TRUEnever evaluated
FALSEnever evaluated
0
556 return StepEnabled(StepUpEnabled | StepDownEnabled);
never executed: return StepEnabled(StepUpEnabled | StepDownEnabled);
0
557 StepEnabled ret = StepNone;-
558 if (d->variantCompare(d->value, d->maximum) < 0) {
d->variantComp...->maximum) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
559 ret |= StepUpEnabled;-
560 }
never executed: end of block
0
561 if (d->variantCompare(d->value, d->minimum) > 0) {
d->variantComp...->minimum) > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
562 ret |= StepDownEnabled;-
563 }
never executed: end of block
0
564 return ret;
never executed: return ret;
0
565}-
566-
567/*!-
568 This virtual function is called by the QAbstractSpinBox to-
569 determine whether \a input is valid. The \a pos parameter indicates-
570 the position in the string. Reimplemented in the various-
571 subclasses.-
572*/-
573-
574QValidator::State QAbstractSpinBox::validate(QString & /* input */, int & /* pos */) const-
575{-
576 return QValidator::Acceptable;
never executed: return QValidator::Acceptable;
0
577}-
578-
579/*!-
580 This virtual function is called by the QAbstractSpinBox if the-
581 \a input is not validated to QValidator::Acceptable when Return is-
582 pressed or interpretText() is called. It will try to change the-
583 text so it is valid. Reimplemented in the various subclasses.-
584*/-
585-
586void QAbstractSpinBox::fixup(QString & /* input */) const-
587{-
588}-
589-
590/*!-
591 Steps up by one linestep-
592 Calling this slot is analogous to calling stepBy(1);-
593 \sa stepBy(), stepDown()-
594*/-
595-
596void QAbstractSpinBox::stepUp()-
597{-
598 stepBy(1);-
599}
never executed: end of block
0
600-
601/*!-
602 Steps down by one linestep-
603 Calling this slot is analogous to calling stepBy(-1);-
604 \sa stepBy(), stepUp()-
605*/-
606-
607void QAbstractSpinBox::stepDown()-
608{-
609 stepBy(-1);-
610}
never executed: end of block
0
611/*!-
612 Virtual function that is called whenever the user triggers a step.-
613 The \a steps parameter indicates how many steps were taken, e.g.-
614 Pressing Qt::Key_Down will trigger a call to stepBy(-1),-
615 whereas pressing Qt::Key_Prior will trigger a call to-
616 stepBy(10).-
617-
618 If you subclass QAbstractSpinBox you must reimplement this-
619 function. Note that this function is called even if the resulting-
620 value will be outside the bounds of minimum and maximum. It's this-
621 function's job to handle these situations.-
622*/-
623-
624void QAbstractSpinBox::stepBy(int steps)-
625{-
626 Q_D(QAbstractSpinBox);-
627-
628 const QVariant old = d->value;-
629 QString tmp = d->edit->displayText();-
630 int cursorPos = d->edit->cursorPosition();-
631 bool dontstep = false;-
632 EmitPolicy e = EmitIfChanged;-
633 if (d->pendingEmit) {
d->pendingEmitDescription
TRUEnever evaluated
FALSEnever evaluated
0
634 dontstep = validate(tmp, cursorPos) != QValidator::Acceptable;-
635 d->cleared = false;-
636 d->interpret(NeverEmit);-
637 if (d->value != old)
d->value != oldDescription
TRUEnever evaluated
FALSEnever evaluated
0
638 e = AlwaysEmit;
never executed: e = AlwaysEmit;
0
639 }
never executed: end of block
0
640 if (!dontstep) {
!dontstepDescription
TRUEnever evaluated
FALSEnever evaluated
0
641 d->setValue(d->bound(d->value + (d->singleStep * steps), old, steps), e);-
642 } else if (e == AlwaysEmit) {
never executed: end of block
e == AlwaysEmitDescription
TRUEnever evaluated
FALSEnever evaluated
0
643 d->emitSignals(e, old);-
644 }
never executed: end of block
0
645 selectAll();-
646}
never executed: end of block
0
647-
648/*!-
649 This function returns a pointer to the line edit of the spin box.-
650*/-
651-
652QLineEdit *QAbstractSpinBox::lineEdit() const-
653{-
654 Q_D(const QAbstractSpinBox);-
655-
656 return d->edit;
never executed: return d->edit;
0
657}-
658-
659-
660/*!-
661 \fn void QAbstractSpinBox::setLineEdit(QLineEdit *lineEdit)-
662-
663 Sets the line edit of the spinbox to be \a lineEdit instead of the-
664 current line edit widget. \a lineEdit can not be 0.-
665-
666 QAbstractSpinBox takes ownership of the new lineEdit-
667-
668 If QLineEdit::validator() for the \a lineEdit returns 0, the internal-
669 validator of the spinbox will be set on the line edit.-
670*/-
671-
672void QAbstractSpinBox::setLineEdit(QLineEdit *lineEdit)-
673{-
674 Q_D(QAbstractSpinBox);-
675-
676 if (!lineEdit) {
!lineEditDescription
TRUEnever evaluated
FALSEnever evaluated
0
677 Q_ASSERT(lineEdit);-
678 return;
never executed: return;
0
679 }-
680 delete d->edit;-
681 d->edit = lineEdit;-
682 if (!d->edit->validator())
!d->edit->validator()Description
TRUEnever evaluated
FALSEnever evaluated
0
683 d->edit->setValidator(d->validator);
never executed: d->edit->setValidator(d->validator);
0
684-
685 if (d->edit->parent() != this)
d->edit->parent() != thisDescription
TRUEnever evaluated
FALSEnever evaluated
0
686 d->edit->setParent(this);
never executed: d->edit->setParent(this);
0
687-
688 d->edit->setFrame(false);-
689 d->edit->setFocusProxy(this);-
690 d->edit->setAcceptDrops(false);-
691-
692 if (d->type != QVariant::Invalid) {
d->type != QVariant::InvalidDescription
TRUEnever evaluated
FALSEnever evaluated
0
693 connect(d->edit, SIGNAL(textChanged(QString)),-
694 this, SLOT(_q_editorTextChanged(QString)));-
695 connect(d->edit, SIGNAL(cursorPositionChanged(int,int)),-
696 this, SLOT(_q_editorCursorPositionChanged(int,int)));-
697 }
never executed: end of block
0
698 d->updateEditFieldGeometry();-
699 d->edit->setContextMenuPolicy(Qt::NoContextMenu);-
700 d->edit->d_func()->control->setAccessibleObject(this);-
701-
702 if (isVisible())
isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
703 d->edit->show();
never executed: d->edit->show();
0
704 if (isVisible())
isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
705 d->updateEdit();
never executed: d->updateEdit();
0
706}
never executed: end of block
0
707-
708-
709/*!-
710 This function interprets the text of the spin box. If the value-
711 has changed since last interpretation it will emit signals.-
712*/-
713-
714void QAbstractSpinBox::interpretText()-
715{-
716 Q_D(QAbstractSpinBox);-
717 d->interpret(EmitIfChanged);-
718}
never executed: end of block
0
719-
720/*-
721 Reimplemented in 4.6, so be careful.-
722 */-
723/*!-
724 \reimp-
725*/-
726QVariant QAbstractSpinBox::inputMethodQuery(Qt::InputMethodQuery query) const-
727{-
728 Q_D(const QAbstractSpinBox);-
729 const QVariant lineEditValue = d->edit->inputMethodQuery(query);-
730 switch (query) {-
731 case Qt::ImHints:
never executed: case Qt::ImHints:
0
732 if (const int hints = inputMethodHints())
const int hint...tMethodHints()Description
TRUEnever evaluated
FALSEnever evaluated
0
733 return QVariant(hints | lineEditValue.toInt());
never executed: return QVariant(hints | lineEditValue.toInt());
0
734 break;
never executed: break;
0
735 default:
never executed: default:
0
736 break;
never executed: break;
0
737 }-
738 return lineEditValue;
never executed: return lineEditValue;
0
739}-
740-
741/*!-
742 \reimp-
743*/-
744-
745bool QAbstractSpinBox::event(QEvent *event)-
746{-
747 Q_D(QAbstractSpinBox);-
748 switch (event->type()) {-
749 case QEvent::FontChange:
never executed: case QEvent::FontChange:
0
750 case QEvent::StyleChange:
never executed: case QEvent::StyleChange:
0
751 d->cachedSizeHint = d->cachedMinimumSizeHint = QSize();-
752 break;
never executed: break;
0
753 case QEvent::ApplicationLayoutDirectionChange:
never executed: case QEvent::ApplicationLayoutDirectionChange:
0
754 case QEvent::LayoutDirectionChange:
never executed: case QEvent::LayoutDirectionChange:
0
755 d->updateEditFieldGeometry();-
756 break;
never executed: break;
0
757 case QEvent::HoverEnter:
never executed: case QEvent::HoverEnter:
0
758 case QEvent::HoverLeave:
never executed: case QEvent::HoverLeave:
0
759 case QEvent::HoverMove:
never executed: case QEvent::HoverMove:
0
760 d->updateHoverControl(static_cast<const QHoverEvent *>(event)->pos());-
761 break;
never executed: break;
0
762 case QEvent::ShortcutOverride:
never executed: case QEvent::ShortcutOverride:
0
763 if (d->edit->event(event))
d->edit->event(event)Description
TRUEnever evaluated
FALSEnever evaluated
0
764 return true;
never executed: return true;
0
765 break;
never executed: break;
0
766#ifdef QT_KEYPAD_NAVIGATION-
767 case QEvent::EnterEditFocus:-
768 case QEvent::LeaveEditFocus:-
769 if (QApplication::keypadNavigationEnabled()) {-
770 const bool b = d->edit->event(event);-
771 d->edit->setSelection(d->edit->displayText().size() - d->suffix.size(),0);-
772 if (event->type() == QEvent::LeaveEditFocus)-
773 emit editingFinished();-
774 if (b)-
775 return true;-
776 }-
777 break;-
778#endif-
779 case QEvent::InputMethod:
never executed: case QEvent::InputMethod:
0
780 return d->edit->event(event);
never executed: return d->edit->event(event);
0
781 default:
never executed: default:
0
782 break;
never executed: break;
0
783 }-
784 return QWidget::event(event);
never executed: return QWidget::event(event);
0
785}-
786-
787/*!-
788 \reimp-
789*/-
790-
791void QAbstractSpinBox::showEvent(QShowEvent *)-
792{-
793 Q_D(QAbstractSpinBox);-
794 d->reset();-
795-
796 if (d->ignoreUpdateEdit) {
d->ignoreUpdateEditDescription
TRUEnever evaluated
FALSEnever evaluated
0
797 d->ignoreUpdateEdit = false;-
798 } else {
never executed: end of block
0
799 d->updateEdit();-
800 }
never executed: end of block
0
801}-
802-
803/*!-
804 \reimp-
805*/-
806-
807void QAbstractSpinBox::changeEvent(QEvent *event)-
808{-
809 Q_D(QAbstractSpinBox);-
810-
811 switch (event->type()) {-
812 case QEvent::StyleChange:
never executed: case QEvent::StyleChange:
0
813 d->spinClickTimerInterval = style()->styleHint(QStyle::SH_SpinBox_ClickAutoRepeatRate, 0, this);-
814 d->spinClickThresholdTimerInterval =-
815 style()->styleHint(QStyle::SH_SpinBox_ClickAutoRepeatThreshold, 0, this);-
816 d->reset();-
817 d->updateEditFieldGeometry();-
818 break;
never executed: break;
0
819 case QEvent::EnabledChange:
never executed: case QEvent::EnabledChange:
0
820 if (!isEnabled()) {
!isEnabled()Description
TRUEnever evaluated
FALSEnever evaluated
0
821 d->reset();-
822 }
never executed: end of block
0
823 break;
never executed: break;
0
824 case QEvent::ActivationChange:
never executed: case QEvent::ActivationChange:
0
825 if (!isActiveWindow()){
!isActiveWindow()Description
TRUEnever evaluated
FALSEnever evaluated
0
826 d->reset();-
827 if (d->pendingEmit) // pendingEmit can be true even if it hasn't changed.
d->pendingEmitDescription
TRUEnever evaluated
FALSEnever evaluated
0
828 d->interpret(EmitIfChanged); // E.g. 10 to 10.0
never executed: d->interpret(EmitIfChanged);
0
829 }
never executed: end of block
0
830 break;
never executed: break;
0
831 default:
never executed: default:
0
832 break;
never executed: break;
0
833 }-
834 QWidget::changeEvent(event);-
835}
never executed: end of block
0
836-
837/*!-
838 \reimp-
839*/-
840-
841void QAbstractSpinBox::resizeEvent(QResizeEvent *event)-
842{-
843 Q_D(QAbstractSpinBox);-
844 QWidget::resizeEvent(event);-
845-
846 d->updateEditFieldGeometry();-
847 update();-
848}
never executed: end of block
0
849-
850/*!-
851 \reimp-
852*/-
853-
854QSize QAbstractSpinBox::sizeHint() const-
855{-
856 Q_D(const QAbstractSpinBox);-
857 if (d->cachedSizeHint.isEmpty()) {
d->cachedSizeHint.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
858 ensurePolished();-
859-
860 const QFontMetrics fm(fontMetrics());-
861 int h = d->edit->sizeHint().height();-
862 int w = 0;-
863 QString s;-
864 QString fixedContent = d->prefix + d->suffix + QLatin1Char(' ');-
865 s = d->textFromValue(d->minimum);-
866 s.truncate(18);-
867 s += fixedContent;-
868 w = qMax(w, fm.width(s));-
869 s = d->textFromValue(d->maximum);-
870 s.truncate(18);-
871 s += fixedContent;-
872 w = qMax(w, fm.width(s));-
873-
874 if (d->specialValueText.size()) {
d->specialValueText.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
875 s = d->specialValueText;-
876 w = qMax(w, fm.width(s));-
877 }
never executed: end of block
0
878 w += 2; // cursor blinking space-
879-
880 QStyleOptionSpinBox opt;-
881 initStyleOption(&opt);-
882 QSize hint(w, h);-
883 d->cachedSizeHint = style()->sizeFromContents(QStyle::CT_SpinBox, &opt, hint, this)-
884 .expandedTo(QApplication::globalStrut());-
885 }
never executed: end of block
0
886 return d->cachedSizeHint;
never executed: return d->cachedSizeHint;
0
887}-
888-
889/*!-
890 \reimp-
891*/-
892-
893QSize QAbstractSpinBox::minimumSizeHint() const-
894{-
895 Q_D(const QAbstractSpinBox);-
896 if (d->cachedMinimumSizeHint.isEmpty()) {
d->cachedMinim...Hint.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
897 //Use the prefix and range to calculate the minimumSizeHint-
898 ensurePolished();-
899-
900 const QFontMetrics fm(fontMetrics());-
901 int h = d->edit->minimumSizeHint().height();-
902 int w = 0;-
903-
904 QString s;-
905 QString fixedContent = d->prefix + QLatin1Char(' ');-
906 s = d->textFromValue(d->minimum);-
907 s.truncate(18);-
908 s += fixedContent;-
909 w = qMax(w, fm.width(s));-
910 s = d->textFromValue(d->maximum);-
911 s.truncate(18);-
912 s += fixedContent;-
913 w = qMax(w, fm.width(s));-
914-
915 if (d->specialValueText.size()) {
d->specialValueText.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
916 s = d->specialValueText;-
917 w = qMax(w, fm.width(s));-
918 }
never executed: end of block
0
919 w += 2; // cursor blinking space-
920-
921 QStyleOptionSpinBox opt;-
922 initStyleOption(&opt);-
923 QSize hint(w, h);-
924-
925 d->cachedMinimumSizeHint = style()->sizeFromContents(QStyle::CT_SpinBox, &opt, hint, this)-
926 .expandedTo(QApplication::globalStrut());-
927 }
never executed: end of block
0
928 return d->cachedMinimumSizeHint;
never executed: return d->cachedMinimumSizeHint;
0
929}-
930-
931/*!-
932 \reimp-
933*/-
934-
935void QAbstractSpinBox::paintEvent(QPaintEvent *)-
936{-
937 QStyleOptionSpinBox opt;-
938 initStyleOption(&opt);-
939 QStylePainter p(this);-
940 p.drawComplexControl(QStyle::CC_SpinBox, opt);-
941}
never executed: end of block
0
942-
943/*!-
944 \reimp-
945-
946 This function handles keyboard input.-
947-
948 The following keys are handled specifically:-
949 \table-
950 \row \li Enter/Return-
951 \li This will reinterpret the text and emit a signal even if the value has not changed-
952 since last time a signal was emitted.-
953 \row \li Up-
954 \li This will invoke stepBy(1)-
955 \row \li Down-
956 \li This will invoke stepBy(-1)-
957 \row \li Page up-
958 \li This will invoke stepBy(10)-
959 \row \li Page down-
960 \li This will invoke stepBy(-10)-
961 \endtable-
962*/-
963-
964-
965void QAbstractSpinBox::keyPressEvent(QKeyEvent *event)-
966{-
967 Q_D(QAbstractSpinBox);-
968-
969 if (!event->text().isEmpty() && d->edit->cursorPosition() < d->prefix.size())
!event->text().isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
d->edit->curso...>prefix.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
970 d->edit->setCursorPosition(d->prefix.size());
never executed: d->edit->setCursorPosition(d->prefix.size());
0
971-
972 int steps = 1;-
973 bool isPgUpOrDown = false;-
974 switch (event->key()) {-
975 case Qt::Key_PageUp:
never executed: case Qt::Key_PageUp:
0
976 case Qt::Key_PageDown:
never executed: case Qt::Key_PageDown:
0
977 steps *= 10;-
978 isPgUpOrDown = true;-
979 case Qt::Key_Up:
code before this statement never executed: case Qt::Key_Up:
never executed: case Qt::Key_Up:
0
980 case Qt::Key_Down: {
never executed: case Qt::Key_Down:
0
981#ifdef QT_KEYPAD_NAVIGATION-
982 if (QApplication::keypadNavigationEnabled()) {-
983 // Reserve up/down for nav - use left/right for edit.-
984 if (!hasEditFocus() && (event->key() == Qt::Key_Up-
985 || event->key() == Qt::Key_Down)) {-
986 event->ignore();-
987 return;-
988 }-
989 }-
990#endif-
991 event->accept();-
992 const bool up = (event->key() == Qt::Key_PageUp || event->key() == Qt::Key_Up);
event->key() == Qt::Key_PageUpDescription
TRUEnever evaluated
FALSEnever evaluated
event->key() == Qt::Key_UpDescription
TRUEnever evaluated
FALSEnever evaluated
0
993 if (!(stepEnabled() & (up ? StepUpEnabled : StepDownEnabled)))
!(stepEnabled(...pDownEnabled))Description
TRUEnever evaluated
FALSEnever evaluated
0
994 return;
never executed: return;
0
995 if (!up)
!upDescription
TRUEnever evaluated
FALSEnever evaluated
0
996 steps *= -1;
never executed: steps *= -1;
0
997 if (style()->styleHint(QStyle::SH_SpinBox_AnimateButton, 0, this)) {
style()->style...tton, 0, this)Description
TRUEnever evaluated
FALSEnever evaluated
0
998 d->buttonState = (Keyboard | (up ? Up : Down));-
999 }
never executed: end of block
0
1000 if (d->spinClickTimerId == -1)
d->spinClickTimerId == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1001 stepBy(steps);
never executed: stepBy(steps);
0
1002 if(event->isAutoRepeat() && !isPgUpOrDown) {
event->isAutoRepeat()Description
TRUEnever evaluated
FALSEnever evaluated
!isPgUpOrDownDescription
TRUEnever evaluated
FALSEnever evaluated
0
1003 if(d->spinClickThresholdTimerId == -1 && d->spinClickTimerId == -1) {
d->spinClickTh...dTimerId == -1Description
TRUEnever evaluated
FALSEnever evaluated
d->spinClickTimerId == -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1004 d->updateState(up, true);-
1005 }
never executed: end of block
0
1006 }
never executed: end of block
0
1007#ifndef QT_NO_ACCESSIBILITY-
1008 QAccessibleValueChangeEvent event(this, d->value);-
1009 QAccessible::updateAccessibility(&event);-
1010#endif-
1011 return;
never executed: return;
0
1012 }-
1013#ifdef QT_KEYPAD_NAVIGATION-
1014 case Qt::Key_Left:-
1015 case Qt::Key_Right:-
1016 if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) {-
1017 event->ignore();-
1018 return;-
1019 }-
1020 break;-
1021 case Qt::Key_Back:-
1022 if (QApplication::keypadNavigationEnabled() && !hasEditFocus()) {-
1023 event->ignore();-
1024 return;-
1025 }-
1026 break;-
1027#endif-
1028 case Qt::Key_Enter:
never executed: case Qt::Key_Enter:
0
1029 case Qt::Key_Return:
never executed: case Qt::Key_Return:
0
1030 d->edit->d_func()->control->clearUndo();-
1031 d->interpret(d->keyboardTracking ? AlwaysEmit : EmitIfChanged);-
1032 selectAll();-
1033 event->ignore();-
1034 emit editingFinished();-
1035 emit d->edit->returnPressed();-
1036 return;
never executed: return;
0
1037-
1038#ifdef QT_KEYPAD_NAVIGATION-
1039 case Qt::Key_Select:-
1040 if (QApplication::keypadNavigationEnabled()) {-
1041 // Toggles between left/right moving cursor and inc/dec.-
1042 setEditFocus(!hasEditFocus());-
1043 }-
1044 return;-
1045#endif-
1046-
1047 case Qt::Key_U:
never executed: case Qt::Key_U:
0
1048 if (event->modifiers() & Qt::ControlModifier
event->modifie...ontrolModifierDescription
TRUEnever evaluated
FALSEnever evaluated
0
1049 && QGuiApplication::platformName() == QLatin1String("xcb")) { // only X11
QGuiApplicatio...1String("xcb")Description
TRUEnever evaluated
FALSEnever evaluated
0
1050 event->accept();-
1051 if (!isReadOnly())
!isReadOnly()Description
TRUEnever evaluated
FALSEnever evaluated
0
1052 clear();
never executed: clear();
0
1053 return;
never executed: return;
0
1054 }-
1055 break;
never executed: break;
0
1056-
1057 case Qt::Key_End:
never executed: case Qt::Key_End:
0
1058 case Qt::Key_Home:
never executed: case Qt::Key_Home:
0
1059 if (event->modifiers() & Qt::ShiftModifier) {
event->modifie...:ShiftModifierDescription
TRUEnever evaluated
FALSEnever evaluated
0
1060 int currentPos = d->edit->cursorPosition();-
1061 const QString text = d->edit->displayText();-
1062 if (event->key() == Qt::Key_End) {
event->key() == Qt::Key_EndDescription
TRUEnever evaluated
FALSEnever evaluated
0
1063 if ((currentPos == 0 && !d->prefix.isEmpty()) || text.size() - d->suffix.size() <= currentPos) {
currentPos == 0Description
TRUEnever evaluated
FALSEnever evaluated
!d->prefix.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
text.size() - ... <= currentPosDescription
TRUEnever evaluated
FALSEnever evaluated
0
1064 break; // let lineedit handle this
never executed: break;
0
1065 } else {-
1066 d->edit->setSelection(currentPos, text.size() - d->suffix.size() - currentPos);-
1067 }
never executed: end of block
0
1068 } else {-
1069 if ((currentPos == text.size() && !d->suffix.isEmpty()) || currentPos <= d->prefix.size()) {
currentPos == text.size()Description
TRUEnever evaluated
FALSEnever evaluated
!d->suffix.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
currentPos <= d->prefix.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
1070 break; // let lineedit handle this
never executed: break;
0
1071 } else {-
1072 d->edit->setSelection(currentPos, d->prefix.size() - currentPos);-
1073 }
never executed: end of block
0
1074 }-
1075 event->accept();-
1076 return;
never executed: return;
0
1077 }-
1078 break;
never executed: break;
0
1079-
1080 default:
never executed: default:
0
1081#ifndef QT_NO_SHORTCUT-
1082 if (event == QKeySequence::SelectAll) {
event == QKeyS...nce::SelectAllDescription
TRUEnever evaluated
FALSEnever evaluated
0
1083 selectAll();-
1084 event->accept();-
1085 return;
never executed: return;
0
1086 }-
1087#endif-
1088 break;
never executed: break;
0
1089 }-
1090-
1091 d->edit->event(event);-
1092 if (!d->edit->text().isEmpty())
!d->edit->text().isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
1093 d->cleared = false;
never executed: d->cleared = false;
0
1094 if (!isVisible())
!isVisible()Description
TRUEnever evaluated
FALSEnever evaluated
0
1095 d->ignoreUpdateEdit = true;
never executed: d->ignoreUpdateEdit = true;
0
1096}
never executed: end of block
0
1097-
1098/*!-
1099 \reimp-
1100*/-
1101-
1102void QAbstractSpinBox::keyReleaseEvent(QKeyEvent *event)-
1103{-
1104 Q_D(QAbstractSpinBox);-
1105-
1106 if (d->buttonState & Keyboard && !event->isAutoRepeat()) {
d->buttonState & KeyboardDescription
TRUEnever evaluated
FALSEnever evaluated
!event->isAutoRepeat()Description
TRUEnever evaluated
FALSEnever evaluated
0
1107 d->reset();-
1108 } else {
never executed: end of block
0
1109 d->edit->event(event);-
1110 }
never executed: end of block
0
1111}-
1112-
1113/*!-
1114 \reimp-
1115*/-
1116-
1117#ifndef QT_NO_WHEELEVENT-
1118void QAbstractSpinBox::wheelEvent(QWheelEvent *event)-
1119{-
1120 Q_D(QAbstractSpinBox);-
1121 d->wheelDeltaRemainder += event->angleDelta().y();-
1122 const int steps = d->wheelDeltaRemainder / 120;-
1123 d->wheelDeltaRemainder -= steps * 120;-
1124 if (stepEnabled() & (steps > 0 ? StepUpEnabled : StepDownEnabled))
stepEnabled() ...epDownEnabled)Description
TRUEnever evaluated
FALSEnever evaluated
0
1125 stepBy(event->modifiers() & Qt::ControlModifier ? steps * 10 : steps);
never executed: stepBy(event->modifiers() & Qt::ControlModifier ? steps * 10 : steps);
0
1126 event->accept();-
1127}
never executed: end of block
0
1128#endif-
1129-
1130-
1131/*!-
1132 \reimp-
1133*/-
1134void QAbstractSpinBox::focusInEvent(QFocusEvent *event)-
1135{-
1136 Q_D(QAbstractSpinBox);-
1137-
1138 d->edit->event(event);-
1139 if (event->reason() == Qt::TabFocusReason || event->reason() == Qt::BacktabFocusReason) {
event->reason(...TabFocusReasonDescription
TRUEnever evaluated
FALSEnever evaluated
event->reason(...tabFocusReasonDescription
TRUEnever evaluated
FALSEnever evaluated
0
1140 selectAll();-
1141 }
never executed: end of block
0
1142 QWidget::focusInEvent(event);-
1143}
never executed: end of block
0
1144-
1145/*!-
1146 \reimp-
1147*/-
1148-
1149void QAbstractSpinBox::focusOutEvent(QFocusEvent *event)-
1150{-
1151 Q_D(QAbstractSpinBox);-
1152-
1153 if (d->pendingEmit)
d->pendingEmitDescription
TRUEnever evaluated
FALSEnever evaluated
0
1154 d->interpret(EmitIfChanged);
never executed: d->interpret(EmitIfChanged);
0
1155-
1156 d->reset();-
1157 d->edit->event(event);-
1158 d->updateEdit();-
1159 QWidget::focusOutEvent(event);-
1160-
1161#ifdef QT_KEYPAD_NAVIGATION-
1162 // editingFinished() is already emitted on LeaveEditFocus-
1163 if (!QApplication::keypadNavigationEnabled())-
1164#endif-
1165 emit editingFinished();-
1166}
never executed: end of block
0
1167-
1168/*!-
1169 \reimp-
1170*/-
1171-
1172void QAbstractSpinBox::closeEvent(QCloseEvent *event)-
1173{-
1174 Q_D(QAbstractSpinBox);-
1175-
1176 d->reset();-
1177 if (d->pendingEmit)
d->pendingEmitDescription
TRUEnever evaluated
FALSEnever evaluated
0
1178 d->interpret(EmitIfChanged);
never executed: d->interpret(EmitIfChanged);
0
1179 QWidget::closeEvent(event);-
1180}
never executed: end of block
0
1181-
1182/*!-
1183 \reimp-
1184*/-
1185-
1186void QAbstractSpinBox::hideEvent(QHideEvent *event)-
1187{-
1188 Q_D(QAbstractSpinBox);-
1189 d->reset();-
1190 if (d->pendingEmit)
d->pendingEmitDescription
TRUEnever evaluated
FALSEnever evaluated
0
1191 d->interpret(EmitIfChanged);
never executed: d->interpret(EmitIfChanged);
0
1192 QWidget::hideEvent(event);-
1193}
never executed: end of block
0
1194-
1195-
1196/*!-
1197 \reimp-
1198*/-
1199-
1200void QAbstractSpinBox::timerEvent(QTimerEvent *event)-
1201{-
1202 Q_D(QAbstractSpinBox);-
1203-
1204 bool doStep = false;-
1205 if (event->timerId() == d->spinClickThresholdTimerId) {
event->timerId...resholdTimerIdDescription
TRUEnever evaluated
FALSEnever evaluated
0
1206 killTimer(d->spinClickThresholdTimerId);-
1207 d->spinClickThresholdTimerId = -1;-
1208 d->effectiveSpinRepeatRate = d->buttonState & Keyboard
d->buttonState & KeyboardDescription
TRUEnever evaluated
FALSEnever evaluated
0
1209 ? QGuiApplication::styleHints()->keyboardAutoRepeatRate()-
1210 : d->spinClickTimerInterval;-
1211 d->spinClickTimerId = startTimer(d->effectiveSpinRepeatRate);-
1212 doStep = true;-
1213 } else if (event->timerId() == d->spinClickTimerId) {
never executed: end of block
event->timerId...inClickTimerIdDescription
TRUEnever evaluated
FALSEnever evaluated
0
1214 if (d->accelerate) {
d->accelerateDescription
TRUEnever evaluated
FALSEnever evaluated
0
1215 d->acceleration = d->acceleration + (int)(d->effectiveSpinRepeatRate * 0.05);-
1216 if (d->effectiveSpinRepeatRate - d->acceleration >= 10) {
d->effectiveSp...leration >= 10Description
TRUEnever evaluated
FALSEnever evaluated
0
1217 killTimer(d->spinClickTimerId);-
1218 d->spinClickTimerId = startTimer(d->effectiveSpinRepeatRate - d->acceleration);-
1219 }
never executed: end of block
0
1220 }
never executed: end of block
0
1221 doStep = true;-
1222 }
never executed: end of block
0
1223-
1224 if (doStep) {
doStepDescription
TRUEnever evaluated
FALSEnever evaluated
0
1225 const StepEnabled st = stepEnabled();-
1226 if (d->buttonState & Up) {
d->buttonState & UpDescription
TRUEnever evaluated
FALSEnever evaluated
0
1227 if (!(st & StepUpEnabled)) {
!(st & StepUpEnabled)Description
TRUEnever evaluated
FALSEnever evaluated
0
1228 d->reset();-
1229 } else {
never executed: end of block
0
1230 stepBy(1);-
1231 }
never executed: end of block
0
1232 } else if (d->buttonState & Down) {
d->buttonState & DownDescription
TRUEnever evaluated
FALSEnever evaluated
0
1233 if (!(st & StepDownEnabled)) {
!(st & StepDownEnabled)Description
TRUEnever evaluated
FALSEnever evaluated
0
1234 d->reset();-
1235 } else {
never executed: end of block
0
1236 stepBy(-1);-
1237 }
never executed: end of block
0
1238 }-
1239 return;
never executed: return;
0
1240 }-
1241 QWidget::timerEvent(event);-
1242 return;
never executed: return;
0
1243}-
1244-
1245/*!-
1246 \reimp-
1247*/-
1248-
1249void QAbstractSpinBox::contextMenuEvent(QContextMenuEvent *event)-
1250{-
1251#ifdef QT_NO_CONTEXTMENU-
1252 Q_UNUSED(event);-
1253#else-
1254 Q_D(QAbstractSpinBox);-
1255-
1256 QPointer<QMenu> menu = d->edit->createStandardContextMenu();-
1257 if (!menu)
!menuDescription
TRUEnever evaluated
FALSEnever evaluated
0
1258 return;
never executed: return;
0
1259-
1260 d->reset();-
1261-
1262 QAction *selAll = new QAction(tr("&Select All"), menu);-
1263 menu->insertAction(d->edit->d_func()->selectAllAction,-
1264 selAll);-
1265 menu->removeAction(d->edit->d_func()->selectAllAction);-
1266 menu->addSeparator();-
1267 const uint se = stepEnabled();-
1268 QAction *up = menu->addAction(tr("&Step up"));-
1269 up->setEnabled(se & StepUpEnabled);-
1270 QAction *down = menu->addAction(tr("Step &down"));-
1271 down->setEnabled(se & StepDownEnabled);-
1272 menu->addSeparator();-
1273-
1274 const QPointer<QAbstractSpinBox> that = this;-
1275 const QPoint pos = (event->reason() == QContextMenuEvent::Mouse)
(event->reason...uEvent::Mouse)Description
TRUEnever evaluated
FALSEnever evaluated
0
1276 ? event->globalPos() : mapToGlobal(QPoint(event->pos().x(), 0)) + QPoint(width() / 2, height() / 2);-
1277 const QAction *action = menu->exec(pos);-
1278 delete static_cast<QMenu *>(menu);-
1279 if (that && action) {
thatDescription
TRUEnever evaluated
FALSEnever evaluated
actionDescription
TRUEnever evaluated
FALSEnever evaluated
0
1280 if (action == up) {
action == upDescription
TRUEnever evaluated
FALSEnever evaluated
0
1281 stepBy(1);-
1282 } else if (action == down) {
never executed: end of block
action == downDescription
TRUEnever evaluated
FALSEnever evaluated
0
1283 stepBy(-1);-
1284 } else if (action == selAll) {
never executed: end of block
action == selAllDescription
TRUEnever evaluated
FALSEnever evaluated
0
1285 selectAll();-
1286 }
never executed: end of block
0
1287 }
never executed: end of block
0
1288 event->accept();-
1289#endif // QT_NO_CONTEXTMENU-
1290}
never executed: end of block
0
1291-
1292/*!-
1293 \reimp-
1294*/-
1295-
1296void QAbstractSpinBox::mouseMoveEvent(QMouseEvent *event)-
1297{-
1298 Q_D(QAbstractSpinBox);-
1299-
1300 d->updateHoverControl(event->pos());-
1301-
1302 // If we have a timer ID, update the state-
1303 if (d->spinClickTimerId != -1 && d->buttonSymbols != NoButtons) {
d->spinClickTimerId != -1Description
TRUEnever evaluated
FALSEnever evaluated
d->buttonSymbols != NoButtonsDescription
TRUEnever evaluated
FALSEnever evaluated
0
1304 const StepEnabled se = stepEnabled();-
1305 if ((se & StepUpEnabled) && d->hoverControl == QStyle::SC_SpinBoxUp)
(se & StepUpEnabled)Description
TRUEnever evaluated
FALSEnever evaluated
d->hoverContro...::SC_SpinBoxUpDescription
TRUEnever evaluated
FALSEnever evaluated
0
1306 d->updateState(true);
never executed: d->updateState(true);
0
1307 else if ((se & StepDownEnabled) && d->hoverControl == QStyle::SC_SpinBoxDown)
(se & StepDownEnabled)Description
TRUEnever evaluated
FALSEnever evaluated
d->hoverContro...SC_SpinBoxDownDescription
TRUEnever evaluated
FALSEnever evaluated
0
1308 d->updateState(false);
never executed: d->updateState(false);
0
1309 else-
1310 d->reset();
never executed: d->reset();
0
1311 event->accept();-
1312 }
never executed: end of block
0
1313}
never executed: end of block
0
1314-
1315/*!-
1316 \reimp-
1317*/-
1318-
1319void QAbstractSpinBox::mousePressEvent(QMouseEvent *event)-
1320{-
1321 Q_D(QAbstractSpinBox);-
1322-
1323 if (event->button() != Qt::LeftButton || d->buttonState != None) {
event->button(...Qt::LeftButtonDescription
TRUEnever evaluated
FALSEnever evaluated
d->buttonState != NoneDescription
TRUEnever evaluated
FALSEnever evaluated
0
1324 return;
never executed: return;
0
1325 }-
1326-
1327 d->updateHoverControl(event->pos());-
1328 event->accept();-
1329-
1330 const StepEnabled se = (d->buttonSymbols == NoButtons) ? StepEnabled(StepNone) : stepEnabled();
(d->buttonSymb... == NoButtons)Description
TRUEnever evaluated
FALSEnever evaluated
0
1331 if ((se & StepUpEnabled) && d->hoverControl == QStyle::SC_SpinBoxUp) {
(se & StepUpEnabled)Description
TRUEnever evaluated
FALSEnever evaluated
d->hoverContro...::SC_SpinBoxUpDescription
TRUEnever evaluated
FALSEnever evaluated
0
1332 d->updateState(true);-
1333 } else if ((se & StepDownEnabled) && d->hoverControl == QStyle::SC_SpinBoxDown) {
never executed: end of block
(se & StepDownEnabled)Description
TRUEnever evaluated
FALSEnever evaluated
d->hoverContro...SC_SpinBoxDownDescription
TRUEnever evaluated
FALSEnever evaluated
0
1334 d->updateState(false);-
1335 } else {
never executed: end of block
0
1336 event->ignore();-
1337 }
never executed: end of block
0
1338}-
1339-
1340/*!-
1341 \reimp-
1342*/-
1343void QAbstractSpinBox::mouseReleaseEvent(QMouseEvent *event)-
1344{-
1345 Q_D(QAbstractSpinBox);-
1346-
1347 if ((d->buttonState & Mouse) != 0)
(d->buttonState & Mouse) != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1348 d->reset();
never executed: d->reset();
0
1349 event->accept();-
1350}
never executed: end of block
0
1351-
1352// --- QAbstractSpinBoxPrivate ----
1353-
1354/*!-
1355 \internal-
1356 Constructs a QAbstractSpinBoxPrivate object-
1357*/-
1358-
1359QAbstractSpinBoxPrivate::QAbstractSpinBoxPrivate()-
1360 : edit(0), type(QVariant::Invalid), spinClickTimerId(-1),-
1361 spinClickTimerInterval(100), spinClickThresholdTimerId(-1), spinClickThresholdTimerInterval(-1),-
1362 effectiveSpinRepeatRate(1), buttonState(None), cachedText(QLatin1String("\x01")),-
1363 cachedState(QValidator::Invalid), pendingEmit(false), readOnly(false), wrapping(false),-
1364 ignoreCursorPositionChanged(false), frame(true), accelerate(false), keyboardTracking(true),-
1365 cleared(false), ignoreUpdateEdit(false), correctionMode(QAbstractSpinBox::CorrectToPreviousValue),-
1366 acceleration(0), hoverControl(QStyle::SC_None), buttonSymbols(QAbstractSpinBox::UpDownArrows), validator(0),-
1367 showGroupSeparator(0), wheelDeltaRemainder(0)-
1368{-
1369}
never executed: end of block
0
1370-
1371/*-
1372 \internal-
1373 Called when the QAbstractSpinBoxPrivate is destroyed-
1374*/-
1375QAbstractSpinBoxPrivate::~QAbstractSpinBoxPrivate()-
1376{-
1377}-
1378-
1379/*!-
1380 \internal-
1381 Updates the old and new hover control. Does nothing if the hover-
1382 control has not changed.-
1383*/-
1384bool QAbstractSpinBoxPrivate::updateHoverControl(const QPoint &pos)-
1385{-
1386 Q_Q(QAbstractSpinBox);-
1387 QRect lastHoverRect = hoverRect;-
1388 QStyle::SubControl lastHoverControl = hoverControl;-
1389 bool doesHover = q->testAttribute(Qt::WA_Hover);-
1390 if (lastHoverControl != newHoverControl(pos) && doesHover) {
lastHoverContr...erControl(pos)Description
TRUEnever evaluated
FALSEnever evaluated
doesHoverDescription
TRUEnever evaluated
FALSEnever evaluated
0
1391 q->update(lastHoverRect);-
1392 q->update(hoverRect);-
1393 return true;
never executed: return true;
0
1394 }-
1395 return !doesHover;
never executed: return !doesHover;
0
1396}-
1397-
1398/*!-
1399 \internal-
1400 Returns the hover control at \a pos.-
1401 This will update the hoverRect and hoverControl.-
1402*/-
1403QStyle::SubControl QAbstractSpinBoxPrivate::newHoverControl(const QPoint &pos)-
1404{-
1405 Q_Q(QAbstractSpinBox);-
1406-
1407 QStyleOptionSpinBox opt;-
1408 q->initStyleOption(&opt);-
1409 opt.subControls = QStyle::SC_All;-
1410 hoverControl = q->style()->hitTestComplexControl(QStyle::CC_SpinBox, &opt, pos, q);-
1411 hoverRect = q->style()->subControlRect(QStyle::CC_SpinBox, &opt, hoverControl, q);-
1412 return hoverControl;
never executed: return hoverControl;
0
1413}-
1414-
1415/*!-
1416 \internal-
1417 Strips any prefix/suffix from \a text.-
1418*/-
1419-
1420QString QAbstractSpinBoxPrivate::stripped(const QString &t, int *pos) const-
1421{-
1422 QStringRef text(&t);-
1423 if (specialValueText.size() == 0 || text != specialValueText) {
specialValueText.size() == 0Description
TRUEnever evaluated
FALSEnever evaluated
text != specialValueTextDescription
TRUEnever evaluated
FALSEnever evaluated
0
1424 int from = 0;-
1425 int size = text.size();-
1426 bool changed = false;-
1427 if (prefix.size() && text.startsWith(prefix)) {
prefix.size()Description
TRUEnever evaluated
FALSEnever evaluated
text.startsWith(prefix)Description
TRUEnever evaluated
FALSEnever evaluated
0
1428 from += prefix.size();-
1429 size -= from;-
1430 changed = true;-
1431 }
never executed: end of block
0
1432 if (suffix.size() && text.endsWith(suffix)) {
suffix.size()Description
TRUEnever evaluated
FALSEnever evaluated
text.endsWith(suffix)Description
TRUEnever evaluated
FALSEnever evaluated
0
1433 size -= suffix.size();-
1434 changed = true;-
1435 }
never executed: end of block
0
1436 if (changed)
changedDescription
TRUEnever evaluated
FALSEnever evaluated
0
1437 text = text.mid(from, size);
never executed: text = text.mid(from, size);
0
1438 }
never executed: end of block
0
1439-
1440 const int s = text.size();-
1441 text = text.trimmed();-
1442 if (pos)
posDescription
TRUEnever evaluated
FALSEnever evaluated
0
1443 (*pos) -= (s - text.size());
never executed: (*pos) -= (s - text.size());
0
1444 return text.toString();
never executed: return text.toString();
0
1445-
1446}-
1447-
1448void QAbstractSpinBoxPrivate::updateEditFieldGeometry()-
1449{-
1450 Q_Q(QAbstractSpinBox);-
1451 QStyleOptionSpinBox opt;-
1452 q->initStyleOption(&opt);-
1453 opt.subControls = QStyle::SC_SpinBoxEditField;-
1454 edit->setGeometry(q->style()->subControlRect(QStyle::CC_SpinBox, &opt,-
1455 QStyle::SC_SpinBoxEditField, q));-
1456}
never executed: end of block
0
1457/*!-
1458 \internal-
1459 Returns \c true if a specialValueText has been set and the current value is minimum.-
1460*/-
1461-
1462bool QAbstractSpinBoxPrivate::specialValue() const-
1463{-
1464 return (value == minimum && !specialValueText.isEmpty());
never executed: return (value == minimum && !specialValueText.isEmpty());
0
1465}-
1466-
1467/*!-
1468 \internal Virtual function that emits signals when the value-
1469 changes. Reimplemented in the different subclasses.-
1470*/-
1471-
1472void QAbstractSpinBoxPrivate::emitSignals(EmitPolicy, const QVariant &)-
1473{-
1474}-
1475-
1476/*!-
1477 \internal-
1478-
1479 Slot connected to the line edit's textChanged(const QString &)-
1480 signal.-
1481*/-
1482-
1483void QAbstractSpinBoxPrivate::_q_editorTextChanged(const QString &t)-
1484{-
1485 Q_Q(QAbstractSpinBox);-
1486-
1487 if (keyboardTracking) {
keyboardTrackingDescription
TRUEnever evaluated
FALSEnever evaluated
0
1488 QString tmp = t;-
1489 int pos = edit->cursorPosition();-
1490 QValidator::State state = q->validate(tmp, pos);-
1491 if (state == QValidator::Acceptable) {
state == QVali...or::AcceptableDescription
TRUEnever evaluated
FALSEnever evaluated
0
1492 const QVariant v = valueFromText(tmp);-
1493 setValue(v, EmitIfChanged, tmp != t);-
1494 pendingEmit = false;-
1495 } else {
never executed: end of block
0
1496 pendingEmit = true;-
1497 }
never executed: end of block
0
1498 } else {-
1499 pendingEmit = true;-
1500 }
never executed: end of block
0
1501}-
1502-
1503/*!-
1504 \internal-
1505-
1506 Virtual slot connected to the line edit's-
1507 cursorPositionChanged(int, int) signal. Will move the cursor to a-
1508 valid position if the new one is invalid. E.g. inside the prefix.-
1509 Reimplemented in Q[Date|Time|DateTime]EditPrivate to account for-
1510 the different sections etc.-
1511*/-
1512-
1513void QAbstractSpinBoxPrivate::_q_editorCursorPositionChanged(int oldpos, int newpos)-
1514{-
1515 if (!edit->hasSelectedText() && !ignoreCursorPositionChanged && !specialValue()) {
!edit->hasSelectedText()Description
TRUEnever evaluated
FALSEnever evaluated
!ignoreCursorPositionChangedDescription
TRUEnever evaluated
FALSEnever evaluated
!specialValue()Description
TRUEnever evaluated
FALSEnever evaluated
0
1516 ignoreCursorPositionChanged = true;-
1517-
1518 bool allowSelection = true;-
1519 int pos = -1;-
1520 if (newpos < prefix.size() && newpos != 0) {
newpos < prefix.size()Description
TRUEnever evaluated
FALSEnever evaluated
newpos != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1521 if (oldpos == 0) {
oldpos == 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1522 allowSelection = false;-
1523 pos = prefix.size();-
1524 } else {
never executed: end of block
0
1525 pos = oldpos;-
1526 }
never executed: end of block
0
1527 } else if (newpos > edit->text().size() - suffix.size()
newpos > edit-... suffix.size()Description
TRUEnever evaluated
FALSEnever evaluated
0
1528 && newpos != edit->text().size()) {
newpos != edit->text().size()Description
TRUEnever evaluated
FALSEnever evaluated
0
1529 if (oldpos == edit->text().size()) {
oldpos == edit->text().size()Description
TRUEnever evaluated
FALSEnever evaluated
0
1530 pos = edit->text().size() - suffix.size();-
1531 allowSelection = false;-
1532 } else {
never executed: end of block
0
1533 pos = edit->text().size();-
1534 }
never executed: end of block
0
1535 }-
1536 if (pos != -1) {
pos != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1537 const int selSize = edit->selectionStart() >= 0 && allowSelection
edit->selectionStart() >= 0Description
TRUEnever evaluated
FALSEnever evaluated
allowSelectionDescription
TRUEnever evaluated
FALSEnever evaluated
0
1538 ? (edit->selectedText().size()-
1539 * (newpos < pos ? -1 : 1)) - newpos + pos-
1540 : 0;-
1541-
1542 const QSignalBlocker blocker(edit);-
1543 if (selSize != 0) {
selSize != 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1544 edit->setSelection(pos - selSize, selSize);-
1545 } else {
never executed: end of block
0
1546 edit->setCursorPosition(pos);-
1547 }
never executed: end of block
0
1548 }-
1549 ignoreCursorPositionChanged = false;-
1550 }
never executed: end of block
0
1551}
never executed: end of block
0
1552-
1553/*!-
1554 \internal-
1555-
1556 Initialises the QAbstractSpinBoxPrivate object.-
1557*/-
1558-
1559void QAbstractSpinBoxPrivate::init()-
1560{-
1561 Q_Q(QAbstractSpinBox);-
1562-
1563 q->setLineEdit(new QLineEdit(q));-
1564 edit->setObjectName(QLatin1String("qt_spinbox_lineedit"));-
1565 validator = new QSpinBoxValidator(q, this);-
1566 edit->setValidator(validator);-
1567-
1568 QStyleOptionSpinBox opt;-
1569 q->initStyleOption(&opt);-
1570 spinClickTimerInterval = q->style()->styleHint(QStyle::SH_SpinBox_ClickAutoRepeatRate, &opt, q);-
1571 spinClickThresholdTimerInterval = q->style()->styleHint(QStyle::SH_SpinBox_ClickAutoRepeatThreshold, &opt, q);-
1572 q->setFocusPolicy(Qt::WheelFocus);-
1573 q->setSizePolicy(QSizePolicy(QSizePolicy::Minimum, QSizePolicy::Fixed, QSizePolicy::SpinBox));-
1574 q->setAttribute(Qt::WA_InputMethodEnabled);-
1575-
1576 q->setAttribute(Qt::WA_MacShowFocusRect);-
1577}
never executed: end of block
0
1578-
1579/*!-
1580 \internal-
1581-
1582 Resets the state of the spinbox. E.g. the state is set to-
1583 (Keyboard|Up) if Key up is currently pressed.-
1584*/-
1585-
1586void QAbstractSpinBoxPrivate::reset()-
1587{-
1588 Q_Q(QAbstractSpinBox);-
1589-
1590 buttonState = None;-
1591 if (q) {
qDescription
TRUEnever evaluated
FALSEnever evaluated
0
1592 if (spinClickTimerId != -1)
spinClickTimerId != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1593 q->killTimer(spinClickTimerId);
never executed: q->killTimer(spinClickTimerId);
0
1594 if (spinClickThresholdTimerId != -1)
spinClickThres...dTimerId != -1Description
TRUEnever evaluated
FALSEnever evaluated
0
1595 q->killTimer(spinClickThresholdTimerId);
never executed: q->killTimer(spinClickThresholdTimerId);
0
1596 spinClickTimerId = spinClickThresholdTimerId = -1;-
1597 acceleration = 0;-
1598 q->update();-
1599 }
never executed: end of block
0
1600}
never executed: end of block
0
1601-
1602/*!-
1603 \internal-
1604-
1605 Updates the state of the spinbox.-
1606*/-
1607-
1608void QAbstractSpinBoxPrivate::updateState(bool up, bool fromKeyboard /* = false */)-
1609{-
1610 Q_Q(QAbstractSpinBox);-
1611 if ((up && (buttonState & Up)) || (!up && (buttonState & Down)))
upDescription
TRUEnever evaluated
FALSEnever evaluated
(buttonState & Up)Description
TRUEnever evaluated
FALSEnever evaluated
!upDescription
TRUEnever evaluated
FALSEnever evaluated
(buttonState & Down)Description
TRUEnever evaluated
FALSEnever evaluated
0
1612 return;
never executed: return;
0
1613 reset();-
1614 if (q && (q->stepEnabled() & (up ? QAbstractSpinBox::StepUpEnabled
qDescription
TRUEnever evaluated
FALSEnever evaluated
(q->stepEnable...pDownEnabled))Description
TRUEnever evaluated
FALSEnever evaluated
0
1615 : QAbstractSpinBox::StepDownEnabled))) {
(q->stepEnable...pDownEnabled))Description
TRUEnever evaluated
FALSEnever evaluated
0
1616 spinClickThresholdTimerId = q->startTimer(spinClickThresholdTimerInterval);-
1617 buttonState = (up ? Up : Down) | (fromKeyboard ? Keyboard : Mouse);
upDescription
TRUEnever evaluated
FALSEnever evaluated
0
1618 q->stepBy(up ? 1 : -1);-
1619#ifndef QT_NO_ACCESSIBILITY-
1620 QAccessibleValueChangeEvent event(q, value);-
1621 QAccessible::updateAccessibility(&event);-
1622#endif-
1623 }
never executed: end of block
0
1624}
never executed: end of block
0
1625-
1626-
1627/*!-
1628 Initialize \a option with the values from this QSpinBox. This method-
1629 is useful for subclasses when they need a QStyleOptionSpinBox, but don't want-
1630 to fill in all the information themselves.-
1631-
1632 \sa QStyleOption::initFrom()-
1633*/-
1634void QAbstractSpinBox::initStyleOption(QStyleOptionSpinBox *option) const-
1635{-
1636 if (!option)
!optionDescription
TRUEnever evaluated
FALSEnever evaluated
0
1637 return;
never executed: return;
0
1638-
1639 Q_D(const QAbstractSpinBox);-
1640 option->initFrom(this);-
1641 option->activeSubControls = QStyle::SC_None;-
1642 option->buttonSymbols = d->buttonSymbols;-
1643 option->subControls = QStyle::SC_SpinBoxFrame | QStyle::SC_SpinBoxEditField;-
1644 if (d->buttonSymbols != QAbstractSpinBox::NoButtons) {
d->buttonSymbo...Box::NoButtonsDescription
TRUEnever evaluated
FALSEnever evaluated
0
1645 option->subControls |= QStyle::SC_SpinBoxUp | QStyle::SC_SpinBoxDown;-
1646 if (d->buttonState & Up) {
d->buttonState & UpDescription
TRUEnever evaluated
FALSEnever evaluated
0
1647 option->activeSubControls = QStyle::SC_SpinBoxUp;-
1648 } else if (d->buttonState & Down) {
never executed: end of block
d->buttonState & DownDescription
TRUEnever evaluated
FALSEnever evaluated
0
1649 option->activeSubControls = QStyle::SC_SpinBoxDown;-
1650 }
never executed: end of block
0
1651 }
never executed: end of block
0
1652-
1653 if (d->buttonState) {
d->buttonStateDescription
TRUEnever evaluated
FALSEnever evaluated
0
1654 option->state |= QStyle::State_Sunken;-
1655 } else {
never executed: end of block
0
1656 option->activeSubControls = d->hoverControl;-
1657 }
never executed: end of block
0
1658-
1659 option->stepEnabled = style()->styleHint(QStyle::SH_SpinControls_DisableOnBounds)
style()->style...sableOnBounds)Description
TRUEnever evaluated
FALSEnever evaluated
0
1660 ? stepEnabled()-
1661 : (QAbstractSpinBox::StepDownEnabled|QAbstractSpinBox::StepUpEnabled);-
1662-
1663 option->frame = d->frame;-
1664}
never executed: end of block
0
1665-
1666/*!-
1667 \internal-
1668-
1669 Bounds \a val to be within minimum and maximum. Also tries to be-
1670 clever about setting it at min and max depending on what it was-
1671 and what direction it was changed etc.-
1672*/-
1673-
1674QVariant QAbstractSpinBoxPrivate::bound(const QVariant &val, const QVariant &old, int steps) const-
1675{-
1676 QVariant v = val;-
1677 if (!wrapping || steps == 0 || old.isNull()) {
!wrappingDescription
TRUEnever evaluated
FALSEnever evaluated
steps == 0Description
TRUEnever evaluated
FALSEnever evaluated
old.isNull()Description
TRUEnever evaluated
FALSEnever evaluated
0
1678 if (variantCompare(v, minimum) < 0) {
variantCompare(v, minimum) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1679 v = wrapping ? maximum : minimum;
wrappingDescription
TRUEnever evaluated
FALSEnever evaluated
0
1680 }
never executed: end of block
0
1681 if (variantCompare(v, maximum) > 0) {
variantCompare(v, maximum) > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1682 v = wrapping ? minimum : maximum;
wrappingDescription
TRUEnever evaluated
FALSEnever evaluated
0
1683 }
never executed: end of block
0
1684 } else {
never executed: end of block
0
1685 const bool wasMin = old == minimum;-
1686 const bool wasMax = old == maximum;-
1687 const int oldcmp = variantCompare(v, old);-
1688 const int maxcmp = variantCompare(v, maximum);-
1689 const int mincmp = variantCompare(v, minimum);-
1690 const bool wrapped = (oldcmp > 0 && steps < 0) || (oldcmp < 0 && steps > 0);
oldcmp > 0Description
TRUEnever evaluated
FALSEnever evaluated
steps < 0Description
TRUEnever evaluated
FALSEnever evaluated
oldcmp < 0Description
TRUEnever evaluated
FALSEnever evaluated
steps > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1691 if (maxcmp > 0) {
maxcmp > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1692 v = ((wasMax && !wrapped && steps > 0) || (steps < 0 && !wasMin && wrapped))
wasMaxDescription
TRUEnever evaluated
FALSEnever evaluated
!wrappedDescription
TRUEnever evaluated
FALSEnever evaluated
steps > 0Description
TRUEnever evaluated
FALSEnever evaluated
steps < 0Description
TRUEnever evaluated
FALSEnever evaluated
!wasMinDescription
TRUEnever evaluated
FALSEnever evaluated
wrappedDescription
TRUEnever evaluated
FALSEnever evaluated
0
1693 ? minimum : maximum;-
1694 } else if (wrapped && (maxcmp > 0 || mincmp < 0)) {
never executed: end of block
wrappedDescription
TRUEnever evaluated
FALSEnever evaluated
maxcmp > 0Description
TRUEnever evaluated
FALSEnever evaluated
mincmp < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1695 v = ((wasMax && steps > 0) || (!wasMin && steps < 0)) ? minimum : maximum;
wasMaxDescription
TRUEnever evaluated
FALSEnever evaluated
steps > 0Description
TRUEnever evaluated
FALSEnever evaluated
!wasMinDescription
TRUEnever evaluated
FALSEnever evaluated
steps < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1696 } else if (mincmp < 0) {
never executed: end of block
mincmp < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1697 v = (!wasMax && !wasMin ? minimum : maximum);
!wasMaxDescription
TRUEnever evaluated
FALSEnever evaluated
!wasMinDescription
TRUEnever evaluated
FALSEnever evaluated
0
1698 }
never executed: end of block
0
1699 }
never executed: end of block
0
1700-
1701 return v;
never executed: return v;
0
1702}-
1703-
1704/*!-
1705 \internal-
1706-
1707 Sets the value of the spin box to \a val. Depending on the value-
1708 of \a ep it will also emit signals.-
1709*/-
1710-
1711void QAbstractSpinBoxPrivate::setValue(const QVariant &val, EmitPolicy ep,-
1712 bool doUpdate)-
1713{-
1714 Q_Q(QAbstractSpinBox);-
1715 const QVariant old = value;-
1716 value = bound(val);-
1717 pendingEmit = false;-
1718 cleared = false;-
1719 if (doUpdate) {
doUpdateDescription
TRUEnever evaluated
FALSEnever evaluated
0
1720 updateEdit();-
1721 }
never executed: end of block
0
1722 q->update();-
1723-
1724 if (ep == AlwaysEmit || (ep == EmitIfChanged && old != value)) {
ep == AlwaysEmitDescription
TRUEnever evaluated
FALSEnever evaluated
ep == EmitIfChangedDescription
TRUEnever evaluated
FALSEnever evaluated
old != valueDescription
TRUEnever evaluated
FALSEnever evaluated
0
1725 emitSignals(ep, old);-
1726 }
never executed: end of block
0
1727}
never executed: end of block
0
1728-
1729/*!-
1730 \internal-
1731-
1732 Updates the line edit to reflect the current value of the spin box.-
1733*/-
1734-
1735void QAbstractSpinBoxPrivate::updateEdit()-
1736{-
1737 Q_Q(QAbstractSpinBox);-
1738 if (type == QVariant::Invalid)
type == QVariant::InvalidDescription
TRUEnever evaluated
FALSEnever evaluated
0
1739 return;
never executed: return;
0
1740 const QString newText = specialValue() ? specialValueText : prefix + textFromValue(value) + suffix;
specialValue()Description
TRUEnever evaluated
FALSEnever evaluated
0
1741 if (newText == edit->displayText() || cleared)
newText == edit->displayText()Description
TRUEnever evaluated
FALSEnever evaluated
clearedDescription
TRUEnever evaluated
FALSEnever evaluated
0
1742 return;
never executed: return;
0
1743-
1744 const bool empty = edit->text().isEmpty();-
1745 int cursor = edit->cursorPosition();-
1746 int selsize = edit->selectedText().size();-
1747 const QSignalBlocker blocker(edit);-
1748 edit->setText(newText);-
1749-
1750 if (!specialValue()) {
!specialValue()Description
TRUEnever evaluated
FALSEnever evaluated
0
1751 cursor = qBound(prefix.size(), cursor, edit->displayText().size() - suffix.size());-
1752-
1753 if (selsize > 0) {
selsize > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1754 edit->setSelection(cursor, selsize);-
1755 } else {
never executed: end of block
0
1756 edit->setCursorPosition(empty ? prefix.size() : cursor);-
1757 }
never executed: end of block
0
1758 }-
1759 q->update();-
1760}
never executed: end of block
0
1761-
1762/*!-
1763 \internal-
1764-
1765 Convenience function to set min/max values.-
1766*/-
1767-
1768void QAbstractSpinBoxPrivate::setRange(const QVariant &min, const QVariant &max)-
1769{-
1770 Q_Q(QAbstractSpinBox);-
1771-
1772 clearCache();-
1773 minimum = min;-
1774 maximum = (variantCompare(min, max) < 0 ? max : min);
variantCompare(min, max) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1775 cachedSizeHint = QSize();-
1776 cachedMinimumSizeHint = QSize(); // minimumSizeHint cares about min/max-
1777-
1778 reset();-
1779 if (!(bound(value) == value)) {
!(bound(value) == value)Description
TRUEnever evaluated
FALSEnever evaluated
0
1780 setValue(bound(value), EmitIfChanged);-
1781 } else if (value == minimum && !specialValueText.isEmpty()) {
never executed: end of block
value == minimumDescription
TRUEnever evaluated
FALSEnever evaluated
!specialValueText.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
0
1782 updateEdit();-
1783 }
never executed: end of block
0
1784-
1785 q->updateGeometry();-
1786}
never executed: end of block
0
1787-
1788/*!-
1789 \internal-
1790-
1791 Convenience function to get a variant of the right type.-
1792*/-
1793-
1794QVariant QAbstractSpinBoxPrivate::getZeroVariant() const-
1795{-
1796 QVariant ret;-
1797 switch (type) {-
1798 case QVariant::Int: ret = QVariant((int)0); break;
never executed: break;
never executed: case QVariant::Int:
0
1799 case QVariant::Double: ret = QVariant((double)0.0); break;
never executed: break;
never executed: case QVariant::Double:
0
1800 default: break;
never executed: break;
never executed: default:
0
1801 }-
1802 return ret;
never executed: return ret;
0
1803}-
1804-
1805/*!-
1806 \internal-
1807-
1808 Virtual method called that calls the public textFromValue()-
1809 functions in the subclasses. Needed to change signature from-
1810 QVariant to int/double/QDateTime etc. Used when needing to display-
1811 a value textually.-
1812-
1813 This method is reimeplemented in the various subclasses.-
1814*/-
1815-
1816QString QAbstractSpinBoxPrivate::textFromValue(const QVariant &) const-
1817{-
1818 return QString();
never executed: return QString();
0
1819}-
1820-
1821/*!-
1822 \internal-
1823-
1824 Virtual method called that calls the public valueFromText()-
1825 functions in the subclasses. Needed to change signature from-
1826 QVariant to int/double/QDateTime etc. Used when needing to-
1827 interpret a string as another type.-
1828-
1829 This method is reimeplemented in the various subclasses.-
1830*/-
1831-
1832QVariant QAbstractSpinBoxPrivate::valueFromText(const QString &) const-
1833{-
1834 return QVariant();
never executed: return QVariant();
0
1835}-
1836/*!-
1837 \internal-
1838-
1839 Interprets text and emits signals. Called when the spinbox needs-
1840 to interpret the text on the lineedit.-
1841*/-
1842-
1843void QAbstractSpinBoxPrivate::interpret(EmitPolicy ep)-
1844{-
1845 Q_Q(QAbstractSpinBox);-
1846 if (type == QVariant::Invalid || cleared)
type == QVariant::InvalidDescription
TRUEnever evaluated
FALSEnever evaluated
clearedDescription
TRUEnever evaluated
FALSEnever evaluated
0
1847 return;
never executed: return;
0
1848-
1849 QVariant v = getZeroVariant();-
1850 bool doInterpret = true;-
1851 QString tmp = edit->displayText();-
1852 int pos = edit->cursorPosition();-
1853 const int oldpos = pos;-
1854-
1855 if (q->validate(tmp, pos) != QValidator::Acceptable) {
q->validate(tm...or::AcceptableDescription
TRUEnever evaluated
FALSEnever evaluated
0
1856 const QString copy = tmp;-
1857 q->fixup(tmp);-
1858 QASBDEBUG() << "QAbstractSpinBoxPrivate::interpret() text '"
dead code: QMessageLogger(__FILE__, 1858, __PRETTY_FUNCTION__).debug() << "QAbstractSpinBoxPrivate::interpret() text '" << edit->displayText() << "' >> '" << copy << '\'' << "' >> '" << tmp << '\'';
-
1859 << edit->displayText()
dead code: QMessageLogger(__FILE__, 1858, __PRETTY_FUNCTION__).debug() << "QAbstractSpinBoxPrivate::interpret() text '" << edit->displayText() << "' >> '" << copy << '\'' << "' >> '" << tmp << '\'';
-
1860 << "' >> '" << copy << '\''
dead code: QMessageLogger(__FILE__, 1858, __PRETTY_FUNCTION__).debug() << "QAbstractSpinBoxPrivate::interpret() text '" << edit->displayText() << "' >> '" << copy << '\'' << "' >> '" << tmp << '\'';
-
1861 << "' >> '" << tmp << '\'';
dead code: QMessageLogger(__FILE__, 1858, __PRETTY_FUNCTION__).debug() << "QAbstractSpinBoxPrivate::interpret() text '" << edit->displayText() << "' >> '" << copy << '\'' << "' >> '" << tmp << '\'';
-
1862-
1863 doInterpret = tmp != copy && (q->validate(tmp, pos) == QValidator::Acceptable);
tmp != copyDescription
TRUEnever evaluated
FALSEnever evaluated
(q->validate(t...r::Acceptable)Description
TRUEnever evaluated
FALSEnever evaluated
0
1864 if (!doInterpret) {
!doInterpretDescription
TRUEnever evaluated
FALSEnever evaluated
0
1865 v = (correctionMode == QAbstractSpinBox::CorrectToNearestValue
correctionMode...ToNearestValueDescription
TRUEnever evaluated
FALSEnever evaluated
0
1866 ? variantBound(minimum, v, maximum) : value);-
1867 }
never executed: end of block
0
1868 }
never executed: end of block
0
1869 if (doInterpret) {
doInterpretDescription
TRUEnever evaluated
FALSEnever evaluated
0
1870 v = valueFromText(tmp);-
1871 }
never executed: end of block
0
1872 clearCache();-
1873 setValue(v, ep, true);-
1874 if (oldpos != pos)
oldpos != posDescription
TRUEnever evaluated
FALSEnever evaluated
0
1875 edit->setCursorPosition(pos);
never executed: edit->setCursorPosition(pos);
0
1876}
never executed: end of block
0
1877-
1878void QAbstractSpinBoxPrivate::clearCache() const-
1879{-
1880 cachedText.clear();-
1881 cachedValue.clear();-
1882 cachedState = QValidator::Acceptable;-
1883}
never executed: end of block
0
1884-
1885-
1886// --- QSpinBoxValidator ----
1887-
1888/*!-
1889 \internal-
1890 Constructs a QSpinBoxValidator object-
1891*/-
1892-
1893QSpinBoxValidator::QSpinBoxValidator(QAbstractSpinBox *qp, QAbstractSpinBoxPrivate *dp)-
1894 : QValidator(qp), qptr(qp), dptr(dp)-
1895{-
1896 setObjectName(QLatin1String("qt_spinboxvalidator"));-
1897}
never executed: end of block
0
1898-
1899/*!-
1900 \internal-
1901-
1902 Checks for specialValueText, prefix, suffix and calls-
1903 the virtual QAbstractSpinBox::validate function.-
1904*/-
1905-
1906QValidator::State QSpinBoxValidator::validate(QString &input, int &pos) const-
1907{-
1908 if (dptr->specialValueText.size() > 0 && input == dptr->specialValueText)
dptr->specialV...ext.size() > 0Description
TRUEnever evaluated
FALSEnever evaluated
input == dptr-...ecialValueTextDescription
TRUEnever evaluated
FALSEnever evaluated
0
1909 return QValidator::Acceptable;
never executed: return QValidator::Acceptable;
0
1910-
1911 if (!dptr->prefix.isEmpty() && !input.startsWith(dptr->prefix)) {
!dptr->prefix.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
!input.startsW...(dptr->prefix)Description
TRUEnever evaluated
FALSEnever evaluated
0
1912 input.prepend(dptr->prefix);-
1913 pos += dptr->prefix.length();-
1914 }
never executed: end of block
0
1915-
1916 if (!dptr->suffix.isEmpty() && !input.endsWith(dptr->suffix))
!dptr->suffix.isEmpty()Description
TRUEnever evaluated
FALSEnever evaluated
!input.endsWith(dptr->suffix)Description
TRUEnever evaluated
FALSEnever evaluated
0
1917 input.append(dptr->suffix);
never executed: input.append(dptr->suffix);
0
1918-
1919 return qptr->validate(input, pos);
never executed: return qptr->validate(input, pos);
0
1920}-
1921/*!-
1922 \internal-
1923 Calls the virtual QAbstractSpinBox::fixup function.-
1924*/-
1925-
1926void QSpinBoxValidator::fixup(QString &input) const-
1927{-
1928 qptr->fixup(input);-
1929}
never executed: end of block
0
1930-
1931// --- global ----
1932-
1933/*!-
1934 \internal-
1935 Adds two variants together and returns the result.-
1936*/-
1937-
1938QVariant operator+(const QVariant &arg1, const QVariant &arg2)-
1939{-
1940 QVariant ret;-
1941 if (Q_UNLIKELY(arg1.type() != arg2.type()))
__builtin_expe...ype()), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
1942 qWarning("QAbstractSpinBox: Internal error: Different types (%s vs %s) (%s:%d)",
never executed: QMessageLogger(__FILE__, 1942, __PRETTY_FUNCTION__).warning("QAbstractSpinBox: Internal error: Different types (%s vs %s) (%s:%d)", arg1.typeName(), arg2.typeName(), __FILE__, 1943);
0
1943 arg1.typeName(), arg2.typeName(), __FILE__, __LINE__);
never executed: QMessageLogger(__FILE__, 1942, __PRETTY_FUNCTION__).warning("QAbstractSpinBox: Internal error: Different types (%s vs %s) (%s:%d)", arg1.typeName(), arg2.typeName(), __FILE__, 1943);
0
1944 switch (arg1.type()) {-
1945 case QVariant::Int: {
never executed: case QVariant::Int:
0
1946 const int int1 = arg1.toInt();-
1947 const int int2 = arg2.toInt();-
1948 if (int1 > 0 && (int2 >= INT_MAX - int1)) {
int1 > 0Description
TRUEnever evaluated
FALSEnever evaluated
(int2 >= 2147483647 - int1)Description
TRUEnever evaluated
FALSEnever evaluated
0
1949 // The increment overflows-
1950 ret = QVariant(INT_MAX);-
1951 } else if (int1 < 0 && (int2 <= INT_MIN - int1)) {
never executed: end of block
int1 < 0Description
TRUEnever evaluated
FALSEnever evaluated
(int2 <= (-214...7 - 1) - int1)Description
TRUEnever evaluated
FALSEnever evaluated
0
1952 // The increment underflows-
1953 ret = QVariant(INT_MIN);-
1954 } else {
never executed: end of block
0
1955 ret = QVariant(int1 + int2);-
1956 }
never executed: end of block
0
1957 break;
never executed: break;
0
1958 }-
1959 case QVariant::Double: ret = QVariant(arg1.toDouble() + arg2.toDouble()); break;
never executed: break;
never executed: case QVariant::Double:
0
1960 case QVariant::DateTime: {
never executed: case QVariant::DateTime:
0
1961 QDateTime a2 = arg2.toDateTime();-
1962 QDateTime a1 = arg1.toDateTime().addDays(QDATETIMEEDIT_DATETIME_MIN.daysTo(a2));-
1963 a1.setTime(a1.time().addMSecs(QTime().msecsTo(a2.time())));-
1964 ret = QVariant(a1);-
1965 }-
1966 default: break;
never executed: break;
code before this statement never executed: default:
never executed: default:
0
1967 }-
1968 return ret;
never executed: return ret;
0
1969}-
1970-
1971-
1972/*!-
1973 \internal-
1974 Subtracts two variants and returns the result.-
1975*/-
1976-
1977QVariant operator-(const QVariant &arg1, const QVariant &arg2)-
1978{-
1979 QVariant ret;-
1980 if (Q_UNLIKELY(arg1.type() != arg2.type()))
__builtin_expe...ype()), false)Description
TRUEnever evaluated
FALSEnever evaluated
0
1981 qWarning("QAbstractSpinBox: Internal error: Different types (%s vs %s) (%s:%d)",
never executed: QMessageLogger(__FILE__, 1981, __PRETTY_FUNCTION__).warning("QAbstractSpinBox: Internal error: Different types (%s vs %s) (%s:%d)", arg1.typeName(), arg2.typeName(), __FILE__, 1982);
0
1982 arg1.typeName(), arg2.typeName(), __FILE__, __LINE__);
never executed: QMessageLogger(__FILE__, 1981, __PRETTY_FUNCTION__).warning("QAbstractSpinBox: Internal error: Different types (%s vs %s) (%s:%d)", arg1.typeName(), arg2.typeName(), __FILE__, 1982);
0
1983 switch (arg1.type()) {-
1984 case QVariant::Int: ret = QVariant(arg1.toInt() - arg2.toInt()); break;
never executed: break;
never executed: case QVariant::Int:
0
1985 case QVariant::Double: ret = QVariant(arg1.toDouble() - arg2.toDouble()); break;
never executed: break;
never executed: case QVariant::Double:
0
1986 case QVariant::DateTime: {
never executed: case QVariant::DateTime:
0
1987 QDateTime a1 = arg1.toDateTime();-
1988 QDateTime a2 = arg2.toDateTime();-
1989 int days = a2.daysTo(a1);-
1990 int secs = a2.secsTo(a1);-
1991 int msecs = qMax(0, a1.time().msec() - a2.time().msec());-
1992 if (days < 0 || secs < 0 || msecs < 0) {
days < 0Description
TRUEnever evaluated
FALSEnever evaluated
secs < 0Description
TRUEnever evaluated
FALSEnever evaluated
msecs < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1993 ret = arg1;-
1994 } else {
never executed: end of block
0
1995 QDateTime dt = a2.addDays(days).addSecs(secs);-
1996 if (msecs > 0)
msecs > 0Description
TRUEnever evaluated
FALSEnever evaluated
0
1997 dt.setTime(dt.time().addMSecs(msecs));
never executed: dt.setTime(dt.time().addMSecs(msecs));
0
1998 ret = QVariant(dt);-
1999 }
never executed: end of block
0
2000 }-
2001 default: break;
never executed: break;
code before this statement never executed: default:
never executed: default:
0
2002 }-
2003 return ret;
never executed: return ret;
0
2004}-
2005-
2006/*!-
2007 \internal-
2008 Multiplies \a arg1 by \a multiplier and returns the result.-
2009*/-
2010-
2011QVariant operator*(const QVariant &arg1, double multiplier)-
2012{-
2013 QVariant ret;-
2014-
2015 switch (arg1.type()) {-
2016 case QVariant::Int:
never executed: case QVariant::Int:
0
2017 ret = static_cast<int>(qBound<double>(INT_MIN, arg1.toInt() * multiplier, INT_MAX));-
2018 break;
never executed: break;
0
2019 case QVariant::Double: ret = QVariant(arg1.toDouble() * multiplier); break;
never executed: break;
never executed: case QVariant::Double:
0
2020 case QVariant::DateTime: {
never executed: case QVariant::DateTime:
0
2021 double days = QDATETIMEEDIT_DATE_MIN.daysTo(arg1.toDateTime().date()) * multiplier;-
2022 int daysInt = (int)days;-
2023 days -= daysInt;-
2024 long msecs = (long)((QDATETIMEEDIT_TIME_MIN.msecsTo(arg1.toDateTime().time()) * multiplier)-
2025 + (days * (24 * 3600 * 1000)));-
2026 ret = QDateTime(QDate().addDays(int(days)), QTime().addMSecs(msecs));-
2027 break;
never executed: break;
0
2028 }-
2029 default: ret = arg1; break;
never executed: break;
never executed: default:
0
2030 }-
2031-
2032 return ret;
never executed: return ret;
0
2033}-
2034-
2035-
2036-
2037double operator/(const QVariant &arg1, const QVariant &arg2)-
2038{-
2039 double a1 = 0;-
2040 double a2 = 0;-
2041-
2042 switch (arg1.type()) {-
2043 case QVariant::Int:
never executed: case QVariant::Int:
0
2044 a1 = (double)arg1.toInt();-
2045 a2 = (double)arg2.toInt();-
2046 break;
never executed: break;
0
2047 case QVariant::Double:
never executed: case QVariant::Double:
0
2048 a1 = arg1.toDouble();-
2049 a2 = arg2.toDouble();-
2050 break;
never executed: break;
0
2051 case QVariant::DateTime:
never executed: case QVariant::DateTime:
0
2052 a1 = QDATETIMEEDIT_DATE_MIN.daysTo(arg1.toDate());-
2053 a2 = QDATETIMEEDIT_DATE_MIN.daysTo(arg2.toDate());-
2054 a1 += (double)QDATETIMEEDIT_TIME_MIN.msecsTo(arg1.toDateTime().time()) / (long)(3600 * 24 * 1000);-
2055 a2 += (double)QDATETIMEEDIT_TIME_MIN.msecsTo(arg2.toDateTime().time()) / (long)(3600 * 24 * 1000);-
2056 default: break;
never executed: break;
code before this statement never executed: default:
never executed: default:
0
2057 }-
2058-
2059 return (a1 != 0 && a2 != 0) ? (a1 / a2) : 0.0;
never executed: return (a1 != 0 && a2 != 0) ? (a1 / a2) : 0.0;
0
2060}-
2061-
2062int QAbstractSpinBoxPrivate::variantCompare(const QVariant &arg1, const QVariant &arg2)-
2063{-
2064 switch (arg2.type()) {-
2065 case QVariant::Date:
never executed: case QVariant::Date:
0
2066 Q_ASSERT_X(arg1.type() == QVariant::Date, "QAbstractSpinBoxPrivate::variantCompare",-
2067 qPrintable(QString::fromLatin1("Internal error 1 (%1)").-
2068 arg(QString::fromLatin1(arg1.typeName()))));-
2069 if (arg1.toDate() == arg2.toDate()) {
arg1.toDate() == arg2.toDate()Description
TRUEnever evaluated
FALSEnever evaluated
0
2070 return 0;
never executed: return 0;
0
2071 } else if (arg1.toDate() < arg2.toDate()) {
arg1.toDate() < arg2.toDate()Description
TRUEnever evaluated
FALSEnever evaluated
0
2072 return -1;
never executed: return -1;
0
2073 } else {-
2074 return 1;
never executed: return 1;
0
2075 }-
2076 case QVariant::Time:
never executed: case QVariant::Time:
0
2077 Q_ASSERT_X(arg1.type() == QVariant::Time, "QAbstractSpinBoxPrivate::variantCompare",-
2078 qPrintable(QString::fromLatin1("Internal error 2 (%1)").-
2079 arg(QString::fromLatin1(arg1.typeName()))));-
2080 if (arg1.toTime() == arg2.toTime()) {
arg1.toTime() == arg2.toTime()Description
TRUEnever evaluated
FALSEnever evaluated
0
2081 return 0;
never executed: return 0;
0
2082 } else if (arg1.toTime() < arg2.toTime()) {
arg1.toTime() < arg2.toTime()Description
TRUEnever evaluated
FALSEnever evaluated
0
2083 return -1;
never executed: return -1;
0
2084 } else {-
2085 return 1;
never executed: return 1;
0
2086 }-
2087-
2088-
2089 case QVariant::DateTime:
never executed: case QVariant::DateTime:
0
2090 if (arg1.toDateTime() == arg2.toDateTime()) {
arg1.toDateTim...2.toDateTime()Description
TRUEnever evaluated
FALSEnever evaluated
0
2091 return 0;
never executed: return 0;
0
2092 } else if (arg1.toDateTime() < arg2.toDateTime()) {
arg1.toDateTim...2.toDateTime()Description
TRUEnever evaluated
FALSEnever evaluated
0
2093 return -1;
never executed: return -1;
0
2094 } else {-
2095 return 1;
never executed: return 1;
0
2096 }-
2097 case QVariant::Int:
never executed: case QVariant::Int:
0
2098 if (arg1.toInt() == arg2.toInt()) {
arg1.toInt() == arg2.toInt()Description
TRUEnever evaluated
FALSEnever evaluated
0
2099 return 0;
never executed: return 0;
0
2100 } else if (arg1.toInt() < arg2.toInt()) {
arg1.toInt() < arg2.toInt()Description
TRUEnever evaluated
FALSEnever evaluated
0
2101 return -1;
never executed: return -1;
0
2102 } else {-
2103 return 1;
never executed: return 1;
0
2104 }-
2105 case QVariant::Double:
never executed: case QVariant::Double:
0
2106 if (arg1.toDouble() == arg2.toDouble()) {
arg1.toDouble(...rg2.toDouble()Description
TRUEnever evaluated
FALSEnever evaluated
0
2107 return 0;
never executed: return 0;
0
2108 } else if (arg1.toDouble() < arg2.toDouble()) {
arg1.toDouble(...rg2.toDouble()Description
TRUEnever evaluated
FALSEnever evaluated
0
2109 return -1;
never executed: return -1;
0
2110 } else {-
2111 return 1;
never executed: return 1;
0
2112 }-
2113 case QVariant::Invalid:
never executed: case QVariant::Invalid:
0
2114 if (arg2.type() == QVariant::Invalid)
arg2.type() ==...riant::InvalidDescription
TRUEnever evaluated
FALSEnever evaluated
0
2115 return 0;
never executed: return 0;
0
2116 default:
code before this statement never executed: default:
never executed: default:
0
2117 Q_ASSERT_X(0, "QAbstractSpinBoxPrivate::variantCompare",-
2118 qPrintable(QString::fromLatin1("Internal error 3 (%1 %2)").-
2119 arg(QString::fromLatin1(arg1.typeName())).-
2120 arg(QString::fromLatin1(arg2.typeName()))));-
2121 }
never executed: end of block
0
2122 return -2;
never executed: return -2;
0
2123}-
2124-
2125QVariant QAbstractSpinBoxPrivate::variantBound(const QVariant &min,-
2126 const QVariant &value,-
2127 const QVariant &max)-
2128{-
2129 Q_ASSERT(variantCompare(min, max) <= 0);-
2130 if (variantCompare(min, value) < 0) {
variantCompare(min, value) < 0Description
TRUEnever evaluated
FALSEnever evaluated
0
2131 const int compMax = variantCompare(value, max);-
2132 return (compMax < 0 ? value : max);
never executed: return (compMax < 0 ? value : max);
0
2133 } else {-
2134 return min;
never executed: return min;
0
2135 }-
2136}-
2137-
2138-
2139QT_END_NAMESPACE-
2140-
2141#include "moc_qabstractspinbox.cpp"-
2142-
2143#endif // QT_NO_SPINBOX-
Source codeSwitch to Preprocessed file

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