Ensure that header/footer resize fixes position.
authorMartin Jones <martin.jones@nokia.com>
Tue, 6 Sep 2011 06:28:32 +0000 (16:28 +1000)
committerQt by Nokia <qt-info@nokia.com>
Tue, 6 Sep 2011 08:31:39 +0000 (10:31 +0200)
If the header or footer is resized the view must ensure that
it is still within bounds.

Change-Id: I5f7aa61dc9ccec8dd16457d8d4e4966434e4b1e0
Reviewed-on: http://codereview.qt.nokia.com/4236
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Bea Lam <bea.lam@nokia.com>
src/declarative/items/qsgitemview.cpp
tests/auto/declarative/qsggridview/tst_qsggridview.cpp
tests/auto/declarative/qsglistview/tst_qsglistview.cpp

index 141be4f..e331501 100644 (file)
@@ -748,10 +748,19 @@ void QSGItemViewPrivate::itemGeometryChanged(QSGItem *item, const QRectF &newGeo
     if (!q->isComponentComplete())
         return;
 
-    if (header && header->item == item)
+    if (header && header->item == item) {
         updateHeader();
-    else if (footer && footer->item == item)
+        minExtentDirty = true;
+        maxExtentDirty = true;
+        if (!q->isMoving() && !q->isFlicking())
+            fixupPosition();
+    } else if (footer && footer->item == item) {
         updateFooter();
+        minExtentDirty = true;
+        maxExtentDirty = true;
+        if (!q->isMoving() && !q->isFlicking())
+            fixupPosition();
+    }
 
     if (currentItem && currentItem->item == item)
         updateHighlight();
index ae4ca7d..f29eb33 100644 (file)
@@ -2296,6 +2296,7 @@ void tst_QSGGridView::footer()
     QFETCH(QPointF, initialContentPos);
     QFETCH(QPointF, changedContentPos);
     QFETCH(QPointF, firstDelegatePos);
+    QFETCH(QPointF, resizeContentPos);
 
     QSGView *canvas = createView();
     canvas->show();
@@ -2385,6 +2386,11 @@ void tst_QSGGridView::footer()
     QVERIFY(item);
     QCOMPARE(item->pos(), firstDelegatePos);
 
+    gridview->positionViewAtEnd();
+    footer->setHeight(10);
+    footer->setWidth(40);
+    QTRY_COMPARE(QPointF(gridview->contentX(), gridview->contentY()), resizeContentPos);
+
     delete canvas;
 }
 
@@ -2397,11 +2403,13 @@ void tst_QSGGridView::footer_data()
     QTest::addColumn<QPointF>("initialContentPos");
     QTest::addColumn<QPointF>("changedContentPos");
     QTest::addColumn<QPointF>("firstDelegatePos");
+    QTest::addColumn<QPointF>("resizeContentPos");
 
     // footer1 = 100 x 30
-    // footer2 = 100 x 20
+    // footer2 = 50 x 20
     // cells = 80 * 60
     // view width = 240
+    // view height = 320
 
     // footer below items, bottom left
     QTest::newRow("flow left to right") << QSGGridView::LeftToRight << Qt::LeftToRight
@@ -2409,7 +2417,8 @@ void tst_QSGGridView::footer_data()
         << QPointF(0, 10 * 60)  // 30 items = 10 rows
         << QPointF(0, 0)
         << QPointF(0, 0)
-        << QPointF(0, 0);
+        << QPointF(0, 0)
+        << QPointF(0, 10 * 60 - 320 + 10);
 
     // footer below items, bottom right
     QTest::newRow("flow left to right, layout right to left") << QSGGridView::LeftToRight << Qt::RightToLeft
@@ -2417,7 +2426,8 @@ void tst_QSGGridView::footer_data()
         << QPointF((240 - 100) + 50, 10 * 60)     // 50 = width diff between old and new footers
         << QPointF(0, 0)
         << QPointF(0, 0)
-        << QPointF(240 - 80, 0);
+        << QPointF(240 - 80, 0)
+        << QPointF(0, 10 * 60 - 320 + 10);
 
     // footer to right of items
     QTest::newRow("flow top to bottom, layout left to right") << QSGGridView::TopToBottom << Qt::LeftToRight
@@ -2425,7 +2435,8 @@ void tst_QSGGridView::footer_data()
         << QPointF(6 * 80, 0)      // 30 items = 6 columns
         << QPointF(0, 0)
         << QPointF(0, 0)
-        << QPointF(0, 0);
+        << QPointF(0, 0)
+        << QPointF(6 * 80 - 240 + 40, 0);
 
     // footer to left of items
     QTest::newRow("flow top to bottom, layout right to left") << QSGGridView::TopToBottom << Qt::RightToLeft
@@ -2433,7 +2444,8 @@ void tst_QSGGridView::footer_data()
         << QPointF(-(6 * 80) - 50, 0)     // 50 = new footer width
         << QPointF(-240, 0)
         << QPointF(-240, 0)    // unchanged, footer change doesn't change content pos
-        << QPointF(-80, 0);
+        << QPointF(-80, 0)
+        << QPointF(-(6 * 80) - 40, 0);
 }
 
 void tst_QSGGridView::header()
@@ -2445,6 +2457,7 @@ void tst_QSGGridView::header()
     QFETCH(QPointF, initialContentPos);
     QFETCH(QPointF, changedContentPos);
     QFETCH(QPointF, firstDelegatePos);
+    QFETCH(QPointF, resizeContentPos);
 
     QSGView *canvas = createView();
 
@@ -2507,6 +2520,10 @@ void tst_QSGGridView::header()
     QVERIFY(item);
     QCOMPARE(item->pos(), firstDelegatePos);
 
+    header->setHeight(10);
+    header->setWidth(40);
+    QTRY_COMPARE(QPointF(gridview->contentX(), gridview->contentY()), resizeContentPos);
+
     delete canvas;
 }
 
@@ -2519,9 +2536,10 @@ void tst_QSGGridView::header_data()
     QTest::addColumn<QPointF>("initialContentPos");
     QTest::addColumn<QPointF>("changedContentPos");
     QTest::addColumn<QPointF>("firstDelegatePos");
+    QTest::addColumn<QPointF>("resizeContentPos");
 
     // header1 = 100 x 30
-    // header2 = 100 x 20
+    // header2 = 50 x 20
     // cells = 80 x 60
     // view width = 240
 
@@ -2531,7 +2549,8 @@ void tst_QSGGridView::header_data()
         << QPointF(0, -20)
         << QPointF(0, -30)
         << QPointF(0, -20)
-        << QPointF(0, 0);
+        << QPointF(0, 0)
+        << QPointF(0, -10);
 
     // header above items, top right
     QTest::newRow("flow left to right, layout right to left") << QSGGridView::LeftToRight << Qt::RightToLeft
@@ -2539,7 +2558,8 @@ void tst_QSGGridView::header_data()
         << QPointF((240 - 100) + 50, -20)     // 50 = width diff between old and new headers
         << QPointF(0, -30)
         << QPointF(0, -20)
-        << QPointF(160, 0);
+        << QPointF(160, 0)
+        << QPointF(0, -10);
 
     // header to left of items
     QTest::newRow("flow top to bottom, layout left to right") << QSGGridView::TopToBottom << Qt::LeftToRight
@@ -2547,7 +2567,8 @@ void tst_QSGGridView::header_data()
         << QPointF(-50, 0)
         << QPointF(-100, 0)
         << QPointF(-50, 0)
-        << QPointF(0, 0);
+        << QPointF(0, 0)
+        << QPointF(-40, 0);
 
     // header to right of items
     QTest::newRow("flow top to bottom, layout right to left") << QSGGridView::TopToBottom << Qt::RightToLeft
@@ -2555,7 +2576,8 @@ void tst_QSGGridView::header_data()
         << QPointF(0, 0)
         << QPointF(-(240 - 100), 0)
         << QPointF(-(240 - 50), 0)
-        << QPointF(-80, 0);
+        << QPointF(-80, 0)
+        << QPointF(-(240 - 40), 0);
 }
 
 void tst_QSGGridView::indexAt()
index df4c5bc..ecbb9b8 100644 (file)
@@ -2461,6 +2461,7 @@ void tst_QSGListView::header()
     QFETCH(QPointF, initialContentPos);
     QFETCH(QPointF, changedHeaderPos);
     QFETCH(QPointF, changedContentPos);
+    QFETCH(QPointF, resizeContentPos);
 
     QSGView *canvas = createView();
 
@@ -2520,6 +2521,10 @@ void tst_QSGListView::header()
     QTRY_COMPARE(QPointF(listview->contentX(), listview->contentY()), changedContentPos);
     QCOMPARE(item->pos(), firstDelegatePos);
 
+    header->setHeight(10);
+    header->setWidth(40);
+    QTRY_COMPARE(QPointF(listview->contentX(), listview->contentY()), resizeContentPos);
+
     delete canvas;
 }
 
@@ -2532,6 +2537,7 @@ void tst_QSGListView::header_data()
     QTest::addColumn<QPointF>("initialContentPos");
     QTest::addColumn<QPointF>("changedContentPos");
     QTest::addColumn<QPointF>("firstDelegatePos");
+    QTest::addColumn<QPointF>("resizeContentPos");
 
     // header1 = 100 x 30
     // header2 = 50 x 20
@@ -2544,7 +2550,8 @@ void tst_QSGListView::header_data()
         << QPointF(0, -20)
         << QPointF(0, -30)
         << QPointF(0, -20)
-        << QPointF(0, 0);
+        << QPointF(0, 0)
+        << QPointF(0, -10);
 
     // header above items, top right
     QTest::newRow("vertical, layout right to left") << QSGListView::Vertical << Qt::RightToLeft
@@ -2552,7 +2559,8 @@ void tst_QSGListView::header_data()
         << QPointF(0, -20)
         << QPointF(0, -30)
         << QPointF(0, -20)
-        << QPointF(0, 0);
+        << QPointF(0, 0)
+        << QPointF(0, -10);
 
     // header to left of items
     QTest::newRow("horizontal, layout left to right") << QSGListView::Horizontal << Qt::LeftToRight
@@ -2560,7 +2568,8 @@ void tst_QSGListView::header_data()
         << QPointF(-50, 0)
         << QPointF(-100, 0)
         << QPointF(-50, 0)
-        << QPointF(0, 0);
+        << QPointF(0, 0)
+        << QPointF(-40, 0);
 
     // header to right of items
     QTest::newRow("horizontal, layout right to left") << QSGListView::Horizontal << Qt::RightToLeft
@@ -2568,7 +2577,8 @@ void tst_QSGListView::header_data()
         << QPointF(0, 0)
         << QPointF(-240 + 100, 0)
         << QPointF(-240 + 50, 0)
-        << QPointF(-240, 0);
+        << QPointF(-240, 0)
+        << QPointF(-240 + 40, 0);
 }
 
 void tst_QSGListView::header_delayItemCreation()
@@ -2607,6 +2617,7 @@ void tst_QSGListView::footer()
     QFETCH(QPointF, initialContentPos);
     QFETCH(QPointF, changedFooterPos);
     QFETCH(QPointF, changedContentPos);
+    QFETCH(QPointF, resizeContentPos);
 
     QSGView *canvas = createView();
 
@@ -2691,6 +2702,11 @@ void tst_QSGListView::footer()
     QVERIFY(item);
     QCOMPARE(item->pos(), firstDelegatePos);
 
+    listview->positionViewAtEnd();
+    footer->setHeight(10);
+    footer->setWidth(40);
+    QTRY_COMPARE(QPointF(listview->contentX(), listview->contentY()), resizeContentPos);
+
     delete canvas;
 }
 
@@ -2703,11 +2719,13 @@ void tst_QSGListView::footer_data()
     QTest::addColumn<QPointF>("initialContentPos");
     QTest::addColumn<QPointF>("changedContentPos");
     QTest::addColumn<QPointF>("firstDelegatePos");
+    QTest::addColumn<QPointF>("resizeContentPos");
 
     // footer1 = 100 x 30
-    // footer2 = 100 x 20
+    // footer2 = 50 x 20
     // delegates = 40 x 20
     // view width = 240
+    // view height = 320
 
     // footer below items, bottom left
     QTest::newRow("vertical, layout left to right") << QSGListView::Vertical << Qt::LeftToRight
@@ -2715,7 +2733,8 @@ void tst_QSGListView::footer_data()
         << QPointF(0, 30 * 20)  // added 30 items
         << QPointF(0, 0)
         << QPointF(0, 0)
-        << QPointF(0, 0);
+        << QPointF(0, 0)
+        << QPointF(0, 30 * 20 - 320 + 10);
 
     // footer below items, bottom right
     QTest::newRow("vertical, layout right to left") << QSGListView::Vertical << Qt::RightToLeft
@@ -2723,7 +2742,8 @@ void tst_QSGListView::footer_data()
         << QPointF(0, 30 * 20)
         << QPointF(0, 0)
         << QPointF(0, 0)
-        << QPointF(0, 0);
+        << QPointF(0, 0)
+        << QPointF(0, 30 * 20 - 320 + 10);
 
     // footer to right of items
     QTest::newRow("horizontal, layout left to right") << QSGListView::Horizontal << Qt::LeftToRight
@@ -2731,7 +2751,8 @@ void tst_QSGListView::footer_data()
         << QPointF(40 * 30, 0)
         << QPointF(0, 0)
         << QPointF(0, 0)
-        << QPointF(0, 0);
+        << QPointF(0, 0)
+        << QPointF(40 * 30 - 240 + 40, 0);
 
     // footer to left of items
     QTest::newRow("horizontal, layout right to left") << QSGListView::Horizontal << Qt::RightToLeft
@@ -2739,7 +2760,8 @@ void tst_QSGListView::footer_data()
         << QPointF(-(40 * 30) - 50, 0)     // 50 = new footer width
         << QPointF(-240, 0)
         << QPointF(-240, 0)
-        << QPointF(-40, 0);
+        << QPointF(-40, 0)
+        << QPointF(-(40 * 30) - 40, 0);
 }
 
 class LVAccessor : public QSGListView