QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QGCFencePolygon.cc
Go to the documentation of this file.
1#include "QGCFencePolygon.h"
2#include "JsonHelper.h"
3
4QGCFencePolygon::QGCFencePolygon(bool inclusion, QObject* parent)
5 : QGCMapPolygon (parent)
6 , _inclusion (inclusion)
7{
8 _init();
9}
10
12 : QGCMapPolygon (other, parent)
13 , _inclusion (other._inclusion)
14{
15 _init();
16}
17
18void QGCFencePolygon::_init(void)
19{
20 connect(this, &QGCFencePolygon::inclusionChanged, this, &QGCFencePolygon::_setDirty);
21}
22
24{
26
27 setInclusion(other._inclusion);
28
29 return *this;
30}
31
32void QGCFencePolygon::_setDirty(void)
33{
34 setDirty(true);
35}
36
37void QGCFencePolygon::saveToJson(QJsonObject& json)
38{
39 json[JsonHelper::jsonVersionKey] = _jsonCurrentVersion;
40 json[_jsonInclusionKey] = _inclusion;
42}
43
44bool QGCFencePolygon::loadFromJson(const QJsonObject& json, bool required, QString& errorString)
45{
46 errorString.clear();
47
48 QList<JsonHelper::KeyValidateInfo> keyInfoList = {
49 { JsonHelper::jsonVersionKey, QJsonValue::Double, true },
50 { _jsonInclusionKey, QJsonValue::Bool, true },
51 };
52 if (!JsonHelper::validateKeys(json, keyInfoList, errorString)) {
53 return false;
54 }
55
56 if (json[JsonHelper::jsonVersionKey].toInt() != _jsonCurrentVersion) {
57 errorString = tr("GeoFence Polygon only supports version %1").arg(_jsonCurrentVersion);
58 return false;
59 }
60
61 if (!QGCMapPolygon::loadFromJson(json, required, errorString)) {
62 return false;
63 }
64
65 setInclusion(json[_jsonInclusionKey].toBool());
66
67 return true;
68}
69
71{
72 if (inclusion != _inclusion) {
73 _inclusion = inclusion;
75 }
76}
QString errorString
The QGCFencePolygon class provides a polygon used by GeoFence support.
bool inclusion READ inclusion WRITE setInclusion NOTIFY inclusionChanged void saveToJson(QJsonObject &json)
void inclusionChanged(bool inclusion)
bool loadFromJson(const QJsonObject &json, bool required, QString &errorString)
QGCFencePolygon(bool inclusion, QObject *parent=nullptr)
bool inclusion(void) const
void setInclusion(bool inclusion)
const QGCFencePolygon & operator=(const QGCFencePolygon &other)
void setDirty(bool dirty)
const QGCMapPolygon & operator=(const QGCMapPolygon &other)
void saveToJson(QJsonObject &json)
bool loadFromJson(const QJsonObject &json, bool required, QString &errorString)
constexpr const char * jsonVersionKey
Definition JsonHelper.h:109
bool validateKeys(const QJsonObject &jsonObject, const QList< KeyValidateInfo > &keyInfo, QString &errorString)