From e587f86d0b89c1b3a84199144d92b568d9daf220 Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Thu, 15 Sep 2011 18:03:32 +1000 Subject: [PATCH] Fix QSGVisualDataModel test failure. Because the list view isn't visible it won't trigger a relayout unless forced by something like calling count() which means the test is looking up a stale list of items. VisualDataModel also wasn't clearing its cache when it changed the root item and so could return an old item if the view didn't release all items before querying a new one. Task-number: QTBUG-21416 Change-Id: I71193e22965f30ea92d9861ccbeff30b64d58309 Reviewed-on: http://codereview.qt-project.org/4953 Reviewed-by: Qt Sanity Bot Reviewed-by: Martin Jones --- src/declarative/items/qsgvisualitemmodel.cpp | 4 ++-- .../qsgvisualdatamodel/tst_qsgvisualdatamodel.cpp | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/declarative/items/qsgvisualitemmodel.cpp b/src/declarative/items/qsgvisualitemmodel.cpp index 4dd508d..c6e5896 100644 --- a/src/declarative/items/qsgvisualitemmodel.cpp +++ b/src/declarative/items/qsgvisualitemmodel.cpp @@ -984,7 +984,7 @@ void QSGVisualDataModel::setDelegate(QDeclarativeComponent *delegate) emit countChanged(); } if (wasValid && !d->m_delegate && d->modelCount()) { - emit itemsRemoved(0, d->modelCount()); + _q_itemsRemoved(0, d->modelCount()); emit countChanged(); } } @@ -1035,7 +1035,7 @@ void QSGVisualDataModel::setRootIndex(const QVariant &root) d->m_abstractItemModel->fetchMore(modelIndex); int newCount = d->modelCount(); if (d->m_delegate && oldCount) - emit itemsRemoved(0, oldCount); + _q_itemsRemoved(0, oldCount); if (d->m_delegate && newCount) emit itemsInserted(0, newCount); if (newCount != oldCount) diff --git a/tests/auto/declarative/qsgvisualdatamodel/tst_qsgvisualdatamodel.cpp b/tests/auto/declarative/qsgvisualdatamodel/tst_qsgvisualdatamodel.cpp index f8a2a1f..d1dc6c9 100644 --- a/tests/auto/declarative/qsgvisualdatamodel/tst_qsgvisualdatamodel.cpp +++ b/tests/auto/declarative/qsgvisualdatamodel/tst_qsgvisualdatamodel.cpp @@ -274,6 +274,7 @@ void tst_qsgvisualdatamodel::childChanged() QSGVisualDataModel *vdm = listview->findChild("visualModel"); vdm->setRootIndex(QVariant::fromValue(model.indexFromItem(model.item(1,0)))); + QCOMPARE(listview->count(), 1); QSGText *name = findItem(contentItem, "display", 0); QVERIFY(name); @@ -289,7 +290,7 @@ void tst_qsgvisualdatamodel::childChanged() QCOMPARE(name->text(), QString("Row 2 updated child")); model.item(1,0)->appendRow(new QStandardItem(QLatin1String("Row 2 Child Item 2"))); - QTest::qWait(300); + QCOMPARE(listview->count(), 2); name = findItem(contentItem, "display", 1); QVERIFY(name != 0); @@ -300,7 +301,7 @@ void tst_qsgvisualdatamodel::childChanged() QVERIFY(name == 0); vdm->setRootIndex(QVariant::fromValue(QModelIndex())); - QTest::qWait(300); + QCOMPARE(listview->count(), 3); name = findItem(contentItem, "display", 0); QVERIFY(name); QCOMPARE(name->text(), QString("Row 1 Item")); -- 1.7.2.5