aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmllocale
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2019-12-02 16:38:31 +0100
committerFabian Kosmale <fabian.kosmale@qt.io>2019-12-05 07:31:30 +0000
commitab7f591a6b18a0a2a03b760fbd6a7fbb53189c72 (patch)
tree0124b56839350bb882523651bd5cfd30022038a5 /tests/auto/qml/qqmllocale
parent6ad3445f1e159d9beea936b66d267dcaacdc5d6c (diff)
Locale: expose NumberOptions to QML
As we want to specify how DoubleValidator and fromLocaleString handle number separators, we need to expose NumberOptions to QML. The referenced bug report is still unsolved, as we we still lack a method to change DoubleValidator's behavior and NumberOptions does not have a value to ignore occurrences of separators at arbitray places. Task-number: QTBUG-75110 Change-Id: I81f48439114cad12e0e977bab09b0aa4e240fbab Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmllocale')
-rw-r--r--tests/auto/qml/qqmllocale/tst_qqmllocale.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp b/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp
index a90749208c..c846ee32df 100644
--- a/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp
+++ b/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp
@@ -102,6 +102,7 @@ private slots:
void numberFromLocaleString_data();
void numberFromLocaleString();
void numberConstToLocaleString();
+ void numberOptions();
void stringLocaleCompare_data();
void stringLocaleCompare();
@@ -1157,6 +1158,35 @@ void tst_qqmllocale::numberConstToLocaleString()
QCOMPARE(obj->property("const2").toString(), l.toString(1234., 'f', 2));
}
+void tst_qqmllocale::numberOptions()
+{
+ QQmlEngine engine;
+ QQmlComponent comp(&engine);
+ comp.setData(R"(
+ import QtQml 2.15
+ QtObject {
+ id: root
+ property string formatted
+ property bool caughtException: false
+ Component.onCompleted: () => {
+ const myLocale = Qt.locale("de_DE")
+ myLocale.numberOptions = Locale.OmitGroupSeparator | Locale.RejectTrailingZeroesAfterDot
+ root.formatted = Number(10000).toLocaleString(myLocale, 'f', 4)
+ try {
+ Number.fromLocaleString(myLocale, "1,10");
+ } catch (e) {console.warn(e); root.caughtException = true}
+ }
+ }
+ )", QUrl("testdata"));
+ QTest::ignoreMessage(QtMsgType::QtWarningMsg, "Error: Locale: Number.fromLocaleString(): Invalid format");
+ QScopedPointer<QObject> root {comp.create()};
+ qDebug() << comp.errorString();
+ QVERIFY(root);
+ QCOMPARE(root->property("formatted").toString(), QLatin1String("10000,0000"));
+ QCOMPARE(root->property("caughtException").toBool(), true);
+
+}
+
void tst_qqmllocale::stringLocaleCompare_data()
{
QTest::addColumn<QString>("string1");