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{
13
14 _factSetup();
15}
16
17RallyPoint::RallyPoint(const RallyPoint& other, QObject* parent)
18 : QObject(parent)
19 , _dirty(false)
20 , _longitudeFact(0, _longitudeFactName, FactMetaData::valueTypeDouble)
21 , _latitudeFact(0, _latitudeFactName, FactMetaData::valueTypeDouble)
22 , _altitudeFact(0, _altitudeFactName, FactMetaData::valueTypeDouble)
23{
24 _longitudeFact.setRawValue(other._longitudeFact.rawValue());
25 _latitudeFact.setRawValue(other._latitudeFact.rawValue());
26 _altitudeFact.setRawValue(other._altitudeFact.rawValue());
27
28 _factSetup();
29}
30
32{
33 _longitudeFact.setRawValue(other._longitudeFact.rawValue());
34 _latitudeFact.setRawValue(other._latitudeFact.rawValue());
35 _altitudeFact.setRawValue(other._altitudeFact.rawValue());
36
38
39 return *this;
40}
41
46
47void RallyPoint::_factSetup(void)
48{
49 _cacheFactMetadata();
50
51 _latitudeFact.setMetaData(_metaDataMap[_latitudeFactName]);
52 _longitudeFact.setMetaData(_metaDataMap[_longitudeFactName]);
53 _altitudeFact.setMetaData(_metaDataMap[_altitudeFactName]);
54
55 _textFieldFacts.append(QVariant::fromValue(&_latitudeFact));
56 _textFieldFacts.append(QVariant::fromValue(&_longitudeFact));
57 _textFieldFacts.append(QVariant::fromValue(&_altitudeFact));
58
59 connect(&_latitudeFact, &Fact::valueChanged, this, &RallyPoint::_sendCoordinateChanged);
60 connect(&_longitudeFact, &Fact::valueChanged, this, &RallyPoint::_sendCoordinateChanged);
61 connect(&_altitudeFact, &Fact::valueChanged, this, &RallyPoint::_sendCoordinateChanged);
62}
63
64void RallyPoint::_cacheFactMetadata() {
65 if (_metaDataMap.isEmpty()) {
66 _metaDataMap = FactMetaData::createMapFromJsonFile(QStringLiteral(":/json/RallyPoint.FactMetaData.json"), nullptr /* metaDataParent */);
67 }
68}
69
70void RallyPoint::setCoordinate(const QGeoCoordinate& coordinate)
71{
72 if (coordinate != this->coordinate()) {
73 _longitudeFact.setRawValue(coordinate.longitude());
74 _latitudeFact.setRawValue(coordinate.latitude());
75 _altitudeFact.setRawValue(coordinate.altitude());
77 setDirty(true);
78 }
79}
80
81void RallyPoint::setDirty(bool dirty)
82{
83 if (dirty != _dirty) {
84 _dirty = dirty;
85 emit dirtyChanged(dirty);
86 }
87}
88
90 _cacheFactMetadata();
91 auto it = _metaDataMap.find(QString(_altitudeFactName));
92 if(it != _metaDataMap.end() && (*it)->defaultValueAvailable()) {
93 return (*it)->rawDefaultValue().toDouble();
94 }
95 return 0.0;
96}
97
98QGeoCoordinate RallyPoint::coordinate(void) const
99{
100 return QGeoCoordinate(_latitudeFact.rawValue().toDouble(), _longitudeFact.rawValue().toDouble(), _altitudeFact.rawValue().toDouble());
101}
102
103void RallyPoint::_sendCoordinateChanged(void)
104{
106}
Holds the meta data associated with a Fact.
static QMap< QString, FactMetaData * > createMapFromJsonFile(const QString &jsonFilename, QObject *metaDataParent)
void setMetaData(FactMetaData *metaData, bool setDefaultFromMetaData=false)
Definition Fact.cc:674
void setRawValue(const QVariant &value)
Definition Fact.cc:128
QVariant rawValue() const
Value after translation.
Definition Fact.h:85
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
Definition RallyPoint.cc:98
void setCoordinate(const QGeoCoordinate &coordinate)
Definition RallyPoint.cc:70
static double getDefaultFactAltitude()
Definition RallyPoint.cc:89
const RallyPoint & operator=(const RallyPoint &other)
Definition RallyPoint.cc:31
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:81