QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QGCMapPolyline.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QObject>
4#include <QtCore/QVariantList>
5#include <QtPositioning/QGeoCoordinate>
6
8
9class QGCMapPolyline : public QObject
10{
11 Q_OBJECT
12
13public:
14 QGCMapPolyline(QObject* parent = nullptr);
15 QGCMapPolyline(const QGCMapPolyline& other, QObject* parent = nullptr);
16
17 ~QGCMapPolyline() override;
18
19 const QGCMapPolyline& operator=(const QGCMapPolyline& other);
20
21 Q_PROPERTY(int count READ count NOTIFY countChanged)
22 Q_PROPERTY(QVariantList path READ path NOTIFY pathChanged)
23 Q_PROPERTY(QVariantList dragPath READ path NOTIFY dragPathChanged)
24 Q_PROPERTY(QmlObjectListModel* pathModel READ qmlPathModel CONSTANT)
25 Q_PROPERTY(bool dirty READ dirty WRITE setDirty NOTIFY dirtyChanged)
26 Q_PROPERTY(bool interactive READ interactive WRITE setInteractive NOTIFY interactiveChanged)
27 Q_PROPERTY(bool vertexDrag READ vertexDrag WRITE setVertexDrag NOTIFY vertexDragChanged)
28 Q_PROPERTY(bool isValid READ isValid NOTIFY isValidChanged)
29 Q_PROPERTY(bool empty READ empty NOTIFY isEmptyChanged)
30 Q_PROPERTY(bool traceMode READ traceMode WRITE setTraceMode NOTIFY traceModeChanged)
31 Q_PROPERTY(int selectedVertex READ selectedVertex WRITE selectVertex NOTIFY selectedVertexChanged)
32
33 Q_INVOKABLE void clear(void);
34 Q_INVOKABLE void appendVertex(const QGeoCoordinate& coordinate);
35 Q_INVOKABLE void removeVertex(int vertexIndex);
36 Q_INVOKABLE void appendVertices(const QList<QGeoCoordinate>& coordinates);
37
41 Q_INVOKABLE void adjustVertex(int vertexIndex, const QGeoCoordinate coordinate);
42
44 Q_INVOKABLE void splitSegment(int vertexIndex);
45
48 QList<QGeoCoordinate> offsetPolyline(double distance);
49
52 Q_INVOKABLE bool loadKMLOrSHPFile(const QString &file);
53
54 Q_INVOKABLE void beginReset (void);
55 Q_INVOKABLE void endReset (void);
56
58 QList<QGeoCoordinate> coordinateList(void) const;
59
61 Q_INVOKABLE QGeoCoordinate vertexCoordinate(int vertex) const;
62
65 void saveToJson(QJsonObject& json);
66
72 bool loadFromJson(const QJsonObject& json, bool required, QString& errorString);
73
75 QList<QPointF> nedPolyline(void);
76
78 double length(void) const;
79
80 // Property methods
81 int count (void) const { return _polylinePath.count(); }
82 bool dirty (void) const { return _dirty; }
83 void setDirty (bool dirty);
84 bool interactive (void) const { return _interactive; }
85 bool vertexDrag (void) const { return _vertexDrag; }
86 QVariantList path (void) const { return _polylinePath; }
87 bool isValid (void) const { return _polylineModel.count() >= 2; }
88 bool empty (void) const { return _polylineModel.count() == 0; }
89 bool traceMode (void) const { return _traceMode; }
90 int selectedVertex() const { return _selectedVertexIndex; }
91
92 QmlObjectListModel* qmlPathModel(void) { return &_polylineModel; }
93 QmlObjectListModel& pathModel (void) { return _polylineModel; }
94
95 void setPath (const QList<QGeoCoordinate>& path);
96 void setPath (const QVariantList& path);
97 void setInteractive (bool interactive);
98 void setVertexDrag (bool vertexDrag);
99 void setTraceMode (bool traceMode);
100 void selectVertex (int index);
101
102 static constexpr const char* jsonPolylineKey = "polyline";
103
104signals:
105 void countChanged (int count);
106 void pathChanged (void);
107 void dragPathChanged (void);
108 void dirtyChanged (bool dirty);
109 void cleared (void);
112 void isValidChanged (void);
113 void isEmptyChanged (void);
115 void selectedVertexChanged(int index);
116
117private slots:
118 void _polylineModelCountChanged(int count);
119 void _polylineModelDirtyChanged(bool dirty);
120
121private:
122 void _init (void);
123 QGeoCoordinate _coordFromPointF (const QPointF& point) const;
124 QPointF _pointFFromCoord (const QGeoCoordinate& coordinate) const;
125
126 QVariantList _polylinePath;
127 QmlObjectListModel _polylineModel;
128 bool _deferredPathChanged = false;
129 bool _dirty;
130 bool _interactive;
131 bool _vertexDrag = false;
132 bool _traceMode = false;
133 int _selectedVertexIndex = -1;
134};
Q_INVOKABLE void beginReset(void)
QList< QGeoCoordinate > offsetPolyline(double distance)
void dirtyChanged(bool dirty)
static constexpr const char * jsonPolylineKey
QList< QPointF > nedPolyline(void)
Convert polyline to NED and return (D is ignored).
Q_INVOKABLE void clear(void)
Q_INVOKABLE bool loadKMLOrSHPFile(const QString &file)
void cleared(void)
Q_INVOKABLE void splitSegment(int vertexIndex)
Splits the line segment comprised of vertexIndex -> vertexIndex + 1.
void pathChanged(void)
Q_INVOKABLE void removeVertex(int vertexIndex)
void interactiveChanged(bool interactive)
QmlObjectListModel & pathModel(void)
void traceModeChanged(bool traceMode)
Q_INVOKABLE void adjustVertex(int vertexIndex, const QGeoCoordinate coordinate)
bool isValid(void) const
void dragPathChanged(void)
void setTraceMode(bool traceMode)
void isEmptyChanged(void)
bool empty(void) const
bool dirty(void) const
Q_INVOKABLE QGeoCoordinate vertexCoordinate(int vertex) const
Returns the QGeoCoordinate for the vertex specified.
void selectVertex(int index)
void setPath(const QList< QGeoCoordinate > &path)
void setDirty(bool dirty)
bool interactive(void) const
Q_INVOKABLE void appendVertex(const QGeoCoordinate &coordinate)
int count(void) const
~QGCMapPolyline() override
void vertexDragChanged(bool vertexDrag)
bool vertexDrag(void) const
void saveToJson(QJsonObject &json)
QmlObjectListModel * qmlPathModel(void)
QList< QGeoCoordinate > coordinateList(void) const
Returns the path in a list of QGeoCoordinate's format.
const QGCMapPolyline & operator=(const QGCMapPolyline &other)
Q_INVOKABLE void endReset(void)
Q_INVOKABLE void appendVertices(const QList< QGeoCoordinate > &coordinates)
int selectedVertex() const
QVariantList path(void) const
void isValidChanged(void)
bool loadFromJson(const QJsonObject &json, bool required, QString &errorString)
QGCMapPolyline(QObject *parent=nullptr)
double length(void) const
Returns the length of the polyline in meters.
void countChanged(int count)
void setVertexDrag(bool vertexDrag)
bool traceMode(void) const
void selectedVertexChanged(int index)
void setInteractive(bool interactive)