From 7f50eca469a24809d6d5812ee94b447966ff81f9 Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Tue, 14 Jan 2014 12:34:35 +0100 Subject: Allow assignment of a QML Locale object to a C++ QLocale property. Task-number: QTBUG-36125 Change-Id: I58454db0c47684aed3e95c52a8135fd5fd6bf2f9 Reviewed-by: Simon Hausmann --- tests/auto/qml/qqmllocale/tst_qqmllocale.cpp | 36 ++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'tests/auto/qml/qqmllocale') diff --git a/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp b/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp index d565ad557c..0eb38d92e6 100644 --- a/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp +++ b/tests/auto/qml/qqmllocale/tst_qqmllocale.cpp @@ -117,6 +117,7 @@ private slots: void stringLocaleCompare_data(); void stringLocaleCompare(); + void localeAsCppProperty(); private: void addPropertyData(const QString &l); QVariant getProperty(QObject *obj, const QString &locale, const QString &property); @@ -1223,6 +1224,41 @@ void tst_qqmllocale::stringLocaleCompare() QCOMPARE(obj->property("comparison").toInt(), QString::localeAwareCompare(string1, string2)); } +class Calendar : public QObject +{ + Q_OBJECT + Q_PROPERTY(QLocale locale READ locale WRITE setLocale) +public: + Calendar() { + } + + QLocale locale() const { + return mLocale; + } + + void setLocale(const QLocale &locale) { + mLocale = locale; + } +private: + QLocale mLocale; +}; + +void tst_qqmllocale::localeAsCppProperty() +{ + QQmlComponent component(&engine); + qmlRegisterType("Test", 1, 0, "Calendar"); + component.setData("import QtQml 2.2\nimport Test 1.0\nCalendar { locale: Qt.locale('en_GB'); property var testLocale }", QUrl()); + QVERIFY(!component.isError()); + QTRY_VERIFY(component.isReady()); + + Calendar *item = qobject_cast(component.create()); + QCOMPARE(item->property("locale").toLocale().name(), QLatin1String("en_GB")); + + QVariant localeVariant(QLocale("nb_NO")); + item->setProperty("testLocale", localeVariant); + QCOMPARE(item->property("testLocale").toLocale().name(), QLatin1String("nb_NO")); +} + class DateFormatter : public QObject { Q_OBJECT -- cgit v1.2.3