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