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>
qreal QQuickItemView::xOrigin() const
{
Q_D(const QQuickItemView);
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);
}
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()
}
void QQuickItemView::updatePolish()
- 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 + ")" }
+ }
void footer_data();
void header();
void header_data();
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();
void resetModel_headerFooter();
void resizeViewAndRepaint();
void resizeGrid();
qreal maxX() const { return maxXExtent(); }
};
qreal maxX() const { return maxXExtent(); }
};
-void tst_QQuickGridView::headerFooter()
+void tst_QQuickGridView::extents()
{
QFETCH(QQuickGridView::Flow, flow);
QFETCH(Qt::LayoutDirection, layoutDirection);
{
QFETCH(QQuickGridView::Flow, flow);
QFETCH(Qt::LayoutDirection, layoutDirection);
QFETCH(QPointF, footerPos);
QFETCH(QPointF, minPos);
QFETCH(QPointF, maxPos);
QFETCH(QPointF, footerPos);
QFETCH(QPointF, minPos);
QFETCH(QPointF, maxPos);
+ QFETCH(QPointF, origin_empty);
+ QFETCH(QPointF, origin_nonEmpty);
QQuickView *canvas = getView();
QQuickView *canvas = getView();
QCOMPARE(static_cast<GVAccessor*>(gridview)->maxX(), maxPos.x());
QCOMPARE(static_cast<GVAccessor*>(gridview)->maxY(), maxPos.y());
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());
+
-void tst_QQuickGridView::headerFooter_data()
+void tst_QQuickGridView::extents_data()
{
QTest::addColumn<QQuickGridView::Flow>("flow");
QTest::addColumn<Qt::LayoutDirection>("layoutDirection");
{
QTest::addColumn<QQuickGridView::Flow>("flow");
QTest::addColumn<Qt::LayoutDirection>("layoutDirection");
QTest::addColumn<QPointF>("footerPos");
QTest::addColumn<QPointF>("minPos");
QTest::addColumn<QPointF>("maxPos");
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)
// 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)
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)
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)
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)
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)
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)
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)
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)
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()
}
void tst_QQuickGridView::resetModel_headerFooter()
QQuickItem *footer = findItem<QQuickItem>(contentItem, "footer");
QVERIFY(footer);
QQuickItem *footer = findItem<QQuickItem>(contentItem, "footer");
QVERIFY(footer);
- QCOMPARE(footer->y(), 80.*2);
+ QCOMPARE(footer->y(), 60.*2);
footer = findItem<QQuickItem>(contentItem, "footer");
QVERIFY(footer);
footer = findItem<QQuickItem>(contentItem, "footer");
QVERIFY(footer);
- QCOMPARE(footer->y(), 80.*2);
+ QCOMPARE(footer->y(), 60.*2);
QTRY_VERIFY(contentItem != 0);
QTRY_COMPARE(gridview->contentX(), -240+50.);
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();
// check end bound
gridview->positionViewAtEnd();
QTRY_COMPARE(model.count(), gridview->count());
gridview->setContentX(-240+50);
gridview->returnToBounds();
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);
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();
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();
pos = gridview->contentX();
gridview->setContentX(pos - 80);
gridview->returnToBounds();
// reduce left margin
pos = gridview->contentX();
gridview->setLeftMargin(20);
// 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;
QTRY_COMPARE(gridview->contentX(), pos+10);
delete canvas;
- delegate: Text { width: 30; height: 30; text: index + "(" + x + ")" }
+ delegate: Rectangle {
+ width: view.width
+ height: 30
+ Text { text: index + "(" + x + ")" }
+ }
void header_delayItemCreation();
void footer();
void footer_data();
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();
void resetModel_headerFooter();
void resizeView();
void resizeViewAndRepaint();
-void tst_QQuickListView::headerFooter()
+void tst_QQuickListView::extents()
{
QFETCH(QQuickListView::Orientation, orientation);
QFETCH(Qt::LayoutDirection, layoutDirection);
{
QFETCH(QQuickListView::Orientation, orientation);
QFETCH(Qt::LayoutDirection, layoutDirection);
QFETCH(QPointF, footerPos);
QFETCH(QPointF, minPos);
QFETCH(QPointF, maxPos);
QFETCH(QPointF, footerPos);
QFETCH(QPointF, minPos);
QFETCH(QPointF, maxPos);
+ QFETCH(QPointF, origin_empty);
+ QFETCH(QPointF, origin_nonEmpty);
QQuickView *canvas = getView();
QQuickView *canvas = getView();
QCOMPARE(static_cast<LVAccessor*>(listview)->maxX(), maxPos.x());
QCOMPARE(static_cast<LVAccessor*>(listview)->maxY(), maxPos.y());
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());
+
-void tst_QQuickListView::headerFooter_data()
+void tst_QQuickListView::extents_data()
{
QTest::addColumn<QQuickListView::Orientation>("orientation");
QTest::addColumn<Qt::LayoutDirection>("layoutDirection");
{
QTest::addColumn<QQuickListView::Orientation>("orientation");
QTest::addColumn<Qt::LayoutDirection>("layoutDirection");
QTest::addColumn<QPointF>("footerPos");
QTest::addColumn<QPointF>("minPos");
QTest::addColumn<QPointF>("maxPos");
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)
// header is 240x20 (or 20x320 in Horizontal orientation)
// footer is 240x30 (or 30x320 in Horizontal orientation)
QTest::newRow("Vertical, TopToBottom")
<< QQuickListView::Vertical << Qt::LeftToRight << QQuickItemView::TopToBottom
<< QPointF(0, -20) << QPointF(0, 0)
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)
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)
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)
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()
}
void tst_QQuickListView::resetModel_headerFooter()