aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFabian Kosmale <fabian.kosmale@qt.io>2022-05-03 14:37:26 +0200
committerOliver Eftevaag <oliver.eftevaag@qt.io>2022-10-31 11:11:23 +0000
commite4cd376599e368edd7e8132903f425530102bfae (patch)
tree4624624b3e8504e1d31563b6828ae49d73011fd8
parenta2c4d27cf9b4992fca6a30e01d31c0a5305b7123 (diff)
Avoid double applyDelegateChange in QQIV::setDelegate
If a QQmlDelegateModel is used together with QQuickItemView, then we will already call applyDelegateChange when the DelegateModel's delegateChanged signal is emitted from QQmlDelegateModel::setDelegate. Calling it manually in QQuickItemView's setDelegate is thus superfluous. Fixes: QTBUG-102793 Fixes: QTBUG-107732 Change-Id: Ifffb23661813c4e71287538ec5342215dfbbdad6 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> (cherry picked from commit 2664b1988f031366c2616581e65b0e02e37e3ff1) Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r--src/quick/items/qquickitemview.cpp2
-rw-r--r--tests/auto/quick/qquickvisualdatamodel/data/setDelegateNoDoubleChange.qml43
-rw-r--r--tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp15
3 files changed, 58 insertions, 2 deletions
diff --git a/src/quick/items/qquickitemview.cpp b/src/quick/items/qquickitemview.cpp
index fda2e6ff79..7146b8d1b7 100644
--- a/src/quick/items/qquickitemview.cpp
+++ b/src/quick/items/qquickitemview.cpp
@@ -290,8 +290,6 @@ void QQuickItemView::setDelegate(QQmlComponent *delegate)
if (QQmlDelegateModel *dataModel = qobject_cast<QQmlDelegateModel*>(d->model)) {
int oldCount = dataModel->count();
dataModel->setDelegate(delegate);
- if (isComponentComplete())
- d->applyDelegateChange();
if (oldCount != dataModel->count())
emit countChanged();
}
diff --git a/tests/auto/quick/qquickvisualdatamodel/data/setDelegateNoDoubleChange.qml b/tests/auto/quick/qquickvisualdatamodel/data/setDelegateNoDoubleChange.qml
new file mode 100644
index 0000000000..05623fbc5b
--- /dev/null
+++ b/tests/auto/quick/qquickvisualdatamodel/data/setDelegateNoDoubleChange.qml
@@ -0,0 +1,43 @@
+import QtQuick 2.0
+
+Item {
+ width: 200
+ height: 200
+ id: root
+ property int creationCount: 0
+ property bool testStarted: false
+
+ ListModel {
+ id: mymodel
+ ListElement {message: "This is my alarm"}
+ }
+
+ Component {
+ id: aDelegate
+ Rectangle {
+ color: "blue"
+ width: 100
+ height: 100
+ }
+ }
+
+ Component {
+ id: bDelegate
+ Rectangle {
+ color: "red"
+ width: 100
+ height: 100
+ Text {text: model.message }
+ Component.onCompleted: root.creationCount++
+ }
+ }
+
+
+ ListView {
+ width: 200
+ height: 200
+ id: myListView
+ model: mymodel
+ delegate: testStarted ? bDelegate : aDelegate
+ }
+}
diff --git a/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp b/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp
index 27bd8aae49..83bdb1a5f8 100644
--- a/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp
+++ b/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp
@@ -434,6 +434,7 @@ private slots:
void invalidContext();
void externalManagedModel();
void delegateModelChangeDelegate();
+ void noDoubleDelegateUpdate();
void checkFilterGroupForDelegate();
void readFromProxyObject();
@@ -4345,6 +4346,20 @@ void tst_qquickvisualdatamodel::delegateModelChangeDelegate()
QCOMPARE(visualModel->count(), 3);
}
+void tst_qquickvisualdatamodel::noDoubleDelegateUpdate()
+{
+ // changing a delegate only refreshes its instances once
+ QQmlEngine engine;
+ QQmlComponent component(&engine, testFileUrl("setDelegateNoDoubleChange.qml"));
+
+ QScopedPointer<QObject> root(component.create());
+ QVERIFY(root);
+
+ bool ok = root->setProperty("testStarted", true);
+ QVERIFY(ok);
+ QCOMPARE(root->property("creationCount").toInt(), 1);
+}
+
void tst_qquickvisualdatamodel::checkFilterGroupForDelegate()
{
QQuickView view;