From 54f15f5df5cf545bf4d675ccbafecd482b4a2b0b Mon Sep 17 00:00:00 2001 From: Joni Poikelin Date: Mon, 23 Oct 2017 13:51:43 +0300 Subject: Fix ListView::positionViewAtIndex with ListView.Contain mode Sticky headers and footers weren't accounted for when calculating new view position causing the requested item to be left behind them. Task-number: QTBUG-63974 Change-Id: Id69579643a942e8558960b2c8b0fee980fa86947 Reviewed-by: Shawn Rutledge --- .../auto/quick/qquicklistview/data/qtbug63974.qml | 34 ++++++++++++++++++ .../quick/qquicklistview/tst_qquicklistview.cpp | 41 ++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 tests/auto/quick/qquicklistview/data/qtbug63974.qml (limited to 'tests') diff --git a/tests/auto/quick/qquicklistview/data/qtbug63974.qml b/tests/auto/quick/qquicklistview/data/qtbug63974.qml new file mode 100644 index 0000000000..1e0afa54f8 --- /dev/null +++ b/tests/auto/quick/qquicklistview/data/qtbug63974.qml @@ -0,0 +1,34 @@ +import QtQuick 2.6 + +ListView { + id: table + height: 200 + width: 100 + + headerPositioning: ListView.OverlayHeader + header: Rectangle { + width: table.width + height: 20 + color: "red" + z: 100 + } + + footerPositioning: ListView.OverlayFooter + footer: Rectangle { + width: table.width + height: 20 + color: "blue" + z: 200 + } + + model: 30 + delegate: Rectangle { + height: 20 + width: table.width + color: "lightgray" + Text { + text: "Item " + index + anchors.centerIn: parent + } + } +} diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp index a31cb37c16..c08d5d31b4 100644 --- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp +++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp @@ -256,6 +256,7 @@ private slots: void keyNavigationEnabled(); void QTBUG_61269_appendDuringScrollDown(); void QTBUG_50097_stickyHeader_positionViewAtIndex(); + void QTBUG_63974_stickyHeader_positionViewAtIndex_Contain(); void itemFiltered(); void releaseItems(); @@ -8561,6 +8562,46 @@ void tst_QQuickListView::QTBUG_50097_stickyHeader_positionViewAtIndex() QTRY_COMPARE(listview->contentY(), -100.0); // back to the same position: header visible, items not under the header. } +void tst_QQuickListView::QTBUG_63974_stickyHeader_positionViewAtIndex_Contain() +{ + QScopedPointer window(createView()); + window->setSource(testFileUrl("qtbug63974.qml")); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window.data())); + + QQuickListView *listview = qobject_cast(window->rootObject()); + QVERIFY(listview != 0); + + const qreal headerSize = 20; + const qreal footerSize = 20; + const qreal itemSize = 20; + const int itemCount = 30; + const qreal contentHeight = itemCount * itemSize; + + const qreal initialY = listview->contentY(); + const qreal endPosition = contentHeight + footerSize - listview->height(); + + QVERIFY(qFuzzyCompare(initialY, -headerSize)); + + listview->positionViewAtIndex(itemCount - 1, QQuickListView::Contain); + QTRY_COMPARE(listview->contentY(), endPosition); + + listview->positionViewAtIndex(0, QQuickListView::Contain); + QTRY_COMPARE(listview->contentY(), -headerSize); + + listview->positionViewAtIndex(itemCount - 1, QQuickListView::Visible); + QTRY_COMPARE(listview->contentY(), endPosition); + + listview->positionViewAtIndex(0, QQuickListView::Visible); + QTRY_COMPARE(listview->contentY(), -headerSize); + + listview->positionViewAtIndex(itemCount - 1, QQuickListView::SnapPosition); + QTRY_COMPARE(listview->contentY(), endPosition); + + listview->positionViewAtIndex(0, QQuickListView::SnapPosition); + QTRY_COMPARE(listview->contentY(), -headerSize); +} + void tst_QQuickListView::itemFiltered() { QStringListModel model(QStringList() << "one" << "two" << "three" << "four" << "five" << "six"); -- cgit v1.2.3