diff options
author | Michael Brasser <michael.brasser@live.com> | 2015-09-07 16:29:55 -0500 |
---|---|---|
committer | Michael Brasser <michael.brasser@live.com> | 2015-09-10 17:57:10 +0000 |
commit | 6338e98729f811fd3a2d960c184e76357e908ab7 (patch) | |
tree | b9901afee0f766a70bf00ec25176a90267582975 /tests | |
parent | 5aa682176613b551812e378e5990607d4a211837 (diff) |
Allow forced completion of asynchronous Loader.
Setting Loader::asynchronous from true to false will attempt to force
complete any operations in progress. This allows the user to begin
loading something in the background, and then force the load to complete
once the Loader's content must be viewed.
Change-Id: I056dcc20faacb38b3529c967245416da9949e64a
Task-number: QTBUG-29789
Reviewed-by: Simon Hausmann <simon.hausmann@theqtcompany.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/quick/qquickloader/tst_qquickloader.cpp | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/tests/auto/quick/qquickloader/tst_qquickloader.cpp b/tests/auto/quick/qquickloader/tst_qquickloader.cpp index e72b38e06c..83294b10ab 100644 --- a/tests/auto/quick/qquickloader/tst_qquickloader.cpp +++ b/tests/auto/quick/qquickloader/tst_qquickloader.cpp @@ -111,6 +111,8 @@ private slots: void asynchronous(); void asynchronous_clear(); void simultaneousSyncAsync(); + void asyncToSync1(); + void asyncToSync2(); void loadedSignal(); void parented(); @@ -1042,6 +1044,73 @@ void tst_QQuickLoader::simultaneousSyncAsync() delete root; } +void tst_QQuickLoader::asyncToSync1() +{ + QQmlEngine engine; + PeriodicIncubationController *controller = new PeriodicIncubationController; + QQmlIncubationController *previous = engine.incubationController(); + engine.setIncubationController(controller); + delete previous; + + QQmlComponent component(&engine, testFileUrl("asynchronous.qml")); + QQuickItem *root = qobject_cast<QQuickItem*>(component.create()); + QVERIFY(root); + + QQuickLoader *loader = root->findChild<QQuickLoader*>("loader"); + QVERIFY(loader); + + QVERIFY(!loader->item()); + root->setProperty("comp", "BigComponent.qml"); + QMetaObject::invokeMethod(root, "loadComponent"); + QVERIFY(!loader->item()); + + controller->start(); + QCOMPARE(loader->status(), QQuickLoader::Loading); + QCOMPARE(engine.incubationController()->incubatingObjectCount(), 0); + + // force completion before component created + loader->setAsynchronous(false); + QVERIFY(loader->item()); + QCOMPARE(loader->progress(), 1.0); + QCOMPARE(loader->status(), QQuickLoader::Ready); + QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().count(), 1); + + delete root; +} + +void tst_QQuickLoader::asyncToSync2() +{ + PeriodicIncubationController *controller = new PeriodicIncubationController; + QQmlIncubationController *previous = engine.incubationController(); + engine.setIncubationController(controller); + delete previous; + + QQmlComponent component(&engine, testFileUrl("asynchronous.qml")); + QQuickItem *root = qobject_cast<QQuickItem*>(component.create()); + QVERIFY(root); + + QQuickLoader *loader = root->findChild<QQuickLoader*>("loader"); + QVERIFY(loader); + + QVERIFY(!loader->item()); + root->setProperty("comp", "BigComponent.qml"); + QMetaObject::invokeMethod(root, "loadComponent"); + QVERIFY(!loader->item()); + + controller->start(); + QCOMPARE(loader->status(), QQuickLoader::Loading); + QTRY_COMPARE(engine.incubationController()->incubatingObjectCount(), 1); + + // force completion after component created but before incubation complete + loader->setAsynchronous(false); + QVERIFY(loader->item()); + QCOMPARE(loader->progress(), 1.0); + QCOMPARE(loader->status(), QQuickLoader::Ready); + QCOMPARE(static_cast<QQuickItem*>(loader)->childItems().count(), 1); + + delete root; +} + void tst_QQuickLoader::loadedSignal() { PeriodicIncubationController *controller = new PeriodicIncubationController; |