From b71363fda9822fab6d7fb93143173c6ba4cb8aa3 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Mon, 17 Oct 2011 15:50:07 +1000 Subject: [PATCH] Fix GridView to repaint when geometry changes Task-number: QTBUG-22078 Change-Id: Ic0ad67832dad9a7b3a7e5501893befe2d30b6c94 Reviewed-by: Bea Lam --- src/declarative/items/qsggridview.cpp | 1 + .../declarative/qsggridview/data/resizeview.qml | 24 ++++++++++++++ .../declarative/qsggridview/tst_qsggridview.cpp | 34 ++++++++++++++++++++ .../declarative/qsglistview/data/resizeview.qml | 22 +++++++++++++ .../declarative/qsglistview/tst_qsglistview.cpp | 34 ++++++++++++++++++++ 5 files changed, 115 insertions(+), 0 deletions(-) create mode 100644 tests/auto/declarative/qsggridview/data/resizeview.qml create mode 100644 tests/auto/declarative/qsglistview/data/resizeview.qml diff --git a/src/declarative/items/qsggridview.cpp b/src/declarative/items/qsggridview.cpp index 6b01583..2507a29 100644 --- a/src/declarative/items/qsggridview.cpp +++ b/src/declarative/items/qsggridview.cpp @@ -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 index 0000000..1f730a4 --- /dev/null +++ b/tests/auto/declarative/qsggridview/data/resizeview.qml @@ -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 + } + } +} + diff --git a/tests/auto/declarative/qsggridview/tst_qsggridview.cpp b/tests/auto/declarative/qsggridview/tst_qsggridview.cpp index b6a601d..5d6cd47 100644 --- a/tests/auto/declarative/qsggridview/tst_qsggridview.cpp +++ b/tests/auto/declarative/qsggridview/tst_qsggridview.cpp @@ -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(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(contentItem, "wrapper", 10)); + + gridview->setHeight(320); + QTRY_VERIFY(findItem(contentItem, "wrapper", 10)); + + gridview->setHeight(100); + QTRY_VERIFY(!findItem(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 index 0000000..071cded --- /dev/null +++ b/tests/auto/declarative/qsglistview/data/resizeview.qml @@ -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 + } + } +} + diff --git a/tests/auto/declarative/qsglistview/tst_qsglistview.cpp b/tests/auto/declarative/qsglistview/tst_qsglistview.cpp index 1b5a8b2..fc1b755 100644 --- a/tests/auto/declarative/qsglistview/tst_qsglistview.cpp +++ b/tests/auto/declarative/qsglistview/tst_qsglistview.cpp @@ -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(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(contentItem, "wrapper", 10)); + + listview->setHeight(320); + QTRY_VERIFY(findItem(contentItem, "wrapper", 10)); + + listview->setHeight(100); + QTRY_VERIFY(!findItem(contentItem, "wrapper", 10)); + + delete canvas; +} + void tst_QSGListView::sizeLessThan1() { QSGView *canvas = createView(); -- 1.7.2.5