Browse Source

QGCMapPolyline select vertexes functionality

Add invalid vertex index warning
QGC4.4
Aleksey Kontsevich 5 years ago
parent
commit
ce27d8fc07
  1. 5
      src/MissionManager/QGCMapPolygon.cc
  2. 19
      src/MissionManager/QGCMapPolyline.cc
  3. 5
      src/MissionManager/QGCMapPolyline.h

5
src/MissionManager/QGCMapPolygon.cc

@ -630,9 +630,12 @@ void QGCMapPolygon::setShowAltColor(bool showAltColor){ @@ -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
}

19
src/MissionManager/QGCMapPolyline.cc

@ -243,6 +243,11 @@ void QGCMapPolyline::removeVertex(int vertexIndex) @@ -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) @@ -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);
}

5
src/MissionManager/QGCMapPolyline.h

@ -33,6 +33,7 @@ public: @@ -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: @@ -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: @@ -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: @@ -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: @@ -128,4 +132,5 @@ private:
bool _interactive;
bool _resetActive;
bool _traceMode = false;
int _selectedVertexIndex = -1;
};

Loading…
Cancel
Save