aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2011-09-29 14:50:27 +1000
committerQt by Nokia <qt-info@nokia.com>2011-10-03 09:04:13 +0200
commitbd2eece4a68808c771d39cd53922ef538d0ba54d (patch)
tree50a819d9ae3fd662cb3799f19c79673fc9c40ad0 /tests
parente59fbf997ece61b36180eb21f9c2cd6ea895b88f (diff)
currentIndex not updated correctly if list is initially empty
The currentIndex shouldn't be incremented when itemCount == 0 and also it should be default to 0 after the first item is added. Task-number: QTBUG-21643 Change-Id: Ia9418c0cd1cd659410123394c880dfe72557fa16 Reviewed-on: http://codereview.qt-project.org/5768 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/declarative/qsglistview/data/fillModelOnComponentCompleted.qml (renamed from tests/auto/declarative/qsglistview/data/header1.qml)3
-rw-r--r--tests/auto/declarative/qsglistview/tst_qsglistview.cpp41
2 files changed, 43 insertions, 1 deletions
diff --git a/tests/auto/declarative/qsglistview/data/header1.qml b/tests/auto/declarative/qsglistview/data/fillModelOnComponentCompleted.qml
index 8ba6e57594..906e6adb6b 100644
--- a/tests/auto/declarative/qsglistview/data/header1.qml
+++ b/tests/auto/declarative/qsglistview/data/fillModelOnComponentCompleted.qml
@@ -14,6 +14,7 @@ Rectangle {
anchors.top: parent.top
anchors.bottom: parent.bottom
model: testModel
+
delegate: Text {
objectName: "wrapper"
font.pointSize: 20
@@ -28,6 +29,8 @@ Rectangle {
}
Component.onCompleted: {
+ if (setCurrentToZero == 0)
+ list.currentIndex = 0
for (var i=0; i<30; i++) testModel.append({"name" : i, "val": i})
}
}
diff --git a/tests/auto/declarative/qsglistview/tst_qsglistview.cpp b/tests/auto/declarative/qsglistview/tst_qsglistview.cpp
index c1be773bf2..101f0fcbfd 100644
--- a/tests/auto/declarative/qsglistview/tst_qsglistview.cpp
+++ b/tests/auto/declarative/qsglistview/tst_qsglistview.cpp
@@ -94,6 +94,8 @@ private slots:
void swapWithFirstItem();
void itemList();
+ void currentIndex_delayedItemCreation();
+ void currentIndex_delayedItemCreation_data();
void currentIndex();
void noCurrentIndex();
void enforceRange();
@@ -1833,6 +1835,42 @@ void tst_QSGListView::sectionsPositioning()
delete canvas;
}
+void tst_QSGListView::currentIndex_delayedItemCreation()
+{
+ QFETCH(bool, setCurrentToZero);
+
+ QSGView *canvas = createView();
+
+ TestModel model;
+
+ // test currentIndexChanged() is emitted even if currentIndex = 0 on start up
+ // (since the currentItem will have changed and that shares the same index)
+ canvas->rootContext()->setContextProperty("setCurrentToZero", setCurrentToZero);
+
+ canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/fillModelOnComponentCompleted.qml"));
+ qApp->processEvents();
+
+ QSGListView *listview = findItem<QSGListView>(canvas->rootObject(), "list");
+ QTRY_VERIFY(listview != 0);
+
+ QSGItem *contentItem = listview->contentItem();
+ QTRY_VERIFY(contentItem != 0);
+
+ QSignalSpy spy(listview, SIGNAL(currentIndexChanged()));
+ QCOMPARE(listview->currentIndex(), 0);
+ QTRY_COMPARE(spy.count(), 1);
+
+ delete canvas;
+}
+
+void tst_QSGListView::currentIndex_delayedItemCreation_data()
+{
+ QTest::addColumn<bool>("setCurrentToZero");
+
+ QTest::newRow("set to 0") << true;
+ QTest::newRow("don't set to 0") << false;
+}
+
void tst_QSGListView::currentIndex()
{
TestModel model;
@@ -2733,7 +2771,8 @@ void tst_QSGListView::header_delayItemCreation()
TestModel model;
- canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/header1.qml"));
+ canvas->rootContext()->setContextProperty("setCurrentToZero", false);
+ canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/fillModelOnComponentCompleted.qml"));
qApp->processEvents();
QSGListView *listview = findItem<QSGListView>(canvas->rootObject(), "list");