diff --git a/src/MissionManager/QGCMapPolygon.cc b/src/MissionManager/QGCMapPolygon.cc index 32001b63e3f1ab7e88e0821499604c2dce70c308..acd949a0f94e9a3b268d4e8d52bbfd5cf6d8415c 100644 --- a/src/MissionManager/QGCMapPolygon.cc +++ b/src/MissionManager/QGCMapPolygon.cc @@ -630,9 +630,12 @@ void QGCMapPolygon::setShowAltColor(bool showAltColor){ void QGCMapPolygon::selectVertex(int index) { - if(0 <= index && index < count() && index != _selectedVertexIndex) { + if(index == _selectedVertexIndex) return; // do nothing + + if((0 <= index && index < count()) || index == -1) { _selectedVertexIndex = index; } else { + qWarning() << "QGCMapPolygon: Selected vertex index is out of bounds!"; _selectedVertexIndex = -1; // deselect vertex } diff --git a/src/MissionManager/QGCMapPolyline.cc b/src/MissionManager/QGCMapPolyline.cc index 5dcb0f4beb75bdf1c323703efb6ea6e2c93c3f16..ba37e98a111346d29802eec9279942b0e3923d47 100644 --- a/src/MissionManager/QGCMapPolyline.cc +++ b/src/MissionManager/QGCMapPolyline.cc @@ -243,6 +243,11 @@ void QGCMapPolyline::removeVertex(int vertexIndex) QObject* coordObj = _polylineModel.removeAt(vertexIndex); coordObj->deleteLater(); + if(vertexIndex == _selectedVertexIndex) { + selectVertex(-1); + } else if (vertexIndex < _selectedVertexIndex) { + selectVertex(_selectedVertexIndex - 1); + } // else do nothing - keep current selected vertex _polylinePath.removeAt(vertexIndex); emit pathChanged(); @@ -439,3 +444,17 @@ void QGCMapPolyline::setTraceMode(bool traceMode) emit traceModeChanged(traceMode); } } + +void QGCMapPolyline::selectVertex(int index) +{ + if(index == _selectedVertexIndex) return; // do nothing + + if((0 <= index && index < count()) || index == -1) { + _selectedVertexIndex = index; + } else { + qWarning() << "QGCMapPolyline: Selected vertex index is out of bounds!"; + _selectedVertexIndex = -1; // deselect vertex + } + + emit selectedVertexChanged(_selectedVertexIndex); +} diff --git a/src/MissionManager/QGCMapPolyline.h b/src/MissionManager/QGCMapPolyline.h index aff17cbc71ebe92780fd51363c4027c004437e3b..bd5cc8b542a18cd1273f53a0a20878718fe9dc42 100644 --- a/src/MissionManager/QGCMapPolyline.h +++ b/src/MissionManager/QGCMapPolyline.h @@ -33,6 +33,7 @@ public: Q_PROPERTY(bool isValid READ isValid NOTIFY isValidChanged) Q_PROPERTY(bool empty READ empty NOTIFY isEmptyChanged) Q_PROPERTY(bool traceMode READ traceMode WRITE setTraceMode NOTIFY traceModeChanged) + Q_PROPERTY(int selectedVertex READ selectedVertex WRITE selectVertex NOTIFY selectedVertexChanged) Q_INVOKABLE void clear(void); Q_INVOKABLE void appendVertex(const QGeoCoordinate& coordinate); @@ -90,6 +91,7 @@ public: bool isValid (void) const { return _polylineModel.count() >= 2; } bool empty (void) const { return _polylineModel.count() == 0; } bool traceMode (void) const { return _traceMode; } + int selectedVertex() const { return _selectedVertexIndex; } QmlObjectListModel* qmlPathModel(void) { return &_polylineModel; } QmlObjectListModel& pathModel (void) { return _polylineModel; } @@ -98,6 +100,7 @@ public: void setPath (const QVariantList& path); void setInteractive (bool interactive); void setTraceMode (bool traceMode); + void selectVertex (int index); static const char* jsonPolylineKey; @@ -110,6 +113,7 @@ signals: void isValidChanged (void); void isEmptyChanged (void); void traceModeChanged (bool traceMode); + void selectedVertexChanged(int index); private slots: void _polylineModelCountChanged(int count); @@ -128,4 +132,5 @@ private: bool _interactive; bool _resetActive; bool _traceMode = false; + int _selectedVertexIndex = -1; };