From 8735ad516f0262d815ab7e846cb8db67a2aff4f4 Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 2 Jul 2018 10:54:52 +0200 Subject: Avoid pushing background views onto the stack --- components/kube/qml/ViewManager.qml | 12 +++--- components/kube/tests/tst_viewmanagertest.qml | 56 +++++++++++++++++++++------ 2 files changed, 51 insertions(+), 17 deletions(-) diff --git a/components/kube/qml/ViewManager.qml b/components/kube/qml/ViewManager.qml index 351026b4..0b32e877 100644 --- a/components/kube/qml/ViewManager.qml +++ b/components/kube/qml/ViewManager.qml @@ -51,13 +51,15 @@ StackView { return Qt.createComponent(source, Qt.Asynchronous) } - function createView(name, properties) { + function createView(name, properties, push) { var component = createComponent(name) function finishCreation() { if (component.status == Component.Ready) { - var view = component.createObject(root); + var view = component.createObject(root, properties ? properties : {}); viewDict[name] = view - pushView(view, properties, name) + if (push) { + pushView(view, properties, name) + } } else { console.error("Error while loading the component: ", source, "\nError: ", component.errorString()) } @@ -96,7 +98,7 @@ StackView { } } - createView(name, properties) + createView(name, properties, true) } function showView(name, properties) { @@ -104,7 +106,7 @@ StackView { } function prepareViewInBackground(name, properties) { - createView(name, properties) + createView(name, properties, false) } function replaceView(name, properties) { diff --git a/components/kube/tests/tst_viewmanagertest.qml b/components/kube/tests/tst_viewmanagertest.qml index 8bd12df4..dc2c5b07 100644 --- a/components/kube/tests/tst_viewmanagertest.qml +++ b/components/kube/tests/tst_viewmanagertest.qml @@ -29,24 +29,29 @@ TestCase { height: 400 name: "ViewManager" - ViewManager { - id: viewManager - anchors.fill: parent + Component { + id: viewManagerComponent + ViewManager { + id: viewManager + anchors.fill: parent - function createComponent(name) { - return testViewComponent - } + function createComponent(name) { + return testViewComponent + } - Component { - id: testViewComponent - Rectangle { - property string test: "not initialized" + Component { + id: testViewComponent + Rectangle { + property string test: "not initialized" + } } } } - function test_testStack() { + function test_1testStack() { + var viewManager = createTemporaryObject(viewManagerComponent, viewmanagerTestcase, {}) + viewManager.showView("view1", {test: "test1"}) compare(viewManager.currentViewName, "view1") compare(viewManager.currentItem.test, "test1") @@ -79,8 +84,35 @@ TestCase { compare(viewManager.currentItem.test, "test1") compare(viewManager.depth, 1) - //Never close the last windows + //Never close the last view viewManager.closeView() compare(viewManager.depth, 1) } + + function test_2testBackgroundView() { + var viewManager = createTemporaryObject(viewManagerComponent, viewmanagerTestcase, {}) + + viewManager.prepareViewInBackground("backgroundView", {test: "background"}) + + viewManager.showView("view1", {test: "test1"}) + compare(viewManager.currentViewName, "view1") + compare(viewManager.currentItem.test, "test1") + compare(viewManager.depth, 1) + + viewManager.showView("backgroundView") + compare(viewManager.currentViewName, "backgroundView") + compare(viewManager.currentItem.test, "background") + compare(viewManager.depth, 2) + + viewManager.closeView() + compare(viewManager.currentViewName, "view1") + compare(viewManager.currentItem.test, "test1") + compare(viewManager.depth, 1) + + //Never close the last view + viewManager.closeView() + compare(viewManager.currentViewName, "view1") + compare(viewManager.currentItem.test, "test1") + compare(viewManager.depth, 1) + } } -- cgit v1.2.3