Update SG items with recent GV item changes.
authorMartin Jones <martin.jones@nokia.com>
Mon, 30 May 2011 06:35:52 +0000 (16:35 +1000)
committerMartin Jones <martin.jones@nokia.com>
Mon, 30 May 2011 06:35:52 +0000 (16:35 +1000)
Change-Id: Ib9cadea91ab3717bee0caf2071102a100e81969d

12 files changed:
src/declarative/items/qsggridview.cpp
src/declarative/items/qsglistview.cpp
src/declarative/items/qsgpathview.cpp
src/declarative/items/qsgvisualitemmodel.cpp
tests/auto/declarative/qsggridview/data/gridview1.qml
tests/auto/declarative/qsggridview/tst_qsggridview.cpp
tests/auto/declarative/qsglistview/data/listviewtest.qml
tests/auto/declarative/qsglistview/tst_qsglistview.cpp
tests/auto/declarative/qsgpathview/data/datamodel.qml
tests/auto/declarative/qsgpathview/data/pathview0.qml
tests/auto/declarative/qsgpathview/tst_qsgpathview.cpp
tests/auto/declarative/qsgvisualdatamodel/tst_qsgvisualdatamodel.cpp

index 43f7f98..b65cd39 100644 (file)
@@ -1,4 +1,4 @@
-// Commit: fda9cc1d8a0e49817d1c6192c52d18dffcecf327
+// Commit: 806f031efeda71d3f4d7d2f949b437493e79cf52
 /****************************************************************************
 **
 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
@@ -814,7 +814,8 @@ void QSGGridViewPrivate::createHighlight()
     if (highlight) {
         if (trackedItem == highlight)
             trackedItem = 0;
-        delete highlight->item;
+        highlight->item->setParentItem(0);
+        highlight->item->deleteLater();
         delete highlight;
         highlight = 0;
         delete highlightXAnimator;
@@ -1348,6 +1349,7 @@ void QSGGridView::setDelegate(QDeclarativeComponent *delegate)
         d->ownModel = true;
     }
     if (QSGVisualDataModel *dataModel = qobject_cast<QSGVisualDataModel*>(d->model)) {
+        int oldCount = dataModel->count();
         dataModel->setDelegate(delegate);
         if (isComponentComplete()) {
             for (int i = 0; i < d->visibleItems.count(); ++i)
@@ -1365,6 +1367,8 @@ void QSGGridView::setDelegate(QDeclarativeComponent *delegate)
             }
             d->moveReason = QSGGridViewPrivate::Other;
         }
+        if (oldCount != dataModel->count())
+            emit countChanged();
         emit delegateChanged();
     }
 }
index 3bc9026..a61ca97 100644 (file)
@@ -1,4 +1,4 @@
-// Commit: cce89db1e2555cbca8fc28072e1c6dd737cec6c4
+// Commit: 806f031efeda71d3f4d7d2f949b437493e79cf52
 /****************************************************************************
 **
 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
@@ -731,6 +731,7 @@ void QSGListViewPrivate::refill(qreal from, qreal to, bool doBuffer)
     if (doBuffer && (bufferMode & BufferBefore))
         fillFrom = bufferFrom;
 
+    bool haveValidItems = false;
     int modelIndex = visibleIndex;
     qreal itemEnd = visiblePos-1;
     if (!visibleItems.isEmpty()) {
@@ -739,11 +740,13 @@ void QSGListViewPrivate::refill(qreal from, qreal to, bool doBuffer)
         int i = visibleItems.count() - 1;
         while (i > 0 && visibleItems.at(i)->index == -1)
             --i;
-        if (visibleItems.at(i)->index != -1)
+        if (visibleItems.at(i)->index != -1) {
+            haveValidItems = true;
             modelIndex = visibleItems.at(i)->index + 1;
+        }
     }
 
-    if (visibleItems.count() && (fillFrom > itemEnd+averageSize+spacing
+    if (haveValidItems && (fillFrom > itemEnd+averageSize+spacing
         || fillTo < visiblePos - averageSize - spacing)) {
         // We've jumped more than a page.  Estimate which items are now
         // visible and fill from there.
@@ -938,7 +941,8 @@ void QSGListViewPrivate::createHighlight()
     if (highlight) {
         if (trackedItem == highlight)
             trackedItem = 0;
-        delete highlight->item;
+        highlight->item->setParentItem(0);
+        highlight->item->deleteLater();
         delete highlight;
         highlight = 0;
         delete highlightPosAnimator;
@@ -1642,6 +1646,7 @@ void QSGListView::setDelegate(QDeclarativeComponent *delegate)
         d->ownModel = true;
     }
     if (QSGVisualDataModel *dataModel = qobject_cast<QSGVisualDataModel*>(d->model)) {
+        int oldCount = dataModel->count();
         dataModel->setDelegate(delegate);
         if (isComponentComplete()) {
             for (int i = 0; i < d->visibleItems.count(); ++i)
@@ -1660,6 +1665,8 @@ void QSGListView::setDelegate(QDeclarativeComponent *delegate)
             }
             d->updateViewport();
         }
+        if (oldCount != dataModel->count())
+            emit countChanged();
     }
     emit delegateChanged();
 }
@@ -2855,9 +2862,9 @@ void QSGListView::itemsRemoved(int modelIndex, int count)
         }
     }
 
-    if (removedVisible && !haveVisibleIndex) {
+    if (!haveVisibleIndex) {
         d->timeline.clear();
-        if (d->itemCount == 0) {
+        if (removedVisible && d->itemCount == 0) {
             d->visibleIndex = 0;
             d->visiblePos = d->header ? d->header->size() : 0;
             d->setPosition(0);
index 87e550b..fc3d39a 100644 (file)
@@ -1,4 +1,4 @@
-// Commit: 8878e2c53a0c9408d4b468e2dad485743c32f58b
+// Commit: 806f031efeda71d3f4d7d2f949b437493e79cf52
 /****************************************************************************
 **
 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
@@ -205,7 +205,8 @@ void QSGPathViewPrivate::createHighlight()
 
     bool changed = false;
     if (highlightItem) {
-        delete highlightItem;
+        highlightItem->setParentItem(0);
+        highlightItem->deleteLater();
         highlightItem = 0;
         changed = true;
     }
@@ -717,9 +718,12 @@ void QSGPathView::setDelegate(QDeclarativeComponent *delegate)
         d->ownModel = true;
     }
     if (QSGVisualDataModel *dataModel = qobject_cast<QSGVisualDataModel*>(d->model)) {
+        int oldCount = dataModel->count();
         dataModel->setDelegate(delegate);
         d->modelCount = dataModel->count();
         d->regenerate();
+        if (oldCount != dataModel->count())
+            emit countChanged();
         emit delegateChanged();
     }
 }
index 0bcd933..daf67b5 100644 (file)
@@ -1,4 +1,4 @@
-// Commit: 45153a37e4d9e39e8c326a0f33ea17be49bb29e2
+// Commit: dcb9148091cbf6872b60407c301d7c92427583a6
 /****************************************************************************
 **
 ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
@@ -1227,7 +1227,12 @@ void QSGVisualDataModel::_q_layoutChanged()
 
 void QSGVisualDataModel::_q_modelReset()
 {
+    Q_D(QSGVisualDataModel);
+    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 QSGVisualDataModel::_q_createdPackage(int index, QDeclarativePackage *package)
index 816fa5f..0f148ed 100644 (file)
@@ -2,6 +2,7 @@ import QtQuick 2.0
 
 Rectangle {
     id: root
+    property int count: grid.count
     property bool showHeader: false
     property bool showFooter: false
     property int added: -1
index 7374479..444e1c7 100644 (file)
@@ -234,6 +234,7 @@ void tst_QSGGridView::items()
     QTRY_VERIFY(contentItem != 0);
 
     QTRY_COMPARE(gridview->count(), model.count());
+    QTRY_COMPARE(canvas->rootObject()->property("count").toInt(), model.count());
     QTRY_COMPARE(contentItem->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item
 
     for (int i = 0; i < model.count(); ++i) {
@@ -318,6 +319,7 @@ void tst_QSGGridView::inserted()
     QTRY_VERIFY(contentItem != 0);
 
     model.insertItem(1, "Will", "9876");
+    QCOMPARE(canvas->rootObject()->property("count").toInt(), model.count());
 
     QTRY_COMPARE(contentItem->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item
 
@@ -396,6 +398,7 @@ void tst_QSGGridView::removed()
     QTRY_VERIFY(contentItem != 0);
 
     model.removeItem(1);
+    QCOMPARE(canvas->rootObject()->property("count").toInt(), model.count());
 
     QSGText *name = findItem<QSGText>(contentItem, "textName", 1);
     QTRY_VERIFY(name != 0);
index 832eaaf..0202de1 100644 (file)
@@ -6,6 +6,7 @@ Rectangle {
     height: 320
     color: "#ffffff"
 
+    property int count: list.count
     property bool showHeader: false
     property bool showFooter: false
     property real hr: list.visibleArea.heightRatio
index 507caed..e32353a 100644 (file)
@@ -399,6 +399,7 @@ void tst_QSGListView::items()
 
     QTRY_VERIFY(listview->highlightItem() != 0);
     QTRY_COMPARE(listview->count(), model.count());
+    QTRY_COMPARE(canvas->rootObject()->property("count").toInt(), model.count());
     QTRY_COMPARE(contentItem->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item
 
     // current item should be first item
@@ -529,6 +530,7 @@ void tst_QSGListView::inserted()
 
     model.insertItem(0, "Foo", "1111"); // zero index, and current item
 
+    QCOMPARE(canvas->rootObject()->property("count").toInt(), model.count());
     QTRY_COMPARE(contentItem->childItems().count(), model.count()+1); // assumes all are visible, +1 for the (default) highlight item
 
     name = findItem<QSGText>(contentItem, "textName", 0);
@@ -597,6 +599,7 @@ void tst_QSGListView::removed(bool animated)
     QTRY_VERIFY(contentItem != 0);
 
     model.removeItem(1);
+    QCOMPARE(canvas->rootObject()->property("count").toInt(), model.count());
 
     QSGText *name = findItem<QSGText>(contentItem, "textName", 1);
     QTRY_VERIFY(name != 0);
@@ -725,6 +728,16 @@ void tst_QSGListView::removed(bool animated)
     QTRY_VERIFY(name = findItem<QSGText>(contentItem, "textName", model.count()-1));
     QCOMPARE(name->text(), QString("New"));
 
+    // Add some more items so that we don't run out
+    for (int i = 50; i < 100; i++)
+        model.addItem("Item" + QString::number(i), "");
+
+    // QTBUG-19198 move to end and remove all visible items one at a time.
+    listview->positionViewAtEnd();
+    for (int i = 0; i < 18; ++i)
+        model.removeItems(model.count() - 1, 1);
+    QTRY_VERIFY(findItems<QSGItem>(contentItem, "wrapper").count() > 16);
+
     delete canvas;
     delete testObject;
 }
index 839049f..44f2aec 100644 (file)
@@ -2,6 +2,7 @@ import QtQuick 2.0
 
 PathView {
     id: pathview
+    property int viewCount: count
     objectName: "pathview"
     width: 240; height: 320
     pathItemCount: testObject.pathItemCount
index 0204112..72b71a3 100644 (file)
@@ -2,6 +2,7 @@ import QtQuick 2.0
 
 Rectangle {
     id: root
+    property int count: view.count
     property int currentA: -1
     property int currentB: -1
     property real delegateWidth: 60
index 5b95ace..2c24748 100644 (file)
@@ -268,6 +268,8 @@ void tst_QSGPathView::items()
     QSGPathView *pathview = findItem<QSGPathView>(canvas->rootObject(), "view");
     QVERIFY(pathview != 0);
 
+    QCOMPARE(pathview->count(), model.count());
+    QCOMPARE(canvas->rootObject()->property("count").toInt(), model.count());
     QCOMPARE(pathview->childItems().count(), model.count()+1); // assumes all are visible, including highlight
 
     for (int i = 0; i < model.count(); ++i) {
@@ -416,6 +418,7 @@ void tst_QSGPathView::dataModel()
     model.insertItem(4, "orange", "10");
     QTest::qWait(100);
 
+    QCOMPARE(canvas->rootObject()->property("viewCount").toInt(), model.count());
     QTRY_COMPARE(findItems<QSGItem>(pathview, "wrapper").count(), 14);
 
     QVERIFY(pathview->currentIndex() == 0);
@@ -425,6 +428,7 @@ void tst_QSGPathView::dataModel()
     QCOMPARE(text->text(), model.name(4));
 
     model.removeItem(2);
+    QCOMPARE(canvas->rootObject()->property("viewCount").toInt(), model.count());
     text = findItem<QSGText>(pathview, "myText", 2);
     QVERIFY(text);
     QCOMPARE(text->text(), model.name(2));
index ce2c816..078c997 100644 (file)
@@ -203,6 +203,11 @@ void tst_qsgvisualdatamodel::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;
 }