aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMartin Jones <martin.jones@nokia.com>2012-08-21 14:47:48 +1000
committerQt by Nokia <qt-info@nokia.com>2012-08-28 04:32:48 +0200
commit4a4a08d61a9771b5f49d7377b48d821075df3d97 (patch)
treec21f3d242a4a1d69f104efa41d66622ea119309f /tests
parenta47597ea986e76cb6deeaaa64b3714add4688a01 (diff)
Add cacheItemCount property to PathView
cacheItemCount specifies the number of items to cache off the path when pathItemCount is specified. This allows up to cacheItemCount items to be kept alive when they move off the path, and also to asynchronously create items off path in preparation for display when the path offset changes. This is the equivalent of cacheBuffer for other views. Task-number: QTBUG-23931 Change-Id: I03497537d3f929e5e3579536850dd43eb2724c38 Reviewed-by: Bea Lam <bea.lam@nokia.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/quick/qquickpathview/data/pathview3.qml5
-rw-r--r--tests/auto/quick/qquickpathview/tst_qquickpathview.cpp80
2 files changed, 84 insertions, 1 deletions
diff --git a/tests/auto/quick/qquickpathview/data/pathview3.qml b/tests/auto/quick/qquickpathview/data/pathview3.qml
index 53b4df1d15..4687776e0b 100644
--- a/tests/auto/quick/qquickpathview/data/pathview3.qml
+++ b/tests/auto/quick/qquickpathview/data/pathview3.qml
@@ -9,6 +9,10 @@ PathView {
preferredHighlightBegin: 0.50
preferredHighlightEnd: 0.50
+ function addColor(color) {
+ model.append({"lColor":color})
+ }
+
path: Path {
startX: -50; startY: 40;
@@ -35,7 +39,6 @@ PathView {
}
model: ListModel {
- id: rssModel
ListElement { lColor: "red" }
ListElement { lColor: "green" }
ListElement { lColor: "yellow" }
diff --git a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp
index 16545fe815..748df947e9 100644
--- a/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp
+++ b/tests/auto/quick/qquickpathview/tst_qquickpathview.cpp
@@ -139,6 +139,7 @@ private slots:
void positionViewAtIndex_data();
void indexAt_itemAt();
void indexAt_itemAt_data();
+ void cacheItemCount();
};
class TestObject : public QObject
@@ -2021,6 +2022,85 @@ void tst_QQuickPathView::indexAt_itemAt_data()
QTest::newRow("Item 7 - 360, 200") << 360. << 200. << 7;
}
+void tst_QQuickPathView::cacheItemCount()
+{
+ QQuickView *window = createView();
+
+ window->setSource(testFileUrl("pathview3.qml"));
+ window->show();
+ qApp->processEvents();
+
+ QQuickPathView *pathview = qobject_cast<QQuickPathView*>(window->rootObject());
+ QVERIFY(pathview != 0);
+
+ QMetaObject::invokeMethod(pathview, "addColor", Q_ARG(QVariant, QString("orange")));
+ QMetaObject::invokeMethod(pathview, "addColor", Q_ARG(QVariant, QString("lightsteelblue")));
+ QMetaObject::invokeMethod(pathview, "addColor", Q_ARG(QVariant, QString("teal")));
+ QMetaObject::invokeMethod(pathview, "addColor", Q_ARG(QVariant, QString("aqua")));
+
+ pathview->setOffset(0);
+
+ pathview->setCacheItemCount(3);
+ QVERIFY(pathview->cacheItemCount() == 3);
+
+ QQmlIncubationController controller;
+ window->engine()->setIncubationController(&controller);
+
+ // Items on the path are created immediately
+ QVERIFY(findItem<QQuickItem>(pathview, "wrapper", 0));
+ QVERIFY(findItem<QQuickItem>(pathview, "wrapper", 1));
+ QVERIFY(findItem<QQuickItem>(pathview, "wrapper", 11));
+ QVERIFY(findItem<QQuickItem>(pathview, "wrapper", 10));
+
+ const int cached[] = { 2, 3, 9, -1 }; // two appended, one prepended
+
+ int i = 0;
+ while (cached[i] >= 0) {
+ // items will be created one at a time
+ QVERIFY(findItem<QQuickItem>(pathview, "wrapper", cached[i]) == 0);
+ QQuickItem *item = 0;
+ while (!item) {
+ bool b = false;
+ controller.incubateWhile(&b);
+ item = findItem<QQuickItem>(pathview, "wrapper", cached[i]);
+ }
+ ++i;
+ }
+
+ {
+ bool b = true;
+ controller.incubateWhile(&b);
+ }
+
+ // move view and confirm items in view are visible immediately and outside are created async
+ pathview->setOffset(4);
+
+ // Items on the path are created immediately
+ QVERIFY(findItem<QQuickItem>(pathview, "wrapper", 6));
+ QVERIFY(findItem<QQuickItem>(pathview, "wrapper", 7));
+ QVERIFY(findItem<QQuickItem>(pathview, "wrapper", 8));
+ QVERIFY(findItem<QQuickItem>(pathview, "wrapper", 9));
+ // already created items within cache stay created
+ QVERIFY(findItem<QQuickItem>(pathview, "wrapper", 10));
+ QVERIFY(findItem<QQuickItem>(pathview, "wrapper", 11));
+
+ // one item prepended async.
+ QVERIFY(findItem<QQuickItem>(pathview, "wrapper", 5) == 0);
+ QQuickItem *item = 0;
+ while (!item) {
+ bool b = false;
+ controller.incubateWhile(&b);
+ item = findItem<QQuickItem>(pathview, "wrapper", 5);
+ }
+
+ {
+ bool b = true;
+ controller.incubateWhile(&b);
+ }
+
+ delete window;
+}
+
QTEST_MAIN(tst_QQuickPathView)
#include "tst_qquickpathview.moc"