diff --git a/ChangeLog.md b/ChangeLog.md index 4021b91..d6c1bad 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -11,6 +11,7 @@ Note: This file only contains high level features or important fixes. * Added Chinese and Turkish localization and partial German localization. * Make Distance to GCS available for display from instrument panel. * Make Heading to Home available for display from instrument panel. +* Edit Position dialog available on polygon vertices. ## 3.4 diff --git a/src/MissionManager/QGCMapPolygon.cc b/src/MissionManager/QGCMapPolygon.cc index ba3619a..26c298a 100644 --- a/src/MissionManager/QGCMapPolygon.cc +++ b/src/MissionManager/QGCMapPolygon.cc @@ -92,11 +92,11 @@ void QGCMapPolygon::clear(void) void QGCMapPolygon::adjustVertex(int vertexIndex, const QGeoCoordinate coordinate) { _polygonPath[vertexIndex] = QVariant::fromValue(coordinate); + _polygonModel.value(vertexIndex)->setCoordinate(coordinate); if (!_centerDrag) { // When dragging center we don't signal path changed until add vertices are updated emit pathChanged(); } - _polygonModel.value(vertexIndex)->setCoordinate(coordinate); setDirty(true); } diff --git a/src/MissionManager/QGCMapPolygon.h b/src/MissionManager/QGCMapPolygon.h index 5d1d103..005823f 100644 --- a/src/MissionManager/QGCMapPolygon.h +++ b/src/MissionManager/QGCMapPolygon.h @@ -64,7 +64,7 @@ public: QList coordinateList(void) const; /// 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. /// @param json Json object to save to diff --git a/src/MissionManager/QGCMapPolygonVisuals.qml b/src/MissionManager/QGCMapPolygonVisuals.qml index d82db1e..f58aa56 100644 --- a/src/MissionManager/QGCMapPolygonVisuals.qml +++ b/src/MissionManager/QGCMapPolygonVisuals.qml @@ -189,20 +189,25 @@ Item { Menu { id: menu - property int _removeVertexIndex + property int _editingVertexIndex: -1 - function popUpWithIndex(curIndex) { - _removeVertexIndex = curIndex - removeVertexItem.visible = (mapPolygon.count > 3 && _removeVertexIndex >= 0) + function popupVertex(curIndex) { + menu._editingVertexIndex = curIndex + removeVertexItem.visible = (mapPolygon.count > 3 && menu._editingVertexIndex >= 0) + menu.popup() + } + + function popupCenter() { menu.popup() } MenuItem { id: removeVertexItem + visible: !_circle text: qsTr("Remove vertex") onTriggered: { - if(menu._removeVertexIndex >= 0) { - mapPolygon.removeVertex(menu._removeVertexIndex) + if (menu._editingVertexIndex >= 0) { + mapPolygon.removeVertex(menu._editingVertexIndex) } } } @@ -229,8 +234,14 @@ Item { MenuItem { text: qsTr("Edit position..." ) - enabled: _circle - onTriggered: qgcView.showDialog(editPositionDialog, qsTr("Edit Position"), qgcView.showDialogDefaultWidth, StandardButton.Close) + visible: _circle + 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 { @@ -345,9 +356,7 @@ Item { } } - onClicked: { - menu.popUpWithIndex(polygonVertex) - } + onClicked: menu.popupVertex(polygonVertex) } } @@ -436,11 +445,26 @@ Item { } Component { - id: editPositionDialog + id: editCenterPositionDialog EditPositionDialog { 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 { onDragStart: mapPolygon.centerDrag = true onDragStop: mapPolygon.centerDrag = false - onClicked: { - menu.popUpWithIndex(-1) //-- Don't offer a choice to delete vertex (cur index == -1) - } + onClicked: menu.popupCenter() function setRadiusFromDialog() { var radius = QGroundControl.appSettingsDistanceUnitsToMeters(radiusField.text)