diff options
Diffstat (limited to 'tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp')
-rw-r--r-- | tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp | 42 |
1 files changed, 41 insertions, 1 deletions
diff --git a/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp b/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp index fac8283e2c..fe56cad018 100644 --- a/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp +++ b/tests/auto/quick/qquickvisualdatamodel/tst_qquickvisualdatamodel.cpp @@ -39,7 +39,7 @@ #include <QtQuick/qquickview.h> #include <private/qquicklistview_p.h> #include <QtQuick/private/qquicktext_p.h> -#include <QtQml/private/qqmldelegatemodel_p.h> +#include <QtQmlModels/private/qqmldelegatemodel_p.h> #include <private/qqmlvaluetype_p.h> #include <private/qqmlchangeset_p.h> #include <private/qqmlengine_p.h> @@ -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" |