QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QGCMapPolygon.cc
Go to the documentation of this file.
1#include "QGCMapPolygon.h"
2
3#include <QMetaMethod>
4
5#include "AppMessages.h"
6#include "GeoJsonHelper.h"
7#include "JsonParsing.h"
8#include "KMLDomDocument.h"
9#include "QGCApplication.h"
10#include "QGCGeo.h"
11#include "QGCLoggingCategory.h"
12#include "QGCPlanarGeometry.h"
13#include "QGCQGeoCoordinate.h"
14#include "ShapeFileHelper.h"
15
16QGC_LOGGING_CATEGORY(QGCMapPolygonLog, "QMLControls.QGCMapPolygon")
17
19 : QObject (parent)
20 , _dirty (false)
21 , _centerDrag (false)
22 , _ignoreCenterUpdates (false)
23 , _interactive (false)
24{
25 _init();
26}
27
28QGCMapPolygon::QGCMapPolygon(const QGCMapPolygon& other, QObject* parent)
29 : QObject (parent)
30 , _dirty (false)
31 , _centerDrag (false)
32 , _ignoreCenterUpdates (false)
33 , _interactive (false)
34{
35 *this = other;
36
37 _init();
38}
39
41{
42 qgcApp()->removeCompressedSignal(QMetaMethod::fromSignal(&QGCMapPolygon::pathChanged));
43}
44
45void QGCMapPolygon::_init(void)
46{
47 connect(&_polygonModel, &QmlObjectListModel::dirtyChanged, this, &QGCMapPolygon::_polygonModelDirtyChanged);
48 connect(&_polygonModel, &QmlObjectListModel::countChanged, this, &QGCMapPolygon::_polygonModelCountChanged);
49 connect(&_polygonModel, &QmlObjectListModel::modelReset, this, [this]() {
50 emit pathChanged();
51 emit centerChanged(_center);
52 });
53
54 connect(this, &QGCMapPolygon::pathChanged, this, &QGCMapPolygon::_updateCenter);
57
58}
59
61{
62 clear();
63
64 QVariantList vertices = other.path();
65 QList<QGeoCoordinate> rgCoord;
66 for (const QVariant& vertexVar: vertices) {
67 rgCoord.append(vertexVar.value<QGeoCoordinate>());
68 }
69 appendVertices(rgCoord);
70
71 setDirty(true);
72
73 return *this;
74}
75
77{
78 // Bug workaround, see below
79 while (_polygonPath.count() > 1) {
80 _polygonPath.takeLast();
81 }
82 if (_vertexDrag) {
83 emit dragPathChanged();
84 } else {
85 emit pathChanged();
86 }
87
88 // Although this code should remove the polygon from the map it doesn't. There appears
89 // to be a bug in QGCMapPolygon which causes it to not be redrawn if the list is empty. So
90 // we work around it by using the code above to remove all but the last point which in turn
91 // will cause the polygon to go away.
92 _polygonPath.clear();
93
94 _polygonModel.clearAndDeleteContents();
95
96 emit cleared();
97
98 setDirty(true);
99}
100
101void QGCMapPolygon::adjustVertex(int vertexIndex, const QGeoCoordinate coordinate)
102{
103 _polygonPath[vertexIndex] = QVariant::fromValue(coordinate);
104 _polygonModel.value<QGCQGeoCoordinate*>(vertexIndex)->setCoordinate(coordinate);
105 if (!_centerDrag) {
106 if (!_deferredPathChanged) {
107 _deferredPathChanged = true;
108 if (_vertexDrag) {
109 // During vertex drag only emit the lightweight visual signal
110 QTimer::singleShot(0, this, [this]() {
111 emit dragPathChanged();
112 _deferredPathChanged = false;
113 });
114 } else {
115 QTimer::singleShot(0, this, [this]() {
116 emit pathChanged();
117 _deferredPathChanged = false;
118 });
119 }
120 }
121 }
122 setDirty(true);
123}
124
126{
127 if (_dirty != dirty) {
128 _dirty = dirty;
129 if (!dirty) {
130 _polygonModel.setDirty(false);
131 }
132 emit dirtyChanged(dirty);
133 }
134}
135
136QGeoCoordinate QGCMapPolygon::_coordFromPointF(const QPointF& point) const
137{
138 QGeoCoordinate coord;
139
140 if (_polygonPath.count() > 0) {
141 QGeoCoordinate tangentOrigin = _polygonPath[0].value<QGeoCoordinate>();
142 QGCGeo::convertNedToGeo(-point.y(), point.x(), 0, tangentOrigin, coord);
143 }
144
145 return coord;
146}
147
148QPointF QGCMapPolygon::_pointFFromCoord(const QGeoCoordinate& coordinate) const
149{
150 if (_polygonPath.count() > 0) {
151 double y, x, down;
152 QGeoCoordinate tangentOrigin = _polygonPath[0].value<QGeoCoordinate>();
153
154 QGCGeo::convertGeoToNed(coordinate, tangentOrigin, y, x, down);
155 return QPointF(x, -y);
156 }
157
158 return QPointF();
159}
160
161QPolygonF QGCMapPolygon::_toPolygonF(void) const
162{
163 QPolygonF polygon;
164
165 if (_polygonPath.count() > 2) {
166 for (int i=0; i<_polygonPath.count(); i++) {
167 polygon.append(_pointFFromCoord(_polygonPath[i].value<QGeoCoordinate>()));
168 }
169 }
170
171 return polygon;
172}
173
174bool QGCMapPolygon::containsCoordinate(const QGeoCoordinate& coordinate) const
175{
176 if (_polygonPath.count() > 2) {
177 return _toPolygonF().containsPoint(_pointFFromCoord(coordinate), Qt::OddEvenFill);
178 } else {
179 return false;
180 }
181}
182
183void QGCMapPolygon::setPath(const QList<QGeoCoordinate>& path)
184{
185 _polygonPath.clear();
186 _polygonModel.clearAndDeleteContents();
187 for(const QGeoCoordinate& coord: path) {
188 _polygonPath.append(QVariant::fromValue(coord));
189 _polygonModel.append(new QGCQGeoCoordinate(coord, this));
190 }
191
192 setDirty(true);
193 emit pathChanged();
194}
195
196void QGCMapPolygon::setPath(const QVariantList& path)
197{
198 _polygonPath = path;
199
200 _polygonModel.clearAndDeleteContents();
201 for (int i=0; i<_polygonPath.count(); i++) {
202 _polygonModel.append(new QGCQGeoCoordinate(_polygonPath[i].value<QGeoCoordinate>(), this));
203 }
204
205 setDirty(true);
206 emit pathChanged();
207}
208
209void QGCMapPolygon::saveToJson(QJsonObject& json)
210{
211 QJsonValue jsonValue;
212
213 GeoJsonHelper::saveGeoCoordinateArray(_polygonPath, false /* writeAltitude*/, jsonValue);
214 json.insert(jsonPolygonKey, jsonValue);
215 setDirty(false);
216}
217
218bool QGCMapPolygon::loadFromJson(const QJsonObject& json, bool required, QString& errorString)
219{
220 errorString.clear();
221 clear();
222
223 if (required) {
224 if (!JsonParsing::validateRequiredKeys(json, QStringList(jsonPolygonKey), errorString)) {
225 return false;
226 }
227 } else if (!json.contains(jsonPolygonKey)) {
228 return true;
229 }
230
231 if (!GeoJsonHelper::loadGeoCoordinateArray(json[jsonPolygonKey], false /* altitudeRequired */, _polygonPath, errorString)) {
232 return false;
233 }
234
235 for (int i=0; i<_polygonPath.count(); i++) {
236 _polygonModel.append(new QGCQGeoCoordinate(_polygonPath[i].value<QGeoCoordinate>(), this));
237 }
238
239 setDirty(false);
240 emit pathChanged();
241
242 return true;
243}
244
245QList<QGeoCoordinate> QGCMapPolygon::coordinateList(void) const
246{
247 QList<QGeoCoordinate> coords;
248
249 for (int i=0; i<_polygonPath.count(); i++) {
250 coords.append(_polygonPath[i].value<QGeoCoordinate>());
251 }
252
253 return coords;
254}
255
257{
258 int nextIndex = vertexIndex + 1;
259 if (nextIndex > _polygonPath.length() - 1) {
260 nextIndex = 0;
261 }
262
263 QGeoCoordinate firstVertex = _polygonPath[vertexIndex].value<QGeoCoordinate>();
264 QGeoCoordinate nextVertex = _polygonPath[nextIndex].value<QGeoCoordinate>();
265
266 double distance = firstVertex.distanceTo(nextVertex);
267 double azimuth = firstVertex.azimuthTo(nextVertex);
268 QGeoCoordinate newVertex = firstVertex.atDistanceAndAzimuth(distance / 2, azimuth);
269
270 if (nextIndex == 0) {
271 appendVertex(newVertex);
272 } else {
273 _polygonModel.insert(nextIndex, new QGCQGeoCoordinate(newVertex, this));
274 _polygonPath.insert(nextIndex, QVariant::fromValue(newVertex));
275 emit pathChanged();
276 if (0 <= _selectedVertexIndex && vertexIndex < _selectedVertexIndex) {
277 selectVertex(_selectedVertexIndex+1);
278 }
279 }
280}
281
282void QGCMapPolygon::appendVertex(const QGeoCoordinate& coordinate)
283{
284 _polygonPath.append(QVariant::fromValue(coordinate));
285 _polygonModel.append(new QGCQGeoCoordinate(coordinate, this));
286 if (!_deferredPathChanged) {
287 // Only update the path once per event loop, to prevent lag-spikes
288 _deferredPathChanged = true;
289 QTimer::singleShot(0, this, [this]() {
290 if (_vertexDrag) {
291 emit dragPathChanged();
292 } else {
293 emit pathChanged();
294 }
295 _deferredPathChanged = false;
296 });
297 }
298}
299
300void QGCMapPolygon::appendVertices(const QList<QGeoCoordinate>& coordinates)
301{
302 QList<QObject*> objects;
303
304 beginReset();
305 for (const QGeoCoordinate& coordinate: coordinates) {
306 objects.append(new QGCQGeoCoordinate(coordinate, this));
307 _polygonPath.append(QVariant::fromValue(coordinate));
308 }
309 _polygonModel.append(objects);
310 endReset();
311
312 if (_vertexDrag) {
313 emit dragPathChanged();
314 } else {
315 emit pathChanged();
316 }
317}
318
319void QGCMapPolygon::appendVertices(const QVariantList& varCoords)
320{
321 QList<QGeoCoordinate> rgCoords;
322 for (const QVariant& varCoord: varCoords) {
323 rgCoords.append(varCoord.value<QGeoCoordinate>());
324 }
325 appendVertices(rgCoords);
326}
327
328void QGCMapPolygon::_polygonModelDirtyChanged(bool dirty)
329{
330 if (dirty) {
331 setDirty(true);
332 }
333}
334
335void QGCMapPolygon::removeVertex(int vertexIndex)
336{
337 if (vertexIndex < 0 || vertexIndex >= _polygonPath.length()) {
338 qCWarning(QGCMapPolygonLog) << "Call to removePolygonCoordinate with bad vertexIndex:count" << vertexIndex << _polygonPath.length();
339 return;
340 }
341
342 if (_polygonPath.length() <= 3) {
343 // Don't allow the user to trash the polygon
344 return;
345 }
346
347 QObject* coordObj = _polygonModel.removeAt(vertexIndex);
348 coordObj->deleteLater();
349 if(vertexIndex == _selectedVertexIndex) {
350 selectVertex(-1);
351 } else if (vertexIndex < _selectedVertexIndex) {
352 selectVertex(_selectedVertexIndex - 1);
353 } // else do nothing - keep current selected vertex
354
355 _polygonPath.removeAt(vertexIndex);
356 emit pathChanged();
357}
358
359void QGCMapPolygon::_polygonModelCountChanged(int count)
360{
361 emit countChanged(count);
362}
363
364void QGCMapPolygon::_updateCenter(void)
365{
366 if (!_ignoreCenterUpdates) {
367 QGeoCoordinate center;
368
369 if (_polygonPath.count() > 2) {
370 QPolygonF polygonF = _toPolygonF();
371 const int n = polygonF.count();
372
373 // Surveyor's (shoelace) formula for polygon centroid
374 double signedArea = 0;
375 double cx = 0;
376 double cy = 0;
377
378 for (int i = 0; i < n; i++) {
379 const int j = (i + 1) % n;
380 const double cross = polygonF[i].x() * polygonF[j].y() - polygonF[j].x() * polygonF[i].y();
381 signedArea += cross;
382 cx += (polygonF[i].x() + polygonF[j].x()) * cross;
383 cy += (polygonF[i].y() + polygonF[j].y()) * cross;
384 }
385
386 if (qAbs(signedArea) < 1e-6) {
387 // Degenerate or near-degenerate polygon (area < 0.5e-6 m²) — fall back to vertex average
388 QPointF avg(0, 0);
389 for (int i = 0; i < n; i++) {
390 avg += polygonF[i];
391 }
392 center = _coordFromPointF(QPointF(avg.x() / n, avg.y() / n));
393 } else {
394 signedArea *= 0.5;
395 cx /= (6.0 * signedArea);
396 cy /= (6.0 * signedArea);
397 center = _coordFromPointF(QPointF(cx, cy));
398 }
399 }
400 if (_center != center) {
401 _center = center;
402 emit centerChanged(center);
403 }
404 }
405}
406
407void QGCMapPolygon::setCenter(QGeoCoordinate newCenter)
408{
409 if (newCenter != _center) {
410 _ignoreCenterUpdates = true;
411
412 // Adjust polygon vertices to new center
413 double distance = _center.distanceTo(newCenter);
414 double azimuth = _center.azimuthTo(newCenter);
415
416 for (int i=0; i<count(); i++) {
417 QGeoCoordinate oldVertex = _polygonPath[i].value<QGeoCoordinate>();
418 QGeoCoordinate newVertex = oldVertex.atDistanceAndAzimuth(distance, azimuth);
419 adjustVertex(i, newVertex);
420 }
421
422 _ignoreCenterUpdates = false;
423 _center = newCenter;
424
425 if (_centerDrag) {
426 // During center drag emit lightweight visual signals only
427 if (!_deferredPathChanged) {
428 _deferredPathChanged = true;
429 QTimer::singleShot(0, this, [this]() {
430 emit dragPathChanged();
431 emit dragCenterChanged(_center);
432 _deferredPathChanged = false;
433 });
434 }
435 } else {
436 if (!_deferredPathChanged) {
437 _deferredPathChanged = true;
438 QTimer::singleShot(0, this, [this]() {
439 emit pathChanged();
440 emit centerChanged(_center);
441 _deferredPathChanged = false;
442 });
443 }
444 }
445 }
446}
447
449{
450 if (centerDrag != _centerDrag) {
451 _centerDrag = centerDrag;
452 if (!centerDrag) {
453 // Drag ended. Center edits do not use vertexDrag, so emit pathChanged here.
454 // For interactive center drag, setVertexDrag(false) emits pathChanged.
455 if (!_vertexDrag) {
456 emit pathChanged();
457 }
458 emit centerChanged(_center);
459 }
461 }
462}
463
465{
466 if (_vertexDrag != vertexDrag) {
467 _vertexDrag = vertexDrag;
468 if (!vertexDrag) {
469 // Drag ended - signal path changed so downstream can recalculate
470 emit pathChanged();
471 }
473 }
474}
475
477{
478 if (_interactive != interactive) {
479 _interactive = interactive;
481 }
482}
483
484QGeoCoordinate QGCMapPolygon::vertexCoordinate(int vertex) const
485{
486 if (vertex >= 0 && vertex < _polygonPath.count()) {
487 return _polygonPath[vertex].value<QGeoCoordinate>();
488 } else {
489 qCWarning(QGCMapPolygonLog) << "QGCMapPolygon::vertexCoordinate bad vertex requested:count" << vertex << _polygonPath.count();
490 return QGeoCoordinate();
491 }
492}
493
494QList<QPointF> QGCMapPolygon::nedPolygon(void) const
495{
496 QList<QPointF> nedPolygon;
497
498 if (count() > 0) {
499 QGeoCoordinate tangentOrigin = vertexCoordinate(0);
500
501 for (int i=0; i<_polygonModel.count(); i++) {
502 double y, x, down;
503 QGeoCoordinate vertex = vertexCoordinate(i);
504 if (i == 0) {
505 // This avoids a nan calculation that comes out of convertGeoToNed
506 x = y = 0;
507 } else {
508 QGCGeo::convertGeoToNed(vertex, tangentOrigin, y, x, down);
509 }
510 nedPolygon += QPointF(x, y);
511 }
512 }
513
514 return nedPolygon;
515}
516
517bool QGCMapPolygon::offset(double distance)
518{
519 if (count() <= 2) {
520 return false;
521 }
522
523 const QList<QPointF> nedVertices = nedPolygon();
524 const QList<QPolygonF> offsetPolygons = QGCPlanarGeometry::offsetPolygon(QPolygonF(nedVertices), distance);
525 if (offsetPolygons.size() != 1) {
526 qCWarning(QGCMapPolygonLog) << "Polygon offset by" << distance << "produced" << offsetPolygons.size()
527 << "polygons";
528 return false;
529 }
530
531 QList<QGeoCoordinate> newPolygon;
532 const QGeoCoordinate tangentOrigin = vertexCoordinate(0);
533 newPolygon.reserve(offsetPolygons.first().size());
534 for (const QPointF& vertex : offsetPolygons.first()) {
535 QGeoCoordinate coordinate;
536 QGCGeo::convertNedToGeo(vertex.y(), vertex.x(), 0, tangentOrigin, coordinate);
537 newPolygon.append(coordinate);
538 }
539
540 // Update internals
541 beginReset();
542 clear();
543 appendVertices(newPolygon);
544 endReset();
545
546 return true;
547}
548
549bool QGCMapPolygon::loadKMLOrSHPFile(const QString& file)
550{
551 QString errorString;
552 QList<QList<QGeoCoordinate>> polygons;
553 if (!ShapeFileHelper::loadPolygonsFromFile(file, polygons, errorString)) {
554 QGC::showAppMessage(errorString);
555 return false;
556 }
557 if (polygons.isEmpty()) {
558 QGC::showAppMessage(tr("No polygons found in file"));
559 return false;
560 }
561 const QList<QGeoCoordinate>& rgCoords = polygons.first();
562
563 beginReset();
564 clear();
565 appendVertices(rgCoords);
566 endReset();
567
568 return true;
569}
570
571double QGCMapPolygon::area(void) const
572{
573 // https://www.mathopenref.com/coordpolygonarea2.html
574
575 if (_polygonPath.count() < 3) {
576 return 0;
577 }
578
579 double coveredArea = 0.0;
580 QList<QPointF> nedVertices = nedPolygon();
581 for (int i=0; i<nedVertices.count(); i++) {
582 if (i != 0) {
583 coveredArea += nedVertices[i - 1].x() * nedVertices[i].y() - nedVertices[i].x() * nedVertices[i -1].y();
584 } else {
585 coveredArea += nedVertices.last().x() * nedVertices[i].y() - nedVertices[i].x() * nedVertices.last().y();
586 }
587 }
588 return 0.5 * fabs(coveredArea);
589}
590
592{
593 double sum = 0;
594 for (int i=0; i<_polygonPath.count(); i++) {
595 QGeoCoordinate coord1 = _polygonPath[i].value<QGeoCoordinate>();
596 QGeoCoordinate coord2 = (i == _polygonPath.count() - 1) ? _polygonPath[0].value<QGeoCoordinate>() : _polygonPath[i+1].value<QGeoCoordinate>();
597
598 sum += (coord2.longitude() - coord1.longitude()) * (coord2.latitude() + coord1.latitude());
599 }
600 return sum >= 0.0;
601}
602
604{
605 if (_polygonPath.count() <= 2) {
606 return;
607 }
608
609 if (!isClockwise()) {
610 // Winding is counter-clockwise and needs reversal
611
612 QList<QGeoCoordinate> rgReversed;
613 for (const QVariant& varCoord: _polygonPath) {
614 rgReversed.prepend(varCoord.value<QGeoCoordinate>());
615 }
616
617 beginReset();
618 clear();
619 appendVertices(rgReversed);
620 endReset();
621 }
622}
623
625{
626 _polygonModel.beginResetModel();
627}
628
630{
631 _polygonModel.endResetModel();
632}
633
635{
636#if 0
637 <Polygon id="ID">
638 <!-- specific to Polygon -->
639 <extrude>0</extrude> <!-- boolean -->
640 <tessellate>0</tessellate> <!-- boolean -->
641 <altitudeMode>clampToGround</altitudeMode>
642 <!-- kml:altitudeModeEnum: clampToGround, relativeToGround, or absolute -->
643 <!-- or, substitute gx:altitudeMode: clampToSeaFloor, relativeToSeaFloor -->
644 <outerBoundaryIs>
645 <LinearRing>
646 <coordinates>...</coordinates> <!-- lon,lat[,alt] -->
647 </LinearRing>
648 </outerBoundaryIs>
649 <innerBoundaryIs>
650 <LinearRing>
651 <coordinates>...</coordinates> <!-- lon,lat[,alt] -->
652 </LinearRing>
653 </innerBoundaryIs>
654 </Polygon>
655#endif
656
657 QDomElement polygonElement = domDocument.createElement("Polygon");
658
659 domDocument.addTextElement(polygonElement, "altitudeMode", "clampToGround");
660
661 QDomElement outerBoundaryIsElement = domDocument.createElement("outerBoundaryIs");
662 QDomElement linearRingElement = domDocument.createElement("LinearRing");
663
664 outerBoundaryIsElement.appendChild(linearRingElement);
665 polygonElement.appendChild(outerBoundaryIsElement);
666
667 QString coordString;
668 for (const QVariant& varCoord : _polygonPath) {
669 coordString += QStringLiteral("%1\n").arg(domDocument.kmlCoordString(varCoord.value<QGeoCoordinate>()));
670 }
671 coordString += QStringLiteral("%1\n").arg(domDocument.kmlCoordString(_polygonPath.first().value<QGeoCoordinate>()));
672 domDocument.addTextElement(linearRingElement, "coordinates", coordString);
673
674 return polygonElement;
675}
676
678{
679 if (traceMode != _traceMode) {
680 _traceMode = traceMode;
682 }
683}
684
686 if (showAltColor != _showAltColor) {
687 _showAltColor = showAltColor;
689 }
690}
691
693{
694 if(index == _selectedVertexIndex) return; // do nothing
695
696 if(-1 <= index && index < count()) {
697 _selectedVertexIndex = index;
698 } else {
699 qCWarning(QGCMapPolygonLog) << QString("QGCMapPolygon: Selected vertex index (%1) is out of bounds! "
700 "Polygon vertices indexes range is [%2..%3].").arg(index).arg(0).arg(count()-1);
701 _selectedVertexIndex = -1; // deselect vertex
702 }
703
704 emit selectedVertexChanged(_selectedVertexIndex);
705}
#define qgcApp()
Geographic coordinate conversion utilities using GeographicLib.
#define QGC_LOGGING_CATEGORY(name, categoryStr)
Used to convert a Plan to a KML document.
static QString kmlCoordString(const QGeoCoordinate &coord)
void addTextElement(QDomElement &parentElement, const QString &name, const QString &value)
void dirtyChanged(bool dirty)
void countChanged(int count)
void cleared(void)
void interactiveChanged(bool interactive)
~QGCMapPolygon() override
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)
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 traceMode(void) const
void vertexDragChanged(bool vertexDrag)
QGeoCoordinate center(void) const
void setTraceMode(bool traceMode)
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 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)
This is a QGeoCoordinate within a QObject such that it can be used on a QmlObjectListModel.
static bool loadPolygonsFromFile(const QString &file, QList< QList< QGeoCoordinate > > &polygons, QString &errorString, double filterMeters=kDefaultVertexFilterMeters)
bool loadGeoCoordinateArray(const QJsonValue &jsonValue, bool altitudeRequired, QVariantList &rgVarPoints, QString &errorString)
Loads a list of QGeoCoordinates (QGC plan format) from a json array.
void saveGeoCoordinateArray(const QVariantList &rgVarPoints, bool writeAltitude, QJsonValue &jsonValue)
Saves a list of QGeoCoordinates (QGC plan format) to a json array.
bool validateRequiredKeys(const QJsonObject &jsonObject, const QStringList &keys, QString &errorString)
Validates that all listed keys are present in the object.
void convertGeoToNed(const QGeoCoordinate &coord, const QGeoCoordinate &origin, double &x, double &y, double &z)
Definition QGCGeo.cc:36
void convertNedToGeo(double x, double y, double z, const QGeoCoordinate &origin, QGeoCoordinate &coord)
Definition QGCGeo.cc:58
QList< QPolygonF > offsetPolygon(const QPolygonF &polygon, double distance)
void showAppMessage(const QString &message, const QString &title)
Modal application message. Queued if the UI isn't ready yet.
Definition AppMessages.cc:9