diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-06-30 09:33:46 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-06-30 09:33:46 +0200 |
commit | c56b187779b53429e868c94e55149c14676a31cb (patch) | |
tree | 591456127e7c15b7a3490362690878902fcb95d5 /components | |
parent | 93859a60f6254154502db56f3629c4c87367da1c (diff) | |
download | kube-c56b187779b53429e868c94e55149c14676a31cb.tar.gz kube-c56b187779b53429e868c94e55149c14676a31cb.zip |
Fixed and tested the viewmanager.
We failed to forward the properties to the view.
Diffstat (limited to 'components')
-rw-r--r-- | components/kube/qml/ViewManager.qml | 13 | ||||
-rw-r--r-- | components/kube/tests/tst_viewmanagertest.qml | 86 |
2 files changed, 94 insertions, 5 deletions
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 { | |||
44 | item.objectName = name | 44 | item.objectName = name |
45 | } | 45 | } |
46 | 46 | ||
47 | function createView(name, properties) { | 47 | function createComponent(name) { |
48 | //Creating a new view | 48 | //Creating a new view |
49 | var source = extensionModel.findSource(name, "View.qml"); | 49 | var source = extensionModel.findSource(name, "View.qml"); |
50 | //On windows it will be async anyways, so just always create it async | 50 | //On windows it will be async anyways, so just always create it async |
51 | var component = Qt.createComponent(source, Qt.Asynchronous) | 51 | return Qt.createComponent(source, Qt.Asynchronous) |
52 | } | ||
52 | 53 | ||
54 | function createView(name, properties) { | ||
55 | var component = createComponent(name) | ||
53 | function finishCreation() { | 56 | function finishCreation() { |
54 | if (component.status == Component.Ready) { | 57 | if (component.status == Component.Ready) { |
55 | var view = component.createObject(root); | 58 | var view = component.createObject(root); |
@@ -93,7 +96,7 @@ StackView { | |||
93 | } | 96 | } |
94 | } | 97 | } |
95 | 98 | ||
96 | createView(name) | 99 | createView(name, properties) |
97 | } | 100 | } |
98 | 101 | ||
99 | function showView(name, properties) { | 102 | function showView(name, properties) { |
@@ -110,8 +113,8 @@ StackView { | |||
110 | 113 | ||
111 | function closeView() { | 114 | function closeView() { |
112 | //The initial view remains | 115 | //The initial view remains |
113 | if (kubeViews.depth > 1) { | 116 | if (root.depth > 1) { |
114 | var item = kubeViews.pop(StackView.Immediate) | 117 | var item = root.pop(StackView.Immediate) |
115 | viewDict[item.objectName] = null | 118 | viewDict[item.objectName] = null |
116 | item.destroy() | 119 | item.destroy() |
117 | } | 120 | } |
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 @@ | |||
1 | /* | ||
2 | * Copyright 2017 Christian Mollekopf <mollekopf@kolabsys.com> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU Library General Public License as | ||
6 | * published by the Free Software Foundation; either version 2, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU Library General Public License for more details | ||
13 | * | ||
14 | * You should have received a copy of the GNU Library General Public | ||
15 | * License along with this program; if not, write to the | ||
16 | * Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
18 | */ | ||
19 | |||
20 | import QtQuick 2.7 | ||
21 | import QtTest 1.0 | ||
22 | import org.kube.framework 1.0 as Kube | ||
23 | import org.kube.test 1.0 | ||
24 | import "../qml" | ||
25 | |||
26 | TestCase { | ||
27 | id: viewmanagerTestcase | ||
28 | width: 400 | ||
29 | height: 400 | ||
30 | name: "ViewManager" | ||
31 | |||
32 | ViewManager { | ||
33 | id: viewManager | ||
34 | anchors.fill: parent | ||
35 | |||
36 | function createComponent(name) { | ||
37 | return testViewComponent | ||
38 | } | ||
39 | |||
40 | Component { | ||
41 | id: testViewComponent | ||
42 | Rectangle { | ||
43 | property string test: "not initialized" | ||
44 | } | ||
45 | } | ||
46 | } | ||
47 | |||
48 | |||
49 | function test_testStack() { | ||
50 | viewManager.showView("view1", {test: "test1"}) | ||
51 | compare(viewManager.currentViewName, "view1") | ||
52 | compare(viewManager.currentItem.test, "test1") | ||
53 | compare(viewManager.depth, 1) | ||
54 | |||
55 | viewManager.showView("view2", {test: "test2"}) | ||
56 | compare(viewManager.currentViewName, "view2") | ||
57 | compare(viewManager.currentItem.test, "test2") | ||
58 | compare(viewManager.depth, 2) | ||
59 | |||
60 | viewManager.replaceView("view3", {test: "test3"}) | ||
61 | compare(viewManager.currentViewName, "view3") | ||
62 | compare(viewManager.currentItem.test, "test3") | ||
63 | compare(viewManager.depth, 2) | ||
64 | |||
65 | //Switch back to the old view (properties are maintained) | ||
66 | viewManager.showView("view2") | ||
67 | compare(viewManager.currentViewName, "view2") | ||
68 | compare(viewManager.currentItem.test, "test2") | ||
69 | compare(viewManager.depth, 2) | ||
70 | |||
71 | //And replace view3 (properties are not maintained) | ||
72 | viewManager.replaceView("view3", {test: "test4"}) | ||
73 | compare(viewManager.currentViewName, "view3") | ||
74 | compare(viewManager.currentItem.test, "test4") | ||
75 | compare(viewManager.depth, 2) | ||
76 | |||
77 | viewManager.closeView() | ||
78 | compare(viewManager.currentViewName, "view1") | ||
79 | compare(viewManager.currentItem.test, "test1") | ||
80 | compare(viewManager.depth, 1) | ||
81 | |||
82 | //Never close the last windows | ||
83 | viewManager.closeView() | ||
84 | compare(viewManager.depth, 1) | ||
85 | } | ||
86 | } | ||