Commit 35fb4ccf authored by Nicolas Fella's avatar Nicolas Fella

Refactor LocationQueryPage to take a title and callback

parent e7bbf134
...@@ -29,15 +29,7 @@ Kirigami.Page ...@@ -29,15 +29,7 @@ Kirigami.Page
property string type property string type
property bool showCached: true property bool showCached: true
title: { property var callback
if (type == "start") {
return i18n("Search for start location")
}
if (type == "destination") {
return i18n("Search for destination location")
}
return "deadbeef"
}
header: TextField { header: TextField {
id: queryTextField id: queryTextField
...@@ -58,12 +50,7 @@ Kirigami.Page ...@@ -58,12 +50,7 @@ Kirigami.Page
reserveSpaceForIcon: false reserveSpaceForIcon: false
onClicked: { onClicked: {
_locationCache.addCachedLocation(modelData) _locationCache.addCachedLocation(modelData)
callback(modelData)
if (type == "start") {
_queryController.start = modelData
} else if (type == "destination") {
_queryController.destination = modelData
}
pageStack.pop() pageStack.pop()
} }
} }
...@@ -83,12 +70,7 @@ Kirigami.Page ...@@ -83,12 +70,7 @@ Kirigami.Page
reserveSpaceForIcon: false reserveSpaceForIcon: false
onClicked: { onClicked: {
_locationCache.addCachedLocation(object) _locationCache.addCachedLocation(object)
callback(object)
if (type == "start") {
_queryController.start = object
} else if (type == "destination") {
_queryController.destination = object
}
pageStack.pop() pageStack.pop()
} }
} }
......
...@@ -36,6 +36,16 @@ Kirigami.Page ...@@ -36,6 +36,16 @@ Kirigami.Page
onTriggered: pageStack.push(Qt.resolvedUrl("ConnectionsPage.qml")) onTriggered: pageStack.push(Qt.resolvedUrl("ConnectionsPage.qml"))
} }
function startPicked(data) {
console.log("Picked start: " + data.name)
_queryController.start = data
}
function destinationPicked(data) {
console.log("Picked destination" + data.name)
_queryController.destination = data
}
ColumnLayout { ColumnLayout {
width: parent.width width: parent.width
...@@ -46,15 +56,16 @@ Kirigami.Page ...@@ -46,15 +56,16 @@ Kirigami.Page
Button { Button {
Layout.fillWidth: true Layout.fillWidth: true
text: _queryController.start.name ? _queryController.start.name : i18n("Pick start") text: _queryController.start.name ? _queryController.start.name : i18n("Pick start")
onClicked: pageStack.push(Qt.resolvedUrl("LocationQueryPage.qml"), {type: "start"}) onClicked: pageStack.push(Qt.resolvedUrl("LocationQueryPage.qml"), {title: i18n("Search for start location"), callback: startPicked})
} }
Label { Label {
text: "To:" text: "To:"
} }
Button { Button {
Layout.fillWidth: true Layout.fillWidth: true
text: _queryController.destination.name ? _queryController.destination.name : i18n("Pick destination") text: _queryController.destination.name ? _queryController.destination.name : i18n("Pick destination")
onClicked: pageStack.push(Qt.resolvedUrl("LocationQueryPage.qml"), {type: "destination"}) onClicked: pageStack.push(Qt.resolvedUrl("LocationQueryPage.qml"), {title: i18n("Search for destination location"), callback: destinationPicked})
} }
Label { Label {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment