Commit 2569c062 authored by Don Gagne's avatar Don Gagne

parent b6d7a46e
...@@ -64,7 +64,7 @@ public: ...@@ -64,7 +64,7 @@ public:
QList<QGeoCoordinate> coordinateList(void) const; QList<QGeoCoordinate> coordinateList(void) const;
/// Returns the QGeoCoordinate for the vertex specified /// Returns the QGeoCoordinate for the vertex specified
QGeoCoordinate vertexCoordinate(int vertex) const; Q_INVOKABLE QGeoCoordinate vertexCoordinate(int vertex) const;
/// Saves the polygon to the json object. /// Saves the polygon to the json object.
/// @param json Json object to save to /// @param json Json object to save to
......
...@@ -189,20 +189,25 @@ Item { ...@@ -189,20 +189,25 @@ Item {
Menu { Menu {
id: menu id: menu
property int _removeVertexIndex property int _editingVertexIndex: -1
function popUpWithIndex(curIndex) { function popupVertex(curIndex) {
_removeVertexIndex = curIndex menu._editingVertexIndex = curIndex
removeVertexItem.visible = (mapPolygon.count > 3 && _removeVertexIndex >= 0) removeVertexItem.visible = (mapPolygon.count > 3 && menu._editingVertexIndex >= 0)
menu.popup()
}
function popupCenter() {
menu.popup() menu.popup()
} }
MenuItem { MenuItem {
id: removeVertexItem id: removeVertexItem
visible: !_circle
text: qsTr("Remove vertex") text: qsTr("Remove vertex")
onTriggered: { onTriggered: {
if(menu._removeVertexIndex >= 0) { if (menu._editingVertexIndex >= 0) {
mapPolygon.removeVertex(menu._removeVertexIndex) mapPolygon.removeVertex(menu._editingVertexIndex)
} }
} }
} }
...@@ -229,8 +234,14 @@ Item { ...@@ -229,8 +234,14 @@ Item {
MenuItem { MenuItem {
text: qsTr("Edit position..." ) text: qsTr("Edit position..." )
enabled: _circle visible: _circle
onTriggered: qgcView.showDialog(editPositionDialog, qsTr("Edit Position"), qgcView.showDialogDefaultWidth, StandardButton.Close) onTriggered: qgcView.showDialog(editCenterPositionDialog, qsTr("Edit Center Position"), qgcView.showDialogDefaultWidth, StandardButton.Close)
}
MenuItem {
text: qsTr("Edit position..." )
visible: !_circle && menu._editingVertexIndex >= 0
onTriggered: qgcView.showDialog(editVertexPositionDialog, qsTr("Edit Vertex Position"), qgcView.showDialogDefaultWidth, StandardButton.Close)
} }
MenuItem { MenuItem {
...@@ -345,9 +356,7 @@ Item { ...@@ -345,9 +356,7 @@ Item {
} }
} }
onClicked: { onClicked: menu.popupVertex(polygonVertex)
menu.popUpWithIndex(polygonVertex)
}
} }
} }
...@@ -436,11 +445,26 @@ Item { ...@@ -436,11 +445,26 @@ Item {
} }
Component { Component {
id: editPositionDialog id: editCenterPositionDialog
EditPositionDialog { EditPositionDialog {
coordinate: mapPolygon.center coordinate: mapPolygon.center
onCoordinateChanged: mapPolygon.center = coordinate onCoordinateChanged: {
// Prevent spamming signals on vertex changes by setting centerDrag = true when changing center position.
// This also fixes a bug where Qt gets confused by all the signalling and draws a bad visual.
mapPolygon.centerDrag = true
mapPolygon.center = coordinate
mapPolygon.centerDrag = false
}
}
}
Component {
id: editVertexPositionDialog
EditPositionDialog {
coordinate: mapPolygon.vertexCoordinate(menu._editingVertexIndex)
onCoordinateChanged: mapPolygon.adjustVertex(menu._editingVertexIndex, coordinate)
} }
} }
...@@ -454,9 +478,7 @@ Item { ...@@ -454,9 +478,7 @@ Item {
onDragStart: mapPolygon.centerDrag = true onDragStart: mapPolygon.centerDrag = true
onDragStop: mapPolygon.centerDrag = false onDragStop: mapPolygon.centerDrag = false
onClicked: { onClicked: menu.popupCenter()
menu.popUpWithIndex(-1) //-- Don't offer a choice to delete vertex (cur index == -1)
}
function setRadiusFromDialog() { function setRadiusFromDialog() {
var radius = QGroundControl.appSettingsDistanceUnitsToMeters(radiusField.text) var radius = QGroundControl.appSettingsDistanceUnitsToMeters(radiusField.text)
......
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