aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2012-07-23 13:19:04 +1000
committerQt by Nokia <qt-info@nokia.com>2012-07-23 06:38:28 +0200
commit22c68738bf2a83eb228b412fbd251bcdf8e7056e (patch)
tree14f0c0efa6a7134a1f98c49f53ce813cf10f2346 /tests
parent2a4bb9608498876c3c2229eef91b8723a7fd8e47 (diff)
Changing model after componentComplete should reset currentIndex
When the model is changed reset currentIndex back to 0. Task-number: QTBUG-26604 Change-Id: I1934e083819537d416acd85c75362daff382aa04 Reviewed-by: Bea Lam <bea.lam@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quick/qquickgridview/tst_qquickgridview.cpp21
-rw-r--r--tests/auto/quick/qquicklistview/tst_qquicklistview.cpp22
2 files changed, 32 insertions, 11 deletions
diff --git a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp
index 13753ea39c..110df07afa 100644
--- a/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp
+++ b/tests/auto/quick/qquickgridview/tst_qquickgridview.cpp
@@ -1801,16 +1801,16 @@ void tst_QQuickGridView::swapWithFirstItem()
void tst_QQuickGridView::currentIndex()
{
- QaimModel model;
+ QaimModel initModel;
for (int i = 0; i < 60; i++)
- model.addItem("Item" + QString::number(i), QString::number(i));
+ initModel.addItem("Item" + QString::number(i), QString::number(i));
QQuickView *window = new QQuickView(0);
window->setGeometry(0,0,240,320);
window->show();
QQmlContext *ctxt = window->rootContext();
- ctxt->setContextProperty("testModel", &model);
+ ctxt->setContextProperty("testModel", &initModel);
QString filename(testFile("gridview-initCurrent.qml"));
window->setSource(QUrl::fromLocalFile(filename));
@@ -1824,16 +1824,27 @@ void tst_QQuickGridView::currentIndex()
QQuickItem *contentItem = gridview->contentItem();
QVERIFY(contentItem != 0);
- // current item should be third item
+ // currentIndex is initialized to 35
+ // currentItem should be in view
QCOMPARE(gridview->currentIndex(), 35);
QCOMPARE(gridview->currentItem(), findItem<QQuickItem>(contentItem, "wrapper", 35));
QCOMPARE(gridview->currentItem()->y(), gridview->highlightItem()->y());
QCOMPARE(gridview->contentY(), 400.0);
- gridview->setCurrentIndex(0);
+ // changing model should reset currentIndex to 0
+ QmlListModel model;
+ for (int i = 0; i < 60; i++)
+ model.addItem("Item" + QString::number(i), QString::number(i));
+ ctxt->setContextProperty("testModel", &model);
+
QCOMPARE(gridview->currentIndex(), 0);
+ QCOMPARE(gridview->currentItem(), findItem<QQuickItem>(contentItem, "wrapper", 0));
+
// confirm that the velocity is updated
+ gridview->setCurrentIndex(35);
QTRY_VERIFY(gridview->verticalVelocity() != 0.0);
+ gridview->setCurrentIndex(0);
+ QTRY_VERIFY(gridview->verticalVelocity() == 0.0);
// footer should become visible if it is out of view, and then current index moves to the first row
window->rootObject()->setProperty("showFooter", true);
diff --git a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
index 9b0cb2c808..50c4a0a1a8 100644
--- a/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
+++ b/tests/auto/quick/qquicklistview/tst_qquicklistview.cpp
@@ -2515,15 +2515,15 @@ void tst_QQuickListView::currentIndex_delayedItemCreation_data()
void tst_QQuickListView::currentIndex()
{
- QmlListModel model;
+ QmlListModel initModel;
for (int i = 0; i < 30; i++)
- model.addItem("Item" + QString::number(i), QString::number(i));
+ initModel.addItem("Item" + QString::number(i), QString::number(i));
QQuickView *window = new QQuickView(0);
window->setGeometry(0,0,240,320);
QQmlContext *ctxt = window->rootContext();
- ctxt->setContextProperty("testModel", &model);
+ ctxt->setContextProperty("testModel", &initModel);
ctxt->setContextProperty("testWrap", QVariant(false));
QString filename(testFile("listview-initCurrent.qml"));
@@ -2537,17 +2537,27 @@ void tst_QQuickListView::currentIndex()
QTRY_VERIFY(contentItem != 0);
QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
- // current item should be 20th item at startup
- // and current item should be in view
+ // currentIndex is initialized to 20
+ // currentItem should be in view
QCOMPARE(listview->currentIndex(), 20);
QCOMPARE(listview->contentY(), 100.0);
QCOMPARE(listview->currentItem(), findItem<QQuickItem>(contentItem, "wrapper", 20));
QCOMPARE(listview->highlightItem()->y(), listview->currentItem()->y());
- listview->setCurrentIndex(0);
+ // changing model should reset currentIndex to 0
+ QmlListModel model;
+ for (int i = 0; i < 30; i++)
+ model.addItem("Item" + QString::number(i), QString::number(i));
+ ctxt->setContextProperty("testModel", &model);
+
QCOMPARE(listview->currentIndex(), 0);
+ QCOMPARE(listview->currentItem(), findItem<QQuickItem>(contentItem, "wrapper", 0));
+
// confirm that the velocity is updated
+ listview->setCurrentIndex(20);
QTRY_VERIFY(listview->verticalVelocity() != 0.0);
+ listview->setCurrentIndex(0);
+ QTRY_VERIFY(listview->verticalVelocity() == 0.0);
// footer should become visible if it is out of view, and then current index is set to count-1
window->rootObject()->setProperty("showFooter", true);