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
15class QGCMapPolygon : public QObject
16{
17 Q_OBJECT
18 QML_ELEMENT
19 QML_UNCREATABLE("")
20public:
21 QGCMapPolygon(QObject* parent = nullptr);
22 QGCMapPolygon(const QGCMapPolygon& other, QObject* parent = nullptr);
23
24 ~QGCMapPolygon() override;
25
26 const QGCMapPolygon& operator=(const QGCMapPolygon& other);
27
28 Q_PROPERTY(int count READ count NOTIFY countChanged)
29 Q_PROPERTY(QVariantList path READ path NOTIFY pathChanged)
30 Q_PROPERTY(double area READ area NOTIFY pathChanged)
31 Q_PROPERTY(QmlObjectListModel* pathModel READ qmlPathModel CONSTANT)
32 Q_PROPERTY(bool dirty READ dirty WRITE setDirty NOTIFY dirtyChanged)
33 Q_PROPERTY(QGeoCoordinate center READ center WRITE setCenter NOTIFY centerChanged)
34 Q_PROPERTY(bool centerDrag READ centerDrag WRITE setCenterDrag NOTIFY centerDragChanged)
35 Q_PROPERTY(bool interactive READ interactive WRITE setInteractive NOTIFY interactiveChanged)
36 Q_PROPERTY(bool isValid READ isValid NOTIFY isValidChanged)
37 Q_PROPERTY(bool empty READ empty NOTIFY isEmptyChanged)
38 Q_PROPERTY(bool traceMode READ traceMode WRITE setTraceMode NOTIFY traceModeChanged)
39 Q_PROPERTY(bool showAltColor READ showAltColor WRITE setShowAltColor NOTIFY showAltColorChanged)
40 Q_PROPERTY(int selectedVertex READ selectedVertex WRITE selectVertex NOTIFY selectedVertexChanged)
41
42 Q_INVOKABLE void clear(void);
43 Q_INVOKABLE void appendVertex(const QGeoCoordinate& coordinate);
44 Q_INVOKABLE void removeVertex(int vertexIndex);
45 Q_INVOKABLE void appendVertices(const QVariantList& varCoords);
46
47 void appendVertices(const QList<QGeoCoordinate>& coordinates);
48
52 Q_INVOKABLE void adjustVertex(int vertexIndex, const QGeoCoordinate coordinate);
53
55 Q_INVOKABLE void splitPolygonSegment(int vertexIndex);
56
58 Q_INVOKABLE bool containsCoordinate(const QGeoCoordinate& coordinate) const;
59
61 Q_INVOKABLE void offset(double distance);
62
65 Q_INVOKABLE bool loadKMLOrSHPFile(const QString& file);
66
68 QList<QGeoCoordinate> coordinateList(void) const;
69
71 Q_INVOKABLE QGeoCoordinate vertexCoordinate(int vertex) const;
72
74 Q_INVOKABLE void verifyClockwiseWinding(void);
75
76 Q_INVOKABLE void beginReset (void);
77 Q_INVOKABLE void endReset (void);
78
81 void saveToJson(QJsonObject& json);
82
88 bool loadFromJson(const QJsonObject& json, bool required, QString& errorString);
89
91 QList<QPointF> nedPolygon(void) const;
92
94 double area(void) const;
95
96 QDomElement kmlPolygonElement(KMLDomDocument& domDocument);
97
98 // Property methods
99
100 int count (void) const { return _polygonPath.count(); }
101 bool dirty (void) const { return _dirty; }
102 void setDirty (bool dirty);
103 QGeoCoordinate center (void) const { return _center; }
104 bool centerDrag (void) const { return _centerDrag; }
105 bool interactive (void) const { return _interactive; }
106 bool isValid (void) const { return _polygonModel.count() >= 3; }
107 bool empty (void) const { return _polygonModel.count() == 0; }
108 bool traceMode (void) const { return _traceMode; }
109 bool showAltColor(void) const { return _showAltColor; }
110 int selectedVertex() const { return _selectedVertexIndex; }
111
112 QVariantList path (void) const { return _polygonPath; }
113 QmlObjectListModel* qmlPathModel(void) { return &_polygonModel; }
114 QmlObjectListModel& pathModel (void) { return _polygonModel; }
115
116 void setPath (const QList<QGeoCoordinate>& path);
117 void setPath (const QVariantList& path);
118 void setCenter (QGeoCoordinate newCenter);
119 void setCenterDrag (bool centerDrag);
120 void setInteractive (bool interactive);
121 void setTraceMode (bool traceMode);
122 void setShowAltColor(bool showAltColor);
123 void selectVertex (int index);
124
125 static constexpr const char* jsonPolygonKey = "polygon";
126
127signals:
128 void countChanged (int count);
129 void pathChanged (void);
130 void dirtyChanged (bool dirty);
131 void cleared (void);
132 void centerChanged (QGeoCoordinate center);
135 bool isValidChanged (void);
136 bool isEmptyChanged (void);
139 void selectedVertexChanged(int index);
140
141private slots:
142 void _polygonModelCountChanged(int count);
143 void _polygonModelDirtyChanged(bool dirty);
144 void _updateCenter(void);
145
146private:
147 void _init (void);
148 QPolygonF _toPolygonF (void) const;
149 QGeoCoordinate _coordFromPointF (const QPointF& point) const;
150 QPointF _pointFFromCoord (const QGeoCoordinate& coordinate) const;
151
152 QVariantList _polygonPath;
153 QmlObjectListModel _polygonModel;
154 bool _dirty = false;
155 QGeoCoordinate _center;
156 bool _centerDrag = false;
157 bool _ignoreCenterUpdates = false;
158 bool _interactive = false;
159 bool _traceMode = false;
160 bool _showAltColor = false;
161 int _selectedVertexIndex = -1;
162 bool _deferredPathChanged = false;
163};
QString errorString
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)
bool loadKMLOrSHPFile(const QString &file)
bool isEmptyChanged(void)
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)
void splitPolygonSegment(int vertexIndex)
Splits the segment comprised of vertextIndex -> vertexIndex + 1.
bool isValid(void) const
bool traceMode(void) const
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 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
bool containsCoordinate(const QGeoCoordinate &coordinate) const
Returns true if the specified coordinate is within the polygon.
QGeoCoordinate vertexCoordinate(int vertex) const
Returns the QGeoCoordinate for the vertex specified.
void removeVertex(int vertexIndex)
void setPath(const QList< QGeoCoordinate > &path)
QVariantList path(void) const
void showAltColorChanged(bool showAltColor)
const QGCMapPolygon & operator=(const QGCMapPolygon &other)
void verifyClockwiseWinding(void)
Adjust polygon winding order to be clockwise (if needed)
void setInteractive(bool interactive)
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)
void endReset(void)
QDomElement kmlPolygonElement(KMLDomDocument &domDocument)
static constexpr const char * jsonPolygonKey
void centerChanged(QGeoCoordinate center)
bool isValidChanged(void)
void setShowAltColor(bool showAltColor)
void appendVertex(const QGeoCoordinate &coordinate)
void pathChanged(void)
void countChanged(int count)
int count(void) const
bool empty(void) const
bool loadFromJson(const QJsonObject &json, bool required, QString &errorString)
void appendVertices(const QVariantList &varCoords)
int count READ count NOTIFY countChanged(QVariantList path READ path NOTIFY pathChanged) 1(double area READ area NOTIFY pathChanged) 1(QmlObjectListModel *pathModel READ qmlPathModel CONSTANT) 1(bool dirty READ dirty WRITE setDirty NOTIFY dirtyChanged) 1(QGeoCoordinate center READ center WRITE setCenter NOTIFY centerChanged) 1(bool centerDrag READ centerDrag WRITE setCenterDrag NOTIFY centerDragChanged) 1(bool interactive READ interactive WRITE setInteractive NOTIFY interactiveChanged) 1(bool isValid READ isValid NOTIFY isValidChanged) 1(bool empty READ empty NOTIFY isEmptyChanged) 1(bool traceMode READ traceMode WRITE setTraceMode NOTIFY traceModeChanged) 1(bool showAltColor READ showAltColor WRITE setShowAltColor NOTIFY showAltColorChanged) 1(int selectedVertex READ selectedVertex WRITE selectVertex NOTIFY selectedVertexChanged) 1 void clear(void)
void setCenterDrag(bool centerDrag)
void centerDragChanged(bool centerDrag)
int count() const override final