diff options
Diffstat (limited to 'tests/auto/qml/qmlcppcodegen')
| -rw-r--r-- | tests/auto/qml/qmlcppcodegen/data/variantMapLookup.h | 21 | ||||
| -rw-r--r-- | tests/auto/qml/qmlcppcodegen/data/variantMapLookup.qml | 18 | ||||
| -rw-r--r-- | tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp | 6 |
3 files changed, 41 insertions, 4 deletions
diff --git a/tests/auto/qml/qmlcppcodegen/data/variantMapLookup.h b/tests/auto/qml/qmlcppcodegen/data/variantMapLookup.h index de7ac4f739..c1e52062b5 100644 --- a/tests/auto/qml/qmlcppcodegen/data/variantMapLookup.h +++ b/tests/auto/qml/qmlcppcodegen/data/variantMapLookup.h @@ -7,19 +7,32 @@ class VariantMapLookupFoo : public QObject { Q_OBJECT QML_ELEMENT - Q_PROPERTY(QVariantMap data READ data CONSTANT) - Q_PROPERTY(QList<QVariantMap> many READ many CONSTANT) + Q_PROPERTY(QVariantMap data READ data WRITE setData NOTIFY dataChanged) + Q_PROPERTY(QList<QVariantMap> many READ many NOTIFY dataChanged) public: VariantMapLookupFoo(QObject *parent = nullptr) : QObject(parent) { } -private: - QVariantMap data() const { return { { QStringLiteral("value"), 42 } }; } + QVariantMap data() const { return m_data; } + void setData(const QVariantMap &data) + { + if (data == m_data) + return; + m_data = data; + emit dataChanged(); + } + QList<QVariantMap> many() const { const QVariantMap one = data(); return QList<QVariantMap>({one, one, one}); } + +signals: + void dataChanged(); + +private: + QVariantMap m_data; }; diff --git a/tests/auto/qml/qmlcppcodegen/data/variantMapLookup.qml b/tests/auto/qml/qmlcppcodegen/data/variantMapLookup.qml index 45cb0edd69..75b4fd0fda 100644 --- a/tests/auto/qml/qmlcppcodegen/data/variantMapLookup.qml +++ b/tests/auto/qml/qmlcppcodegen/data/variantMapLookup.qml @@ -3,10 +3,28 @@ import TestTypes import QtQuick Item { + id: root property int i: moo.data.value property int j: moo.many[1].value + property string foo: moo.data.foo VariantMapLookupFoo { id: moo + data: { + let result = { value: 42 }; + switch(root.visible) { + case true: + result.foo = "blue"; + break; + case false: + result.foo = "green"; + break; + } + return result; + } + } + + function doI() { + moo.data.value = i + 1 } } diff --git a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp index 884372bfa4..016d4c95a0 100644 --- a/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp +++ b/tests/auto/qml/qmlcppcodegen/tst_qmlcppcodegen.cpp @@ -6126,6 +6126,12 @@ void tst_QmlCppCodegen::variantMapLookup() QVERIFY(!o.isNull()); QCOMPARE(o->property("i"), 42); QCOMPARE(o->property("j"), 42); + QCOMPARE(o->property("foo"), u"blue"_s); + + QMetaObject::invokeMethod(o.data(), "doI"); + QCOMPARE(o->property("i"), 43); + QCOMPARE(o->property("j"), 43); + QCOMPARE(o->property("foo"), u"blue"_s); } void tst_QmlCppCodegen::variantReturn() |
