diff options
author | Martin Jones <martin.jones@nokia.com> | 2009-11-04 00:33:45 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2009-11-04 00:33:45 (GMT) |
commit | 162f9d19231612f2b5ae55156ecfd449d3f2f8d7 (patch) | |
tree | 94addf99cfd8c7530af8a3687768d8b54e57b032 /tests | |
parent | 3550d1b22b3a5f8f974ca2ba17a3d4f5d52b3743 (diff) | |
download | Qt-162f9d19231612f2b5ae55156ecfd449d3f2f8d7.zip Qt-162f9d19231612f2b5ae55156ecfd449d3f2f8d7.tar.gz Qt-162f9d19231612f2b5ae55156ecfd449d3f2f8d7.tar.bz2 |
Fix moving items in visual item model.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/declarative/listview/data/listview.qml | 4 | ||||
-rw-r--r-- | tests/auto/declarative/listview/tst_listview.cpp | 120 |
2 files changed, 122 insertions, 2 deletions
diff --git a/tests/auto/declarative/listview/data/listview.qml b/tests/auto/declarative/listview/data/listview.qml index 9039b55..b7b838b 100644 --- a/tests/auto/declarative/listview/data/listview.qml +++ b/tests/auto/declarative/listview/data/listview.qml @@ -6,7 +6,7 @@ Rectangle { color: "#ffffff" resources: [ Component { - id: Delegate + id: myDelegate Rectangle { id: wrapper objectName: "wrapper" @@ -41,6 +41,6 @@ Rectangle { width: 240 height: 320 model: testModel - delegate: Delegate + delegate: myDelegate } } diff --git a/tests/auto/declarative/listview/tst_listview.cpp b/tests/auto/declarative/listview/tst_listview.cpp index 42d4900..441138b 100644 --- a/tests/auto/declarative/listview/tst_listview.cpp +++ b/tests/auto/declarative/listview/tst_listview.cpp @@ -66,11 +66,15 @@ private slots: void qListModelInterface_removed(); void qAbstractItemModel_removed(); + void qListModelInterface_moved(); + void qAbstractItemModel_moved(); + private: template <class T> void items(); template <class T> void changed(); template <class T> void inserted(); template <class T> void removed(); + template <class T> void moved(); QmlView *createView(const QString &filename); template<typename T> T *findItem(QmlGraphicsItem *parent, const QString &id, int index=-1); @@ -140,6 +144,11 @@ public: emit itemsRemoved(index, 1); } + void moveItem(int from, int to) { + list.move(from, to); + emit itemsMoved(from, to, 1); + } + void modifyItem(int index, const QString &name, const QString &number) { list[index] = QPair<QString,QString>(name, number); emit itemsChanged(index, 1, roles()); @@ -195,6 +204,12 @@ public: emit endRemoveRows(); } + void moveItem(int from, int to) { + emit beginMoveRows(QModelIndex(), from, from, QModelIndex(), to); + list.move(from, to); + emit endMoveRows(); + } + void modifyItem(int idx, const QString &name, const QString &number) { list[idx] = QPair<QString,QString>(name, number); emit dataChanged(index(idx,0), index(idx,0)); @@ -454,6 +469,100 @@ void tst_QmlGraphicsListView::removed() delete canvas; } +template <class T> +void tst_QmlGraphicsListView::moved() +{ + QmlView *canvas = createView(SRCDIR "/data/listview.qml"); + + T model; + for (int i = 0; i < 30; i++) + model.addItem("Item" + QString::number(i), ""); + + QmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsListView *listview = findItem<QmlGraphicsListView>(canvas->root(), "list"); + QVERIFY(listview != 0); + + QmlGraphicsItem *viewport = listview->viewport(); + QVERIFY(viewport != 0); + + model.moveItem(1, 4); + + // let transitions settle. + QTest::qWait(1000); + + QmlGraphicsText *name = findItem<QmlGraphicsText>(viewport, "textName", 1); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(1)); + QmlGraphicsText *number = findItem<QmlGraphicsText>(viewport, "textNumber", 1); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(1)); + + name = findItem<QmlGraphicsText>(viewport, "textName", 4); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(4)); + number = findItem<QmlGraphicsText>(viewport, "textNumber", 4); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(4)); + + // Confirm items positioned correctly + int itemCount = findItems<QmlGraphicsItem>(viewport, "wrapper").count(); + for (int i = 0; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem<QmlGraphicsItem>(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QVERIFY(item->y() == i*20); + } + + listview->setViewportY(80); + + // move outside visible area + model.moveItem(1, 18); + + // let transitions settle. + QTest::qWait(1000); + + // Confirm items positioned correctly and indexes correct + for (int i = 3; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem<QmlGraphicsItem>(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QVERIFY(item->y() == i*20 + 20); + name = findItem<QmlGraphicsText>(viewport, "textName", i); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(i)); + number = findItem<QmlGraphicsText>(viewport, "textNumber", i); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(i)); + } + + // move from outside visible into visible + model.moveItem(20, 4); + + // let transitions settle. + QTest::qWait(1000); + + // Confirm items positioned correctly and indexes correct + for (int i = 3; i < model.count() && i < itemCount; ++i) { + QmlGraphicsItem *item = findItem<QmlGraphicsItem>(viewport, "wrapper", i); + if (!item) qWarning() << "Item" << i << "not found"; + QVERIFY(item); + QVERIFY(item->y() == i*20 + 20); + name = findItem<QmlGraphicsText>(viewport, "textName", i); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(i)); + number = findItem<QmlGraphicsText>(viewport, "textNumber", i); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(i)); + } + + delete canvas; +} + void tst_QmlGraphicsListView::qListModelInterface_items() { items<TestModel>(); @@ -494,6 +603,17 @@ void tst_QmlGraphicsListView::qAbstractItemModel_removed() removed<TestModel2>(); } +void tst_QmlGraphicsListView::qListModelInterface_moved() +{ + moved<TestModel>(); +} + +void tst_QmlGraphicsListView::qAbstractItemModel_moved() +{ + moved<TestModel2>(); +} + + QmlView *tst_QmlGraphicsListView::createView(const QString &filename) { QmlView *canvas = new QmlView(0); |