QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QGCMapCircle.cc
Go to the documentation of this file.
1#include "QGCMapCircle.h"
2#include "JsonHelper.h"
3#include "ParameterManager.h"
4
6 : QObject (parent)
7 , _dirty (false)
8 , _interactive (false)
9 , _showRotation (false)
10 , _clockwiseRotation(true)
11{
12 _init();
13}
14
15QGCMapCircle::QGCMapCircle(const QGeoCoordinate& center, double radius, bool showRotation, bool clockwiseRotation, QObject* parent)
16 : QObject (parent)
17 , _dirty (false)
18 , _center (center)
19 , _radius (ParameterManager::defaultComponentId, _radiusFactName, FactMetaData::valueTypeDouble)
20 , _interactive (false)
21 , _showRotation (showRotation)
22 , _clockwiseRotation(clockwiseRotation)
23{
24 _radius.setRawValue(radius);
25 _init();
26}
27
28QGCMapCircle::QGCMapCircle(const QGCMapCircle& other, QObject* parent)
29 : QObject (parent)
30 , _dirty (false)
31 , _center (other._center)
32 , _radius (ParameterManager::defaultComponentId, _radiusFactName, FactMetaData::valueTypeDouble)
33 , _interactive (false)
34 , _showRotation (other._showRotation)
35 , _clockwiseRotation(other._clockwiseRotation)
36{
37 _radius.setRawValue(other._radius.rawValue());
38 _init();
39}
40
42{
43 setCenter(other._center);
44 _radius.setRawValue(other._radius.rawValue());
45 setDirty(true);
46
47 return *this;
48}
49
50void QGCMapCircle::_init(void)
51{
52 _nameToMetaDataMap = FactMetaData::createMapFromJsonFile(QStringLiteral(":/json/QGCMapCircle.Facts.json"), this);
53 _radius.setMetaData(_nameToMetaDataMap[_radiusFactName]);
54
55 connect(this, &QGCMapCircle::centerChanged, this, &QGCMapCircle::_setDirty);
56 connect(&_radius, &Fact::rawValueChanged, this, &QGCMapCircle::_setDirty);
57}
58
59void QGCMapCircle::setDirty(bool dirty)
60{
61 if (_dirty != dirty) {
62 _dirty = dirty;
63 emit dirtyChanged(dirty);
64 }
65}
66
67void QGCMapCircle::saveToJson(QJsonObject& json)
68{
69 QJsonValue jsonValue;
70 QJsonObject circleObject;
71
72 JsonHelper::saveGeoCoordinate(_center, false /* writeAltitude*/, jsonValue);
73 circleObject.insert(_jsonCenterKey, jsonValue);
74 circleObject.insert(_jsonRadiusKey, _radius.rawValue().toDouble());
75
76 json.insert(jsonCircleKey, circleObject);
77}
78
79bool QGCMapCircle::loadFromJson(const QJsonObject& json, QString& errorString)
80{
81 errorString.clear();
82
83 QList<JsonHelper::KeyValidateInfo> circleKeyInfo = {
84 { jsonCircleKey, QJsonValue::Object, true },
85 };
86 if (!JsonHelper::validateKeys(json, circleKeyInfo, errorString)) {
87 return false;
88 }
89
90 QJsonObject circleObject = json[jsonCircleKey].toObject();
91
92 QList<JsonHelper::KeyValidateInfo> circleObjectKeyInfo = {
93 { _jsonCenterKey, QJsonValue::Array, true },
94 { _jsonRadiusKey, QJsonValue::Double, true },
95 };
96 if (!JsonHelper::validateKeys(circleObject, circleObjectKeyInfo, errorString)) {
97 return false;
98 }
99
100 QGeoCoordinate center;
101 if (!JsonHelper::loadGeoCoordinate(circleObject[_jsonCenterKey], false /* altitudeRequired */, center, errorString)) {
102 return false;
103 }
105 _radius.setRawValue(circleObject[_jsonRadiusKey].toDouble());
106
107 _interactive = false;
108 _showRotation = false;
109 _clockwiseRotation = true;
110
111 return true;
112}
113
114void QGCMapCircle::setCenter(QGeoCoordinate newCenter)
115{
116 if (newCenter != _center) {
117 _center = newCenter;
118 setDirty(true);
119 emit centerChanged(newCenter);
120 }
121}
122
123void QGCMapCircle::_setDirty(void)
124{
125 setDirty(true);
126}
127
128void QGCMapCircle::setInteractive(bool interactive)
129{
130 if (_interactive != interactive) {
131 _interactive = interactive;
133 }
134}
135
136void QGCMapCircle::setShowRotation(bool showRotation)
137{
138 if (showRotation != _showRotation) {
139 _showRotation = showRotation;
141 }
142}
143
144void QGCMapCircle::setClockwiseRotation(bool clockwiseRotation)
145{
146 if (clockwiseRotation != _clockwiseRotation) {
147 _clockwiseRotation = clockwiseRotation;
149 }
150}
QString errorString
static QMap< QString, FactMetaData * > createMapFromJsonFile(const QString &jsonFilename, QObject *metaDataParent)
void rawValueChanged(const QVariant &value)
The QGCMapCircle represents a circular area which can be displayed on a Map control.
void setInteractive(bool interactive)
bool dirty READ dirty WRITE setDirty NOTIFY dirtyChanged(QGeoCoordinate center READ center WRITE setCenter NOTIFY centerChanged) 1(Fact *radius READ radius CONSTANT) 1(bool interactive READ interactive WRITE setInteractive NOTIFY interactiveChanged) 1(bool showRotation READ showRotation WRITE setShowRotation NOTIFY showRotationChanged) 1(bool clockwiseRotation READ clockwiseRotation WRITE setClockwiseRotation NOTIFY clockwiseRotationChanged) void saveToJson(QJsonObject &json)
void interactiveChanged(bool interactive)
bool clockwiseRotation(void) const
void setClockwiseRotation(bool clockwiseRotation)
QGCMapCircle(QObject *parent=nullptr)
static constexpr const char * jsonCircleKey
void clockwiseRotationChanged(bool clockwiseRotation)
bool interactive(void) const
void setShowRotation(bool showRotation)
void centerChanged(QGeoCoordinate center)
bool showRotation(void) const
void showRotationChanged(bool showRotation)
void setDirty(bool dirty)
Fact * radius(void)
void setCenter(QGeoCoordinate newCenter)
const QGCMapCircle & operator=(const QGCMapCircle &other)
QGeoCoordinate center(void) const
bool loadFromJson(const QJsonObject &json, QString &errorString)
bool dirty(void) const
bool validateKeys(const QJsonObject &jsonObject, const QList< KeyValidateInfo > &keyInfo, QString &errorString)
void saveGeoCoordinate(const QGeoCoordinate &coordinate, bool writeAltitude, QJsonValue &jsonValue, bool geoJsonFormat=false)
bool loadGeoCoordinate(const QJsonValue &jsonValue, bool altitudeRequired, QGeoCoordinate &coordinate, QString &errorString, bool geoJsonFormat=false)
if true, use [lon, lat], [lat, lon] otherwise