diff options
author | Bea Lam <bea.lam@nokia.com> | 2012-05-10 15:15:50 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-05-14 03:03:36 +0200 |
commit | 73a5e30f44aa2cbb9a181bd9d47ffa9d942f0cfb (patch) | |
tree | 888b20797c52c4adc59f248d34ecee3fb81afa1c /tests | |
parent | bd5e23a00e97603c1cc73328c508a044f1528802 (diff) |
Fix xOrigin and yOrigin to always be top-left pos
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>
Diffstat (limited to 'tests')
4 files changed, 75 insertions, 31 deletions
diff --git a/tests/auto/quick/qquickgridview/data/headerfooter.qml b/tests/auto/quick/qquickgridview/data/headerfooter.qml index f0f73a0dac..a1f31ea224 100644 --- a/tests/auto/quick/qquickgridview/data/headerfooter.qml +++ b/tests/auto/quick/qquickgridview/data/headerfooter.qml @@ -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 + ")" } + } } diff --git a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp index d39fbe5e29..8dc7fda49a 100644 --- a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp +++ b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp @@ -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; diff --git a/tests/auto/quick/qquicklistview/data/headerfooter.qml b/tests/auto/quick/qquicklistview/data/headerfooter.qml index 07a331a4b7..592e2ce6a5 100644 --- a/tests/auto/quick/qquicklistview/data/headerfooter.qml +++ b/tests/auto/quick/qquicklistview/data/headerfooter.qml @@ -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 + ")" } + } } diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index b38bb0dc58..46520519fe 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -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() |