Commit ce27d8fc authored by Aleksey Kontsevich's avatar Aleksey Kontsevich

QGCMapPolyline select vertexes functionality

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