aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2019-05-16 10:10:30 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2019-10-09 18:58:18 +0200
commit2d9cf3ef0fc09254b1a63ab04b86d9beb52e71bc (patch)
tree2a4a09fc481336b193677b7e58fc995aeda41681 /tests
parentd522746afa394960bef225ba08080d8364b69a7e (diff)
When a DelegateModel delegate changes, refill the view
It looked a bit odd that the DelegateModel delegate property was not a notifying property. Adding the delegateChanged signal makes it easier to update the view when this happens. The previous approach of removing all delegates and adding all new ones resulted in the view losing its currentIndex and often scrolling to a different place. It's also nice to reduce the number of d-> indirections by adding the QQuickItemViewPrivate::applyDelegateChange() function, so that we just need one indirection to call it, and then it updates all the internal stuff in one place. Done-with: Frederik Gladhorn Done-with: Joni Poikelin Fixes: QTBUG-63477 Change-Id: I2d17fd11ff4a2fcb20968a7182dd2c403abb715a Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp b/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp
index 32008f675a..fe56cad018 100644
--- a/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp
+++ b/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp
@@ -432,6 +432,7 @@ private slots:
void asynchronousCancel();
void invalidContext();
void externalManagedModel();
+ void delegateModelChangeDelegate();
private:
template <int N> void groups_verify(
@@ -4302,6 +4303,45 @@ void tst_qquickvisualdatamodel::externalManagedModel()
QTRY_VERIFY(!object->property("running").toBool());
}
+void tst_qquickvisualdatamodel::delegateModelChangeDelegate()
+{
+ // Verify that QTBUG-63477 is fixed.
+ // Changing the delegate would not update existing items.
+ QQmlEngine engine;
+ QScopedPointer<QQmlContext> context(new QQmlContext(engine.rootContext()));
+
+ QQmlComponent c(&engine);
+ c.setData("import QtQml.Models 2.2\nDelegateModel {}\n", QUrl());
+ QCOMPARE(c.status(), QQmlComponent::Ready);
+
+ QQmlDelegateModel *visualModel = qobject_cast<QQmlDelegateModel*>(c.create(context.data()));
+ QVERIFY(visualModel);
+ visualModel->setModel(QVariant(3));
+
+ QQmlComponent first(&engine);
+ first.setData("import QtQuick 2.0\nItem { objectName: \"old\" }\n", QUrl());
+ QCOMPARE(first.status(), QQmlComponent::Ready);
+
+ // Without delegate, claim to have an item count of 0
+ QCOMPARE(visualModel->count(), 0);
+
+ visualModel->setDelegate(&first);
+ // The first delegate has been set, verify we get it
+ QObject* old = visualModel->object(0, QQmlIncubator::Synchronous);
+ QVERIFY(old);
+ QCOMPARE(visualModel->object(0, QQmlIncubator::Synchronous)->objectName(), QStringLiteral("old"));
+ QCOMPARE(visualModel->count(), 3);
+
+ QQmlComponent second(&engine);
+ second.setData("import QtQuick 2.0\nItem { objectName: \"new\" }\n", QUrl());
+ QCOMPARE(second.status(), QQmlComponent::Ready);
+
+ visualModel->setDelegate(&second);
+ // After changing the delegate, expect the existing item to have the new delegate
+ QCOMPARE(visualModel->object(0, QQmlIncubator::Synchronous)->objectName(), QStringLiteral("new"));
+ QCOMPARE(visualModel->count(), 3);
+}
+
QTEST_MAIN(tst_qquickvisualdatamodel)
#include "tst_qquickvisualdatamodel.moc"