diff options
author | Leander Beernaert <leander.beernaert@qt.io> | 2020-01-16 16:25:06 +0100 |
---|---|---|
committer | Leander Beernaert <leander.beernaert@qt.io> | 2020-01-16 16:25:06 +0100 |
commit | 1d333d3375874efb8d37df37dc5ef561573794ad (patch) | |
tree | 2d8c995f64c05c84c1fcceb2c5cb40fcae69855f /tests/auto/quick/qquickvisualdatamodel | |
parent | b106d86c433706928b0b0c206a0d9f831681e1bf (diff) | |
parent | e79a2658cde899d6ee11ec3c0d0a3768eb2c864b (diff) |
Merge remote-tracking branch 'origin/dev' into wip/cmake
Change-Id: I0c5b939c70bdb91ccdf7068784308416dcaa5736
Diffstat (limited to 'tests/auto/quick/qquickvisualdatamodel')
3 files changed, 130 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickvisualdatamodel/data/filterGroupForDelegate.qml b/tests/auto/quick/qquickvisualdatamodel/data/filterGroupForDelegate.qml new file mode 100644 index 0000000000..d72ca51d7f --- /dev/null +++ b/tests/auto/quick/qquickvisualdatamodel/data/filterGroupForDelegate.qml @@ -0,0 +1,77 @@ +import QtQml.Models 2.12 +import Qt.labs.qmlmodels 1.0 +import QtQuick 2.12 + +Item { + id: root + width: 200 + height: 320 + + property int numChanges: 0 + property bool ok: true + + DelegateModel { + id: theModel + + model: ListModel { + ListElement { role: "section" } + ListElement { role: "item" } + ListElement { role: "section" } + ListElement { role: "item" } + ListElement { role: "section" } + ListElement { role: "item" } + ListElement { role: "item" } + ListElement { role: "item" } + } + + filterOnGroup: "expanded" + groups: DelegateModelGroup { + name: "expanded" + } + + delegate: DelegateChooser { + role: "role" + + DelegateChoice { + roleValue: "section" + Text { + text: "+ Section " + index + + Timer { + interval: (index + 10) + repeat: true + running: true + onTriggered: { + ++ root.numChanges; + if (model.role !== "section") { + root.ok = false; + console.warn("wrong!", root.numChanges); + } + let i = parent.DelegateModel.itemsIndex + 1; + for (; i < theModel.items.count; ++i) { + let item = theModel.items.get(i); + if (item.model.role === "section") + break; + item.inExpanded = !item.inExpanded; + } + } + } + } + } + + DelegateChoice { + roleValue: "item" + Text { + text: "Item " + index + } + } + } + + Component.onCompleted: items.addGroups(0, items.count, ["expanded"]) + } + + ListView { + anchors.fill: parent + model: theModel + } +} diff --git a/tests/auto/quick/qquickvisualdatamodel/data/readFromProxyObject.qml b/tests/auto/quick/qquickvisualdatamodel/data/readFromProxyObject.qml new file mode 100644 index 0000000000..3983c707a1 --- /dev/null +++ b/tests/auto/quick/qquickvisualdatamodel/data/readFromProxyObject.qml @@ -0,0 +1,23 @@ +import QtQuick 2.15 +import QtQuick.Window 2.15 + +Window { + id: window + width: 200 + height: 200 + color: "red" + visible: true + Repeater { + model: Qt.application.screens + Text { + required property string name + required property int virtualX + required property int virtualY + + text: name + virtualX + ", " + virtualY + Component.onCompleted: window.name = name + } + } + + property string name: "wrong" +} diff --git a/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp b/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp index fe56cad018..66069c48cb 100644 --- a/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp +++ b/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp @@ -433,6 +433,8 @@ private slots: void invalidContext(); void externalManagedModel(); void delegateModelChangeDelegate(); + void checkFilterGroupForDelegate(); + void readFromProxyObject(); private: template <int N> void groups_verify( @@ -4342,6 +4344,34 @@ void tst_qquickvisualdatamodel::delegateModelChangeDelegate() QCOMPARE(visualModel->count(), 3); } +void tst_qquickvisualdatamodel::checkFilterGroupForDelegate() +{ + QQuickView view; + view.setSource(testFileUrl("filterGroupForDelegate.qml")); + view.show(); + + QQuickItem *obj = view.rootObject(); + QVERIFY(obj); + + QTRY_VERIFY(obj->property("numChanges").toInt() > 100); + QVERIFY(obj->property("ok").toBool()); +} + +void tst_qquickvisualdatamodel::readFromProxyObject() +{ + QQmlEngine engine; + QQmlComponent component(&engine, testFileUrl("readFromProxyObject.qml")); + + QScopedPointer<QObject> obj(component.create()); + QVERIFY(obj); + + auto *window = qobject_cast<QQuickWindow *>(obj.get()); + QVERIFY(window); + + QCOMPARE(window->property("name").type(), QMetaType::QString); + QTRY_VERIFY(window->property("name").toString() != QLatin1String("wrong")); +} + QTEST_MAIN(tst_qquickvisualdatamodel) #include "tst_qquickvisualdatamodel.moc" |