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