From 6338e98729f811fd3a2d960c184e76357e908ab7 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 7 Sep 2015 16:29:55 -0500 Subject: 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 --- tests/auto/quick/qquickloader/tst_qquickloader.cpp | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'tests') 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(component.create()); + QVERIFY(root); + + QQuickLoader *loader = root->findChild("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(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(component.create()); + QVERIFY(root); + + QQuickLoader *loader = root->findChild("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(loader)->childItems().count(), 1); + + delete root; +} + void tst_QQuickLoader::loadedSignal() { PeriodicIncubationController *controller = new PeriodicIncubationController; -- cgit v1.2.3