aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmllistmodel
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2022-08-02 18:20:18 +0200
committerUlf Hermann <ulf.hermann@qt.io>2022-08-29 13:20:53 +0200
commitcad5c89a0f0ebb24f17171fdbab8355832f0f415 (patch)
tree1e49190e51018b27296858e5e4248f29b1965617 /tests/auto/qml/qqmllistmodel
parentd937a53cbcd72304ba1c613ed2d2dc2010542f7e (diff)
QmlModels: Fix enum resolution in ListElement
There were two problems: a, We need to allow recursion when querying for enums. Otherwise we cannot find enums in the same document. b, when the enum resolution is done in the validation phase, we cannot query the current document's QQmlType for enums, yet, as it's not finalized. However, the QQmlPropertyValidator has the QQmlPropertyCache we're looking for in that case. c, As a drive-by, fix the excessive conversions between QByteArray and QString. Pick-to: 6.4 Fixes: QTBUG-95864 Change-Id: If0d2687986e1483a27ce11373a204235b92a6efd Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmllistmodel')
-rw-r--r--tests/auto/qml/qqmllistmodel/data/Model.qml9
-rw-r--r--tests/auto/qml/qqmllistmodel/data/enumsInListElement.qml8
-rw-r--r--tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp18
3 files changed, 35 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmllistmodel/data/Model.qml b/tests/auto/qml/qqmllistmodel/data/Model.qml
new file mode 100644
index 0000000000..f6aeed5bdd
--- /dev/null
+++ b/tests/auto/qml/qqmllistmodel/data/Model.qml
@@ -0,0 +1,9 @@
+import QtQml.Models
+
+ListModel {
+ enum Choose { Foo, Bar, Baz }
+
+ ListElement { choose: Model.Choose.Foo }
+ ListElement { choose: Model.Choose.Bar }
+ ListElement { choose: Model.Choose.Baz }
+}
diff --git a/tests/auto/qml/qqmllistmodel/data/enumsInListElement.qml b/tests/auto/qml/qqmllistmodel/data/enumsInListElement.qml
new file mode 100644
index 0000000000..e8d594dfd8
--- /dev/null
+++ b/tests/auto/qml/qqmllistmodel/data/enumsInListElement.qml
@@ -0,0 +1,8 @@
+import QtQuick
+
+ListView {
+ width: 180
+ height: 200
+ model: Model {}
+ delegate: Text { text: choose }
+}
diff --git a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp
index c92956bd49..7f31e43b1e 100644
--- a/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp
+++ b/tests/auto/qml/qqmllistmodel/tst_qqmllistmodel.cpp
@@ -4,6 +4,7 @@
#include <QtQuick/private/qquickitem_p.h>
#include <QtQuick/private/qquicktext_p.h>
#include <QtQuick/private/qquickanimation_p.h>
+#include <QtQuick/private/qquicklistview_p.h>
#include <QtQml/private/qqmlengine_p.h>
#include <QtQmlModels/private/qqmllistmodel_p.h>
#include <QtQml/private/qqmlexpression_p.h>
@@ -116,6 +117,7 @@ private slots:
void listElementWithTemplateString();
void destroyComponentObject();
void objectOwnershipFlip();
+ void enumsInListElement();
};
bool tst_qqmllistmodel::compareVariantList(const QVariantList &testList, QVariant object)
@@ -1891,6 +1893,22 @@ void tst_qqmllistmodel::objectOwnershipFlip()
QCOMPARE(QJSEngine::objectOwnership(item.data()), QJSEngine::CppOwnership);
}
+void tst_qqmllistmodel::enumsInListElement()
+{
+ QQmlEngine engine;
+ QQmlComponent component(&engine, testFileUrl("enumsInListElement.qml"));
+ QVERIFY2(component.isReady(), qPrintable(component.errorString()));
+ QScopedPointer<QObject> root(component.create());
+ QVERIFY(!root.isNull());
+
+ QQuickListView *listView = qobject_cast<QQuickListView *>(root.data());
+ QVERIFY(listView);
+ QCOMPARE(listView->count(), 3);
+ for (int i = 0; i < 3; ++i) {
+ QCOMPARE(listView->itemAtIndex(i)->property("text"), QVariant(QString::number(i)));
+ }
+}
+
QTEST_MAIN(tst_qqmllistmodel)
#include "tst_qqmllistmodel.moc"