Fix QSGVisualDataModel test failure.
authorAndrew den Exter <andrew.den-exter@nokia.com>
Thu, 15 Sep 2011 08:03:32 +0000 (18:03 +1000)
committerQt by Nokia <qt-info@nokia.com>
Tue, 20 Sep 2011 01:51:11 +0000 (03:51 +0200)
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 <qt_sanity_bot@ovi.com>
Reviewed-by: Martin Jones <martin.jones@nokia.com>

src/declarative/items/qsgvisualitemmodel.cpp
tests/auto/declarative/qsgvisualdatamodel/tst_qsgvisualdatamodel.cpp

index 4dd508d..c6e5896 100644 (file)
@@ -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)
index f8a2a1f..d1dc6c9 100644 (file)
@@ -274,6 +274,7 @@ void tst_qsgvisualdatamodel::childChanged()
 
     QSGVisualDataModel *vdm = listview->findChild<QSGVisualDataModel*>("visualModel");
     vdm->setRootIndex(QVariant::fromValue(model.indexFromItem(model.item(1,0))));
+    QCOMPARE(listview->count(), 1);
 
     QSGText *name = findItem<QSGText>(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<QSGText>(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<QSGText>(contentItem, "display", 0);
     QVERIFY(name);
     QCOMPARE(name->text(), QString("Row 1 Item"));