diff options
author | Martin Jones <martin.jones@nokia.com> | 2009-11-10 05:54:53 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2009-11-10 05:54:53 (GMT) |
commit | 27cf19d3234336edc2c89ebc010808de25136d1e (patch) | |
tree | bbfcf9dd411939eadfb09ba4ccc8809f260686ce /tests | |
parent | d99decf13bc35d0eb8e9da3ccc828a4a947d7dad (diff) | |
download | Qt-27cf19d3234336edc2c89ebc010808de25136d1e.zip Qt-27cf19d3234336edc2c89ebc010808de25136d1e.tar.gz Qt-27cf19d3234336edc2c89ebc010808de25136d1e.tar.bz2 |
ListView and GridView tests.
Diffstat (limited to 'tests')
3 files changed, 70 insertions, 3 deletions
diff --git a/tests/auto/declarative/qmlgraphicsgridview/data/gridview.qml b/tests/auto/declarative/qmlgraphicsgridview/data/gridview.qml index 37eb622..344b4b5 100644 --- a/tests/auto/declarative/qmlgraphicsgridview/data/gridview.qml +++ b/tests/auto/declarative/qmlgraphicsgridview/data/gridview.qml @@ -43,6 +43,7 @@ Rectangle { height: 320 cellWidth: 80 cellHeight: 60 + flow: (testTopToBottom == false) ? "LeftToRight" : "TopToBottom" model: testModel delegate: myDelegate } diff --git a/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp b/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp index f89e02f..d99b16f 100644 --- a/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp +++ b/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp @@ -53,12 +53,13 @@ public: tst_QmlGraphicsGridView(); private slots: - void currentIndex(); void items(); void changed(); void inserted(); void removed(); void moved(); + void currentIndex(); + void changeFlow(); private: QmlView *createView(const QString &filename); @@ -147,6 +148,7 @@ void tst_QmlGraphicsGridView::items() QmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); + ctxt->setContextProperty("testTopToBottom", QVariant(false)); canvas->execute(); qApp->processEvents(); @@ -194,6 +196,7 @@ void tst_QmlGraphicsGridView::changed() QmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); + ctxt->setContextProperty("testTopToBottom", QVariant(false)); canvas->execute(); qApp->processEvents(); @@ -226,6 +229,7 @@ void tst_QmlGraphicsGridView::inserted() QmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); + ctxt->setContextProperty("testTopToBottom", QVariant(false)); canvas->execute(); qApp->processEvents(); @@ -253,8 +257,8 @@ void tst_QmlGraphicsGridView::inserted() // Confirm items positioned correctly for (int i = 0; i < model.count(); ++i) { QmlGraphicsItem *item = findItem<QmlGraphicsItem>(viewport, "wrapper", i); - QVERIFY(item->x() == (i%3)*80); - QVERIFY(item->y() == (i/3)*60); + QCOMPARE(item->x(), (i%3)*80.0); + QCOMPARE(item->y(), (i/3)*60.0); } model.insertItem(0, "Foo", "1111"); // zero index, and current item @@ -306,6 +310,7 @@ void tst_QmlGraphicsGridView::removed() QmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); + ctxt->setContextProperty("testTopToBottom", QVariant(false)); canvas->execute(); qApp->processEvents(); @@ -420,6 +425,7 @@ void tst_QmlGraphicsGridView::moved() QmlContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); + ctxt->setContextProperty("testTopToBottom", QVariant(false)); canvas->execute(); qApp->processEvents(); @@ -625,6 +631,65 @@ void tst_QmlGraphicsGridView::currentIndex() delete canvas; } +void tst_QmlGraphicsGridView::changeFlow() +{ + QmlView *canvas = createView(SRCDIR "/data/gridview.qml"); + + TestModel model; + for (int i = 0; i < 30; i++) + model.addItem("Item" + QString::number(i), QString::number(i)); + + QmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + ctxt->setContextProperty("testTopToBottom", QVariant(false)); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsGridView *gridview = findItem<QmlGraphicsGridView>(canvas->root(), "grid"); + QVERIFY(gridview != 0); + + QmlGraphicsItem *viewport = gridview->viewport(); + QVERIFY(viewport != 0); + + // Confirm items positioned correctly and indexes correct + int itemCount = findItems<QmlGraphicsItem>(viewport, "wrapper").count(); + 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); + QCOMPARE(item->x(), qreal((i%3)*80)); + QCOMPARE(item->y(), qreal((i/3)*60)); + QmlGraphicsText *name = findItem<QmlGraphicsText>(viewport, "textName", i); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(i)); + QmlGraphicsText *number = findItem<QmlGraphicsText>(viewport, "textNumber", i); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(i)); + } + + ctxt->setContextProperty("testTopToBottom", QVariant(true)); + QTest::qWait(500); + + // Confirm items positioned correctly and indexes correct + itemCount = findItems<QmlGraphicsItem>(viewport, "wrapper").count(); + 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); + QCOMPARE(item->x(), qreal((i/5)*80)); + QCOMPARE(item->y(), qreal((i%5)*60)); + QmlGraphicsText *name = findItem<QmlGraphicsText>(viewport, "textName", i); + QVERIFY(name != 0); + QCOMPARE(name->text(), model.name(i)); + QmlGraphicsText *number = findItem<QmlGraphicsText>(viewport, "textNumber", i); + QVERIFY(number != 0); + QCOMPARE(number->text(), model.number(i)); + } + + delete canvas; +} + QmlView *tst_QmlGraphicsGridView::createView(const QString &filename) { QmlView *canvas = new QmlView(0); diff --git a/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp b/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp index a4949eb..83b8d79 100644 --- a/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp +++ b/tests/auto/declarative/qmlgraphicslistview/tst_qmlgraphicslistview.cpp @@ -625,6 +625,7 @@ void tst_QmlGraphicsListView::enforceRange() QCOMPARE(listview->preferredHighlightBegin(), 100.0); QCOMPARE(listview->preferredHighlightEnd(), 100.0); + QCOMPARE(listview->highlightRangeMode(), QmlGraphicsListView::StrictlyEnforceRange); QmlGraphicsItem *viewport = listview->viewport(); QVERIFY(viewport != 0); |