aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquicklistview
diff options
context:
space:
mode:
authorMichael Brasser <mbrasser@ford.com>2018-03-13 19:50:17 -0500
committerMichael Brasser <michael.brasser@live.com>2018-10-17 14:32:15 +0000
commit50924bd8557db9a398f3c1ccdd6996d968658b23 (patch)
treef48a98741f6863e0ccd9579735c0425c27434473 /tests/auto/quick/qquicklistview
parentd973907f6e4aae492dfad3eaad6827ffdc49962b (diff)
Improve interaction between snapping and sections
* Use velocity to prefer snapping in the active direction. * Calculate snap based on where the item is, rather than where the section is. Change-Id: I2531501dbe0a58f26f20bc3e719e435185e047a5 Task-number: QTBUG-67051 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests/auto/quick/qquicklistview')
-rw-r--r--tests/auto/quick/qquicklistview/data/sectionSnapping.qml49
-rw-r--r--tests/auto/quick/qquicklistview/tst_qquicklistview.cpp58
2 files changed, 107 insertions, 0 deletions
diff --git a/tests/auto/quick/qquicklistview/data/sectionSnapping.qml b/tests/auto/quick/qquicklistview/data/sectionSnapping.qml
new file mode 100644
index 0000000000..2583cc0377
--- /dev/null
+++ b/tests/auto/quick/qquicklistview/data/sectionSnapping.qml
@@ -0,0 +1,49 @@
+import QtQuick 2.0
+
+ListView {
+ width: 400
+ height: 400
+ preferredHighlightBegin: 100
+ preferredHighlightEnd: 100
+ highlightRangeMode: ListView.StrictlyEnforceRange
+
+ model: ListModel {
+ ListElement { section: "1" }
+ ListElement { section: "1" }
+ ListElement { section: "1" }
+ ListElement { section: "2" }
+ ListElement { section: "2" }
+ ListElement { section: "2" }
+ }
+
+ delegate: Rectangle {
+ width: parent.width
+ height: 50
+ color: index % 2 ? "lightsteelblue" : "steelblue"
+ Text {
+ anchors.centerIn: parent
+ color: "white"
+ text: model.index
+ }
+ }
+
+ section.property: "section"
+ section.delegate: Rectangle {
+ width: parent.width
+ height: 50
+ color: "green"
+ Text {
+ anchors.centerIn: parent
+ color: "white"
+ text: "section"
+ }
+ }
+
+ highlight: Rectangle {
+ y: 100
+ z: 100
+ width: parent.width
+ height: 50
+ color: "#80FF0000"
+ }
+}
diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
index 2574eb9c6c..ae02352293 100644
--- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
+++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
@@ -132,6 +132,8 @@ private slots:
void sectionPropertyChange();
void sectionDelegateChange();
void sectionsItemInsertion();
+ void sectionsSnap_data();
+ void sectionsSnap();
void cacheBuffer();
void positionViewAtBeginningEnd();
void positionViewAtIndex();
@@ -2667,6 +2669,62 @@ void tst_QQuickListView::sectionsItemInsertion()
}
}
+void tst_QQuickListView::sectionsSnap_data()
+{
+ QTest::addColumn<QQuickListView::SnapMode>("snapMode");
+ QTest::addColumn<QPoint>("point");
+ QTest::addColumn<int>("duration");
+
+ QTest::newRow("drag") << QQuickListView::NoSnap << QPoint(100, 45) << 500;
+ QTest::newRow("flick") << QQuickListView::SnapOneItem << QPoint(100, 75) << 50;
+}
+
+void tst_QQuickListView::sectionsSnap()
+{
+ QFETCH(QQuickListView::SnapMode, snapMode);
+ QFETCH(QPoint, point);
+ QFETCH(int, duration);
+
+ QScopedPointer<QQuickView> window(createView());
+ window->setSource(testFileUrl("sectionSnapping.qml"));
+ window->show();
+ QVERIFY(QTest::qWaitForWindowExposed(window.data()));
+
+ QQuickListView *listview = qobject_cast<QQuickListView*>(window->rootObject());
+ QTRY_VERIFY(listview != nullptr);
+ listview->setSnapMode(snapMode);
+
+ QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
+ QTRY_COMPARE(listview->currentIndex(), 0);
+ QCOMPARE(listview->contentY(), qreal(-50));
+
+ // move down
+ flick(window.data(), QPoint(100, 100), point, duration);
+ QTRY_VERIFY(!listview->isMovingVertically());
+ QCOMPARE(listview->contentY(), qreal(0));
+
+ flick(window.data(), QPoint(100, 100), point, duration);
+ QTRY_VERIFY(!listview->isMovingVertically());
+ QCOMPARE(listview->contentY(), qreal(50));
+
+ flick(window.data(), QPoint(100, 100), point, duration);
+ QTRY_VERIFY(!listview->isMovingVertically());
+ QCOMPARE(listview->contentY(), qreal(150));
+
+ // move back up
+ flick(window.data(), point, QPoint(100, 100), duration);
+ QTRY_VERIFY(!listview->isMovingVertically());
+ QCOMPARE(listview->contentY(), qreal(50));
+
+ flick(window.data(), point, QPoint(100, 100), duration);
+ QTRY_VERIFY(!listview->isMovingVertically());
+ QCOMPARE(listview->contentY(), qreal(0));
+
+ flick(window.data(), point, QPoint(100, 100), duration);
+ QTRY_VERIFY(!listview->isMovingVertically());
+ QCOMPARE(listview->contentY(), qreal(-50));
+}
+
void tst_QQuickListView::currentIndex_delayedItemCreation()
{
QFETCH(bool, setCurrentToZero);