From e913972d5268a2b1e5bfc12a0a72e4811e764d86 Mon Sep 17 00:00:00 2001 From: Oto Magaldadze Date: Tue, 17 Sep 2013 14:02:49 +0400 Subject: added QAbstractSpinBox::setGroupSeparatorShown function. [ChangeLog][QtWidgets][QAbstractSpinBox] QTBUG-5142 - This will allow a group (thousand) separator to be shown in QSpinBox and QDoubleSpinBox widgets. Task-number: QTBUG-5142 Change-Id: I2e23f5f83c93bb092a2dbd784e06d17d40d42909 Reviewed-by: Marc Mutz --- .../widgets/qdoublespinbox/tst_qdoublespinbox.cpp | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'tests/auto/widgets/widgets/qdoublespinbox/tst_qdoublespinbox.cpp') diff --git a/tests/auto/widgets/widgets/qdoublespinbox/tst_qdoublespinbox.cpp b/tests/auto/widgets/widgets/qdoublespinbox/tst_qdoublespinbox.cpp index b880ebe078..49f058862d 100644 --- a/tests/auto/widgets/widgets/qdoublespinbox/tst_qdoublespinbox.cpp +++ b/tests/auto/widgets/widgets/qdoublespinbox/tst_qdoublespinbox.cpp @@ -145,6 +145,9 @@ private slots: void taskQTBUG_6670_selectAllWithPrefix(); void taskQTBUG_6496_fiddlingWithPrecision(); + void setGroupSeparatorShown_data(); + void setGroupSeparatorShown(); + public slots: void valueChangedHelper(const QString &); void valueChangedHelper(double); @@ -156,6 +159,9 @@ private: typedef QList DoubleList; +Q_DECLARE_METATYPE(QLocale::Language) +Q_DECLARE_METATYPE(QLocale::Country) + tst_QDoubleSpinBox::tst_QDoubleSpinBox() { @@ -1099,5 +1105,45 @@ void tst_QDoubleSpinBox::taskQTBUG_6496_fiddlingWithPrecision() QCOMPARE(dsb.maximum(), 0.991); } +void tst_QDoubleSpinBox::setGroupSeparatorShown_data() +{ + QTest::addColumn("lang"); + QTest::addColumn("country"); + + QTest::newRow("data0") << QLocale::English << QLocale::UnitedStates; + QTest::newRow("data1") << QLocale::Swedish << QLocale::Sweden; + QTest::newRow("data2") << QLocale::German << QLocale::Germany; + QTest::newRow("data3") << QLocale::Georgian << QLocale::Georgia; + QTest::newRow("data3") << QLocale::Macedonian << QLocale::Macedonia; +} + +void tst_QDoubleSpinBox::setGroupSeparatorShown() +{ + QFETCH(QLocale::Language, lang); + QFETCH(QLocale::Country, country); + + QLocale loc(lang, country); + QLocale::setDefault(loc); + DoubleSpinBox spinBox; + spinBox.setMaximum(99999999); + spinBox.setValue(1300000.00); + spinBox.setGroupSeparatorShown(true); + QCOMPARE(spinBox.lineEdit()->text(), spinBox.locale().toString(1300000.00, 'f', 2)); + QCOMPARE(spinBox.isGroupSeparatorShown(), true); + QCOMPARE(spinBox.textFromValue(23421),spinBox.locale().toString(23421.00, 'f', 2)); + + spinBox.setGroupSeparatorShown(false); + QCOMPARE(spinBox.lineEdit()->text(), spinBox.locale().toString(1300000.00, 'f', 2).remove( + spinBox.locale().groupSeparator())); + QCOMPARE(spinBox.isGroupSeparatorShown(), false); + + spinBox.setMaximum(72000); + spinBox.lineEdit()->setText(spinBox.locale().toString(32000.64, 'f', 2)); + QCOMPARE(spinBox.value()+1000, 33000.64); + + spinBox.lineEdit()->setText(spinBox.locale().toString(32000.44, 'f', 2)); + QCOMPARE(spinBox.value()+1000, 33000.44); +} + QTEST_MAIN(tst_QDoubleSpinBox) #include "tst_qdoublespinbox.moc" -- cgit v1.2.3