From c56b187779b53429e868c94e55149c14676a31cb Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sat, 30 Jun 2018 09:33:46 +0200 Subject: Fixed and tested the viewmanager. We failed to forward the properties to the view. --- components/kube/qml/ViewManager.qml | 13 ++-- components/kube/tests/tst_viewmanagertest.qml | 86 +++++++++++++++++++++++++++ 2 files changed, 94 insertions(+), 5 deletions(-) create mode 100644 components/kube/tests/tst_viewmanagertest.qml diff --git a/components/kube/qml/ViewManager.qml b/components/kube/qml/ViewManager.qml index e29efaaf..351026b4 100644 --- a/components/kube/qml/ViewManager.qml +++ b/components/kube/qml/ViewManager.qml @@ -44,12 +44,15 @@ StackView { item.objectName = name } - function createView(name, properties) { + function createComponent(name) { //Creating a new view var source = extensionModel.findSource(name, "View.qml"); //On windows it will be async anyways, so just always create it async - var component = Qt.createComponent(source, Qt.Asynchronous) + return Qt.createComponent(source, Qt.Asynchronous) + } + function createView(name, properties) { + var component = createComponent(name) function finishCreation() { if (component.status == Component.Ready) { var view = component.createObject(root); @@ -93,7 +96,7 @@ StackView { } } - createView(name) + createView(name, properties) } function showView(name, properties) { @@ -110,8 +113,8 @@ StackView { function closeView() { //The initial view remains - if (kubeViews.depth > 1) { - var item = kubeViews.pop(StackView.Immediate) + if (root.depth > 1) { + var item = root.pop(StackView.Immediate) viewDict[item.objectName] = null item.destroy() } diff --git a/components/kube/tests/tst_viewmanagertest.qml b/components/kube/tests/tst_viewmanagertest.qml new file mode 100644 index 00000000..8bd12df4 --- /dev/null +++ b/components/kube/tests/tst_viewmanagertest.qml @@ -0,0 +1,86 @@ +/* + * Copyright 2017 Christian Mollekopf + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details + * + * You should have received a copy of the GNU Library General Public + * License along with this program; if not, write to the + * Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +import QtQuick 2.7 +import QtTest 1.0 +import org.kube.framework 1.0 as Kube +import org.kube.test 1.0 +import "../qml" + +TestCase { + id: viewmanagerTestcase + width: 400 + height: 400 + name: "ViewManager" + + ViewManager { + id: viewManager + anchors.fill: parent + + function createComponent(name) { + return testViewComponent + } + + Component { + id: testViewComponent + Rectangle { + property string test: "not initialized" + } + } + } + + + function test_testStack() { + viewManager.showView("view1", {test: "test1"}) + compare(viewManager.currentViewName, "view1") + compare(viewManager.currentItem.test, "test1") + compare(viewManager.depth, 1) + + viewManager.showView("view2", {test: "test2"}) + compare(viewManager.currentViewName, "view2") + compare(viewManager.currentItem.test, "test2") + compare(viewManager.depth, 2) + + viewManager.replaceView("view3", {test: "test3"}) + compare(viewManager.currentViewName, "view3") + compare(viewManager.currentItem.test, "test3") + compare(viewManager.depth, 2) + + //Switch back to the old view (properties are maintained) + viewManager.showView("view2") + compare(viewManager.currentViewName, "view2") + compare(viewManager.currentItem.test, "test2") + compare(viewManager.depth, 2) + + //And replace view3 (properties are not maintained) + viewManager.replaceView("view3", {test: "test4"}) + compare(viewManager.currentViewName, "view3") + compare(viewManager.currentItem.test, "test4") + compare(viewManager.depth, 2) + + viewManager.closeView() + compare(viewManager.currentViewName, "view1") + compare(viewManager.currentItem.test, "test1") + compare(viewManager.depth, 1) + + //Never close the last windows + viewManager.closeView() + compare(viewManager.depth, 1) + } +} -- cgit v1.2.3