Clear the root index when the model is reset.
authorGirish Ramakrishnan <girish@forwardbias.in>
Wed, 27 Apr 2011 05:53:43 +0000 (15:53 +1000)
committerOlivier Goffart <olivier.goffart@nokia.com>
Wed, 11 May 2011 15:00:06 +0000 (17:00 +0200)
Task-number: QTBUG-18839

Change-Id: I46608d7481d820fa74a9be60df1e018e70a761c6
Merge-request: 2598
Reviewed-by: Martin Jones <martin.jones@nokia.com>
(cherry picked from commit f6b7ce204ee88be0fedb4cfcff382f208fa4ed33)

src/declarative/graphicsitems/qdeclarativevisualitemmodel.cpp
tests/auto/declarative/qdeclarativevisualdatamodel/tst_qdeclarativevisualdatamodel.cpp

index 97ce059..4c839a1 100644 (file)
@@ -1398,7 +1398,12 @@ void QDeclarativeVisualDataModel::_q_layoutChanged()
 
 void QDeclarativeVisualDataModel::_q_modelReset()
 {
+    Q_D(QDeclarativeVisualDataModel);
+    d->m_root = QModelIndex();
     emit modelReset();
+    emit rootIndexChanged();
+    if (d->m_abstractItemModel && d->m_abstractItemModel->canFetchMore(d->m_root))
+        d->m_abstractItemModel->fetchMore(d->m_root);
 }
 
 void QDeclarativeVisualDataModel::_q_createdPackage(int index, QDeclarativePackage *package)
index 85d7876..7b384f8 100644 (file)
@@ -190,6 +190,11 @@ void tst_qdeclarativevisualdatamodel::rootIndex()
     QMetaObject::invokeMethod(obj, "setRootToParent");
     QVERIFY(qvariant_cast<QModelIndex>(obj->rootIndex()) == QModelIndex());
 
+    QMetaObject::invokeMethod(obj, "setRoot");
+    QVERIFY(qvariant_cast<QModelIndex>(obj->rootIndex()) == model.index(0,0));
+    model.clear(); // will emit modelReset()
+    QVERIFY(qvariant_cast<QModelIndex>(obj->rootIndex()) == QModelIndex());
+
     delete obj;
 }