Fix xOrigin and yOrigin to always be top-left pos
authorBea Lam <bea.lam@nokia.com>
Thu, 10 May 2012 05:15:50 +0000 (15:15 +1000)
committerQt by Nokia <qt-info@nokia.com>
Mon, 14 May 2012 01:03:36 +0000 (03:03 +0200)
Currently xOrigin is reversed for right-to-left and yOrigin is reversed
for bottom-to-top. This is wrong since xOrigin and yOrigin come from
Flickable so they should keep that meaning, i.e. the top left corner of
where the content begins, in ListView and GridView.

Change-Id: I88c77fadd1cf784f4b4d62677168b84675e921b0
Reviewed-by: Martin Jones <martin.jones@nokia.com>
src/quick/items/qquickitemview.cpp
tests/auto/quick/qquickgridview/data/headerfooter.qml
tests/auto/quick/qquickgridview/tst_qquickgridview.cpp
tests/auto/quick/qquicklistview/data/headerfooter.qml
tests/auto/quick/qquicklistview/tst_qquicklistview.cpp

index 1b48a32..bab505e 100644 (file)
@@ -1344,19 +1344,23 @@ void QQuickItemView::setContentY(qreal pos)
 qreal QQuickItemView::xOrigin() const
 {
     Q_D(const QQuickItemView);
-    if (d->isContentFlowReversed())
-        return -maxXExtent() + d->size() - d->hData.endMargin;
-    else
-        return -minXExtent() + d->hData.startMargin;
+    if (d->layoutOrientation() == Qt::Horizontal
+            && effectiveLayoutDirection() == Qt::RightToLeft
+            && contentWidth() < width()) {
+        return d->lastPosition() - d->footerSize();
+    }
+    return QQuickFlickable::xOrigin();
 }
 
 qreal QQuickItemView::yOrigin() const
 {
     Q_D(const QQuickItemView);
-    if (d->isContentFlowReversed())
-        return -maxYExtent() + d->size() - d->vData.endMargin;
-    else
-        return -minYExtent() + d->vData.startMargin;
+    if (d->layoutOrientation() == Qt::Vertical
+            && d->verticalLayoutDirection == QQuickItemView::BottomToTop
+            && contentHeight() < height()) {
+        return d->lastPosition() - d->footerSize();
+    }
+    return QQuickFlickable::yOrigin();
 }
 
 void QQuickItemView::updatePolish()
index f0f73a0..a1f31ea 100644 (file)
@@ -22,7 +22,11 @@ GridView {
     }
 
     cellWidth: 80;
-    cellHeight: 80;
+    cellHeight: 60;
 
-    delegate: Text { width: 80; height: 80; text: index + "(" + x + ")" }
+    delegate: Rectangle {
+        width: 80; height: 60
+        border.width: 1
+        Text { text: index + "(" + parent.x + "," + parent.y + ")" }
+    }
 }
index d39fbe5..8dc7fda 100644 (file)
@@ -120,8 +120,8 @@ private slots:
     void footer_data();
     void header();
     void header_data();
-    void headerFooter();
-    void headerFooter_data();
+    void extents();
+    void extents_data();
     void resetModel_headerFooter();
     void resizeViewAndRepaint();
     void resizeGrid();
@@ -3485,7 +3485,7 @@ public:
     qreal maxX() const { return maxXExtent(); }
 };
 
-void tst_QQuickGridView::headerFooter()
+void tst_QQuickGridView::extents()
 {
     QFETCH(QQuickGridView::Flow, flow);
     QFETCH(Qt::LayoutDirection, layoutDirection);
@@ -3494,6 +3494,8 @@ void tst_QQuickGridView::headerFooter()
     QFETCH(QPointF, footerPos);
     QFETCH(QPointF, minPos);
     QFETCH(QPointF, maxPos);
+    QFETCH(QPointF, origin_empty);
+    QFETCH(QPointF, origin_nonEmpty);
 
     QQuickView *canvas = getView();
 
@@ -3527,10 +3529,18 @@ void tst_QQuickGridView::headerFooter()
     QCOMPARE(static_cast<GVAccessor*>(gridview)->maxX(), maxPos.x());
     QCOMPARE(static_cast<GVAccessor*>(gridview)->maxY(), maxPos.y());
 
+    QCOMPARE(gridview->xOrigin(), origin_empty.x());
+    QCOMPARE(gridview->yOrigin(), origin_empty.y());
+    for (int i=0; i<30; i++)
+        model.addItem("Item" + QString::number(i), "");
+    QTRY_COMPARE(gridview->count(), model.count());
+    QCOMPARE(gridview->xOrigin(), origin_nonEmpty.x());
+    QCOMPARE(gridview->yOrigin(), origin_nonEmpty.y());
+
     releaseView(canvas);
 }
 
-void tst_QQuickGridView::headerFooter_data()
+void tst_QQuickGridView::extents_data()
 {
     QTest::addColumn<QQuickGridView::Flow>("flow");
     QTest::addColumn<Qt::LayoutDirection>("layoutDirection");
@@ -3539,50 +3549,61 @@ void tst_QQuickGridView::headerFooter_data()
     QTest::addColumn<QPointF>("footerPos");
     QTest::addColumn<QPointF>("minPos");
     QTest::addColumn<QPointF>("maxPos");
+    QTest::addColumn<QPointF>("origin_empty");
+    QTest::addColumn<QPointF>("origin_nonEmpty");
 
     // header is 240x20 (or 20x320 in TopToBottom)
     // footer is 240x30 (or 30x320 in TopToBottom)
+    // grid has 10 rows in LeftToRight mode and 6 columns in TopToBottom
 
     QTest::newRow("LeftToRight, LtR, TtB")
             << QQuickGridView::FlowLeftToRight << Qt::LeftToRight << QQuickItemView::TopToBottom
             << QPointF(0, -20) << QPointF(0, 0)
-            << QPointF(0, 20) << QPointF(240, 20);
+            << QPointF(0, 20) << QPointF(240, 20)
+            << QPointF(0, -20) << QPointF(0, -20);
 
     QTest::newRow("LeftToRight, RtL, TtB")
             << QQuickGridView::FlowLeftToRight << Qt::RightToLeft << QQuickItemView::TopToBottom
             << QPointF(0, -20) << QPointF(0, 0)
-            << QPointF(0, 20) << QPointF(240, 20);
+            << QPointF(0, 20) << QPointF(240, 20)
+            << QPointF(0, -20) << QPointF(0, -20);
 
     QTest::newRow("LeftToRight, LtR, BtT")
             << QQuickGridView::FlowLeftToRight << Qt::LeftToRight << QQuickItemView::BottomToTop
             << QPointF(0, 0) << QPointF(0, -30)
-            << QPointF(0, 320 - 20) << QPointF(240, 320 - 20);  // content flow is reversed
+            << QPointF(0, 320 - 20) << QPointF(240, 320 - 20)  // content flow is reversed
+            << QPointF(0, -30) << QPointF(0, (-60.0 * 10) - 30);
 
     QTest::newRow("LeftToRight, RtL, BtT")
             << QQuickGridView::FlowLeftToRight << Qt::RightToLeft << QQuickItemView::BottomToTop
             << QPointF(0, 0) << QPointF(0, -30)
-            << QPointF(0, 320 - 20) << QPointF(240, 320 - 20);  // content flow is reversed
+            << QPointF(0, 320 - 20) << QPointF(240, 320 - 20)  // content flow is reversed
+            << QPointF(0, -30) << QPointF(0, (-60.0 * 10) - 30);
 
 
     QTest::newRow("TopToBottom, LtR, TtB")
             << QQuickGridView::FlowTopToBottom << Qt::LeftToRight << QQuickItemView::TopToBottom
             << QPointF(-20, 0) << QPointF(0, 0)
-            << QPointF(20, 0) << QPointF(20, 320);
+            << QPointF(20, 0) << QPointF(20, 320)
+            << QPointF(-20, 0) << QPointF(-20, 0);
 
     QTest::newRow("TopToBottom, RtL, TtB")
             << QQuickGridView::FlowTopToBottom << Qt::RightToLeft << QQuickItemView::TopToBottom
             << QPointF(0, 0) << QPointF(-30, 0)
-            << QPointF(240 - 20, 0) << QPointF(240 - 20, 320);  // content flow is reversed
+            << QPointF(240 - 20, 0) << QPointF(240 - 20, 320)  // content flow is reversed
+            << QPointF(-30, 0) << QPointF((-80.0 * 6) - 30, 0);
 
     QTest::newRow("TopToBottom, LtR, BtT")
             << QQuickGridView::FlowTopToBottom << Qt::LeftToRight << QQuickItemView::BottomToTop
             << QPointF(-20, -320) << QPointF(0, -320)
-            << QPointF(20, 0) << QPointF(20, 320);
+            << QPointF(20, 0) << QPointF(20, 320)
+            << QPointF(-20, 0) << QPointF(-20, 0);
 
     QTest::newRow("TopToBottom, RtL, BtT")
             << QQuickGridView::FlowTopToBottom << Qt::RightToLeft << QQuickItemView::BottomToTop
             << QPointF(0, -320) << QPointF(-30, -320)
-            << QPointF(240 - 20, 0) << QPointF(240 - 20, 320);  // content flow is reversed
+            << QPointF(240 - 20, 0) << QPointF(240 - 20, 320)  // content flow is reversed
+            << QPointF(-30, 0) << QPointF((-80.0 * 6) - 30, 0);
 }
 
 void tst_QQuickGridView::resetModel_headerFooter()
@@ -3612,7 +3633,7 @@ void tst_QQuickGridView::resetModel_headerFooter()
 
     QQuickItem *footer = findItem<QQuickItem>(contentItem, "footer");
     QVERIFY(footer);
-    QCOMPARE(footer->y(), 80.*2);
+    QCOMPARE(footer->y(), 60.*2);
 
     model.reset();
 
@@ -3622,7 +3643,7 @@ void tst_QQuickGridView::resetModel_headerFooter()
 
     footer = findItem<QQuickItem>(contentItem, "footer");
     QVERIFY(footer);
-    QCOMPARE(footer->y(), 80.*2);
+    QCOMPARE(footer->y(), 60.*2);
 
     delete canvas;
 }
@@ -4166,7 +4187,7 @@ void tst_QQuickGridView::margins()
         QTRY_VERIFY(contentItem != 0);
 
         QTRY_COMPARE(gridview->contentX(), -240+50.);
-        QTRY_COMPARE(gridview->xOrigin(), 0.);
+        QTRY_COMPARE(gridview->xOrigin(), -100. * 10);
 
         // check end bound
         gridview->positionViewAtEnd();
@@ -4183,18 +4204,18 @@ void tst_QQuickGridView::margins()
         QTRY_COMPARE(model.count(), gridview->count());
         gridview->setContentX(-240+50);
         gridview->returnToBounds();
-        QCOMPARE(gridview->xOrigin(), -100.);
+        QCOMPARE(gridview->xOrigin(), -1000.);
         QTRY_COMPARE(gridview->contentX(), -240-50.);
 
         // reduce right margin
         pos = gridview->contentX();
         gridview->setRightMargin(40);
-        QCOMPARE(gridview->xOrigin(), -100.);
+        QCOMPARE(gridview->xOrigin(), -1000.);
         QTRY_COMPARE(gridview->contentX(), -240-100 + 40.);
 
         // check end bound
         gridview->positionViewAtEnd();
-        QCOMPARE(gridview->xOrigin(), 0.); // positionViewAtEnd() resets origin
+        QCOMPARE(gridview->xOrigin(), -900.); // positionViewAtEnd() resets origin
         pos = gridview->contentX();
         gridview->setContentX(pos - 80);
         gridview->returnToBounds();
@@ -4203,7 +4224,7 @@ void tst_QQuickGridView::margins()
         // reduce left margin
         pos = gridview->contentX();
         gridview->setLeftMargin(20);
-        QCOMPARE(gridview->xOrigin(), 0.);
+        QCOMPARE(gridview->xOrigin(), -900.);
         QTRY_COMPARE(gridview->contentX(), pos+10);
 
         delete canvas;
index 07a331a..592e2ce 100644 (file)
@@ -21,5 +21,9 @@ ListView {
         color: "blue"
     }
 
-    delegate: Text { width: 30; height: 30; text: index + "(" + x + ")" }
+    delegate: Rectangle {
+        width: view.width
+        height: 30
+        Text { text: index + "(" + x + ")" }
+    }
 }
index b38bb0d..4652051 100644 (file)
@@ -154,8 +154,8 @@ private slots:
     void header_delayItemCreation();
     void footer();
     void footer_data();
-    void headerFooter();
-    void headerFooter_data();
+    void extents();
+    void extents_data();
     void resetModel_headerFooter();
     void resizeView();
     void resizeViewAndRepaint();
@@ -3609,7 +3609,7 @@ public:
 };
 
 
-void tst_QQuickListView::headerFooter()
+void tst_QQuickListView::extents()
 {
     QFETCH(QQuickListView::Orientation, orientation);
     QFETCH(Qt::LayoutDirection, layoutDirection);
@@ -3618,6 +3618,8 @@ void tst_QQuickListView::headerFooter()
     QFETCH(QPointF, footerPos);
     QFETCH(QPointF, minPos);
     QFETCH(QPointF, maxPos);
+    QFETCH(QPointF, origin_empty);
+    QFETCH(QPointF, origin_nonEmpty);
 
     QQuickView *canvas = getView();
 
@@ -3651,10 +3653,18 @@ void tst_QQuickListView::headerFooter()
     QCOMPARE(static_cast<LVAccessor*>(listview)->maxX(), maxPos.x());
     QCOMPARE(static_cast<LVAccessor*>(listview)->maxY(), maxPos.y());
 
+    QCOMPARE(listview->xOrigin(), origin_empty.x());
+    QCOMPARE(listview->yOrigin(), origin_empty.y());
+    for (int i=0; i<30; i++)
+        model.addItem("Item" + QString::number(i), "");
+    QTRY_COMPARE(listview->count(), model.count());
+    QCOMPARE(listview->xOrigin(), origin_nonEmpty.x());
+    QCOMPARE(listview->yOrigin(), origin_nonEmpty.y());
+
     releaseView(canvas);
 }
 
-void tst_QQuickListView::headerFooter_data()
+void tst_QQuickListView::extents_data()
 {
     QTest::addColumn<QQuickListView::Orientation>("orientation");
     QTest::addColumn<Qt::LayoutDirection>("layoutDirection");
@@ -3663,6 +3673,8 @@ void tst_QQuickListView::headerFooter_data()
     QTest::addColumn<QPointF>("footerPos");
     QTest::addColumn<QPointF>("minPos");
     QTest::addColumn<QPointF>("maxPos");
+    QTest::addColumn<QPointF>("origin_empty");
+    QTest::addColumn<QPointF>("origin_nonEmpty");
 
     // header is 240x20 (or 20x320 in Horizontal orientation)
     // footer is 240x30 (or 30x320 in Horizontal orientation)
@@ -3670,23 +3682,26 @@ void tst_QQuickListView::headerFooter_data()
     QTest::newRow("Vertical, TopToBottom")
             << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::TopToBottom
             << QPointF(0, -20) << QPointF(0, 0)
-            << QPointF(0, 20) << QPointF(240, 20);
+            << QPointF(0, 20) << QPointF(240, 20)
+            << QPointF(0, -20) << QPointF(0, -20);
 
     QTest::newRow("Vertical, BottomToTop")
             << QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::BottomToTop
             << QPointF(0, 0) << QPointF(0, -30)
-            << QPointF(0, 320 - 20) << QPointF(240, 320 - 20);  // content flow is reversed
-
+            << QPointF(0, 320 - 20) << QPointF(240, 320 - 20)  // content flow is reversed
+            << QPointF(0, -30) << QPointF(0, (-30.0 * 30) - 30);
 
     QTest::newRow("Horizontal, LeftToRight")
             << QQuickListView::Horizontal << Qt::LeftToRight << QQuickItemView::TopToBottom
             << QPointF(-20, 0) << QPointF(0, 0)
-            << QPointF(20, 0) << QPointF(20, 320);
+            << QPointF(20, 0) << QPointF(20, 320)
+            << QPointF(-20, 0) << QPointF(-20, 0);
 
     QTest::newRow("Horizontal, RightToLeft")
             << QQuickListView::Horizontal << Qt::RightToLeft << QQuickItemView::TopToBottom
             << QPointF(0, 0) << QPointF(-30, 0)
-            << QPointF(240 - 20, 0) << QPointF(240 - 20, 320);  // content flow is reversed
+            << QPointF(240 - 20, 0) << QPointF(240 - 20, 320)  // content flow is reversed
+            << QPointF(-30, 0) << QPointF((-240.0 * 30) - 30, 0);
 }
 
 void tst_QQuickListView::resetModel_headerFooter()