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
67 Q_INVOKABLE bool offset(double distance);
68
71 Q_INVOKABLE bool loadKMLOrSHPFile(const QString& file);
72
74 QList<QGeoCoordinate> coordinateList(void) const;
75
77 Q_INVOKABLE QGeoCoordinate vertexCoordinate(int vertex) const;
78
80 Q_INVOKABLE void verifyClockwiseWinding(void);
81
82 bool isClockwise() const;
83
84 Q_INVOKABLE void beginReset (void);
85 Q_INVOKABLE void endReset (void);
86
89 void saveToJson(QJsonObject& json);
90
96 bool loadFromJson(const QJsonObject& json, bool required, QString& errorString);
97
99 QList<QPointF> nedPolygon(void) const;
100
102 double area(void) const;
103
104 QDomElement kmlPolygonElement(KMLDomDocument& domDocument);
105
106 // Property methods
107
108 int count (void) const { return _polygonPath.count(); }
109 bool dirty (void) const { return _dirty; }
110 void setDirty (bool dirty);
111 QGeoCoordinate center (void) const { return _center; }
112 bool centerDrag (void) const { return _centerDrag; }
113 bool vertexDrag (void) const { return _vertexDrag; }
114 bool interactive (void) const { return _interactive; }
115 bool isValid (void) const { return _polygonModel.count() >= 3; }
116 bool empty (void) const { return _polygonModel.count() == 0; }
117 bool traceMode (void) const { return _traceMode; }
118 bool showAltColor(void) const { return _showAltColor; }
119 int selectedVertex() const { return _selectedVertexIndex; }
120
121 QVariantList path (void) const { return _polygonPath; }
122 QmlObjectListModel* qmlPathModel(void) { return &_polygonModel; }
123 QmlObjectListModel& pathModel (void) { return _polygonModel; }
124
125 void setPath (const QList<QGeoCoordinate>& path);
126 void setPath (const QVariantList& path);
127 void setCenter (QGeoCoordinate newCenter);
128 void setCenterDrag (bool centerDrag);
129 void setVertexDrag (bool vertexDrag);
130 void setInteractive (bool interactive);
131 void setTraceMode (bool traceMode);
132 void setShowAltColor(bool showAltColor);
133 void selectVertex (int index);
134
135 static constexpr const char* jsonPolygonKey = "polygon";
136
137signals:
138 void countChanged (int count);
139 void pathChanged (void);
140 void dragPathChanged (void);
141 void dirtyChanged (bool dirty);
142 void cleared (void);
143 void centerChanged (QGeoCoordinate center);
144 void dragCenterChanged (QGeoCoordinate center);
148 bool isValidChanged (void);
149 bool isEmptyChanged (void);
152 void selectedVertexChanged(int index);
153
154private slots:
155 void _polygonModelCountChanged(int count);
156 void _polygonModelDirtyChanged(bool dirty);
157 void _updateCenter(void);
158
159private:
160 void _init (void);
161 QPolygonF _toPolygonF (void) const;
162 QGeoCoordinate _coordFromPointF (const QPointF& point) const;
163 QPointF _pointFFromCoord (const QGeoCoordinate& coordinate) const;
164
165 QVariantList _polygonPath;
166 QmlObjectListModel _polygonModel;
167 bool _dirty = false;
168 QGeoCoordinate _center;
169 bool _centerDrag = false;
170 bool _vertexDrag = false;
171 bool _ignoreCenterUpdates = false;
172 bool _interactive = false;
173 bool _traceMode = false;
174 bool _showAltColor = false;
175 int _selectedVertexIndex = -1;
176 bool _deferredPathChanged = false;
177};
Used to convert a Plan to a KML document.
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 bool offset(double distance)
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)
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)
bool isClockwise() const
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)
QGCMapPolygon(QObject *parent=nullptr)
void centerDragChanged(bool centerDrag)