QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QGCMapPolygon.h
Go to the documentation of this file.
1#pragma once
2
3#include <QtCore/QObject>
4#include <QtPositioning/QGeoCoordinate>
5#include <QtCore/QVariantList>
6#include <QtGui/QPolygonF>
7#include <QtXml/QDomElement>
8
10
11class KMLDomDocument;
12
17class QGCMapPolygon : public QObject
18{
19 Q_OBJECT
20 QML_ELEMENT
21 QML_UNCREATABLE("")
22public:
23 QGCMapPolygon(QObject* parent = nullptr);
24 QGCMapPolygon(const QGCMapPolygon& other, QObject* parent = nullptr);
25
26 ~QGCMapPolygon() override;
27
28 const QGCMapPolygon& operator=(const QGCMapPolygon& other);
29
30 Q_PROPERTY(int count READ count NOTIFY countChanged)
31 Q_PROPERTY(QVariantList path READ path NOTIFY pathChanged)
32 Q_PROPERTY(QVariantList dragPath READ path NOTIFY dragPathChanged)
33 Q_PROPERTY(double area READ area NOTIFY pathChanged)
34 Q_PROPERTY(QmlObjectListModel* pathModel READ qmlPathModel CONSTANT)
35 Q_PROPERTY(bool dirty READ dirty WRITE setDirty NOTIFY dirtyChanged)
36 Q_PROPERTY(QGeoCoordinate center READ center WRITE setCenter NOTIFY centerChanged)
37 Q_PROPERTY(QGeoCoordinate dragCenter READ center NOTIFY dragCenterChanged)
38 Q_PROPERTY(bool centerDrag READ centerDrag WRITE setCenterDrag NOTIFY centerDragChanged)
39 Q_PROPERTY(bool vertexDrag READ vertexDrag WRITE setVertexDrag NOTIFY vertexDragChanged)
40 Q_PROPERTY(bool interactive READ interactive WRITE setInteractive NOTIFY interactiveChanged)
41 Q_PROPERTY(bool isValid READ isValid NOTIFY isValidChanged)
42 Q_PROPERTY(bool empty READ empty NOTIFY isEmptyChanged)
43 Q_PROPERTY(bool traceMode READ traceMode WRITE setTraceMode NOTIFY traceModeChanged)
44 Q_PROPERTY(bool showAltColor READ showAltColor WRITE setShowAltColor NOTIFY showAltColorChanged)
45 Q_PROPERTY(int selectedVertex READ selectedVertex WRITE selectVertex NOTIFY selectedVertexChanged)
46
47 Q_INVOKABLE void clear(void);
48 Q_INVOKABLE void appendVertex(const QGeoCoordinate& coordinate);
49 Q_INVOKABLE void removeVertex(int vertexIndex);
50 Q_INVOKABLE void appendVertices(const QVariantList& varCoords);
51
52 void appendVertices(const QList<QGeoCoordinate>& coordinates);
53
57 Q_INVOKABLE void adjustVertex(int vertexIndex, const QGeoCoordinate coordinate);
58
60 Q_INVOKABLE void splitPolygonSegment(int vertexIndex);
61
63 Q_INVOKABLE bool containsCoordinate(const QGeoCoordinate& coordinate) const;
64
66 Q_INVOKABLE void offset(double distance);
67
70 Q_INVOKABLE bool loadKMLOrSHPFile(const QString& file);
71
73 QList<QGeoCoordinate> coordinateList(void) const;
74
76 Q_INVOKABLE QGeoCoordinate vertexCoordinate(int vertex) const;
77
79 Q_INVOKABLE void verifyClockwiseWinding(void);
80
81 Q_INVOKABLE void beginReset (void);
82 Q_INVOKABLE void endReset (void);
83
86 void saveToJson(QJsonObject& json);
87
93 bool loadFromJson(const QJsonObject& json, bool required, QString& errorString);
94
96 QList<QPointF> nedPolygon(void) const;
97
99 double area(void) const;
100
101 QDomElement kmlPolygonElement(KMLDomDocument& domDocument);
102
103 // Property methods
104
105 int count (void) const { return _polygonPath.count(); }
106 bool dirty (void) const { return _dirty; }
107 void setDirty (bool dirty);
108 QGeoCoordinate center (void) const { return _center; }
109 bool centerDrag (void) const { return _centerDrag; }
110 bool vertexDrag (void) const { return _vertexDrag; }
111 bool interactive (void) const { return _interactive; }
112 bool isValid (void) const { return _polygonModel.count() >= 3; }
113 bool empty (void) const { return _polygonModel.count() == 0; }
114 bool traceMode (void) const { return _traceMode; }
115 bool showAltColor(void) const { return _showAltColor; }
116 int selectedVertex() const { return _selectedVertexIndex; }
117
118 QVariantList path (void) const { return _polygonPath; }
119 QmlObjectListModel* qmlPathModel(void) { return &_polygonModel; }
120 QmlObjectListModel& pathModel (void) { return _polygonModel; }
121
122 void setPath (const QList<QGeoCoordinate>& path);
123 void setPath (const QVariantList& path);
124 void setCenter (QGeoCoordinate newCenter);
125 void setCenterDrag (bool centerDrag);
126 void setVertexDrag (bool vertexDrag);
127 void setInteractive (bool interactive);
128 void setTraceMode (bool traceMode);
129 void setShowAltColor(bool showAltColor);
130 void selectVertex (int index);
131
132 static constexpr const char* jsonPolygonKey = "polygon";
133
134signals:
135 void countChanged (int count);
136 void pathChanged (void);
137 void dragPathChanged (void);
138 void dirtyChanged (bool dirty);
139 void cleared (void);
140 void centerChanged (QGeoCoordinate center);
141 void dragCenterChanged (QGeoCoordinate center);
145 bool isValidChanged (void);
146 bool isEmptyChanged (void);
149 void selectedVertexChanged(int index);
150
151private slots:
152 void _polygonModelCountChanged(int count);
153 void _polygonModelDirtyChanged(bool dirty);
154 void _updateCenter(void);
155
156private:
157 void _init (void);
158 QPolygonF _toPolygonF (void) const;
159 QGeoCoordinate _coordFromPointF (const QPointF& point) const;
160 QPointF _pointFFromCoord (const QGeoCoordinate& coordinate) const;
161
162 QVariantList _polygonPath;
163 QmlObjectListModel _polygonModel;
164 bool _dirty = false;
165 QGeoCoordinate _center;
166 bool _centerDrag = false;
167 bool _vertexDrag = false;
168 bool _ignoreCenterUpdates = false;
169 bool _interactive = false;
170 bool _traceMode = false;
171 bool _showAltColor = false;
172 int _selectedVertexIndex = -1;
173 bool _deferredPathChanged = false;
174};
QString errorString
Used to convert a Plan to a KML document.
The QGCMapPolygon class provides a polygon which can be displayed on a map using a map visuals contro...
void cleared(void)
void interactiveChanged(bool interactive)
~QGCMapPolygon() override
int selectedVertex() const
void dirtyChanged(bool dirty)
void selectVertex(int index)
Q_INVOKABLE bool loadKMLOrSHPFile(const QString &file)
bool isEmptyChanged(void)
Q_INVOKABLE void adjustVertex(int vertexIndex, const QGeoCoordinate coordinate)
QmlObjectListModel & pathModel(void)
double area(void) const
Returns the area of the polygon in meters squared.
void setCenter(QGeoCoordinate newCenter)
Q_INVOKABLE void splitPolygonSegment(int vertexIndex)
Splits the segment comprised of vertextIndex -> vertexIndex + 1.
bool isValid(void) const
bool traceMode(void) const
void vertexDragChanged(bool vertexDrag)
QGeoCoordinate center(void) const
void setTraceMode(bool traceMode)
QmlObjectListModel * qmlPathModel(void)
QList< QGeoCoordinate > coordinateList(void) const
Returns the path in a list of QGeoCoordinate's format.
void setVertexDrag(bool vertexDrag)
void dragPathChanged(void)
Q_INVOKABLE void offset(double distance)
Offsets the current polygon edges by the specified distance in meters.
void setDirty(bool dirty)
bool centerDrag(void) const
void selectedVertexChanged(int index)
void traceModeChanged(bool traceMode)
bool showAltColor(void) const
bool dirty(void) const
Q_INVOKABLE bool containsCoordinate(const QGeoCoordinate &coordinate) const
Returns true if the specified coordinate is within the polygon.
Q_INVOKABLE QGeoCoordinate vertexCoordinate(int vertex) const
Returns the QGeoCoordinate for the vertex specified.
Q_INVOKABLE void removeVertex(int vertexIndex)
void setPath(const QList< QGeoCoordinate > &path)
QVariantList path(void) const
void showAltColorChanged(bool showAltColor)
void dragCenterChanged(QGeoCoordinate center)
const QGCMapPolygon & operator=(const QGCMapPolygon &other)
Q_INVOKABLE void verifyClockwiseWinding(void)
Adjust polygon winding order to be clockwise (if needed)
void setInteractive(bool interactive)
Q_INVOKABLE void beginReset(void)
bool interactive(void) const
void saveToJson(QJsonObject &json)
QList< QPointF > nedPolygon(void) const
Convert polygon to NED and return (D is ignored)
Q_INVOKABLE void endReset(void)
QDomElement kmlPolygonElement(KMLDomDocument &domDocument)
static constexpr const char * jsonPolygonKey
void centerChanged(QGeoCoordinate center)
Q_INVOKABLE void clear(void)
bool isValidChanged(void)
void setShowAltColor(bool showAltColor)
Q_INVOKABLE void appendVertex(const QGeoCoordinate &coordinate)
void pathChanged(void)
bool vertexDrag(void) const
void countChanged(int count)
int count(void) const
bool empty(void) const
bool loadFromJson(const QJsonObject &json, bool required, QString &errorString)
Q_INVOKABLE void appendVertices(const QVariantList &varCoords)
void setCenterDrag(bool centerDrag)
void centerDragChanged(bool centerDrag)
int count() const override final