mobile/page-selection: consistently use showPage to select a page

We still used pageStack.push() all over the place.

Also, in showPage, disable the map hack if the user actively picks a
different page.

This should fix an issue where the user picked the map and then tried to
add a dive to the dive list - and instead of the dive edit was shown the
map again.

Reported-by: Hartley Horwitz <hhrwtz@gmail.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2020-03-25 20:29:05 -07:00
parent 69272eefa8
commit f2a48e813f
2 changed files with 17 additions and 20 deletions

View file

@ -65,12 +65,7 @@ Kirigami.ScrollablePage {
manager.appendTextToLog("clicked on dive") manager.appendTextToLog("clicked on dive")
if (detailsWindow.state === "view") { if (detailsWindow.state === "view") {
manager.selectRow(model.row); manager.selectRow(model.row);
// switch to detailsWindow (or push it if it's not in the stack) showPage(detailsWindow)
var i = rootItem.pageIndex(detailsWindow)
if (i === -1)
pageStack.push(detailsWindow)
else
pageStack.currentIndex = i
} }
} }
} }
@ -305,7 +300,7 @@ Kirigami.ScrollablePage {
tripEditWindow.tripId = currentItem.myData.tripId tripEditWindow.tripId = currentItem.myData.tripId
tripEditWindow.tripLocation = currentItem.myData.tripLocation tripEditWindow.tripLocation = currentItem.myData.tripLocation
tripEditWindow.tripNotes = currentItem.myData.tripNotes tripEditWindow.tripNotes = currentItem.myData.tripNotes
pageStack.push(tripEditWindow) showPage(tripEditWindow)
} }
} }

View file

@ -78,6 +78,8 @@ Kirigami.ApplicationWindow {
} }
function showPage(page) { function showPage(page) {
if (page !== mapPage)
hackToOpenMap = 0 // we really want a different page
if (globalDrawer.drawerOpen) if (globalDrawer.drawerOpen)
globalDrawer.close() globalDrawer.close()
var i=pageIndex(page) var i=pageIndex(page)
@ -139,7 +141,7 @@ Kirigami.ApplicationWindow {
detailsWindow.startpressure = [] detailsWindow.startpressure = []
detailsWindow.endpressure = [] detailsWindow.endpressure = []
detailsWindow.gpsCheckbox = false detailsWindow.gpsCheckbox = false
pageStack.push(detailsWindow) showPage(detailsWindow)
} }
contextDrawer: Kirigami.ContextDrawer { contextDrawer: Kirigami.ContextDrawer {
@ -152,7 +154,7 @@ Kirigami.ApplicationWindow {
height: rootItem.height height: rootItem.height
rightPadding: 0 rightPadding: 0
enabled: (Backend.cloud_verification_status === Enums.CS_NOCLOUD || enabled: (Backend.cloud_verification_status === Enums.CS_NOCLOUD ||
Backend.cloud_verification_status === Enums.CS_VERIFIED) Backend.cloud_verification_status === Enums.CS_VERIFIED)
topContent: Image { topContent: Image {
source: "qrc:/qml/icons/dive.jpg" source: "qrc:/qml/icons/dive.jpg"
Layout.fillWidth: true Layout.fillWidth: true
@ -269,7 +271,7 @@ Kirigami.ApplicationWindow {
onTriggered: { onTriggered: {
globalDrawer.close() globalDrawer.close()
downloadFromDc.dcImportModel.clearTable() downloadFromDc.dcImportModel.clearTable()
pageStack.push(downloadFromDc) showPage(downloadFromDc)
} }
} }
Kirigami.Action { Kirigami.Action {
@ -328,7 +330,7 @@ if you have network connectivity and want to sync your data to cloud storage."),
text: qsTr("Dive summary") text: qsTr("Dive summary")
onTriggered: { onTriggered: {
globalDrawer.close() globalDrawer.close()
pageStack.push(diveSummaryWindow) showPage(diveSummaryWindow)
detailsWindow.endEditMode() detailsWindow.endEditMode()
} }
} }
@ -339,7 +341,7 @@ if you have network connectivity and want to sync your data to cloud storage."),
text: qsTr("Export") text: qsTr("Export")
onTriggered: { onTriggered: {
globalDrawer.close() globalDrawer.close()
pageStack.push(exportWindow) showPage(exportWindow)
detailsWindow.endEditMode() detailsWindow.endEditMode()
} }
} }
@ -375,7 +377,7 @@ if you have network connectivity and want to sync your data to cloud storage."),
globalDrawer.close() globalDrawer.close()
returnTopPage() returnTopPage()
manager.populateGpsData(); manager.populateGpsData();
pageStack.push(gpsWindow) showPage(gpsWindow)
} }
} }
@ -410,7 +412,7 @@ if you have network connectivity and want to sync your data to cloud storage."),
globalDrawer.close() globalDrawer.close()
settingsWindow.defaultCylinderModel = manager.cylinderInit settingsWindow.defaultCylinderModel = manager.cylinderInit
PrefEquipment.default_cylinder === "" ? defaultCylinderIndex = "-1" : defaultCylinderIndex = settingsWindow.defaultCylinderModel.indexOf(PrefEquipment.default_cylinder) PrefEquipment.default_cylinder === "" ? defaultCylinderIndex = "-1" : defaultCylinderIndex = settingsWindow.defaultCylinderModel.indexOf(PrefEquipment.default_cylinder)
pageStack.push(settingsWindow) showPage(settingsWindow)
detailsWindow.endEditMode() detailsWindow.endEditMode()
} }
}, },
@ -433,7 +435,7 @@ if you have network connectivity and want to sync your data to cloud storage."),
text: qsTr("About") text: qsTr("About")
onTriggered: { onTriggered: {
globalDrawer.close() globalDrawer.close()
pageStack.push(aboutWindow) showPage(aboutWindow)
detailsWindow.endEditMode() detailsWindow.endEditMode()
} }
} }
@ -488,7 +490,7 @@ if you have network connectivity and want to sync your data to cloud storage."),
text: qsTr("App log") text: qsTr("App log")
onTriggered: { onTriggered: {
globalDrawer.close() globalDrawer.close()
pageStack.push(logWindow) showPage(logWindow)
} }
} }
Kirigami.Action { Kirigami.Action {
@ -511,7 +513,7 @@ if you have network connectivity and want to sync your data to cloud storage."),
text: qsTr("Theme information") text: qsTr("Theme information")
onTriggered: { onTriggered: {
globalDrawer.close() globalDrawer.close()
pageStack.push(themetest) showPage(themetest)
} }
} }
@ -649,7 +651,7 @@ if you have network connectivity and want to sync your data to cloud storage."),
/* I really want an enum, but those are painful in QML, so let's use numbers /* I really want an enum, but those are painful in QML, so let's use numbers
* 0 (Otherpage) - the last page selected was a non-map page * 0 (Otherpage) - the last page selected was a non-map page
* 1 (MapSelected) - the map page was selected by the user * 1 (MapSelected) - the map page was selected by the user
* 2 (MapForced) - the map page was forced by out hack * 2 (MapForced) - the map page was forced by this hack
*/ */
pageStack.onCurrentItemChanged: { pageStack.onCurrentItemChanged: {
@ -671,8 +673,8 @@ if you have network connectivity and want to sync your data to cloud storage."),
manager.appendTextToLog("pageStack forced back to map") manager.appendTextToLog("pageStack forced back to map")
} }
} else if (pageStack.currentItem.objectName !== mapPage.objectName && } else if (pageStack.currentItem.objectName !== mapPage.objectName &&
pageStack.lastItem.objectName === mapPage.objectName && pageStack.lastItem.objectName === mapPage.objectName &&
hackToOpenMap === 1 /* MapSelected */) { hackToOpenMap === 1 /* MapSelected */) {
// if we just picked the mapPage and are suddenly back on a different page // if we just picked the mapPage and are suddenly back on a different page
// force things back to the mapPage // force things back to the mapPage
manager.appendTextToLog("pageStack wrong page, switching back to map") manager.appendTextToLog("pageStack wrong page, switching back to map")