aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2011-10-17 15:50:07 +1000
committerQt by Nokia <qt-info@nokia.com>2011-10-17 07:52:06 +0200
commitb71363fda9822fab6d7fb93143173c6ba4cb8aa3 (patch)
treea8b78ec0c0db9476aaaa47d96e478c37c4de72e1
parentd06594d69bb35aacc00693e7480295cb33d1fb6f (diff)
Fix GridView to repaint when geometry changes
Task-number: QTBUG-22078 Change-Id: Ic0ad67832dad9a7b3a7e5501893befe2d30b6c94 Reviewed-by: Bea Lam <bea.lam@nokia.com>
-rw-r--r--src/declarative/items/qsggridview.cpp1
-rw-r--r--tests/auto/declarative/qsggridview/data/resizeview.qml24
-rw-r--r--tests/auto/declarative/qsggridview/tst_qsggridview.cpp34
-rw-r--r--tests/auto/declarative/qsglistview/data/resizeview.qml22
-rw-r--r--tests/auto/declarative/qsglistview/tst_qsglistview.cpp34
5 files changed, 115 insertions, 0 deletions
diff --git a/src/declarative/items/qsggridview.cpp b/src/declarative/items/qsggridview.cpp
index 6b01583497..2507a293de 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 0000000000..1f730a4a8a
--- /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 b6a601d8d7..5d6cd47a6f 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<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
index 0000000000..071cdedf2e
--- /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 1b5a8b2a4c..fc1b7551ed 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<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();