aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickpathview
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2012-07-23 11:08:06 +1000
committerQt by Nokia <qt-info@nokia.com>2012-07-23 06:38:18 +0200
commit2a4bb9608498876c3c2229eef91b8723a7fd8e47 (patch)
tree0c54b33736537633a5ab73cc4ee1a5777bf4323e /tests/auto/quick/qquickpathview
parent773d722ff2f503c3805e802022cbc487d5bb4126 (diff)
Add methods to PathView: positionViewAtIndex(), indexAt(), itemAt()
These methods are already present in ListView and GridView. Change-Id: I3777fccdecd77c8ab756a0062c71c6e1bfb749ef Reviewed-by: Bea Lam <bea.lam@nokia.com>
Diffstat (limited to 'tests/auto/quick/qquickpathview')
-rw-r--r--tests/auto/quick/qquickpathview/data/pathview3.qml9
-rw-r--r--tests/auto/quick/qquickpathview/tst_qquickpathview.cpp111
2 files changed, 119 insertions, 1 deletions
diff --git a/tests/auto/quick/qquickpathview/data/pathview3.qml b/tests/auto/quick/qquickpathview/data/pathview3.qml
index ded5a3911c..53b4df1d15 100644
--- a/tests/auto/quick/qquickpathview/data/pathview3.qml
+++ b/tests/auto/quick/qquickpathview/data/pathview3.qml
@@ -2,8 +2,10 @@ import QtQuick 2.0
PathView {
id: photoPathView
- y: 100; width: 800; height: 330; pathItemCount: 4; offset: 1
+ property bool enforceRange: true
+ width: 800; height: 330; pathItemCount: 4; offset: 1
dragMargin: 24
+ highlightRangeMode: enforceRange ? PathView.StrictlyEnforceRange : PathView.NoHighlightRange
preferredHighlightBegin: 0.50
preferredHighlightEnd: 0.50
@@ -48,12 +50,17 @@ PathView {
id: photoDelegate
Rectangle {
id: wrapper
+ objectName: "wrapper"
width: 85; height: 85; color: lColor
+ Text { text: index }
+
transform: Rotation {
id: itemRotation; origin.x: wrapper.width/2; origin.y: wrapper.height/2
axis.y: 1; axis.z: 0
}
}
}
+
+ Text { text: "Offset: " + photoPathView.offset }
}
diff --git a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp
index b6b6d24b0f..c007310b53 100644
--- a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp
+++ b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp
@@ -64,6 +64,7 @@ using namespace QQuickViewTestUtil;
using namespace QQuickVisualTestUtil;
Q_DECLARE_METATYPE(QQuickPathView::HighlightRangeMode)
+Q_DECLARE_METATYPE(QQuickPathView::PositionMode)
static void initStandardTreeModel(QStandardItemModel *model)
{
@@ -134,6 +135,10 @@ private slots:
void snapToItem_data();
void snapOneItem();
void snapOneItem_data();
+ void positionViewAtIndex();
+ void positionViewAtIndex_data();
+ void indexAt_itemAt();
+ void indexAt_itemAt_data();
};
class TestObject : public QObject
@@ -1909,6 +1914,112 @@ void tst_QQuickPathView::snapOneItem_data()
QTest::newRow("enforce range") << true;
}
+void tst_QQuickPathView::positionViewAtIndex()
+{
+ QFETCH(bool, enforceRange);
+ QFETCH(int, pathItemCount);
+ QFETCH(qreal, initOffset);
+ QFETCH(int, index);
+ QFETCH(QQuickPathView::PositionMode, mode);
+ QFETCH(qreal, offset);
+
+ QQuickView *window = createView();
+ window->setSource(testFileUrl("pathview3.qml"));
+ window->show();
+ window->requestActivateWindow();
+ QTest::qWaitForWindowShown(window);
+ QTRY_COMPARE(window, qGuiApp->focusWindow());
+
+ QQuickPathView *pathview = qobject_cast<QQuickPathView*>(window->rootObject());
+ QVERIFY(pathview != 0);
+
+ window->rootObject()->setProperty("enforceRange", enforceRange);
+ if (pathItemCount == -1)
+ pathview->resetPathItemCount();
+ else
+ pathview->setPathItemCount(pathItemCount);
+ pathview->setOffset(initOffset);
+
+ pathview->positionViewAtIndex(index, mode);
+
+ QCOMPARE(pathview->offset(), offset);
+
+ delete window;
+}
+
+void tst_QQuickPathView::positionViewAtIndex_data()
+{
+ QTest::addColumn<bool>("enforceRange");
+ QTest::addColumn<int>("pathItemCount");
+ QTest::addColumn<qreal>("initOffset");
+ QTest::addColumn<int>("index");
+ QTest::addColumn<QQuickPathView::PositionMode>("mode");
+ QTest::addColumn<qreal>("offset");
+
+ QTest::newRow("no range, all items, Beginning") << false << -1 << 0.0 << 3 << QQuickPathView::Beginning << 5.0;
+ QTest::newRow("no range, all items, Center") << false << -1 << 0.0 << 3 << QQuickPathView::Center << 1.0;
+ QTest::newRow("no range, all items, End") << false << -1 << 0.0 << 3 << QQuickPathView::End << 5.0;
+ QTest::newRow("no range, 5 items, Beginning") << false << 5 << 0.0 << 3 << QQuickPathView::Beginning << 5.0;
+ QTest::newRow("no range, 5 items, Center") << false << 5 << 0.0 << 3 << QQuickPathView::Center << 7.5;
+ QTest::newRow("no range, 5 items, End") << false << 5 << 0.0 << 3 << QQuickPathView::End << 2.0;
+ QTest::newRow("no range, 5 items, Contain") << false << 5 << 0.0 << 3 << QQuickPathView::Contain << 0.0;
+ QTest::newRow("no range, 5 items, init offset 4.0, Contain") << false << 5 << 4.0 << 3 << QQuickPathView::Contain << 5.0;
+ QTest::newRow("no range, 5 items, init offset 3.0, Contain") << false << 5 << 3.0 << 3 << QQuickPathView::Contain << 2.0;
+
+ QTest::newRow("strict range, all items, Beginning") << true << -1 << 0.0 << 3 << QQuickPathView::Beginning << 1.0;
+ QTest::newRow("strict range, all items, Center") << true << -1 << 0.0 << 3 << QQuickPathView::Center << 5.0;
+ QTest::newRow("strict range, all items, End") << true << -1 << 0.0 << 3 << QQuickPathView::End << 0.0;
+ QTest::newRow("strict range, all items, Contain") << true << -1 << 0.0 << 3 << QQuickPathView::Contain << 0.0;
+ QTest::newRow("strict range, all items, init offset 1.0, Contain") << true << -1 << 1.0 << 3 << QQuickPathView::Contain << 1.0;
+ QTest::newRow("strict range, all items, SnapPosition") << true << -1 << 0.0 << 3 << QQuickPathView::SnapPosition << 5.0;
+ QTest::newRow("strict range, 5 items, Beginning") << true << 5 << 0.0 << 3 << QQuickPathView::Beginning << 3.0;
+ QTest::newRow("strict range, 5 items, Center") << true << 5 << 0.0 << 3 << QQuickPathView::Center << 5.0;
+ QTest::newRow("strict range, 5 items, End") << true << 5 << 0.0 << 3 << QQuickPathView::End << 7.0;
+ QTest::newRow("strict range, 5 items, Contain") << true << 5 << 0.0 << 3 << QQuickPathView::Contain << 7.0;
+ QTest::newRow("strict range, 5 items, init offset 1.0, Contain") << true << 5 << 1.0 << 3 << QQuickPathView::Contain << 7.0;
+ QTest::newRow("strict range, 5 items, init offset 2.0, Contain") << true << 5 << 2.0 << 3 << QQuickPathView::Contain << 3.0;
+ QTest::newRow("strict range, 5 items, SnapPosition") << true << 5 << 0.0 << 3 << QQuickPathView::SnapPosition << 5.0;
+}
+
+void tst_QQuickPathView::indexAt_itemAt()
+{
+ QFETCH(qreal, x);
+ QFETCH(qreal, y);
+ QFETCH(int, index);
+
+ QQuickView *window = createView();
+ window->setSource(testFileUrl("pathview3.qml"));
+ window->show();
+ window->requestActivateWindow();
+ QTest::qWaitForWindowShown(window);
+ QTRY_COMPARE(window, qGuiApp->focusWindow());
+
+ QQuickPathView *pathview = qobject_cast<QQuickPathView*>(window->rootObject());
+ QVERIFY(pathview != 0);
+
+ QQuickItem *item = 0;
+ if (index >= 0) {
+ item = findItem<QQuickItem>(pathview, "wrapper", index);
+ QVERIFY(item);
+ }
+ QCOMPARE(pathview->indexAt(x,y), index);
+ QVERIFY(pathview->itemAt(x,y) == item);
+
+ delete window;
+}
+
+void tst_QQuickPathView::indexAt_itemAt_data()
+{
+ QTest::addColumn<qreal>("x");
+ QTest::addColumn<qreal>("y");
+ QTest::addColumn<int>("index");
+
+ QTest::newRow("Item 0 - 585, 95") << 585. << 95. << 0;
+ QTest::newRow("Item 0 - 660, 165") << 660. << 165. << 0;
+ QTest::newRow("No Item a - 580, 95") << 580. << 95. << -1;
+ QTest::newRow("No Item b - 585, 85") << 585. << 85. << -1;
+ QTest::newRow("Item 7 - 360, 200") << 360. << 200. << 7;
+}
QTEST_MAIN(tst_QQuickPathView)