Merge lp:~tpeeters/ubuntu-ui-toolkit/push into lp:ubuntu-ui-toolkit/staging

Proposed by Tim Peeters
Status: Merged
Approved by: Cris Dywan
Approved revision: 1281
Merged at revision: 1278
Proposed branch: lp:~tpeeters/ubuntu-ui-toolkit/push
Merge into: lp:ubuntu-ui-toolkit/staging
Diff against target: 193 lines (+67/-15)
5 files modified
modules/Ubuntu/Components/PageStack.qml (+20/-13)
modules/Ubuntu/Components/PageWrapper.qml (+2/-0)
modules/Ubuntu/Components/PageWrapperUtils.js (+2/-2)
tests/unit_x11/tst_components/MyExternalPage.qml (+22/-0)
tests/unit_x11/tst_components/tst_pagestack_new_header.qml (+21/-0)
To merge this branch: bzr merge lp:~tpeeters/ubuntu-ui-toolkit/push
Reviewer Review Type Date Requested Status
Cris Dywan Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+237074@code.launchpad.net

Commit message

PageStack push returns the pushed page.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
lp:~tpeeters/ubuntu-ui-toolkit/push updated
1275. By Tim Peeters

add unit tests

1276. By Tim Peeters

finish previous action before clearing pagestack

1277. By Tim Peeters

remove debugging code

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
lp:~tpeeters/ubuntu-ui-toolkit/push updated
1278. By Tim Peeters

update docs

1279. By Tim Peeters

update internal docs

1280. By Tim Peeters

update internal docs

1281. By Tim Peeters

kick jenkins

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Cris Dywan (kalikiana) wrote :

Makes sense. Got slightly confused as to activation but re-reading the code resolved it.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'modules/Ubuntu/Components/PageStack.qml'
2--- modules/Ubuntu/Components/PageStack.qml 2014-09-25 22:28:29 +0000
3+++ modules/Ubuntu/Components/PageStack.qml 2014-10-04 16:44:50 +0000
4@@ -14,7 +14,7 @@
5 * along with this program. If not, see <http://www.gnu.org/licenses/>.
6 */
7
8-import QtQuick 2.0
9+import QtQuick 2.2
10 import "stack.js" as Stack
11
12 /*!
13@@ -159,17 +159,22 @@
14 \preliminary
15 Push a page to the stack, and apply the given (optional) properties to the page.
16 The pushed page may be an Item, Component or URL.
17+ The function returns the Item that was pushed, or the Item that was created from
18+ the Component or URL. Depending on the animation of the header, the returned
19+ Page may or may not be active and on top of the PageStack yet.
20 */
21 function push(page, properties) {
22 internal.finishPreviousAction();
23- internal.pageToPush = page;
24- internal.propertiesToPush = properties;
25+ internal.pageWrapper = internal.createWrapper(page, properties);
26+ var pageObject = internal.pageWrapper.object;
27+
28 if (internal.animateHeader && internal.stack.size() > 0) {
29- internal.headStyle.animateOutFinished.connect(internal.createAndPush);
30+ internal.headStyle.animateOutFinished.connect(internal.pushWrapperObject);
31 internal.headStyle.animateOut();
32 } else {
33- internal.createAndPush();
34+ internal.pushWrapperObject();
35 }
36+ return pageObject;
37 }
38
39 /*!
40@@ -197,6 +202,7 @@
41 Deactivate the active page and clear the stack.
42 */
43 function clear() {
44+ internal.finishPreviousAction();
45 while (internal.stack.size() > 0) {
46 internal.stack.top().active = false;
47 if (internal.stack.top().canDestroy) internal.stack.top().destroyObject();
48@@ -239,19 +245,18 @@
49 }
50 }
51
52- // The page and properties to push on the stack when the OUT animation
53- // finishes.
54- property var pageToPush
55- property var propertiesToPush
56+ // The PageWrapper to be pushed on the stack by pushWrapperObject().
57+ property var pageWrapper: null
58
59 // Called when the header animate OUT transition finishes for push() or instantly
60 // when header animations are disabled.
61- function createAndPush() {
62+ function pushWrapperObject() {
63 if (internal.animateHeader) {
64- headStyle.animateOutFinished.disconnect(internal.createAndPush);
65+ headStyle.animateOutFinished.disconnect(internal.pushWrapperObject);
66 }
67 if (internal.stack.size() > 0) internal.stack.top().active = false;
68- internal.stack.push(internal.createWrapper(pageToPush, propertiesToPush));
69+ internal.stack.push(internal.pageWrapper);
70+ internal.pageWrapper = null;
71 internal.stackUpdated();
72 }
73
74@@ -275,9 +280,11 @@
75 function createWrapper(page, properties) {
76 var wrapperComponent = Qt.createComponent("PageWrapper.qml");
77 var wrapperObject = wrapperComponent.createObject(pageStack);
78- wrapperObject.reference = page;
79 wrapperObject.pageStack = pageStack;
80 wrapperObject.properties = properties;
81+ // set reference last because it will trigger creation of the object
82+ // with specified properties.
83+ wrapperObject.reference = page;
84 return wrapperObject;
85 }
86
87
88=== modified file 'modules/Ubuntu/Components/PageWrapper.qml'
89--- modules/Ubuntu/Components/PageWrapper.qml 2014-04-23 08:50:20 +0000
90+++ modules/Ubuntu/Components/PageWrapper.qml 2014-10-04 16:44:50 +0000
91@@ -71,6 +71,7 @@
92 \preliminary
93 Properties are use to initialize a new object, or if reference
94 is already an object, properties are copied to the object when activated.
95+ Set properties before setting the reference.
96 */
97 property var properties
98
99@@ -80,6 +81,7 @@
100 onReferenceChanged: {
101 Utils.deactivate(pageWrapper);
102 if (pageWrapper.object) pageWrapper.object = null;
103+ Utils.initPage(pageWrapper);
104 if (pageWrapper.active && reference) {
105 Utils.activate(pageWrapper);
106 }
107
108=== modified file 'modules/Ubuntu/Components/PageWrapperUtils.js'
109--- modules/Ubuntu/Components/PageWrapperUtils.js 2014-09-03 16:15:53 +0000
110+++ modules/Ubuntu/Components/PageWrapperUtils.js 2014-10-04 16:44:50 +0000
111@@ -24,7 +24,7 @@
112 \internal
113 Initialize pageWrapper.object.
114 */
115-function __initPage(pageWrapper) {
116+function initPage(pageWrapper) {
117 var pageComponent;
118
119 if (pageWrapper.reference.createObject) {
120@@ -74,7 +74,7 @@
121 */
122 function activate(pageWrapper) {
123 if (!pageWrapper.object) {
124- __initPage(pageWrapper);
125+ initPage(pageWrapper);
126 }
127 // Having the same page pushed multiple times on a stack changes
128 // the parent of the page object. Change it back here.
129
130=== added file 'tests/unit_x11/tst_components/MyExternalPage.qml'
131--- tests/unit_x11/tst_components/MyExternalPage.qml 1970-01-01 00:00:00 +0000
132+++ tests/unit_x11/tst_components/MyExternalPage.qml 2014-10-04 16:44:50 +0000
133@@ -0,0 +1,22 @@
134+/*
135+ * Copyright 2012-2014 Canonical Ltd.
136+ *
137+ * This program is free software; you can redistribute it and/or modify
138+ * it under the terms of the GNU Lesser General Public License as published by
139+ * the Free Software Foundation; version 3.
140+ *
141+ * This program is distributed in the hope that it will be useful,
142+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
143+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
144+ * GNU Lesser General Public License for more details.
145+ *
146+ * You should have received a copy of the GNU Lesser General Public License
147+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
148+ */
149+
150+import QtQuick 2.2
151+import Ubuntu.Components 1.1
152+
153+Page {
154+ title: "Page from QML file"
155+}
156
157=== modified file 'tests/unit_x11/tst_components/tst_pagestack_new_header.qml'
158--- tests/unit_x11/tst_components/tst_pagestack_new_header.qml 2014-09-25 14:07:07 +0000
159+++ tests/unit_x11/tst_components/tst_pagestack_new_header.qml 2014-10-04 16:44:50 +0000
160@@ -61,6 +61,13 @@
161 }
162 }
163
164+ Component {
165+ id: pageComponent
166+ Page {
167+ title: "Page from component"
168+ }
169+ }
170+
171 UbuntuTestCase {
172 name: "PageStackAPI"
173 when: windowShown
174@@ -206,5 +213,19 @@
175 pageStack.clear();
176 wait_for_animation();
177 }
178+
179+ function test_push_return_values() {
180+ var pushedPage = pageStack.push(page1);
181+ compare(pushedPage, page1,
182+ "PageStack.push() returns pushed Page");
183+ pushedPage = pageStack.push(pageComponent);
184+ compare(pushedPage.title, "Page from component",
185+ "PageStack.push() returns Page created from Component");
186+ pushedPage = pageStack.push(Qt.resolvedUrl("MyExternalPage.qml"));
187+ compare(pushedPage.title, "Page from QML file",
188+ "PageStack.push() returns Page created from QML file");
189+ pageStack.clear();
190+ wait_for_animation();
191+ }
192 }
193 }

Subscribers

People subscribed via source and target branches