From 1f81686f00869dce6cc33e1bc92bf24370ef3e12 Mon Sep 17 00:00:00 2001 From: Arseniy Movshev Date: Sun, 8 Jan 2023 00:13:02 +0000 Subject: switch to using json as the carrier format for waypoints --- src/MainMapView.qml | 19 +++++++++++-------- src/SetPointPage.qml | 49 +++++++++++++++++++++++++++++++++++++++---------- src/SettingsPage.qml | 10 ---------- 3 files changed, 50 insertions(+), 28 deletions(-) (limited to 'src') 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 @@ -17,16 +17,6 @@ Item { id: contentColumn anchors.fill: parent Item { width: parent.width ; height: root.width*0.2 } - 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 -- cgit v1.2.3-54-g00ecf