aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/declarative/qsglistview
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/declarative/qsglistview')
-rw-r--r--tests/auto/declarative/qsglistview/data/listview-enforcerange-nohighlight.qml60
-rw-r--r--tests/auto/declarative/qsglistview/tst_qsglistview.cpp46
2 files changed, 106 insertions, 0 deletions
diff --git a/tests/auto/declarative/qsglistview/data/listview-enforcerange-nohighlight.qml b/tests/auto/declarative/qsglistview/data/listview-enforcerange-nohighlight.qml
new file mode 100644
index 0000000000..946f4f2046
--- /dev/null
+++ b/tests/auto/declarative/qsglistview/data/listview-enforcerange-nohighlight.qml
@@ -0,0 +1,60 @@
+import QtQuick 2.0
+
+Rectangle {
+ width: 240
+ height: 320
+
+ Component {
+ id: myDelegate
+ Rectangle {
+ id: wrapper
+ objectName: "wrapper"
+ height: 20
+ width: 240
+ color: "transparent"
+ Text {
+ text: index
+ }
+ Text {
+ x: 30
+ id: textName
+ objectName: "textName"
+ text: name
+ }
+ Text {
+ x: 120
+ id: textNumber
+ objectName: "textNumber"
+ text: number
+ }
+ Text {
+ x: 200
+ text: wrapper.y
+ }
+ }
+ }
+
+ Rectangle { // current listview item should be always in this area
+ y: 100
+ height: 20
+ width: 240
+ color: "purple"
+ }
+
+ ListView {
+ id: list
+ objectName: "list"
+ width: 240
+ height: 320
+ model: testModel
+ delegate: myDelegate
+
+ preferredHighlightBegin: 100
+ preferredHighlightEnd: 100
+ highlightRangeMode: "StrictlyEnforceRange"
+
+ section.property: "number"
+ section.delegate: Rectangle { width: 240; height: 10; color: "lightsteelblue" }
+ }
+}
+
diff --git a/tests/auto/declarative/qsglistview/tst_qsglistview.cpp b/tests/auto/declarative/qsglistview/tst_qsglistview.cpp
index 5ee13e8724..f4a2384729 100644
--- a/tests/auto/declarative/qsglistview/tst_qsglistview.cpp
+++ b/tests/auto/declarative/qsglistview/tst_qsglistview.cpp
@@ -98,6 +98,7 @@ private slots:
void currentIndex();
void noCurrentIndex();
void enforceRange();
+ void enforceRange_withoutHighlight();
void spacing();
void sections();
void sectionsDelegate();
@@ -1113,6 +1114,51 @@ void tst_QSGListView::enforceRange()
delete canvas;
}
+void tst_QSGListView::enforceRange_withoutHighlight()
+{
+ // QTBUG-20287
+ // If no highlight is set but StrictlyEnforceRange is used, the content should still move
+ // to the correct position (i.e. to the next/previous item, not next/previous section)
+ // when moving up/down via incrementCurrentIndex() and decrementCurrentIndex()
+
+ QSGView *canvas = createView();
+ canvas->show();
+
+ TestModel model;
+ model.addItem("Item 0", "a");
+ model.addItem("Item 1", "b");
+ model.addItem("Item 2", "b");
+ model.addItem("Item 3", "c");
+
+ QDeclarativeContext *ctxt = canvas->rootContext();
+ ctxt->setContextProperty("testModel", &model);
+
+ canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/listview-enforcerange-nohighlight.qml"));
+ qApp->processEvents();
+
+ QSGListView *listview = findItem<QSGListView>(canvas->rootObject(), "list");
+ QTRY_VERIFY(listview != 0);
+
+ qreal expectedPos = -100.0;
+
+ expectedPos += 10.0; // scroll past 1st section's delegate (10px height)
+ QTRY_COMPARE(listview->contentY(), expectedPos);
+
+ expectedPos += 20 + 10; // scroll past 1st section and section delegate of 2nd section
+ QTest::keyClick(canvas, Qt::Key_Down);
+ QTRY_COMPARE(listview->contentY(), expectedPos);
+
+ expectedPos += 20; // scroll past 1st item of 2nd section
+ QTest::keyClick(canvas, Qt::Key_Down);
+ QTRY_COMPARE(listview->contentY(), expectedPos);
+
+ expectedPos += 20 + 10; // scroll past 2nd item of 2nd section and section delegate of 3rd section
+ QTest::keyClick(canvas, Qt::Key_Down);
+ QTRY_COMPARE(listview->contentY(), expectedPos);
+
+ delete canvas;
+}
+
void tst_QSGListView::spacing()
{
QSGView *canvas = createView();