aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2019-11-22 15:54:24 +0100
committerUlf Hermann <ulf.hermann@qt.io>2019-11-23 17:19:59 +0100
commitb7030c2efb90fd1109166d8d476aeab7194c41e1 (patch)
treee202d155125819ade0743a4602d7cb5634c7a79a
parentfad8ef3e4133538e3785d7067c35c652bc894711 (diff)
QQmlDelegateModel: Use cache item's index for resolving delegates
The raw index doesn't take the filter group into account. Fixes: QTBUG-78297 Change-Id: Ie6514c8acdc380fe3f8f267d02335afc357abd17 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io> Reviewed-by: Joshua GPBeta <studiocghibli@gmail.com>
-rw-r--r--src/qmlmodels/qqmldelegatemodel.cpp2
-rw-r--r--tests/auto/quick/qquickvisualdatamodel/data/filterGroupForDelegate.qml77
-rw-r--r--tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp14
3 files changed, 92 insertions, 1 deletions
diff --git a/src/qmlmodels/qqmldelegatemodel.cpp b/src/qmlmodels/qqmldelegatemodel.cpp
index 24632fe16b..d5b30df45b 100644
--- a/src/qmlmodels/qqmldelegatemodel.cpp
+++ b/src/qmlmodels/qqmldelegatemodel.cpp
@@ -1038,7 +1038,7 @@ QObject *QQmlDelegateModelPrivate::object(Compositor::Group group, int index, QQ
if (m_delegateChooser) {
QQmlAbstractDelegateComponent *chooser = m_delegateChooser;
do {
- delegate = chooser->delegate(&m_adaptorModel, index);
+ delegate = chooser->delegate(&m_adaptorModel, cacheItem->index);
chooser = qobject_cast<QQmlAbstractDelegateComponent *>(delegate);
} while (chooser);
if (!delegate)
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/tst_qquickvisualdatamodel.cpp b/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp
index fe56cad018..c5a3bceee0 100644
--- a/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp
+++ b/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp
@@ -433,6 +433,7 @@ private slots:
void invalidContext();
void externalManagedModel();
void delegateModelChangeDelegate();
+ void checkFilterGroupForDelegate();
private:
template <int N> void groups_verify(
@@ -4342,6 +4343,19 @@ 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());
+}
+
QTEST_MAIN(tst_qquickvisualdatamodel)
#include "tst_qquickvisualdatamodel.moc"