From c6fc74ed3442c9892a8bb5c2293d0696e869f64a Mon Sep 17 00:00:00 2001 From: Sergey Chupligin Date: Thu, 26 Jul 2018 12:47:25 +0300 Subject: [PATCH] [PageStack] be pageStack sagety --- examples/touch/content/BrokenPage.qml | 5 +++ examples/touch/glacier-components.qml | 4 ++ src/controls/controls.pro | 3 +- src/controls/qml/ApplicationWindow.qml | 44 ++++++++++++++++++++ src/controls/qml/ErrorStackPage.qml | 56 ++++++++++++++++++++++++++ 5 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 examples/touch/content/BrokenPage.qml create mode 100644 src/controls/qml/ErrorStackPage.qml diff --git a/examples/touch/content/BrokenPage.qml b/examples/touch/content/BrokenPage.qml new file mode 100644 index 0000000..3d26bb4 --- /dev/null +++ b/examples/touch/content/BrokenPage.qml @@ -0,0 +1,5 @@ +import QtQuick 2.6 + +SomeBrokenPage { + +} diff --git a/examples/touch/glacier-components.qml b/examples/touch/glacier-components.qml index 2c52e0c..6b886f2 100644 --- a/examples/touch/glacier-components.qml +++ b/examples/touch/glacier-components.qml @@ -133,6 +133,10 @@ ApplicationWindow { title: "Notifications" page: "content/NotificationsPage.qml" } + ListElement { + title: "Broken page" + page: "content/BrokenPage.qml" + } } diff --git a/src/controls/controls.pro b/src/controls/controls.pro index 1ddad92..9a2ed7d 100644 --- a/src/controls/controls.pro +++ b/src/controls/controls.pro @@ -27,8 +27,9 @@ QML_FILES += \ qml/DatePicker.qml \ qml/TimePicker.qml \ qml/ScrollDecorator.qml \ - qml/dialogs/QueryDialog.qml \ qml/TextField.qml \ + qml/ErrorStackPage.qml \ + qml/dialogs/QueryDialog.qml \ qml/dialogs/SelectionDialog.qml \ qml/dialogs/Dialog.qml diff --git a/src/controls/qml/ApplicationWindow.qml b/src/controls/qml/ApplicationWindow.qml index 1984916..6873fa2 100644 --- a/src/controls/qml/ApplicationWindow.qml +++ b/src/controls/qml/ApplicationWindow.qml @@ -66,6 +66,50 @@ NemoWindow { } } + //Safety version of pageStack.push - if we can't load component - show error page page with + //error message and back button + + function push(url, params) { + if(!params){ + params = {} + } + console.log("##", url, params, pageStack) + var component = Qt.createComponent(url) + if (component.status === Component.Ready) { + pageStack.push(component.createObject(pageStack, params)) + } else { + console.warn("Error loading component", url, component.errorString()) + pageStack.push(Qt.resolvedUrl("ErrorStackPage.qml"), {error: component.errorString()}) + } + } + + Timer { + id: _errorTimer + property string errorString + interval: 50 + repeat: false + onTriggered: { + pageStack.replace(Qt.resolvedUrl("ErrorStackPage.qml"), {error: errorString}) + errorString = "" + } + } + + Connections { + target: pageStack + onBusyChanged: { + if (_errorTimer.errorString && !pageStack.busy) { + _errorTimer.start() + } + } + + onCurrentItemChanged: { + var qmltype = pageStack.currentItem.toString() + if (qmltype.slice(0, 10) === "QQuickText") { + _errorTimer.errorString = pageStack.currentItem.text + } + } + } + function orientationConstraintsChanged() { //if the current orientation is not allowed anymore, fallback to an allowed one diff --git a/src/controls/qml/ErrorStackPage.qml b/src/controls/qml/ErrorStackPage.qml new file mode 100644 index 0000000..d25acf2 --- /dev/null +++ b/src/controls/qml/ErrorStackPage.qml @@ -0,0 +1,56 @@ +/**************************************************************************************** +** +** Copyright (C) 2018 Chupligin Sergey +** All rights reserved. +** +** You may use this file under the terms of BSD license as follows: +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions are met: +** * Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** * Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** * Neither the name of the author nor the +** names of its contributors may be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +** WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +** DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR +** ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +** (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +** LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +** +****************************************************************************************/ + +import QtQuick 2.6 +import QtQuick.Controls.Styles.Nemo 1.0 + +Page { + id: root + + property alias error: errorLabel.text + + headerTools: HeaderToolsLayout { + showBackButton: true; + title: qsTr("Error") + } + + Column { + spacing: 40 + width: parent.width + anchors.centerIn: parent + Label { + id: errorLabel + width: parent.width + text: qsTr("We got some error") + wrapMode: Text.WrapAtWordBoundaryOrAnywhere + } + } +}