aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2011-07-27 17:57:48 +1000
committerQt by Nokia <qt-info@nokia.com>2011-07-28 02:21:28 +0200
commit70cb4d6d9a2193444d785519a9811dc6693a6ab6 (patch)
treefccb6286bfe7a138a790d4590679d961d25fc2e0 /tests
parent5266db7357f8a0ce4ce175b5becdbdd2c094a808 (diff)
Don't move view content position item 0 is being replaced
Usually if item 0 moves down, the next item becomes the first visible item and all content moves down. Don't do this if another item is moving up to take its place. Change-Id: If625cfc0eaa70fd1094c7bc0fdd29f5f56766a42 Reviewed-on: http://codereview.qt.nokia.com/2260 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/qsggridview/tst_qsggridview.cpp25
-rw-r--r--tests/auto/declarative/qsglistview/tst_qsglistview.cpp31
2 files changed, 56 insertions, 0 deletions
diff --git a/tests/auto/declarative/qsggridview/tst_qsggridview.cpp b/tests/auto/declarative/qsggridview/tst_qsggridview.cpp
index d8b084ae9f..76b30322c6 100644
--- a/tests/auto/declarative/qsggridview/tst_qsggridview.cpp
+++ b/tests/auto/declarative/qsggridview/tst_qsggridview.cpp
@@ -77,6 +77,7 @@ private slots:
void removed();
void clear();
void moved();
+ void swapWithFirstItem();
void changeFlow();
void currentIndex();
void noCurrentIndex();
@@ -650,6 +651,30 @@ void tst_QSGGridView::moved()
QTRY_COMPARE(number->text(), model.number(i));
}
+ delete canvas;
+}
+
+void tst_QSGGridView::swapWithFirstItem()
+{
+ // QTBUG_9697
+ QSGView *canvas = createView();
+ canvas->show();
+
+ TestModel model;
+ for (int i = 0; i < 30; i++)
+ model.addItem("Item" + QString::number(i), "");
+
+ QDeclarativeContext *ctxt = canvas->rootContext();
+ ctxt->setContextProperty("testModel", &model);
+ ctxt->setContextProperty("testRightToLeft", QVariant(false));
+ ctxt->setContextProperty("testTopToBottom", QVariant(false));
+
+ canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/gridview1.qml"));
+ qApp->processEvents();
+
+ QSGGridView *gridview = findItem<QSGGridView>(canvas->rootObject(), "grid");
+ QTRY_VERIFY(gridview != 0);
+
// ensure content position is stable
gridview->setContentY(0);
model.moveItem(10, 0);
diff --git a/tests/auto/declarative/qsglistview/tst_qsglistview.cpp b/tests/auto/declarative/qsglistview/tst_qsglistview.cpp
index 4d6920cd20..19bc0f0e8a 100644
--- a/tests/auto/declarative/qsglistview/tst_qsglistview.cpp
+++ b/tests/auto/declarative/qsglistview/tst_qsglistview.cpp
@@ -91,6 +91,7 @@ private slots:
void qListModelInterface_clear();
void qAbstractItemModel_clear();
+ void swapWithFirstItem();
void itemList();
void currentIndex();
void noCurrentIndex();
@@ -879,6 +880,36 @@ void tst_QSGListView::moved()
delete testObject;
}
+void tst_QSGListView::swapWithFirstItem()
+{
+ QSGView *canvas = createView();
+ canvas->show();
+
+ TestModel model;
+ for (int i = 0; i < 30; i++)
+ model.addItem("Item" + QString::number(i), "");
+
+ QDeclarativeContext *ctxt = canvas->rootContext();
+ ctxt->setContextProperty("testModel", &model);
+
+ TestObject *testObject = new TestObject;
+ ctxt->setContextProperty("testObject", testObject);
+
+ canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/listviewtest.qml"));
+ qApp->processEvents();
+
+ QSGListView *listview = findItem<QSGListView>(canvas->rootObject(), "list");
+ QTRY_VERIFY(listview != 0);
+
+ // ensure content position is stable
+ listview->setContentY(0);
+ model.moveItem(10, 0);
+ QTRY_VERIFY(listview->contentY() == 0);
+
+ delete testObject;
+ delete canvas;
+}
+
void tst_QSGListView::enforceRange()
{
QSGView *canvas = createView();