diff options
author | Martin Jones <martin.jones@nokia.com> | 2009-11-09 04:54:19 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2009-11-09 04:54:19 (GMT) |
commit | 26dbd51beadc290ea2ad7ce046d1bf8485fbffc4 (patch) | |
tree | a999bda642740dc22e25e3b3c24649075ae26e5a /tests/auto/declarative/qmlgraphicsgridview | |
parent | 714a957a9144e6c4189dacf96132cf01bf9350e8 (diff) | |
download | Qt-26dbd51beadc290ea2ad7ce046d1bf8485fbffc4.zip Qt-26dbd51beadc290ea2ad7ce046d1bf8485fbffc4.tar.gz Qt-26dbd51beadc290ea2ad7ce046d1bf8485fbffc4.tar.bz2 |
More tests and fixes for ListView and GridView
Diffstat (limited to 'tests/auto/declarative/qmlgraphicsgridview')
-rw-r--r-- | tests/auto/declarative/qmlgraphicsgridview/data/gridview-initCurrent.qml | 51 | ||||
-rw-r--r-- | tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp | 111 |
2 files changed, 153 insertions, 9 deletions
diff --git a/tests/auto/declarative/qmlgraphicsgridview/data/gridview-initCurrent.qml b/tests/auto/declarative/qmlgraphicsgridview/data/gridview-initCurrent.qml new file mode 100644 index 0000000..d9e9f27 --- /dev/null +++ b/tests/auto/declarative/qmlgraphicsgridview/data/gridview-initCurrent.qml @@ -0,0 +1,51 @@ +import Qt 4.6 + +Rectangle { + width: 240 + height: 320 + color: "#ffffff" + resources: [ + Component { + id: myDelegate + Rectangle { + id: wrapper + objectName: "wrapper" + width: 80 + height: 60 + border.color: "blue" + Text { + text: index + } + Text { + x: 40 + text: wrapper.x + ", " + wrapper.y + } + Text { + y: 20 + id: textName + objectName: "textName" + text: name + } + Text { + y: 40 + id: textNumber + objectName: "textNumber" + text: number + } + color: GridView.isCurrentItem ? "lightsteelblue" : "white" + } + } + ] + GridView { + id: grid + objectName: "grid" + focus: true + width: 240 + height: 320 + currentIndex: 5 + cellWidth: 80 + cellHeight: 60 + model: testModel + delegate: myDelegate + } +} diff --git a/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp b/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp index c6ea25a..7c32d14 100644 --- a/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp +++ b/tests/auto/declarative/qmlgraphicsgridview/tst_qmlgraphicsgridview.cpp @@ -53,6 +53,7 @@ public: tst_QmlGraphicsGridView(); private slots: + void currentIndex(); void items(); void changed(); void inserted(); @@ -168,15 +169,6 @@ void tst_QmlGraphicsGridView::items() QCOMPARE(number->text(), model.number(i)); } - gridview->moveCurrentIndexRight(); - QCOMPARE(gridview->currentIndex(), 1); - gridview->moveCurrentIndexDown(); - QCOMPARE(gridview->currentIndex(), 4); - gridview->moveCurrentIndexUp(); - QCOMPARE(gridview->currentIndex(), 1); - gridview->moveCurrentIndexLeft(); - QCOMPARE(gridview->currentIndex(), 0); - // set an empty model and confirm that items are destroyed TestModel model2; ctxt->setContextProperty("testModel", &model2); @@ -515,6 +507,107 @@ void tst_QmlGraphicsGridView::moved() delete canvas; } +void tst_QmlGraphicsGridView::currentIndex() +{ + TestModel model; + for (int i = 0; i < 30; i++) + model.addItem("Item" + QString::number(i), QString::number(i)); + + QmlView *canvas = new QmlView(0); + canvas->setFixedSize(240,320); + + QmlContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + QString filename(SRCDIR "/data/gridview-initCurrent.qml"); + QFile file(filename); + file.open(QFile::ReadOnly); + QString qml = file.readAll(); + canvas->setQml(qml, filename); + + canvas->execute(); + qApp->processEvents(); + + QmlGraphicsGridView *gridview = findItem<QmlGraphicsGridView>(canvas->root(), "grid"); + QVERIFY(gridview != 0); + + QmlGraphicsItem *viewport = gridview->viewport(); + QVERIFY(viewport != 0); + + // current item should be third item + QCOMPARE(gridview->currentIndex(), 5); + QCOMPARE(gridview->currentItem(), findItem<QmlGraphicsItem>(viewport, "wrapper", 5)); + + gridview->moveCurrentIndexRight(); + QCOMPARE(gridview->currentIndex(), 6); + gridview->moveCurrentIndexDown(); + QCOMPARE(gridview->currentIndex(), 9); + gridview->moveCurrentIndexUp(); + QCOMPARE(gridview->currentIndex(), 6); + gridview->moveCurrentIndexLeft(); + QCOMPARE(gridview->currentIndex(), 5); + + // no wrap + gridview->setCurrentIndex(0); + QCOMPARE(gridview->currentIndex(), 0); + + gridview->moveCurrentIndexUp(); + QCOMPARE(gridview->currentIndex(), 0); + + gridview->moveCurrentIndexLeft(); + QCOMPARE(gridview->currentIndex(), 0); + + gridview->setCurrentIndex(model.count()-1); + QTest::qWait(500); + QCOMPARE(gridview->currentIndex(), model.count()-1); + + gridview->moveCurrentIndexRight(); + QCOMPARE(gridview->currentIndex(), model.count()-1); + + gridview->moveCurrentIndexDown(); + QCOMPARE(gridview->currentIndex(), model.count()-1); + + // with wrap + gridview->setWrapEnabled(true); + + gridview->setCurrentIndex(0); + QCOMPARE(gridview->currentIndex(), 0); + QTest::qWait(500); + + gridview->moveCurrentIndexLeft(); + QCOMPARE(gridview->currentIndex(), model.count()-1); + + QTest::qWait(500); + QCOMPARE(gridview->viewportY(), 279.0); + + gridview->moveCurrentIndexRight(); + QCOMPARE(gridview->currentIndex(), 0); + + QTest::qWait(500); + QCOMPARE(gridview->viewportY(), 0.0); + + // Test keys + canvas->show(); + qApp->processEvents(); + + QEvent wa(QEvent::WindowActivate); + QApplication::sendEvent(canvas, &wa); + QFocusEvent fe(QEvent::FocusIn); + QApplication::sendEvent(canvas, &fe); + + QKeyEvent key(QEvent::KeyPress, Qt::Key_Down, Qt::NoModifier, "", false, 1); + QApplication::sendEvent(canvas, &key); + QVERIFY(key.isAccepted()); + QCOMPARE(gridview->currentIndex(), 3); + + key = QKeyEvent(QEvent::KeyPress, Qt::Key_Up, Qt::NoModifier, "", false, 1); + QApplication::sendEvent(canvas, &key); + QVERIFY(key.isAccepted()); + QCOMPARE(gridview->currentIndex(), 0); + + delete canvas; +} + QmlView *tst_QmlGraphicsGridView::createView(const QString &filename) { QmlView *canvas = new QmlView(0); |