aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qmltc
diff options
context:
space:
mode:
authorSami Shalayel <sami.shalayel@qt.io>2022-10-17 15:27:12 +0200
committerSami Shalayel <sami.shalayel@qt.io>2022-10-28 17:34:03 +0200
commit1f726ea143a031776db45790b531656892c1d343 (patch)
tree1724312f4f1ba67b178bd37988b06e35816897d7 /tests/auto/qml/qmltc
parent19b3c6ec7f82383c2062c529bae2967e16a075b6 (diff)
qmltc: Add some sugar for generated reference-type-list properties
When compiling a reference type list with qmltc into a QQmlListProperty, also generate helper methods to make the manipulation of those lists by the user easier in c++. For a list myList, generate the methods myListAt(), myListAppend(), ... as shown in the Birthdayparty example. Also add some documentation about the ownership of the arguments, and tests to see if the list can be accessed from C++. Task-number: QTBUG-107570 Change-Id: Iec0041015311639ead39660fdccf147749566592 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'tests/auto/qml/qmltc')
-rw-r--r--tests/auto/qml/qmltc/QmltcTests/listProperty.qml16
-rw-r--r--tests/auto/qml/qmltc/tst_qmltc.cpp35
2 files changed, 51 insertions, 0 deletions
diff --git a/tests/auto/qml/qmltc/QmltcTests/listProperty.qml b/tests/auto/qml/qmltc/QmltcTests/listProperty.qml
index b2f16fe11c..1f87f7fb9e 100644
--- a/tests/auto/qml/qmltc/QmltcTests/listProperty.qml
+++ b/tests/auto/qml/qmltc/QmltcTests/listProperty.qml
@@ -11,5 +11,21 @@ QtObject {
QtObject { id: a2; property string hello: "Hello from parent.children[1]" }
]
+ property QtObject appendMe: QtObject { id: a3; property string hello: "Hello from parent.children[2]" }
+
ids: [a, a1, a2]
+
+ property list<int> myList: [1,2,3,4]
+
+ property int count: myList.length
+
+ property int firstCount
+ property int secondCount
+
+ Component.onCompleted: {
+ firstCount = count
+ myList.push(43)
+ secondCount = count
+ }
+
}
diff --git a/tests/auto/qml/qmltc/tst_qmltc.cpp b/tests/auto/qml/qmltc/tst_qmltc.cpp
index 2c5a164989..731d90af20 100644
--- a/tests/auto/qml/qmltc/tst_qmltc.cpp
+++ b/tests/auto/qml/qmltc/tst_qmltc.cpp
@@ -1526,6 +1526,11 @@ void tst_qmltc::listProperty()
QQmlEngine e;
PREPEND_NAMESPACE(listProperty) created(&e);
+ QQmlComponent c(&e);
+ c.loadUrl(QUrl("qrc:/qt/qml/QmltcTests/listProperty.qml"));
+ QScopedPointer<QObject> fromEngine(c.create());
+ QVERIFY2(fromEngine, qPrintable(c.errorString()));
+
QCOMPARE(created.hello(), QStringLiteral("Hello from parent"));
QQmlListReference ref(&created, "children");
@@ -1544,6 +1549,36 @@ void tst_qmltc::listProperty()
QCOMPARE(refIds.at(0), &created);
QCOMPARE(refIds.at(1), ref.at(0));
QCOMPARE(refIds.at(2), ref.at(1));
+
+ QCOMPARE(fromEngine->property("firstCount"), 4);
+ QCOMPARE(fromEngine->property("secondCount"), 5);
+
+ QCOMPARE(created.firstCount(), 4);
+ QCOMPARE(created.secondCount(), 5);
+
+ QCOMPARE(created.childrenCount(), 2);
+ QCOMPARE(created.childrenAt(0)->property("hello"), u"Hello from parent.children[0]"_s);
+ QCOMPARE(created.childrenAt(1)->property("hello"), u"Hello from parent.children[1]"_s);
+
+ created.childrenAppend(created.appendMe());
+ QCOMPARE(created.childrenCount(), 3);
+ QCOMPARE(created.childrenAt(0)->property("hello"), u"Hello from parent.children[0]"_s);
+ QCOMPARE(created.childrenAt(1)->property("hello"), u"Hello from parent.children[1]"_s);
+ QCOMPARE(created.childrenAt(2)->property("hello"), u"Hello from parent.children[2]"_s);
+
+ created.childrenReplace(0, created.appendMe());
+ QCOMPARE(created.childrenCount(), 3);
+ QCOMPARE(created.childrenAt(0)->property("hello"), u"Hello from parent.children[2]"_s);
+ QCOMPARE(created.childrenAt(1)->property("hello"), u"Hello from parent.children[1]"_s);
+ QCOMPARE(created.childrenAt(2)->property("hello"), u"Hello from parent.children[2]"_s);
+
+ created.childrenRemoveLast();
+ QCOMPARE(created.childrenCount(), 2);
+ QCOMPARE(created.childrenAt(0)->property("hello"), u"Hello from parent.children[2]"_s);
+ QCOMPARE(created.childrenAt(1)->property("hello"), u"Hello from parent.children[1]"_s);
+
+ created.childrenClear();
+ QCOMPARE(created.childrenCount(), 0);
}
void tst_qmltc::listPropertiesWithTheSameName()