diff options
author | Martin Jones <martin.jones@nokia.com> | 2009-11-05 03:48:33 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2009-11-05 03:48:33 (GMT) |
commit | 8fbff4dffd53546e4c3acecd0a9700a7ad970c83 (patch) | |
tree | 03c25280b2e1840cf2160c168297f5ad746444a7 | |
parent | 9e5c80bd52467afa481775fe9695bac7edcf7324 (diff) | |
download | Qt-8fbff4dffd53546e4c3acecd0a9700a7ad970c83.zip Qt-8fbff4dffd53546e4c3acecd0a9700a7ad970c83.tar.gz Qt-8fbff4dffd53546e4c3acecd0a9700a7ad970c83.tar.bz2 |
Test more ListView.
-rw-r--r-- | tests/auto/declarative/listview/tst_listview.cpp | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/tests/auto/declarative/listview/tst_listview.cpp b/tests/auto/declarative/listview/tst_listview.cpp index 6bf1080..b8f87b7 100644 --- a/tests/auto/declarative/listview/tst_listview.cpp +++ b/tests/auto/declarative/listview/tst_listview.cpp @@ -70,6 +70,8 @@ private slots: void qAbstractItemModel_moved(); void enforceRange(); + void spacing(); + void sections(); private: template <class T> void items(); @@ -264,6 +266,13 @@ void tst_QmlGraphicsListView::items() listview->decrementCurrentIndex(); QCOMPARE(listview->currentIndex(), 0); + // set an empty model and confirm that items are destroyed + T model2; + ctxt->setContextProperty("testModel", &model2); + + int itemCount = findItems<QmlGraphicsItem>(viewport, "wrapper").count(); + QVERIFY(itemCount == 0); + delete canvas; } @@ -632,6 +641,91 @@ void tst_QmlGraphicsListView::enforceRange() delete canvas; } +void tst_QmlGraphicsListView::spacing() +{ + QmlView *canvas = createView(SRCDIR "/data/listview.qml"); + + TestModel 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); + + // 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->setSpacing(10); + + // Confirm items positioned correctly + 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*30); + } + + listview->setSpacing(0); + + // Confirm items positioned correctly + 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); + } + + delete canvas; +} + +void tst_QmlGraphicsListView::sections() +{ + QmlView *canvas = createView(SRCDIR "/data/listview-sections.qml"); + + TestModel 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); + + // 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); + QVERIFY(item); + QCOMPARE(item->y(), qreal(i*20 + ((i+4)/5) * 20)); + } + + delete canvas; +} + void tst_QmlGraphicsListView::qListModelInterface_items() { items<TestModel>(); |