0
|
1 |
/****************************************************************************
|
|
2 |
**
|
|
3 |
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
4 |
** All rights reserved.
|
|
5 |
** Contact: Nokia Corporation (qt-info@nokia.com)
|
|
6 |
**
|
|
7 |
** This file is part of the test suite of the Qt Toolkit.
|
|
8 |
**
|
|
9 |
** $QT_BEGIN_LICENSE:LGPL$
|
|
10 |
** No Commercial Usage
|
|
11 |
** This file contains pre-release code and may not be distributed.
|
|
12 |
** You may use this file in accordance with the terms and conditions
|
|
13 |
** contained in the Technology Preview License Agreement accompanying
|
|
14 |
** this package.
|
|
15 |
**
|
|
16 |
** GNU Lesser General Public License Usage
|
|
17 |
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
18 |
** General Public License version 2.1 as published by the Free Software
|
|
19 |
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
20 |
** packaging of this file. Please review the following information to
|
|
21 |
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
22 |
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
23 |
**
|
|
24 |
** In addition, as a special exception, Nokia gives you certain additional
|
|
25 |
** rights. These rights are described in the Nokia Qt LGPL Exception
|
|
26 |
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
27 |
**
|
|
28 |
** If you have questions regarding the use of this file, please contact
|
|
29 |
** Nokia at qt-info@nokia.com.
|
|
30 |
**
|
|
31 |
**
|
|
32 |
**
|
|
33 |
**
|
|
34 |
**
|
|
35 |
**
|
|
36 |
**
|
|
37 |
**
|
|
38 |
** $QT_END_LICENSE$
|
|
39 |
**
|
|
40 |
****************************************************************************/
|
|
41 |
|
|
42 |
|
|
43 |
#include <QtTest/QtTest>
|
|
44 |
#include <qapplication.h>
|
|
45 |
#include <limits.h>
|
|
46 |
|
|
47 |
#include <float.h>
|
|
48 |
|
|
49 |
#include <qspinbox.h>
|
|
50 |
#include <qlocale.h>
|
|
51 |
#include <qlayout.h>
|
|
52 |
|
|
53 |
#include <qlineedit.h>
|
|
54 |
#include <qdebug.h>
|
|
55 |
|
|
56 |
#include "../../shared/util.h"
|
|
57 |
|
|
58 |
//TESTED_CLASS=
|
|
59 |
//TESTED_FILES=gui/widgets/qspinbox.h gui/widgets/qspinbox.cpp gui/widgets/qabstractspinbox.cpp gui/widgets/qabstractspinbox_p.h gui/widgets/qabstractspinbox.h
|
|
60 |
|
|
61 |
|
|
62 |
class DoubleSpinBox : public QDoubleSpinBox
|
|
63 |
{
|
|
64 |
Q_OBJECT
|
|
65 |
public:
|
|
66 |
DoubleSpinBox(QWidget *parent = 0)
|
|
67 |
: QDoubleSpinBox(parent)
|
|
68 |
{ /*connect(this, SIGNAL(valueChanged(double)), this, SLOT(foo(double)));*/ }
|
|
69 |
QString textFromValue(double v) const
|
|
70 |
{
|
|
71 |
return QDoubleSpinBox::textFromValue(v);
|
|
72 |
}
|
|
73 |
QValidator::State validate(QString &text, int &pos) const
|
|
74 |
{
|
|
75 |
return QDoubleSpinBox::validate(text, pos);
|
|
76 |
}
|
|
77 |
double valueFromText(const QString &text) const
|
|
78 |
{
|
|
79 |
return QDoubleSpinBox::valueFromText(text);
|
|
80 |
}
|
|
81 |
|
|
82 |
QLineEdit* lineEdit() const { return QDoubleSpinBox::lineEdit(); }
|
|
83 |
public slots:
|
|
84 |
void foo(double vla)
|
|
85 |
{
|
|
86 |
qDebug() << vla;
|
|
87 |
}
|
|
88 |
};
|
|
89 |
|
|
90 |
|
|
91 |
class tst_QDoubleSpinBox : public QObject
|
|
92 |
{
|
|
93 |
Q_OBJECT
|
|
94 |
public:
|
|
95 |
tst_QDoubleSpinBox();
|
|
96 |
virtual ~tst_QDoubleSpinBox();
|
|
97 |
public slots:
|
|
98 |
void initTestCase();
|
|
99 |
void cleanupTestCase();
|
|
100 |
void init();
|
|
101 |
|
|
102 |
private slots:
|
|
103 |
void germanTest();
|
|
104 |
|
|
105 |
void task54433();
|
|
106 |
|
|
107 |
void setValue_data();
|
|
108 |
void setValue();
|
|
109 |
|
|
110 |
void setPrefixSuffix_data();
|
|
111 |
void setPrefixSuffix();
|
|
112 |
|
|
113 |
void setTracking_data();
|
|
114 |
void setTracking();
|
|
115 |
|
|
116 |
void setWrapping_data();
|
|
117 |
void setWrapping();
|
|
118 |
|
|
119 |
void setSpecialValueText_data();
|
|
120 |
void setSpecialValueText();
|
|
121 |
|
|
122 |
void setSingleStep_data();
|
|
123 |
void setSingleStep();
|
|
124 |
|
|
125 |
void setMinMax_data();
|
|
126 |
void setMinMax();
|
|
127 |
|
|
128 |
void setDecimals_data();
|
|
129 |
void setDecimals();
|
|
130 |
|
|
131 |
void doubleDot();
|
|
132 |
|
|
133 |
void undoRedo();
|
|
134 |
|
|
135 |
void valueFromTextAndValidate_data();
|
|
136 |
void valueFromTextAndValidate();
|
|
137 |
|
|
138 |
void setReadOnly();
|
|
139 |
|
|
140 |
void editingFinished();
|
|
141 |
|
|
142 |
void removeAll();
|
|
143 |
|
|
144 |
void task199226_stateAfterEnter();
|
|
145 |
void task224497_fltMax();
|
|
146 |
|
|
147 |
void task221221();
|
|
148 |
void task255471_decimalsValidation();
|
|
149 |
|
|
150 |
public slots:
|
|
151 |
void valueChangedHelper(const QString &);
|
|
152 |
void valueChangedHelper(double);
|
|
153 |
private:
|
|
154 |
QStringList actualTexts;
|
|
155 |
QList<double> actualValues;
|
|
156 |
QWidget *testFocusWidget;
|
|
157 |
};
|
|
158 |
|
|
159 |
typedef QList<double> DoubleList;
|
|
160 |
Q_DECLARE_METATYPE(DoubleList)
|
|
161 |
|
|
162 |
tst_QDoubleSpinBox::tst_QDoubleSpinBox()
|
|
163 |
|
|
164 |
{
|
|
165 |
}
|
|
166 |
|
|
167 |
tst_QDoubleSpinBox::~tst_QDoubleSpinBox()
|
|
168 |
{
|
|
169 |
|
|
170 |
}
|
|
171 |
|
|
172 |
void tst_QDoubleSpinBox::initTestCase()
|
|
173 |
{
|
|
174 |
testFocusWidget = new QWidget(0);
|
|
175 |
testFocusWidget->resize(200, 100);
|
|
176 |
testFocusWidget->show();
|
|
177 |
}
|
|
178 |
|
|
179 |
void tst_QDoubleSpinBox::cleanupTestCase()
|
|
180 |
{
|
|
181 |
delete testFocusWidget;
|
|
182 |
testFocusWidget = 0;
|
|
183 |
}
|
|
184 |
|
|
185 |
void tst_QDoubleSpinBox::init()
|
|
186 |
{
|
|
187 |
QLocale::setDefault(QLocale(QLocale::C));
|
|
188 |
}
|
|
189 |
|
|
190 |
void tst_QDoubleSpinBox::setValue_data()
|
|
191 |
{
|
|
192 |
QTest::addColumn<double>("val");
|
|
193 |
|
|
194 |
QTest::newRow("data0") << 0.0;
|
|
195 |
QTest::newRow("data1") << 100.5;
|
|
196 |
QTest::newRow("data2") << -100.5;
|
|
197 |
QTest::newRow("data3") << -DBL_MAX;
|
|
198 |
QTest::newRow("data4") << DBL_MAX;
|
|
199 |
}
|
|
200 |
|
|
201 |
void tst_QDoubleSpinBox::setValue()
|
|
202 |
{
|
|
203 |
QFETCH(double, val);
|
|
204 |
QDoubleSpinBox spin(0);
|
|
205 |
spin.setRange(-DBL_MAX, DBL_MAX);
|
|
206 |
spin.setValue(val);
|
|
207 |
QCOMPARE(spin.value(), val);
|
|
208 |
}
|
|
209 |
|
|
210 |
void tst_QDoubleSpinBox::setPrefixSuffix_data()
|
|
211 |
{
|
|
212 |
QTest::addColumn<QString>("prefix");
|
|
213 |
QTest::addColumn<QString>("suffix");
|
|
214 |
QTest::addColumn<double>("value");
|
|
215 |
QTest::addColumn<int>("decimals");
|
|
216 |
QTest::addColumn<QString>("expectedText");
|
|
217 |
QTest::addColumn<QString>("expectedCleanText");
|
|
218 |
QTest::addColumn<bool>("show");
|
|
219 |
|
|
220 |
QTest::newRow("data0") << QString() << QString() << 10.5 << 1 << "10.5" << "10.5" << false;
|
|
221 |
QTest::newRow("data1") << QString() << "cm" << 10.5 << 2 << "10.50cm" << "10.50" << false;
|
|
222 |
QTest::newRow("data2") << "cm: " << QString() << 10.5 << 0 << "cm: 10" << "10" << false;
|
|
223 |
QTest::newRow("data3") << "length: " << "cm" << 10.5 << 3 << "length: 10.500cm" << "10.500" << false;
|
|
224 |
|
|
225 |
QTest::newRow("data4") << QString() << QString() << 10.5 << 1 << "10.5" << "10.5" << true;
|
|
226 |
QTest::newRow("data5") << QString() << "cm" << 10.5 << 2 << "10.50cm" << "10.50" << true;
|
|
227 |
QTest::newRow("data6") << "cm: " << QString() << 10.5 << 0 << "cm: 10" << "10" << true;
|
|
228 |
QTest::newRow("data7") << "length: " << "cm" << 10.5 << 3 << "length: 10.500cm" << "10.500" << true;
|
|
229 |
}
|
|
230 |
|
|
231 |
void tst_QDoubleSpinBox::setPrefixSuffix()
|
|
232 |
{
|
|
233 |
QFETCH(QString, prefix);
|
|
234 |
QFETCH(QString, suffix);
|
|
235 |
QFETCH(double, value);
|
|
236 |
QFETCH(int, decimals);
|
|
237 |
QFETCH(QString, expectedText);
|
|
238 |
QFETCH(QString, expectedCleanText);
|
|
239 |
QFETCH(bool, show);
|
|
240 |
|
|
241 |
QDoubleSpinBox spin(0);
|
|
242 |
spin.setDecimals(decimals);
|
|
243 |
spin.setPrefix(prefix);
|
|
244 |
spin.setSuffix(suffix);
|
|
245 |
spin.setValue(value);
|
|
246 |
if (show)
|
|
247 |
spin.show();
|
|
248 |
|
|
249 |
QCOMPARE(spin.text(), expectedText);
|
|
250 |
QCOMPARE(spin.cleanText(), expectedCleanText);
|
|
251 |
}
|
|
252 |
|
|
253 |
void tst_QDoubleSpinBox::valueChangedHelper(const QString &text)
|
|
254 |
{
|
|
255 |
actualTexts << text;
|
|
256 |
}
|
|
257 |
|
|
258 |
void tst_QDoubleSpinBox::valueChangedHelper(double value)
|
|
259 |
{
|
|
260 |
actualValues << value;
|
|
261 |
}
|
|
262 |
|
|
263 |
void tst_QDoubleSpinBox::setTracking_data()
|
|
264 |
{
|
|
265 |
QTest::addColumn<int>("decimals");
|
|
266 |
QTest::addColumn<QTestEventList>("keys");
|
|
267 |
QTest::addColumn<QStringList>("texts");
|
|
268 |
QTest::addColumn<bool>("tracking");
|
|
269 |
|
|
270 |
QTestEventList keys;
|
|
271 |
QStringList texts1;
|
|
272 |
QStringList texts2;
|
|
273 |
#ifdef Q_WS_MAC
|
|
274 |
keys.addKeyClick(Qt::Key_Right, Qt::ControlModifier);
|
|
275 |
#else
|
|
276 |
keys.addKeyClick(Qt::Key_End);
|
|
277 |
#endif
|
|
278 |
keys.addKeyClick(Qt::Key_Backspace);
|
|
279 |
keys.addKeyClick(Qt::Key_Backspace);
|
|
280 |
keys.addKeyClick(Qt::Key_Backspace);
|
|
281 |
keys.addKeyClick(Qt::Key_Backspace);
|
|
282 |
keys.addKeyClick(Qt::Key_Backspace);
|
|
283 |
keys.addKeyClick(Qt::Key_Backspace);
|
|
284 |
keys.addKeyClick(Qt::Key_Backspace);
|
|
285 |
keys.addKeyClick(Qt::Key_Backspace);
|
|
286 |
keys.addKeyClick('7');
|
|
287 |
keys.addKeyClick('.');
|
|
288 |
keys.addKeyClick('9');
|
|
289 |
keys.addKeyClick(Qt::Key_Backspace);
|
|
290 |
keys.addKeyClick('2');
|
|
291 |
keys.addKeyClick(Qt::Key_Enter);
|
|
292 |
keys.addKeyClick(Qt::Key_Enter);
|
|
293 |
keys.addKeyClick(Qt::Key_Enter);
|
|
294 |
texts1 << "7" << "7.9" << "7." << "7.2" << "7.200" << "7.200" << "7.200";
|
|
295 |
texts2 << "7.200";
|
|
296 |
QTest::newRow("data1") << 3 << keys << texts1 << true;
|
|
297 |
QTest::newRow("data2") << 3 << keys << texts2 << false;
|
|
298 |
|
|
299 |
}
|
|
300 |
|
|
301 |
void tst_QDoubleSpinBox::setTracking()
|
|
302 |
{
|
|
303 |
QLocale::setDefault(QLocale(QLocale::C));
|
|
304 |
|
|
305 |
actualTexts.clear();
|
|
306 |
QFETCH(int, decimals);
|
|
307 |
QFETCH(QTestEventList, keys);
|
|
308 |
QFETCH(QStringList, texts);
|
|
309 |
QFETCH(bool, tracking);
|
|
310 |
|
|
311 |
QDoubleSpinBox spin(0);
|
|
312 |
spin.setKeyboardTracking(tracking);
|
|
313 |
spin.setDecimals(decimals);
|
|
314 |
spin.show();
|
|
315 |
|
|
316 |
connect(&spin, SIGNAL(valueChanged(QString)), this, SLOT(valueChangedHelper(const QString &)));
|
|
317 |
|
|
318 |
keys.simulate(&spin);
|
|
319 |
QCOMPARE(actualTexts, texts);
|
|
320 |
}
|
|
321 |
|
|
322 |
void tst_QDoubleSpinBox::setWrapping_data()
|
|
323 |
{
|
|
324 |
QTest::addColumn<bool>("wrapping");
|
|
325 |
QTest::addColumn<double>("minimum");
|
|
326 |
QTest::addColumn<double>("maximum");
|
|
327 |
QTest::addColumn<double>("startValue");
|
|
328 |
QTest::addColumn<QTestEventList>("keys");
|
|
329 |
QTest::addColumn<DoubleList>("expected");
|
|
330 |
|
|
331 |
QTestEventList keys;
|
|
332 |
DoubleList values;
|
|
333 |
keys.addKeyClick(Qt::Key_Up);
|
|
334 |
values << 10;
|
|
335 |
keys.addKeyClick(Qt::Key_Up);
|
|
336 |
QTest::newRow("data0") << false << 0.0 << 10.0 << 9.0 << keys << values;
|
|
337 |
|
|
338 |
keys.clear();
|
|
339 |
values.clear();
|
|
340 |
keys.addKeyClick(Qt::Key_Up);
|
|
341 |
values << 10;
|
|
342 |
keys.addKeyClick(Qt::Key_Up);
|
|
343 |
values << 0;
|
|
344 |
QTest::newRow("data1") << true << 0.0 << 10.0 << 9.0 << keys << values;
|
|
345 |
|
|
346 |
keys.clear();
|
|
347 |
values.clear();
|
|
348 |
#ifdef Q_WS_MAC
|
|
349 |
keys.addKeyClick(Qt::Key_Right, Qt::ControlModifier);
|
|
350 |
#else
|
|
351 |
keys.addKeyClick(Qt::Key_End);
|
|
352 |
#endif
|
|
353 |
keys.addKeyClick(Qt::Key_Backspace);
|
|
354 |
keys.addKeyClick('1');
|
|
355 |
keys.addKeyClick(Qt::Key_Down);
|
|
356 |
keys.addKeyClick(Qt::Key_Down);
|
|
357 |
keys.addKeyClick(Qt::Key_PageDown);
|
|
358 |
values << 9.01 << 8.01 << 7.01 << 0.0;
|
|
359 |
QTest::newRow("data2") << false << 0.0 << 10.0 << 9.0 << keys << values;
|
|
360 |
|
|
361 |
keys.clear();
|
|
362 |
values.clear();
|
|
363 |
#ifdef Q_WS_MAC
|
|
364 |
keys.addKeyClick(Qt::Key_Left, Qt::ControlModifier);
|
|
365 |
#else
|
|
366 |
keys.addKeyClick(Qt::Key_Home);
|
|
367 |
#endif
|
|
368 |
keys.addKeyClick(Qt::Key_Delete);
|
|
369 |
keys.addKeyClick(Qt::Key_Delete);
|
|
370 |
keys.addKeyClick(Qt::Key_Delete);
|
|
371 |
keys.addKeyClick(Qt::Key_Delete);
|
|
372 |
keys.addKeyClick(Qt::Key_Delete);
|
|
373 |
keys.addKeyClick(Qt::Key_Delete);
|
|
374 |
keys.addKeyClick(Qt::Key_Delete);
|
|
375 |
keys.addKeyClick('1');
|
|
376 |
keys.addKeyClick(Qt::Key_Down);
|
|
377 |
keys.addKeyClick(Qt::Key_Down);
|
|
378 |
values << 0 << 1 << 0 << 10;
|
|
379 |
QTest::newRow("data3") << true << 0.0 << 10.0 << 9.0 << keys << values;
|
|
380 |
|
|
381 |
keys.clear();
|
|
382 |
values.clear();
|
|
383 |
keys.addKeyClick(Qt::Key_PageDown);
|
|
384 |
keys.addKeyClick(Qt::Key_Down);
|
|
385 |
values << 0;
|
|
386 |
QTest::newRow("data4") << false << 0.0 << 10.0 << 6.0 << keys << values;
|
|
387 |
|
|
388 |
keys.clear();
|
|
389 |
values.clear();
|
|
390 |
keys.addKeyClick(Qt::Key_PageDown);
|
|
391 |
keys.addKeyClick(Qt::Key_Down);
|
|
392 |
values << 0 << 10;
|
|
393 |
QTest::newRow("data5") << true << 0.0 << 10.0 << 6.0 << keys << values;
|
|
394 |
|
|
395 |
keys.clear();
|
|
396 |
values.clear();
|
|
397 |
keys.addKeyClick(Qt::Key_PageUp);
|
|
398 |
keys.addKeyClick(Qt::Key_PageDown);
|
|
399 |
keys.addKeyClick(Qt::Key_Down);
|
|
400 |
keys.addKeyClick(Qt::Key_Up);
|
|
401 |
keys.addKeyClick(Qt::Key_PageDown);
|
|
402 |
keys.addKeyClick(Qt::Key_PageDown);
|
|
403 |
values << 10 << 0 << 10 << 0 << 10 << 0;
|
|
404 |
QTest::newRow("data6") << true << 0.0 << 10.0 << 6.0 << keys << values;
|
|
405 |
|
|
406 |
}
|
|
407 |
|
|
408 |
|
|
409 |
void tst_QDoubleSpinBox::setWrapping()
|
|
410 |
{
|
|
411 |
QLocale::setDefault(QLocale(QLocale::C));
|
|
412 |
QFETCH(bool, wrapping);
|
|
413 |
QFETCH(double, minimum);
|
|
414 |
QFETCH(double, maximum);
|
|
415 |
QFETCH(double, startValue);
|
|
416 |
QFETCH(QTestEventList, keys);
|
|
417 |
QFETCH(DoubleList, expected);
|
|
418 |
|
|
419 |
QDoubleSpinBox spin(0);
|
|
420 |
spin.setMinimum(minimum);
|
|
421 |
spin.setMaximum(maximum);
|
|
422 |
spin.setValue(startValue);
|
|
423 |
spin.setWrapping(wrapping);
|
|
424 |
spin.show();
|
|
425 |
actualValues.clear();
|
|
426 |
connect(&spin, SIGNAL(valueChanged(double)), this, SLOT(valueChangedHelper(double)));
|
|
427 |
|
|
428 |
keys.simulate(&spin);
|
|
429 |
|
|
430 |
QCOMPARE(actualValues.size(), expected.size());
|
|
431 |
for (int i=0; i<qMin(actualValues.size(), expected.size()); ++i) {
|
|
432 |
QCOMPARE(actualValues.at(i), expected.at(i));
|
|
433 |
}
|
|
434 |
}
|
|
435 |
|
|
436 |
void tst_QDoubleSpinBox::setSpecialValueText_data()
|
|
437 |
{
|
|
438 |
QTest::addColumn<QString>("specialValueText");
|
|
439 |
QTest::addColumn<double>("minimum");
|
|
440 |
QTest::addColumn<double>("maximum");
|
|
441 |
QTest::addColumn<double>("value");
|
|
442 |
QTest::addColumn<int>("decimals");
|
|
443 |
QTest::addColumn<QString>("expected");
|
|
444 |
QTest::addColumn<bool>("show");
|
|
445 |
|
|
446 |
QTest::newRow("data0") << QString() << 0.0 << 10.0 << 1.0 << 4 << "1.0000" << false;
|
|
447 |
QTest::newRow("data1") << QString() << 0.0 << 10.0 << 1.0 << 4 << "1.0000" << true;
|
|
448 |
QTest::newRow("data2") << "foo" << 0.0 << 10.0 << 0.0 << 2 << "foo" << false;
|
|
449 |
QTest::newRow("data3") << "foo" << 0.0 << 10.0 << 0.0 << 2 << "foo" << true;
|
|
450 |
}
|
|
451 |
|
|
452 |
void tst_QDoubleSpinBox::setSpecialValueText()
|
|
453 |
{
|
|
454 |
QFETCH(QString, specialValueText);
|
|
455 |
QFETCH(double, minimum);
|
|
456 |
QFETCH(double, maximum);
|
|
457 |
QFETCH(double, value);
|
|
458 |
QFETCH(int, decimals);
|
|
459 |
QFETCH(QString, expected);
|
|
460 |
QFETCH(bool, show);
|
|
461 |
|
|
462 |
QDoubleSpinBox spin(0);
|
|
463 |
spin.setSpecialValueText(specialValueText);
|
|
464 |
spin.setMinimum(minimum);
|
|
465 |
spin.setMaximum(maximum);
|
|
466 |
spin.setValue(value);
|
|
467 |
spin.setDecimals(decimals);
|
|
468 |
if (show)
|
|
469 |
spin.show();
|
|
470 |
|
|
471 |
QCOMPARE(spin.text(), expected);
|
|
472 |
}
|
|
473 |
|
|
474 |
void tst_QDoubleSpinBox::setSingleStep_data()
|
|
475 |
{
|
|
476 |
QTest::addColumn<double>("singleStep");
|
|
477 |
QTest::addColumn<double>("startValue");
|
|
478 |
QTest::addColumn<QTestEventList>("keys");
|
|
479 |
QTest::addColumn<DoubleList>("expected");
|
|
480 |
QTest::addColumn<bool>("show");
|
|
481 |
|
|
482 |
QTestEventList keys;
|
|
483 |
DoubleList values;
|
|
484 |
keys.addKeyClick(Qt::Key_Up);
|
|
485 |
keys.addKeyClick(Qt::Key_Down);
|
|
486 |
keys.addKeyClick(Qt::Key_Up);
|
|
487 |
values << 11 << 10 << 11;
|
|
488 |
QTest::newRow("data0") << 1.0 << 10.0 << keys << values << false;
|
|
489 |
QTest::newRow("data1") << 1.0 << 10.0 << keys << values << true;
|
|
490 |
|
|
491 |
keys.clear();
|
|
492 |
values.clear();
|
|
493 |
keys.addKeyClick(Qt::Key_Up);
|
|
494 |
keys.addKeyClick(Qt::Key_Down);
|
|
495 |
keys.addKeyClick(Qt::Key_Up);
|
|
496 |
values << 12.5 << 10.0 << 12.5;
|
|
497 |
QTest::newRow("data2") << 2.5 << 10.0 << keys << values << false;
|
|
498 |
QTest::newRow("data3") << 2.5 << 10.0 << keys << values << true;
|
|
499 |
}
|
|
500 |
|
|
501 |
void tst_QDoubleSpinBox::setSingleStep()
|
|
502 |
{
|
|
503 |
QFETCH(double, singleStep);
|
|
504 |
QFETCH(double, startValue);
|
|
505 |
QFETCH(QTestEventList, keys);
|
|
506 |
QFETCH(DoubleList, expected);
|
|
507 |
QFETCH(bool, show);
|
|
508 |
|
|
509 |
QDoubleSpinBox spin(0);
|
|
510 |
actualValues.clear();
|
|
511 |
spin.setSingleStep(singleStep);
|
|
512 |
spin.setValue(startValue);
|
|
513 |
if (show)
|
|
514 |
spin.show();
|
|
515 |
connect(&spin, SIGNAL(valueChanged(double)), this, SLOT(valueChangedHelper(double)));
|
|
516 |
|
|
517 |
QCOMPARE(actualValues.size(), 0);
|
|
518 |
keys.simulate(&spin);
|
|
519 |
QCOMPARE(actualValues.size(), expected.size());
|
|
520 |
for (int i=0; i<qMin(actualValues.size(), expected.size()); ++i) {
|
|
521 |
QCOMPARE(actualValues.at(i), expected.at(i));
|
|
522 |
}
|
|
523 |
}
|
|
524 |
|
|
525 |
void tst_QDoubleSpinBox::setMinMax_data()
|
|
526 |
{
|
|
527 |
QTest::addColumn<double>("startValue");
|
|
528 |
QTest::addColumn<double>("minimum");
|
|
529 |
QTest::addColumn<double>("maximum");
|
|
530 |
QTest::addColumn<QTestEventList>("keys");
|
|
531 |
QTest::addColumn<double>("expected");
|
|
532 |
QTest::addColumn<bool>("show");
|
|
533 |
|
|
534 |
QTestEventList keys;
|
|
535 |
keys.addKeyClick(Qt::Key_Up);
|
|
536 |
keys.addKeyClick(Qt::Key_Up);
|
|
537 |
keys.addKeyClick(Qt::Key_Up);
|
|
538 |
keys.addKeyClick(Qt::Key_Up);
|
|
539 |
keys.addKeyClick(Qt::Key_Up);
|
|
540 |
QTest::newRow("data0") << 1.0 << -DBL_MAX << 2.0 << keys << 2.0 << false;
|
|
541 |
QTest::newRow("data1") << 1.0 << -DBL_MAX << 2.0 << keys << 2.0 << true;
|
|
542 |
QTest::newRow("data2") << -20000.0 << -15000.0 << -13000.0 << keys << -14995.0 << false;
|
|
543 |
QTest::newRow("data3") << -20000.0 << -15000.0 << -13000.0 << keys << -14995.0 << true;
|
|
544 |
QTest::newRow("data4") << 20.0 << -101.2 << -102.0 << QTestEventList() << -102.0 << false;
|
|
545 |
QTest::newRow("data5") << 20.0 << -101.2 << -102.0 << QTestEventList() << -102.0 << true;
|
|
546 |
}
|
|
547 |
|
|
548 |
void tst_QDoubleSpinBox::setMinMax()
|
|
549 |
{
|
|
550 |
QFETCH(double, startValue);
|
|
551 |
QFETCH(double, minimum);
|
|
552 |
QFETCH(double, maximum);
|
|
553 |
QFETCH(QTestEventList, keys);
|
|
554 |
QFETCH(double, expected);
|
|
555 |
QFETCH(bool, show);
|
|
556 |
|
|
557 |
{
|
|
558 |
QDoubleSpinBox spin(0);
|
|
559 |
spin.setMinimum(minimum);
|
|
560 |
spin.setMaximum(maximum);
|
|
561 |
spin.setValue(startValue);
|
|
562 |
|
|
563 |
if (show)
|
|
564 |
spin.show();
|
|
565 |
keys.simulate(&spin);
|
|
566 |
QCOMPARE(spin.value(), expected);
|
|
567 |
}
|
|
568 |
|
|
569 |
{
|
|
570 |
QDoubleSpinBox spin(0);
|
|
571 |
spin.setMaximum(maximum);
|
|
572 |
spin.setMinimum(minimum);
|
|
573 |
spin.setValue(startValue);
|
|
574 |
|
|
575 |
if (show)
|
|
576 |
spin.show();
|
|
577 |
keys.simulate(&spin);
|
|
578 |
}
|
|
579 |
|
|
580 |
{
|
|
581 |
QDoubleSpinBox spin(0);
|
|
582 |
spin.setRange(minimum, maximum);
|
|
583 |
spin.setValue(startValue);
|
|
584 |
|
|
585 |
if (show)
|
|
586 |
spin.show();
|
|
587 |
keys.simulate(&spin);
|
|
588 |
}
|
|
589 |
|
|
590 |
|
|
591 |
}
|
|
592 |
|
|
593 |
void tst_QDoubleSpinBox::setDecimals_data()
|
|
594 |
{
|
|
595 |
QTest::addColumn<int>("decimals");
|
|
596 |
QTest::addColumn<int>("expectedDecimals");
|
|
597 |
QTest::addColumn<double>("startValue");
|
|
598 |
QTest::addColumn<QString>("expected");
|
|
599 |
|
|
600 |
QTest::newRow("data0") << 4 << 4 << 1.0 << "1.0000";
|
|
601 |
QTest::newRow("data1") << 1 << 1 << 1.243443 << "1.2";
|
|
602 |
QTest::newRow("data2") << 6 << 6 << 1.29 << "1.290000";
|
|
603 |
QTest::newRow("data3") << 8 << 8 << 9.1234567809 << "9.12345678";
|
|
604 |
QTest::newRow("data4") << 13 << 13 << 0.12345678901237 << "0.1234567890124";
|
|
605 |
QTest::newRow("data5") << 13 << 13 << -0.12345678901237 << "-0.1234567890124";
|
|
606 |
QTest::newRow("data6") << 13 << 13 << -0.12345678901237 << "-0.1234567890124";
|
|
607 |
QTest::newRow("data7") << -1 << 0 << 0.1 << "0";
|
|
608 |
QTest::newRow("data8") << 120 << 120 << -0.12345678901237 << "-0.123456789012370005131913330842508003115653991699218750000000000000000000000000000000000000000000000000000000000000000000";
|
|
609 |
|
|
610 |
}
|
|
611 |
|
|
612 |
void tst_QDoubleSpinBox::setDecimals()
|
|
613 |
{
|
|
614 |
QFETCH(int, decimals);
|
|
615 |
QFETCH(int, expectedDecimals);
|
|
616 |
QFETCH(double, startValue);
|
|
617 |
QFETCH(QString, expected);
|
|
618 |
|
|
619 |
QDoubleSpinBox spin(0);
|
|
620 |
spin.setRange(-DBL_MAX, DBL_MAX);
|
|
621 |
spin.setDecimals(decimals);
|
|
622 |
spin.setValue(startValue);
|
|
623 |
QCOMPARE(spin.decimals(), expectedDecimals);
|
|
624 |
if (sizeof(qreal) == sizeof(float))
|
|
625 |
QCOMPARE(spin.text().left(17), expected.left(17));
|
|
626 |
else
|
|
627 |
QCOMPARE(spin.text(), expected);
|
|
628 |
|
|
629 |
if (spin.decimals() > 0) {
|
|
630 |
#ifdef Q_WS_MAC
|
|
631 |
QTest::keyClick(&spin, Qt::Key_Right, Qt::ControlModifier);
|
|
632 |
#else
|
|
633 |
QTest::keyClick(&spin, Qt::Key_End);
|
|
634 |
#endif
|
|
635 |
QTest::keyClick(&spin, Qt::Key_1); // just make sure we can't input more decimals than what is specified
|
|
636 |
QTest::keyClick(&spin, Qt::Key_1);
|
|
637 |
QTest::keyClick(&spin, Qt::Key_1);
|
|
638 |
QTest::keyClick(&spin, Qt::Key_1);
|
|
639 |
QTest::keyClick(&spin, Qt::Key_1);
|
|
640 |
if (sizeof(qreal) == sizeof(float))
|
|
641 |
QCOMPARE(spin.text().left(17), expected.left(17));
|
|
642 |
else
|
|
643 |
QCOMPARE(spin.text(), expected);
|
|
644 |
}
|
|
645 |
}
|
|
646 |
|
|
647 |
static QString stateName(int state)
|
|
648 |
{
|
|
649 |
switch (state) {
|
|
650 |
case QValidator::Acceptable: return QString("Acceptable");
|
|
651 |
case QValidator::Intermediate: return QString("Intermediate");
|
|
652 |
case QValidator::Invalid: return QString("Invalid");
|
|
653 |
default: break;
|
|
654 |
}
|
|
655 |
qWarning("%s %d: this should never happen", __FILE__, __LINE__);
|
|
656 |
return QString();
|
|
657 |
}
|
|
658 |
|
|
659 |
void tst_QDoubleSpinBox::valueFromTextAndValidate_data()
|
|
660 |
{
|
|
661 |
const int Intermediate = QValidator::Intermediate;
|
|
662 |
const int Invalid = QValidator::Invalid;
|
|
663 |
const int Acceptable = QValidator::Acceptable;
|
|
664 |
|
|
665 |
QTest::addColumn<QString>("txt");
|
|
666 |
QTest::addColumn<int>("state");
|
|
667 |
QTest::addColumn<double>("mini");
|
|
668 |
QTest::addColumn<double>("maxi");
|
|
669 |
QTest::addColumn<int>("language");
|
|
670 |
QTest::addColumn<QString>("expectedText"); // if empty we don't check
|
|
671 |
|
|
672 |
QTest::newRow("data0") << QString("2.2") << Intermediate << 3.0 << 5.0 << (int)QLocale::C << QString();
|
|
673 |
QTest::newRow("data1") << QString() << Intermediate << 0.0 << 100.0 << (int)QLocale::C << QString();
|
|
674 |
QTest::newRow("data2") << QString("asd") << Invalid << 0.0 << 100.0 << (int)QLocale::C << QString();
|
|
675 |
QTest::newRow("data3") << QString("2.2") << Acceptable << 0.0 << 100.0 << (int)QLocale::C << QString();
|
|
676 |
QTest::newRow("data4") << QString(" ") << Intermediate << 0.0 << 100.0 << (int)QLocale::Norwegian << QString();
|
|
677 |
QTest::newRow("data5") << QString(" ") << Intermediate << 0.0 << 100.0 << (int)QLocale::C << QString();
|
|
678 |
QTest::newRow("data6") << QString(",") << Intermediate << 0.0 << 100.0 << (int)QLocale::Norwegian << QString();
|
|
679 |
QTest::newRow("data7") << QString(",") << Invalid << 0.0 << 100.0 << (int)QLocale::C << QString();
|
|
680 |
QTest::newRow("data8") << QString("1 ") << Acceptable << 0.0 << 1000.0 << (int)QLocale::Norwegian << QString("1");
|
|
681 |
QTest::newRow("data9") << QString("1 ") << Acceptable << 0.0 << 100.0 << (int)QLocale::C << QString("1");
|
|
682 |
QTest::newRow("data10") << QString(" 1") << Acceptable << 0.0 << 100.0 << (int)QLocale::Norwegian << QString("1");
|
|
683 |
QTest::newRow("data11") << QString(" 1") << Acceptable << 0.0 << 100.0 << (int)QLocale::C << QString("1");
|
|
684 |
QTest::newRow("data12") << QString("1,") << Acceptable << 0.0 << 100.0 << (int)QLocale::Norwegian << QString();
|
|
685 |
QTest::newRow("data13") << QString("1,") << Intermediate << 0.0 << 1000.0 << (int)QLocale::C << QString();
|
|
686 |
QTest::newRow("data14") << QString("1, ") << Acceptable << 0.0 << 100.0 << (int)QLocale::Norwegian << QString("1,");
|
|
687 |
QTest::newRow("data15") << QString("1, ") << Invalid << 0.0 << 100.0 << (int)QLocale::C << QString();
|
|
688 |
QTest::newRow("data16") << QString("2") << Intermediate << 100.0 << 102.0 << (int)QLocale::C << QString();
|
|
689 |
QTest::newRow("data17") << QString("22.0") << Intermediate << 100.0 << 102.0 << (int)QLocale::C << QString();
|
|
690 |
QTest::newRow("data18") << QString("12.0") << Intermediate << 100.0 << 102.0 << (int)QLocale::C << QString();
|
|
691 |
QTest::newRow("data19") << QString("12.2") << Intermediate << 100. << 102.0 << (int)QLocale::C << QString();
|
|
692 |
QTest::newRow("data20") << QString("21.") << Intermediate << 100.0 << 102.0 << (int)QLocale::C << QString();
|
|
693 |
QTest::newRow("data21") << QString("-21.") << Intermediate << -102.0 << -100.0 << (int)QLocale::C << QString();
|
|
694 |
QTest::newRow("data22") << QString("-12.") << Intermediate << -102.0 << -100.0 << (int)QLocale::C << QString();
|
|
695 |
QTest::newRow("data23") << QString("-11.11") << Intermediate << -102.0 << -101.2 << (int)QLocale::C << QString();
|
|
696 |
QTest::newRow("data24") << QString("-11.4") << Intermediate << -102.0 << -101.3 << (int)QLocale::C << QString();
|
|
697 |
QTest::newRow("data25") << QString("11.400") << Invalid << 0.0 << 100.0 << (int)QLocale::C << QString();
|
|
698 |
QTest::newRow("data26") << QString(".4") << Intermediate << 0.45 << 0.5 << (int)QLocale::C << QString();
|
|
699 |
QTest::newRow("data27") << QString("+.4") << Intermediate << 0.45 << 0.5 << (int)QLocale::C << QString();
|
|
700 |
QTest::newRow("data28") << QString("-.4") << Intermediate << -0.5 << -0.45 << (int)QLocale::C << QString();
|
|
701 |
QTest::newRow("data29") << QString(".4") << Intermediate << 1.0 << 2.4 << (int)QLocale::C << QString();
|
|
702 |
QTest::newRow("data30") << QString("-.4") << Intermediate << -2.3 << -1.9 << (int)QLocale::C << QString();
|
|
703 |
QTest::newRow("data31") << QString("-42") << Invalid << -2.43 << -1.0 << (int)QLocale::C << QString();
|
|
704 |
QTest::newRow("data32") << QString("-4") << Invalid << -1.4 << -1.0 << (int)QLocale::C << QString();
|
|
705 |
QTest::newRow("data33") << QString("-42") << Invalid << -1.4 << -1.0 << (int)QLocale::C << QString();
|
|
706 |
QTest::newRow("data34") << QString("1000000000000") << Invalid << -140.0 << -120.2 << (int)QLocale::C << QString();
|
|
707 |
QTest::newRow("data35") << QString("+.12") << Invalid << -5.0 << -3.2 << (int)QLocale::C << QString();
|
|
708 |
QTest::newRow("data36") << QString("-.12") << Invalid << 5.0 << 33.2 << (int)QLocale::C << QString();
|
|
709 |
QTest::newRow("data37") << QString("12.2") << Intermediate << 100. << 103.0 << (int)QLocale::C << QString();
|
|
710 |
QTest::newRow("data38") << QString("12.2") << Intermediate << 100. << 102.3 << (int)QLocale::C << QString();
|
|
711 |
QTest::newRow("data39") << QString("-12.") << Acceptable << -102.0 << 102.0 << (int)QLocale::C << QString();
|
|
712 |
QTest::newRow("data40") << QString("12.") << Invalid << -102.0 << 11.0 << (int)QLocale::C << QString();
|
|
713 |
QTest::newRow("data41") << QString("103.") << Invalid << -102.0 << 11.0 << (int)QLocale::C << QString();
|
|
714 |
QTest::newRow("data42") << QString("122") << Invalid << 10.0 << 12.2 << (int)QLocale::C << QString();
|
|
715 |
QTest::newRow("data43") << QString("-2.2") << Intermediate << -12.2 << -3.2 << (int)QLocale::C << QString();
|
|
716 |
QTest::newRow("data44") << QString("-2.20") << Intermediate << -12.1 << -3.2 << (int)QLocale::C << QString();
|
|
717 |
QTest::newRow("data45") << QString("200,2") << Invalid << 0.0 << 1000.0 << (int)QLocale::C << QString();
|
|
718 |
QTest::newRow("data46") << QString("200,2") << Acceptable << 0.0 << 1000.0 << (int)QLocale::German << QString();
|
|
719 |
QTest::newRow("data47") << QString("2.2") << Acceptable << 0.0 << 1000.0 << (int)QLocale::C << QString();
|
|
720 |
QTest::newRow("data48") << QString("2.2") << Intermediate << 0.0 << 1000.0 << (int)QLocale::German << QString();
|
|
721 |
QTest::newRow("data49") << QString("2.2,00") << Intermediate << 0.0 << 1000.0 << (int)QLocale::German << QString();
|
|
722 |
QTest::newRow("data50") << QString("2.2") << Acceptable << 0.0 << 1000.0 << (int)QLocale::C << QString();
|
|
723 |
QTest::newRow("data51") << QString("2.2,00") << Invalid << 0.0 << 1000.0 << (int)QLocale::C << QString();
|
|
724 |
QTest::newRow("data52") << QString("2..2,00") << Invalid << 0.0 << 1000.0 << (int)QLocale::German << QString();
|
|
725 |
QTest::newRow("data53") << QString("2.2") << Invalid << 0.0 << 1000.0 << (int)QLocale::Norwegian << QString();
|
|
726 |
QTest::newRow("data54") << QString(" 2.2") << Acceptable << 0.0 << 1000.0 << (int)QLocale::C << QString();
|
|
727 |
QTest::newRow("data55") << QString("2.2 ") << Acceptable << 0.0 << 1000.0 << (int)QLocale::C << QString("2.2");
|
|
728 |
QTest::newRow("data56") << QString(" 2.2 ") << Acceptable << 0.0 << 1000.0 << (int)QLocale::C << QString("2.2");
|
|
729 |
QTest::newRow("data57") << QString("2 2") << Invalid << 0.0 << 1000.0 << (int)QLocale::C << QString();
|
|
730 |
}
|
|
731 |
|
|
732 |
void tst_QDoubleSpinBox::valueFromTextAndValidate()
|
|
733 |
{
|
|
734 |
QFETCH(QString, txt);
|
|
735 |
QFETCH(int, state);
|
|
736 |
QFETCH(double, mini);
|
|
737 |
QFETCH(double, maxi);
|
|
738 |
QFETCH(int, language);
|
|
739 |
QFETCH(QString, expectedText);
|
|
740 |
QLocale::setDefault(QLocale((QLocale::Language)language));
|
|
741 |
|
|
742 |
DoubleSpinBox sb(0);
|
|
743 |
sb.show();
|
|
744 |
sb.setRange(mini, maxi);
|
|
745 |
|
|
746 |
int unused = 0;
|
|
747 |
QCOMPARE(stateName(sb.validate(txt, unused)), stateName(state));
|
|
748 |
if (!expectedText.isEmpty())
|
|
749 |
QCOMPARE(txt, expectedText);
|
|
750 |
}
|
|
751 |
|
|
752 |
void tst_QDoubleSpinBox::setReadOnly()
|
|
753 |
{
|
|
754 |
QDoubleSpinBox spin(0);
|
|
755 |
spin.setValue(0.2);
|
|
756 |
spin.show();
|
|
757 |
QCOMPARE(spin.value(), 0.2);
|
|
758 |
QTest::keyClick(&spin, Qt::Key_Up);
|
|
759 |
QCOMPARE(spin.value(), 1.2);
|
|
760 |
spin.setReadOnly(true);
|
|
761 |
QTest::keyClick(&spin, Qt::Key_Up);
|
|
762 |
QCOMPARE(spin.value(), 1.2);
|
|
763 |
spin.stepBy(1);
|
|
764 |
QCOMPARE(spin.value(), 2.2);
|
|
765 |
spin.setReadOnly(false);
|
|
766 |
QTest::keyClick(&spin, Qt::Key_Up);
|
|
767 |
QCOMPARE(spin.value(), 3.2);
|
|
768 |
}
|
|
769 |
|
|
770 |
void tst_QDoubleSpinBox::editingFinished()
|
|
771 |
{
|
|
772 |
QVBoxLayout *layout = new QVBoxLayout(testFocusWidget);
|
|
773 |
QDoubleSpinBox *box = new QDoubleSpinBox(testFocusWidget);
|
|
774 |
layout->addWidget(box);
|
|
775 |
QDoubleSpinBox *box2 = new QDoubleSpinBox(testFocusWidget);
|
|
776 |
layout->addWidget(box2);
|
|
777 |
|
|
778 |
testFocusWidget->show();
|
|
779 |
QApplication::setActiveWindow(testFocusWidget);
|
|
780 |
QTest::qWait(10);
|
|
781 |
QTRY_VERIFY(testFocusWidget->isActiveWindow());
|
|
782 |
box->setFocus();
|
|
783 |
QTRY_VERIFY(box->hasFocus());
|
|
784 |
|
|
785 |
QSignalSpy editingFinishedSpy1(box, SIGNAL(editingFinished()));
|
|
786 |
QSignalSpy editingFinishedSpy2(box2, SIGNAL(editingFinished()));
|
|
787 |
|
|
788 |
box->setFocus();
|
|
789 |
QTest::keyClick(box, Qt::Key_Up);
|
|
790 |
QTest::keyClick(box, Qt::Key_Up);
|
|
791 |
|
|
792 |
|
|
793 |
QCOMPARE(editingFinishedSpy1.count(), 0);
|
|
794 |
QCOMPARE(editingFinishedSpy2.count(), 0);
|
|
795 |
|
|
796 |
QTest::keyClick(box2, Qt::Key_Up);
|
|
797 |
QTest::keyClick(box2, Qt::Key_Up);
|
|
798 |
box2->setFocus();
|
|
799 |
QCOMPARE(editingFinishedSpy1.count(), 1);
|
|
800 |
box->setFocus();
|
|
801 |
QCOMPARE(editingFinishedSpy1.count(), 1);
|
|
802 |
QCOMPARE(editingFinishedSpy2.count(), 1);
|
|
803 |
QTest::keyClick(box, Qt::Key_Up);
|
|
804 |
QCOMPARE(editingFinishedSpy1.count(), 1);
|
|
805 |
QCOMPARE(editingFinishedSpy2.count(), 1);
|
|
806 |
QTest::keyClick(box, Qt::Key_Enter);
|
|
807 |
QCOMPARE(editingFinishedSpy1.count(), 2);
|
|
808 |
QCOMPARE(editingFinishedSpy2.count(), 1);
|
|
809 |
QTest::keyClick(box, Qt::Key_Return);
|
|
810 |
QCOMPARE(editingFinishedSpy1.count(), 3);
|
|
811 |
QCOMPARE(editingFinishedSpy2.count(), 1);
|
|
812 |
box2->setFocus();
|
|
813 |
QCOMPARE(editingFinishedSpy1.count(), 4);
|
|
814 |
QCOMPARE(editingFinishedSpy2.count(), 1);
|
|
815 |
QTest::keyClick(box2, Qt::Key_Enter);
|
|
816 |
QCOMPARE(editingFinishedSpy1.count(), 4);
|
|
817 |
QCOMPARE(editingFinishedSpy2.count(), 2);
|
|
818 |
QTest::keyClick(box2, Qt::Key_Return);
|
|
819 |
QCOMPARE(editingFinishedSpy1.count(), 4);
|
|
820 |
QCOMPARE(editingFinishedSpy2.count(), 3);
|
|
821 |
testFocusWidget->hide();
|
|
822 |
QCOMPARE(editingFinishedSpy1.count(), 4);
|
|
823 |
QCOMPARE(editingFinishedSpy2.count(), 4);
|
|
824 |
|
|
825 |
}
|
|
826 |
|
|
827 |
void tst_QDoubleSpinBox::removeAll()
|
|
828 |
{
|
|
829 |
DoubleSpinBox spin(0);
|
|
830 |
spin.setPrefix("foo");
|
|
831 |
spin.setSuffix("bar");
|
|
832 |
spin.setValue(0.2);
|
|
833 |
spin.setDecimals(1);
|
|
834 |
spin.show();
|
|
835 |
#ifdef Q_WS_MAC
|
|
836 |
QTest::keyClick(&spin, Qt::Key_Left, Qt::ControlModifier);
|
|
837 |
#else
|
|
838 |
QTest::keyClick(&spin, Qt::Key_Home);
|
|
839 |
#endif
|
|
840 |
|
|
841 |
#ifdef Q_WS_MAC
|
|
842 |
QTest::keyClick(&spin, Qt::Key_Right, Qt::ControlModifier|Qt::ShiftModifier);
|
|
843 |
#else
|
|
844 |
QTest::keyClick(&spin, Qt::Key_End, Qt::ShiftModifier);
|
|
845 |
#endif
|
|
846 |
|
|
847 |
QCOMPARE(spin.lineEdit()->selectedText(), QString("foo0.2bar"));
|
|
848 |
QTest::keyClick(&spin, Qt::Key_1);
|
|
849 |
QCOMPARE(spin.text(), QString("foo1bar"));
|
|
850 |
}
|
|
851 |
|
|
852 |
void tst_QDoubleSpinBox::task54433()
|
|
853 |
{
|
|
854 |
DoubleSpinBox priceSpinBox;
|
|
855 |
priceSpinBox.show();
|
|
856 |
priceSpinBox.setRange(0.0, 999.99);
|
|
857 |
priceSpinBox.setDecimals(2);
|
|
858 |
priceSpinBox.setValue(999.99);
|
|
859 |
QCOMPARE(priceSpinBox.text(), QString("999.99"));
|
|
860 |
QCOMPARE(priceSpinBox.value(), 999.99);
|
|
861 |
QCOMPARE(priceSpinBox.maximum(), 999.99);
|
|
862 |
priceSpinBox.setDecimals(1);
|
|
863 |
QCOMPARE(priceSpinBox.value(), 1000.0);
|
|
864 |
QCOMPARE(priceSpinBox.maximum(), 1000.0);
|
|
865 |
QCOMPARE(priceSpinBox.text(), QString("1000.0"));
|
|
866 |
|
|
867 |
priceSpinBox.setDecimals(2);
|
|
868 |
priceSpinBox.setRange(-999.99, 0.0);
|
|
869 |
priceSpinBox.setValue(-999.99);
|
|
870 |
QCOMPARE(priceSpinBox.text(), QString("-999.99"));
|
|
871 |
QCOMPARE(priceSpinBox.value(), -999.99);
|
|
872 |
QCOMPARE(priceSpinBox.minimum(), -999.99);
|
|
873 |
priceSpinBox.setDecimals(1);
|
|
874 |
QCOMPARE(priceSpinBox.value(), -1000.0);
|
|
875 |
QCOMPARE(priceSpinBox.minimum(), -1000.0);
|
|
876 |
QCOMPARE(priceSpinBox.text(), QString("-1000.0"));
|
|
877 |
}
|
|
878 |
|
|
879 |
|
|
880 |
|
|
881 |
void tst_QDoubleSpinBox::germanTest()
|
|
882 |
{
|
|
883 |
QLocale::setDefault(QLocale(QLocale::German));
|
|
884 |
DoubleSpinBox spin;
|
|
885 |
spin.show();
|
|
886 |
spin.setValue(2.12);
|
|
887 |
#ifdef Q_WS_MAC
|
|
888 |
QTest::keyClick(&spin, Qt::Key_Right, Qt::ControlModifier);
|
|
889 |
#else
|
|
890 |
QTest::keyClick(&spin, Qt::Key_End);
|
|
891 |
#endif
|
|
892 |
QTest::keyClick(&spin, Qt::Key_Backspace);
|
|
893 |
QCOMPARE(spin.text(), QString("2,1"));
|
|
894 |
QTest::keyClick(&spin, Qt::Key_Enter);
|
|
895 |
QCOMPARE(spin.text(), QString("2,10"));
|
|
896 |
}
|
|
897 |
|
|
898 |
void tst_QDoubleSpinBox::doubleDot()
|
|
899 |
{
|
|
900 |
DoubleSpinBox spin;
|
|
901 |
spin.show();
|
|
902 |
spin.setValue(2.12);
|
|
903 |
QTest::keyClick(&spin, Qt::Key_Backspace);
|
|
904 |
QCOMPARE(spin.text(), QString("2.12"));
|
|
905 |
#ifdef Q_WS_MAC
|
|
906 |
QTest::keyClick(&spin, Qt::Key_Left, Qt::ControlModifier);
|
|
907 |
#else
|
|
908 |
QTest::keyClick(&spin, Qt::Key_Home);
|
|
909 |
#endif
|
|
910 |
QTest::keyClick(&spin, Qt::Key_Right, Qt::ShiftModifier);
|
|
911 |
QCOMPARE(spin.lineEdit()->selectedText(), QString("2"));
|
|
912 |
QTest::keyClick(&spin, Qt::Key_1);
|
|
913 |
QCOMPARE(spin.text(), QString("1.12"));
|
|
914 |
QCOMPARE(spin.lineEdit()->cursorPosition(), 1);
|
|
915 |
QTest::keyClick(&spin, Qt::Key_Period);
|
|
916 |
QCOMPARE(spin.text(), QString("1.12"));
|
|
917 |
QCOMPARE(spin.lineEdit()->cursorPosition(), 2);
|
|
918 |
}
|
|
919 |
|
|
920 |
void tst_QDoubleSpinBox::undoRedo()
|
|
921 |
{
|
|
922 |
//test undo/redo feature (in conjunction with the "undoRedoEnabled" property)
|
|
923 |
DoubleSpinBox spin(0);
|
|
924 |
spin.show();
|
|
925 |
|
|
926 |
//the undo/redo is disabled by default
|
|
927 |
|
|
928 |
QCOMPARE(spin.value(), 0.0); //this is the default value
|
|
929 |
QVERIFY(!spin.lineEdit()->isUndoAvailable());
|
|
930 |
QVERIFY(!spin.lineEdit()->isRedoAvailable());
|
|
931 |
|
|
932 |
spin.lineEdit()->selectAll(); //ensures everything is selected and will be cleared by typing a key
|
|
933 |
QTest::keyClick(&spin, Qt::Key_1); //we put 1 into the spinbox
|
|
934 |
QCOMPARE(spin.value(), 1.0);
|
|
935 |
QVERIFY(spin.lineEdit()->isUndoAvailable());
|
|
936 |
|
|
937 |
//testing CTRL+Z (undo)
|
|
938 |
int val = QKeySequence(QKeySequence::Undo)[0];
|
|
939 |
if (val != 0) {
|
|
940 |
Qt::KeyboardModifiers mods = (Qt::KeyboardModifiers)(val & Qt::KeyboardModifierMask);
|
|
941 |
QTest::keyClick(&spin, val & ~mods, mods);
|
|
942 |
QCOMPARE(spin.value(), 0.0);
|
|
943 |
QVERIFY(!spin.lineEdit()->isUndoAvailable());
|
|
944 |
QVERIFY(spin.lineEdit()->isRedoAvailable());
|
|
945 |
} else {
|
|
946 |
QWARN("Undo not tested because no key sequence associated to QKeySequence::Redo");
|
|
947 |
}
|
|
948 |
|
|
949 |
|
|
950 |
//testing CTRL+Y (redo)
|
|
951 |
val = QKeySequence(QKeySequence::Redo)[0];
|
|
952 |
if (val != 0) {
|
|
953 |
Qt::KeyboardModifiers mods = (Qt::KeyboardModifiers)(val & Qt::KeyboardModifierMask);
|
|
954 |
QTest::keyClick(&spin, val & ~mods, mods);
|
|
955 |
QCOMPARE(spin.value(), 1.0);
|
|
956 |
QVERIFY(!spin.lineEdit()->isRedoAvailable());
|
|
957 |
QVERIFY(spin.lineEdit()->isUndoAvailable());
|
|
958 |
} else {
|
|
959 |
QWARN("Redo not tested because no key sequence associated to QKeySequence::Redo");
|
|
960 |
}
|
|
961 |
|
|
962 |
|
|
963 |
spin.setValue(55.0);
|
|
964 |
QVERIFY(!spin.lineEdit()->isUndoAvailable());
|
|
965 |
QVERIFY(!spin.lineEdit()->isRedoAvailable());
|
|
966 |
}
|
|
967 |
|
|
968 |
struct task199226_DoubleSpinBox : public QDoubleSpinBox
|
|
969 |
{
|
|
970 |
task199226_DoubleSpinBox(QWidget *parent = 0) : QDoubleSpinBox(parent) {}
|
|
971 |
QLineEdit *lineEdit() { return QAbstractSpinBox::lineEdit(); }
|
|
972 |
};
|
|
973 |
|
|
974 |
void tst_QDoubleSpinBox::task199226_stateAfterEnter()
|
|
975 |
{
|
|
976 |
task199226_DoubleSpinBox spin;
|
|
977 |
spin.setMinimum(0);
|
|
978 |
spin.setMaximum(10);
|
|
979 |
spin.setDecimals(0);
|
|
980 |
spin.show();
|
|
981 |
QTest::mouseDClick(spin.lineEdit(), Qt::LeftButton);
|
|
982 |
QTest::keyClick(spin.lineEdit(), Qt::Key_3);
|
|
983 |
QVERIFY(spin.lineEdit()->isModified());
|
|
984 |
QVERIFY(spin.lineEdit()->isUndoAvailable());
|
|
985 |
QTest::keyClick(spin.lineEdit(), Qt::Key_Enter);
|
|
986 |
QVERIFY(!spin.lineEdit()->isModified());
|
|
987 |
QVERIFY(!spin.lineEdit()->isUndoAvailable());
|
|
988 |
}
|
|
989 |
|
|
990 |
class task224497_fltMax_DoubleSpinBox : public QDoubleSpinBox
|
|
991 |
{
|
|
992 |
public:
|
|
993 |
QLineEdit * lineEdit () const { return QDoubleSpinBox::lineEdit(); }
|
|
994 |
};
|
|
995 |
|
|
996 |
void tst_QDoubleSpinBox::task224497_fltMax()
|
|
997 |
{
|
|
998 |
task224497_fltMax_DoubleSpinBox *dspin = new task224497_fltMax_DoubleSpinBox;
|
|
999 |
dspin->setMinimum(3);
|
|
1000 |
dspin->setMaximum(FLT_MAX);
|
|
1001 |
dspin->show();
|
|
1002 |
QTest::qWait(1000);
|
|
1003 |
dspin->lineEdit()->selectAll();
|
|
1004 |
QTest::keyClick(dspin->lineEdit(), Qt::Key_Delete);
|
|
1005 |
QTest::keyClick(dspin->lineEdit(), Qt::Key_1);
|
|
1006 |
QCOMPARE(dspin->cleanText(), QLatin1String("1"));
|
|
1007 |
}
|
|
1008 |
|
|
1009 |
void tst_QDoubleSpinBox::task221221()
|
|
1010 |
{
|
|
1011 |
QDoubleSpinBox spin;
|
|
1012 |
QTest::keyClick(&spin, Qt::Key_1);
|
|
1013 |
QCOMPARE(spin.text(), QLatin1String("1"));
|
|
1014 |
spin.show();
|
|
1015 |
#ifdef Q_WS_X11
|
|
1016 |
qt_x11_wait_for_window_manager(&spin);
|
|
1017 |
#endif
|
|
1018 |
QVERIFY(spin.isVisible());
|
|
1019 |
QCOMPARE(spin.text(), QLatin1String("1"));
|
|
1020 |
}
|
|
1021 |
|
|
1022 |
void tst_QDoubleSpinBox::task255471_decimalsValidation()
|
|
1023 |
{
|
|
1024 |
// QDoubleSpinBox shouldn't crash with large numbers of decimals. Even if
|
|
1025 |
// the results are useless ;-)
|
|
1026 |
for (int i = 0; i < 32; ++i)
|
|
1027 |
{
|
|
1028 |
QDoubleSpinBox spinBox;
|
|
1029 |
spinBox.setDecimals(i);
|
|
1030 |
spinBox.setMinimum(0.3);
|
|
1031 |
spinBox.setMaximum(12);
|
|
1032 |
|
|
1033 |
spinBox.show();
|
|
1034 |
QTRY_VERIFY(spinBox.isVisible());
|
|
1035 |
spinBox.setFocus();
|
|
1036 |
QTRY_VERIFY(spinBox.hasFocus());
|
|
1037 |
|
|
1038 |
QTest::keyPress(&spinBox, Qt::Key_Right);
|
|
1039 |
QTest::keyPress(&spinBox, Qt::Key_Right);
|
|
1040 |
QTest::keyPress(&spinBox, Qt::Key_Delete);
|
|
1041 |
|
|
1042 |
// Don't crash!
|
|
1043 |
QTest::keyPress(&spinBox, Qt::Key_2);
|
|
1044 |
}
|
|
1045 |
}
|
|
1046 |
|
|
1047 |
|
|
1048 |
QTEST_MAIN(tst_QDoubleSpinBox)
|
|
1049 |
#include "tst_qdoublespinbox.moc"
|