Skip to content

Commit

Permalink
[PageStack] be pageStack sagety
Browse files Browse the repository at this point in the history
  • Loading branch information
neochapay committed Jul 26, 2018
1 parent 98f52cc commit c6fc74e
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 1 deletion.
5 changes: 5 additions & 0 deletions examples/touch/content/BrokenPage.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import QtQuick 2.6

SomeBrokenPage {

}
4 changes: 4 additions & 0 deletions examples/touch/glacier-components.qml
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ ApplicationWindow {
title: "Notifications"
page: "content/NotificationsPage.qml"
}
ListElement {
title: "Broken page"
page: "content/BrokenPage.qml"
}
}


Expand Down
3 changes: 2 additions & 1 deletion src/controls/controls.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
44 changes: 44 additions & 0 deletions src/controls/qml/ApplicationWindow.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 56 additions & 0 deletions src/controls/qml/ErrorStackPage.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/****************************************************************************************
**
** Copyright (C) 2018 Chupligin Sergey <[email protected]>
** 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
}
}
}

0 comments on commit c6fc74e

Please sign in to comment.