Fix GridView to repaint when geometry changes
authorBea Lam <bea.lam@nokia.com>
Mon, 17 Oct 2011 05:50:07 +0000 (15:50 +1000)
committerQt by Nokia <qt-info@nokia.com>
Mon, 17 Oct 2011 05:52:06 +0000 (07:52 +0200)
Task-number: QTBUG-22078
Change-Id: Ic0ad67832dad9a7b3a7e5501893befe2d30b6c94
Reviewed-by: Bea Lam <bea.lam@nokia.com>
src/declarative/items/qsggridview.cpp
tests/auto/declarative/qsggridview/data/resizeview.qml [new file with mode: 0644]
tests/auto/declarative/qsggridview/tst_qsggridview.cpp
tests/auto/declarative/qsglistview/data/resizeview.qml [new file with mode: 0644]
tests/auto/declarative/qsglistview/tst_qsglistview.cpp

index 6b01583..2507a29 100644 (file)
@@ -788,6 +788,7 @@ void QSGGridViewPrivate::itemGeometryChanged(QSGItem *item, const QRectF &newGeo
     if (item == q) {
         if (newGeometry.height() != oldGeometry.height() || newGeometry.width() != oldGeometry.width()) {
             updateViewport();
+            forceLayout = true;
             q->polish();
         }
     }
diff --git a/tests/auto/declarative/qsggridview/data/resizeview.qml b/tests/auto/declarative/qsggridview/data/resizeview.qml
new file mode 100644 (file)
index 0000000..1f730a4
--- /dev/null
@@ -0,0 +1,24 @@
+import QtQuick 2.0
+
+Rectangle {
+    id: root
+
+    property real initialHeight
+
+    GridView {
+        id: grid
+        objectName: "grid"
+        width: 240
+        height: initialHeight
+        cellWidth: 80
+        cellHeight: 60
+        model: testModel
+        delegate: Rectangle {
+            objectName: "wrapper"
+            width: 80
+            height: 60
+            border.width: 1
+        }
+    }
+}
+
index b6a601d..5d6cd47 100644 (file)
@@ -100,6 +100,7 @@ private slots:
     void footer_data();
     void header();
     void header_data();
+    void resizeViewAndRepaint();
     void indexAt();
     void onAdd();
     void onAdd_data();
@@ -2768,6 +2769,39 @@ void tst_QSGGridView::header_data()
         << QPointF(-(240 - 40), 0);
 }
 
+void tst_QSGGridView::resizeViewAndRepaint()
+{
+    QSGView *canvas = createView();
+    canvas->show();
+
+    TestModel model;
+    for (int i = 0; i < 40; i++)
+        model.addItem("Item" + QString::number(i), "");
+
+    QDeclarativeContext *ctxt = canvas->rootContext();
+    ctxt->setContextProperty("testModel", &model);
+    ctxt->setContextProperty("initialHeight", 100);
+
+    canvas->setSource(QUrl::fromLocalFile(TESTDATA("resizeview.qml")));
+    qApp->processEvents();
+
+    QSGGridView *gridview = findItem<QSGGridView>(canvas->rootObject(), "grid");
+    QTRY_VERIFY(gridview != 0);
+    QSGItem *contentItem = gridview->contentItem();
+    QTRY_VERIFY(contentItem != 0);
+
+    // item at index 10 should not be currently visible
+    QVERIFY(!findItem<QSGItem>(contentItem, "wrapper", 10));
+
+    gridview->setHeight(320);
+    QTRY_VERIFY(findItem<QSGItem>(contentItem, "wrapper", 10));
+
+    gridview->setHeight(100);
+    QTRY_VERIFY(!findItem<QSGItem>(contentItem, "wrapper", 10));
+
+    delete canvas;
+}
+
 void tst_QSGGridView::indexAt()
 {
     QSGView *canvas = createView();
diff --git a/tests/auto/declarative/qsglistview/data/resizeview.qml b/tests/auto/declarative/qsglistview/data/resizeview.qml
new file mode 100644 (file)
index 0000000..071cded
--- /dev/null
@@ -0,0 +1,22 @@
+import QtQuick 2.0
+
+Rectangle {
+    id: root
+
+    property real initialHeight
+
+    ListView {
+        id: list
+        objectName: "list"
+        width: 240
+        height: initialHeight
+        model: testModel
+        delegate: Rectangle {
+            objectName: "wrapper"
+            width: 240
+            height: 20
+            border.width: 1
+        }
+    }
+}
+
index 1b5a8b2..fc1b755 100644 (file)
@@ -125,6 +125,7 @@ private slots:
     void footer_data();
     void headerFooter();
     void resizeView();
+    void resizeViewAndRepaint();
     void sizeLessThan1();
     void QTBUG_14821();
     void resizeDelegate();
@@ -3257,6 +3258,39 @@ void tst_QSGListView::resizeView()
     delete testObject;
 }
 
+void tst_QSGListView::resizeViewAndRepaint()
+{
+    QSGView *canvas = createView();
+    canvas->show();
+
+    TestModel model;
+    for (int i = 0; i < 40; i++)
+        model.addItem("Item" + QString::number(i), "");
+
+    QDeclarativeContext *ctxt = canvas->rootContext();
+    ctxt->setContextProperty("testModel", &model);
+    ctxt->setContextProperty("initialHeight", 100);
+
+    canvas->setSource(QUrl::fromLocalFile(TESTDATA("resizeview.qml")));
+    qApp->processEvents();
+
+    QSGListView *listview = findItem<QSGListView>(canvas->rootObject(), "list");
+    QTRY_VERIFY(listview != 0);
+    QSGItem *contentItem = listview->contentItem();
+    QTRY_VERIFY(contentItem != 0);
+
+    // item at index 10 should not be currently visible
+    QVERIFY(!findItem<QSGItem>(contentItem, "wrapper", 10));
+
+    listview->setHeight(320);
+    QTRY_VERIFY(findItem<QSGItem>(contentItem, "wrapper", 10));
+
+    listview->setHeight(100);
+    QTRY_VERIFY(!findItem<QSGItem>(contentItem, "wrapper", 10));
+
+    delete canvas;
+}
+
 void tst_QSGListView::sizeLessThan1()
 {
     QSGView *canvas = createView();