diff options
author | Martin Jones <martin.jones@nokia.com> | 2010-03-08 02:38:17 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2010-03-08 02:38:17 (GMT) |
commit | 2d3323d239c9d20c98e09c9398931e60bb799cca (patch) | |
tree | b5484d2eb06cfc60759e45f7b8fc82176ab09b07 /tests/auto/declarative/qdeclarativepathview | |
parent | 9bc81769eb6ebc9bd62fe3c1d86e67ddccbed8b6 (diff) | |
download | Qt-2d3323d239c9d20c98e09c9398931e60bb799cca.zip Qt-2d3323d239c9d20c98e09c9398931e60bb799cca.tar.gz Qt-2d3323d239c9d20c98e09c9398931e60bb799cca.tar.bz2 |
Add PathView.isCurrentIndex and PathView.view attached properties
Adding PathView attached properties to be in line with other views.
Task-number: QT-319
Diffstat (limited to 'tests/auto/declarative/qdeclarativepathview')
-rw-r--r-- | tests/auto/declarative/qdeclarativepathview/data/pathview.qml | 11 | ||||
-rw-r--r-- | tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp | 46 |
2 files changed, 54 insertions, 3 deletions
diff --git a/tests/auto/declarative/qdeclarativepathview/data/pathview.qml b/tests/auto/declarative/qdeclarativepathview/data/pathview.qml index c5d88cd..ae0c86a 100644 --- a/tests/auto/declarative/qdeclarativepathview/data/pathview.qml +++ b/tests/auto/declarative/qdeclarativepathview/data/pathview.qml @@ -1,6 +1,9 @@ import Qt 4.6 Rectangle { + id: root + property int currentA: -1 + property int currentB: -1 width: 240 height: 320 color: "#ffffff" @@ -12,7 +15,7 @@ Rectangle { objectName: "wrapper" height: 20 width: 60 - color: "white" + color: PathView.isCurrentItem ? "lightsteelblue" : "white" border.color: "black" Text { text: index @@ -29,6 +32,12 @@ Rectangle { objectName: "textNumber" text: number } + PathView.onCurrentItemChanged: { + if (PathView.isCurrentItem) { + root.currentA = index; + root.currentB = wrapper.PathView.view.currentIndex; + } + } } } ] diff --git a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp index fa4e9d3..62eb8c3 100644 --- a/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp +++ b/tests/auto/declarative/qdeclarativepathview/tst_qdeclarativepathview.cpp @@ -71,6 +71,7 @@ private slots: void pathview3(); void path(); void pathMoved(); + void setCurrentIndex(); void resetModel(); void propertyChanges(); void pathChanges(); @@ -207,6 +208,7 @@ void tst_QDeclarativePathView::items() model.addItem("Fred", "12345"); model.addItem("John", "2345"); model.addItem("Bob", "54321"); + model.addItem("Bill", "4321"); QDeclarativeContext *ctxt = canvas->rootContext(); ctxt->setContextProperty("testModel", &model); @@ -421,7 +423,6 @@ void tst_QDeclarativePathView::pathMoved() offset.setY(firstItem->height()/2); QCOMPARE(firstItem->pos() + offset, start); pathview->setOffset(10); - QTest::qWait(1000);//Moving is animated? for(int i=0; i<model.count(); i++){ QDeclarativeRectangle *curItem = findItem<QDeclarativeRectangle>(pathview, "wrapper", i); @@ -429,12 +430,53 @@ void tst_QDeclarativePathView::pathMoved() } pathview->setOffset(100); - QTest::qWait(1000);//Moving is animated? QCOMPARE(firstItem->pos() + offset, start); delete canvas; } +void tst_QDeclarativePathView::setCurrentIndex() +{ + QDeclarativeView *canvas = createView(); + + TestModel model; + model.addItem("Ben", "12345"); + model.addItem("Bohn", "2345"); + model.addItem("Bob", "54321"); + model.addItem("Bill", "4321"); + + QDeclarativeContext *ctxt = canvas->rootContext(); + ctxt->setContextProperty("testModel", &model); + + canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/pathview.qml")); + qApp->processEvents(); + + QDeclarativePathView *pathview = findItem<QDeclarativePathView>(canvas->rootObject(), "view"); + QVERIFY(pathview != 0); + + QDeclarativeRectangle *firstItem = findItem<QDeclarativeRectangle>(pathview, "wrapper", 0); + QVERIFY(firstItem); + QDeclarativePath *path = qobject_cast<QDeclarativePath*>(pathview->path()); + QVERIFY(path); + QPointF start = path->pointAt(0.0); + QPointF offset;//Center of item is at point, but pos is from corner + offset.setX(firstItem->width()/2); + offset.setY(firstItem->height()/2); + QCOMPARE(firstItem->pos() + offset, start); + QCOMPARE(canvas->rootObject()->property("currentA").toInt(), 0); + QCOMPARE(canvas->rootObject()->property("currentB").toInt(), 0); + + pathview->setCurrentIndex(2); + QTest::qWait(1000); + + firstItem = findItem<QDeclarativeRectangle>(pathview, "wrapper", 2); + QCOMPARE(firstItem->pos() + offset, start); + QCOMPARE(canvas->rootObject()->property("currentA").toInt(), 2); + QCOMPARE(canvas->rootObject()->property("currentB").toInt(), 2); + + delete canvas; +} + void tst_QDeclarativePathView::resetModel() { QDeclarativeView *canvas = createView(); |