diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-07-02 10:54:52 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2018-07-02 10:54:52 +0200 |
commit | 8735ad516f0262d815ab7e846cb8db67a2aff4f4 (patch) | |
tree | e5a5f932b1db9c3e625efa4bb1b82b757364ab1e | |
parent | fae47bbae2efd0ea40dfd4ca563591c1e4acca5c (diff) | |
download | kube-8735ad516f0262d815ab7e846cb8db67a2aff4f4.tar.gz kube-8735ad516f0262d815ab7e846cb8db67a2aff4f4.zip |
Avoid pushing background views onto the stack
-rw-r--r-- | components/kube/qml/ViewManager.qml | 12 | ||||
-rw-r--r-- | 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 { | |||
51 | return Qt.createComponent(source, Qt.Asynchronous) | 51 | return Qt.createComponent(source, Qt.Asynchronous) |
52 | } | 52 | } |
53 | 53 | ||
54 | function createView(name, properties) { | 54 | function createView(name, properties, push) { |
55 | var component = createComponent(name) | 55 | var component = createComponent(name) |
56 | function finishCreation() { | 56 | function finishCreation() { |
57 | if (component.status == Component.Ready) { | 57 | if (component.status == Component.Ready) { |
58 | var view = component.createObject(root); | 58 | var view = component.createObject(root, properties ? properties : {}); |
59 | viewDict[name] = view | 59 | viewDict[name] = view |
60 | pushView(view, properties, name) | 60 | if (push) { |
61 | pushView(view, properties, name) | ||
62 | } | ||
61 | } else { | 63 | } else { |
62 | console.error("Error while loading the component: ", source, "\nError: ", component.errorString()) | 64 | console.error("Error while loading the component: ", source, "\nError: ", component.errorString()) |
63 | } | 65 | } |
@@ -96,7 +98,7 @@ StackView { | |||
96 | } | 98 | } |
97 | } | 99 | } |
98 | 100 | ||
99 | createView(name, properties) | 101 | createView(name, properties, true) |
100 | } | 102 | } |
101 | 103 | ||
102 | function showView(name, properties) { | 104 | function showView(name, properties) { |
@@ -104,7 +106,7 @@ StackView { | |||
104 | } | 106 | } |
105 | 107 | ||
106 | function prepareViewInBackground(name, properties) { | 108 | function prepareViewInBackground(name, properties) { |
107 | createView(name, properties) | 109 | createView(name, properties, false) |
108 | } | 110 | } |
109 | 111 | ||
110 | function replaceView(name, properties) { | 112 | 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 { | |||
29 | height: 400 | 29 | height: 400 |
30 | name: "ViewManager" | 30 | name: "ViewManager" |
31 | 31 | ||
32 | ViewManager { | 32 | Component { |
33 | id: viewManager | 33 | id: viewManagerComponent |
34 | anchors.fill: parent | 34 | ViewManager { |
35 | id: viewManager | ||
36 | anchors.fill: parent | ||
35 | 37 | ||
36 | function createComponent(name) { | 38 | function createComponent(name) { |
37 | return testViewComponent | 39 | return testViewComponent |
38 | } | 40 | } |
39 | 41 | ||
40 | Component { | 42 | Component { |
41 | id: testViewComponent | 43 | id: testViewComponent |
42 | Rectangle { | 44 | Rectangle { |
43 | property string test: "not initialized" | 45 | property string test: "not initialized" |
46 | } | ||
44 | } | 47 | } |
45 | } | 48 | } |
46 | } | 49 | } |
47 | 50 | ||
48 | 51 | ||
49 | function test_testStack() { | 52 | function test_1testStack() { |
53 | var viewManager = createTemporaryObject(viewManagerComponent, viewmanagerTestcase, {}) | ||
54 | |||
50 | viewManager.showView("view1", {test: "test1"}) | 55 | viewManager.showView("view1", {test: "test1"}) |
51 | compare(viewManager.currentViewName, "view1") | 56 | compare(viewManager.currentViewName, "view1") |
52 | compare(viewManager.currentItem.test, "test1") | 57 | compare(viewManager.currentItem.test, "test1") |
@@ -79,8 +84,35 @@ TestCase { | |||
79 | compare(viewManager.currentItem.test, "test1") | 84 | compare(viewManager.currentItem.test, "test1") |
80 | compare(viewManager.depth, 1) | 85 | compare(viewManager.depth, 1) |
81 | 86 | ||
82 | //Never close the last windows | 87 | //Never close the last view |
83 | viewManager.closeView() | 88 | viewManager.closeView() |
84 | compare(viewManager.depth, 1) | 89 | compare(viewManager.depth, 1) |
85 | } | 90 | } |
91 | |||
92 | function test_2testBackgroundView() { | ||
93 | var viewManager = createTemporaryObject(viewManagerComponent, viewmanagerTestcase, {}) | ||
94 | |||
95 | viewManager.prepareViewInBackground("backgroundView", {test: "background"}) | ||
96 | |||
97 | viewManager.showView("view1", {test: "test1"}) | ||
98 | compare(viewManager.currentViewName, "view1") | ||
99 | compare(viewManager.currentItem.test, "test1") | ||
100 | compare(viewManager.depth, 1) | ||
101 | |||
102 | viewManager.showView("backgroundView") | ||
103 | compare(viewManager.currentViewName, "backgroundView") | ||
104 | compare(viewManager.currentItem.test, "background") | ||
105 | compare(viewManager.depth, 2) | ||
106 | |||
107 | viewManager.closeView() | ||
108 | compare(viewManager.currentViewName, "view1") | ||
109 | compare(viewManager.currentItem.test, "test1") | ||
110 | compare(viewManager.depth, 1) | ||
111 | |||
112 | //Never close the last view | ||
113 | viewManager.closeView() | ||
114 | compare(viewManager.currentViewName, "view1") | ||
115 | compare(viewManager.currentItem.test, "test1") | ||
116 | compare(viewManager.depth, 1) | ||
117 | } | ||
86 | } | 118 | } |