=== modified file 'modules/Ubuntu/Components/PageStack.qml'
--- modules/Ubuntu/Components/PageStack.qml 2014-09-25 22:28:29 +0000
+++ modules/Ubuntu/Components/PageStack.qml 2014-10-04 16:44:50 +0000
@@ -14,7 +14,7 @@
* along with this program. If not, see .
*/
-import QtQuick 2.0
+import QtQuick 2.2
import "stack.js" as Stack
/*!
@@ -159,17 +159,22 @@
\preliminary
Push a page to the stack, and apply the given (optional) properties to the page.
The pushed page may be an Item, Component or URL.
+ The function returns the Item that was pushed, or the Item that was created from
+ the Component or URL. Depending on the animation of the header, the returned
+ Page may or may not be active and on top of the PageStack yet.
*/
function push(page, properties) {
internal.finishPreviousAction();
- internal.pageToPush = page;
- internal.propertiesToPush = properties;
+ internal.pageWrapper = internal.createWrapper(page, properties);
+ var pageObject = internal.pageWrapper.object;
+
if (internal.animateHeader && internal.stack.size() > 0) {
- internal.headStyle.animateOutFinished.connect(internal.createAndPush);
+ internal.headStyle.animateOutFinished.connect(internal.pushWrapperObject);
internal.headStyle.animateOut();
} else {
- internal.createAndPush();
+ internal.pushWrapperObject();
}
+ return pageObject;
}
/*!
@@ -197,6 +202,7 @@
Deactivate the active page and clear the stack.
*/
function clear() {
+ internal.finishPreviousAction();
while (internal.stack.size() > 0) {
internal.stack.top().active = false;
if (internal.stack.top().canDestroy) internal.stack.top().destroyObject();
@@ -239,19 +245,18 @@
}
}
- // The page and properties to push on the stack when the OUT animation
- // finishes.
- property var pageToPush
- property var propertiesToPush
+ // The PageWrapper to be pushed on the stack by pushWrapperObject().
+ property var pageWrapper: null
// Called when the header animate OUT transition finishes for push() or instantly
// when header animations are disabled.
- function createAndPush() {
+ function pushWrapperObject() {
if (internal.animateHeader) {
- headStyle.animateOutFinished.disconnect(internal.createAndPush);
+ headStyle.animateOutFinished.disconnect(internal.pushWrapperObject);
}
if (internal.stack.size() > 0) internal.stack.top().active = false;
- internal.stack.push(internal.createWrapper(pageToPush, propertiesToPush));
+ internal.stack.push(internal.pageWrapper);
+ internal.pageWrapper = null;
internal.stackUpdated();
}
@@ -275,9 +280,11 @@
function createWrapper(page, properties) {
var wrapperComponent = Qt.createComponent("PageWrapper.qml");
var wrapperObject = wrapperComponent.createObject(pageStack);
- wrapperObject.reference = page;
wrapperObject.pageStack = pageStack;
wrapperObject.properties = properties;
+ // set reference last because it will trigger creation of the object
+ // with specified properties.
+ wrapperObject.reference = page;
return wrapperObject;
}
=== modified file 'modules/Ubuntu/Components/PageWrapper.qml'
--- modules/Ubuntu/Components/PageWrapper.qml 2014-04-23 08:50:20 +0000
+++ modules/Ubuntu/Components/PageWrapper.qml 2014-10-04 16:44:50 +0000
@@ -71,6 +71,7 @@
\preliminary
Properties are use to initialize a new object, or if reference
is already an object, properties are copied to the object when activated.
+ Set properties before setting the reference.
*/
property var properties
@@ -80,6 +81,7 @@
onReferenceChanged: {
Utils.deactivate(pageWrapper);
if (pageWrapper.object) pageWrapper.object = null;
+ Utils.initPage(pageWrapper);
if (pageWrapper.active && reference) {
Utils.activate(pageWrapper);
}
=== modified file 'modules/Ubuntu/Components/PageWrapperUtils.js'
--- modules/Ubuntu/Components/PageWrapperUtils.js 2014-09-03 16:15:53 +0000
+++ modules/Ubuntu/Components/PageWrapperUtils.js 2014-10-04 16:44:50 +0000
@@ -24,7 +24,7 @@
\internal
Initialize pageWrapper.object.
*/
-function __initPage(pageWrapper) {
+function initPage(pageWrapper) {
var pageComponent;
if (pageWrapper.reference.createObject) {
@@ -74,7 +74,7 @@
*/
function activate(pageWrapper) {
if (!pageWrapper.object) {
- __initPage(pageWrapper);
+ initPage(pageWrapper);
}
// Having the same page pushed multiple times on a stack changes
// the parent of the page object. Change it back here.
=== added file 'tests/unit_x11/tst_components/MyExternalPage.qml'
--- tests/unit_x11/tst_components/MyExternalPage.qml 1970-01-01 00:00:00 +0000
+++ tests/unit_x11/tst_components/MyExternalPage.qml 2014-10-04 16:44:50 +0000
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2012-2014 Canonical Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; version 3.
+ *
+ * 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 Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see .
+ */
+
+import QtQuick 2.2
+import Ubuntu.Components 1.1
+
+Page {
+ title: "Page from QML file"
+}
=== modified file 'tests/unit_x11/tst_components/tst_pagestack_new_header.qml'
--- tests/unit_x11/tst_components/tst_pagestack_new_header.qml 2014-09-25 14:07:07 +0000
+++ tests/unit_x11/tst_components/tst_pagestack_new_header.qml 2014-10-04 16:44:50 +0000
@@ -61,6 +61,13 @@
}
}
+ Component {
+ id: pageComponent
+ Page {
+ title: "Page from component"
+ }
+ }
+
UbuntuTestCase {
name: "PageStackAPI"
when: windowShown
@@ -206,5 +213,19 @@
pageStack.clear();
wait_for_animation();
}
+
+ function test_push_return_values() {
+ var pushedPage = pageStack.push(page1);
+ compare(pushedPage, page1,
+ "PageStack.push() returns pushed Page");
+ pushedPage = pageStack.push(pageComponent);
+ compare(pushedPage.title, "Page from component",
+ "PageStack.push() returns Page created from Component");
+ pushedPage = pageStack.push(Qt.resolvedUrl("MyExternalPage.qml"));
+ compare(pushedPage.title, "Page from QML file",
+ "PageStack.push() returns Page created from QML file");
+ pageStack.clear();
+ wait_for_animation();
+ }
}
}