diff options
author | Arseniy Movshev <dodoradio@outlook.com> | 2023-01-08 00:13:02 +0000 |
---|---|---|
committer | Arseniy Movshev <dodoradio@outlook.com> | 2023-01-15 16:58:12 +0000 |
commit | 1f81686f00869dce6cc33e1bc92bf24370ef3e12 (patch) | |
tree | aae5631666d35e87ba707219faba512f31b3934a /src | |
parent | 7dfd22e942567bf151a8d373a64e6aed2e662b89 (diff) |
switch to using json as the carrier format for waypoints
Diffstat (limited to 'src')
-rw-r--r-- | src/MainMapView.qml | 19 | ||||
-rw-r--r-- | src/SetPointPage.qml | 49 | ||||
-rw-r--r-- | src/SettingsPage.qml | 10 |
3 files changed, 50 insertions, 28 deletions
diff --git a/src/MainMapView.qml b/src/MainMapView.qml index 40c42c8..584fcfd 100644 --- a/src/MainMapView.qml +++ b/src/MainMapView.qml @@ -69,18 +69,21 @@ Item { } property MapQuickItem mapItem function updateWaypoints() { - console.log("waypoints updated") - var waypointsList = waypointSource.value.split(">") - for(var i = 0, size = waypointsList.length-1; i < size ; i++){ - var currWaypointData = waypointsList[i].split(";") - var currWaypointCoord = currWaypointData[1].split(",") + clearMapItems() + var waypointsList = JSON.parse(waypointSource.value) + console.log(waypointsList) + for(var i = 0, size = waypointsList.length; i < size ; i++){ + var currWaypointData = waypointsList[i] mapItem = waypoint.createObject(mapView) - mapItem.coordinate = QtPositioning.coordinate(currWaypointCoord[0],currWaypointCoord[1]) + mapItem.coordinate = QtPositioning.coordinate(currWaypointData[1][0],currWaypointData[1][1]) + console.log(mapItem.coordinate) mapItem.iconName = currWaypointData[0] + console.log(currWaypointData[2]) mapItem.iconColor = currWaypointData[2] mapItem.index = i mapView.addMapItem(mapItem) } + console.log("waypoints updated") } } DefaultMapControls { @@ -97,8 +100,8 @@ Item { pageStack.push(setPointPage,{coord: mapView.center}) } } - function editWaypoint(number) { - console.log("invoking the edit page for waypoint number ", number) + function editWaypoint(index) { + pageStack.push(setPointPage,{editMode: true, editIndex: index}) } Component { id: waypoint diff --git a/src/SetPointPage.qml b/src/SetPointPage.qml index 1b5f571..fbd9131 100644 --- a/src/SetPointPage.qml +++ b/src/SetPointPage.qml @@ -13,9 +13,24 @@ Item { id: waypointList key: "/map/waypointList" defaultValue: "" + Component.onCompleted: { + var waypointArray = JSON.parse(waypointList.value) + if (editMode) { + var currWaypointData = waypointArray[editIndex] + root.coord = QtPositioning.coordinate(currWaypointData[1][0],currWaypointData[1][1]) + root.selectedIcon = currWaypointData[0] + root.selectedColor = currWaypointData[2] + } else { + editIndex = waypointArray.length + selectedColor = colours.primary + } + } } property string selectedIcon: "ios-locate-outline" + property string selectedColor property variant coord + property bool editMode: false + property int editIndex Flickable { anchors.fill: parent contentHeight: contentColumn.implicitHeight @@ -77,29 +92,43 @@ Item { Row { height: root.width*0.2 width: parent.width + anchors.horizontalCenter: parent.horizontalCenter Asteroid.IconButton { height: parent.height width: height - iconName: "ios-checkmark-circle-outline" - anchors.horizontalCenter: parent.horizontalCenter - onClicked: appendWayPoint() + iconName: "ios-trash-circle" + visible: editMode + onClicked: removeWaypoint(editIndex) } Asteroid.IconButton { height: parent.height width: height - iconName: "ios-trash-circle" - anchors.horizontalCenter: parent.horizontalCenter - onClicked: removeWaypoint() + iconName: "ios-checkmark-circle-outline" + onClicked: commitChanges(editIndex) } } Item { width: parent.width ; height: root.width*0.2 } } } - function appendWayPoint() { //the colours.primary is currently a placeholder. it would be nice to let users select colours, but I CBA to write a colour picker right now. - var newWayPointString = selectedIcon + ";" + coord.latitude + "," + coord.longitude + ";" + colours.primary + ";" + textBox.text + ";" + Date.now() + ">" - console.log(newWayPointString) - waypointList.value = waypointList.value + newWayPointString + function commitChanges(index) { + var waypointArray = JSON.parse(waypointList.value) + var writebuffer = {} + writebuffer[0] = selectedIcon + writebuffer[1] = [coord.latitude,coord.longitude] + writebuffer[2] = selectedColor //the colours.primary is currently a placeholder. it would be nice to let users select colours, but I CBA to write a colour picker right now + writebuffer[3] = textBox.text + writebuffer[4] = Date.now() + waypointArray[index] = writebuffer + waypointList.value = JSON.stringify(waypointArray) + setPointControls.visible = false + mapControls.visible = true + pageStack.pop(pageStack.currentLayer) + } + function removeWaypoint(index) { + var waypointArray = JSON.parse(waypointList.value) + waypointArray.splice(index) + waypointList.value = JSON.stringify(waypointArray) setPointControls.visible = false mapControls.visible = true pageStack.pop(pageStack.currentLayer) diff --git a/src/SettingsPage.qml b/src/SettingsPage.qml index f196d92..920dc0a 100644 --- a/src/SettingsPage.qml +++ b/src/SettingsPage.qml @@ -20,16 +20,6 @@ Item { LabeledSwitch { width: parent.width height: root.width*0.2 - text: "show zoom controls" - } - LabeledSwitch { - width: parent.width - height: root.width*0.2 - text: "center on GPS" - } - LabeledSwitch { - width: parent.width - height: root.width*0.2 text: "enable compass" Component.onCompleted: checked = enableCompass.value onCheckedChanged: enableCompass.value = checked |