QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
RallyPoint.cc
Go to the documentation of this file.
1#include "RallyPoint.h"
2
3QMap<QString, FactMetaData*> RallyPoint::_metaDataMap;
4
5RallyPoint::RallyPoint(const QGeoCoordinate& coordinate, QObject* parent)
6 : QObject(parent)
7 , _dirty(false)
8 , _longitudeFact(0, _longitudeFactName, FactMetaData::valueTypeDouble)
9 , _latitudeFact(0, _latitudeFactName, FactMetaData::valueTypeDouble)
10 , _altitudeFact(0, _altitudeFactName, FactMetaData::valueTypeDouble)
11{
12 // Using setCoordinate() would set dirty
13 _longitudeFact.setRawValue(coordinate.longitude());
14 _latitudeFact.setRawValue(coordinate.latitude());
15 _altitudeFact.setRawValue(coordinate.altitude());
16
17 _factSetup();
18}
19
20RallyPoint::RallyPoint(const RallyPoint& other, QObject* parent)
21 : QObject(parent)
22 , _dirty(false)
23 , _longitudeFact(0, _longitudeFactName, FactMetaData::valueTypeDouble)
24 , _latitudeFact(0, _latitudeFactName, FactMetaData::valueTypeDouble)
25 , _altitudeFact(0, _altitudeFactName, FactMetaData::valueTypeDouble)
26{
27 _longitudeFact.setRawValue(other._longitudeFact.rawValue());
28 _latitudeFact.setRawValue(other._latitudeFact.rawValue());
29 _altitudeFact.setRawValue(other._altitudeFact.rawValue());
30
31 _factSetup();
32}
33
35{
36 _longitudeFact.setRawValue(other._longitudeFact.rawValue());
37 _latitudeFact.setRawValue(other._latitudeFact.rawValue());
38 _altitudeFact.setRawValue(other._altitudeFact.rawValue());
39
41
42 return *this;
43}
44
49
50void RallyPoint::_factSetup(void)
51{
52 _cacheFactMetadata();
53
54 _latitudeFact.setMetaData(_metaDataMap[_latitudeFactName]);
55 _longitudeFact.setMetaData(_metaDataMap[_longitudeFactName]);
56 _altitudeFact.setMetaData(_metaDataMap[_altitudeFactName]);
57
58 _textFieldFacts.append(QVariant::fromValue(&_latitudeFact));
59 _textFieldFacts.append(QVariant::fromValue(&_longitudeFact));
60 _textFieldFacts.append(QVariant::fromValue(&_altitudeFact));
61
62 connect(&_latitudeFact, &Fact::valueChanged, this, &RallyPoint::_sendCoordinateChanged);
63 connect(&_longitudeFact, &Fact::valueChanged, this, &RallyPoint::_sendCoordinateChanged);
64 connect(&_altitudeFact, &Fact::valueChanged, this, &RallyPoint::_sendCoordinateChanged);
65
66 // Raw, not cooked: a units change must not dirty the point
67 for (Fact* const fact : {&_latitudeFact, &_longitudeFact, &_altitudeFact}) {
68 connect(fact, &Fact::rawValueChanged, this, [this]() { setDirty(true); });
69 }
70}
71
72void RallyPoint::_cacheFactMetadata() {
73 if (_metaDataMap.isEmpty()) {
74 _metaDataMap = FactMetaData::createMapFromJsonFile(QStringLiteral(":/json/RallyPoint.FactMetaData.json"), nullptr /* metaDataParent */);
75 }
76}
77
78void RallyPoint::setCoordinate(const QGeoCoordinate& coordinate)
79{
80 if (coordinate != this->coordinate()) {
81 _longitudeFact.setRawValue(coordinate.longitude());
82 _latitudeFact.setRawValue(coordinate.latitude());
83 _altitudeFact.setRawValue(coordinate.altitude());
85 setDirty(true);
86 }
87}
88
89void RallyPoint::setDirty(bool dirty)
90{
91 if (dirty != _dirty) {
92 _dirty = dirty;
93 emit dirtyChanged(dirty);
94 }
95}
96
98 _cacheFactMetadata();
99 auto it = _metaDataMap.find(QString(_altitudeFactName));
100 if(it != _metaDataMap.end() && (*it)->defaultValueAvailable()) {
101 return (*it)->rawDefaultValue().toDouble();
102 }
103 return 0.0;
104}
105
106QGeoCoordinate RallyPoint::coordinate(void) const
107{
108 return QGeoCoordinate(_latitudeFact.rawValue().toDouble(), _longitudeFact.rawValue().toDouble(), _altitudeFact.rawValue().toDouble());
109}
110
111void RallyPoint::_sendCoordinateChanged(void)
112{
114}
Holds the meta data associated with a Fact.
static QMap< QString, FactMetaData * > createMapFromJsonFile(const QString &jsonFilename, QObject *metaDataParent)
A Fact is used to hold a single value within the system.
Definition Fact.h:15
void setMetaData(FactMetaData *metaData, bool setDefaultFromMetaData=false)
Definition Fact.cc:742
void rawValueChanged(const QVariant &value)
void setRawValue(const QVariant &value)
Definition Fact.cc:135
QVariant rawValue() const
Definition Fact.h:87
void valueChanged(const QVariant &value)
This signal is only meant for use by the QT property system. It should not be connected to by client ...
This class is used to encapsulate the QGeoCoordinate associated with a Rally Point into a QObject suc...
Definition RallyPoint.h:12
QGeoCoordinate coordinate(void) const
void setCoordinate(const QGeoCoordinate &coordinate)
Definition RallyPoint.cc:78
static double getDefaultFactAltitude()
Definition RallyPoint.cc:97
const RallyPoint & operator=(const RallyPoint &other)
Definition RallyPoint.cc:34
void dirtyChanged(bool dirty)
bool dirty(void) const
Definition RallyPoint.h:30
RallyPoint(const QGeoCoordinate &coordinate, QObject *parent=nullptr)
Definition RallyPoint.cc:5
void coordinateChanged(const QGeoCoordinate &coordinate)
void setDirty(bool dirty)
Definition RallyPoint.cc:89