Unverified Commit e1cf0a16 authored by Don Gagne's avatar Don Gagne Committed by GitHub

Merge pull request #8055 from mavlink/pr-fix_rally_point_default_value

Set Rally Point default value to 0.0 and get it from Fact's default
parents a4be3aef 312d2652
...@@ -12,10 +12,11 @@ ...@@ -12,10 +12,11 @@
"decimalPlaces": 7 "decimalPlaces": 7
}, },
{ {
"name": "Altitude", "name": "Relative Altitude",
"shortDescription": "Altitude of rally point position (home relative)", "shortDescription": "Altitude of rally point position (home relative)",
"type": "double", "type": "double",
"decimalPlaces": 2, "decimalPlaces": 2,
"units": "m" "units": "m",
"defaultValue": 0.0
} }
] ]
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
const char* RallyPoint::_longitudeFactName = "Longitude"; const char* RallyPoint::_longitudeFactName = "Longitude";
const char* RallyPoint::_latitudeFactName = "Latitude"; const char* RallyPoint::_latitudeFactName = "Latitude";
const char* RallyPoint::_altitudeFactName = "Altitude"; const char* RallyPoint::_altitudeFactName = "Relative Altitude";
QMap<QString, FactMetaData*> RallyPoint::_metaDataMap; QMap<QString, FactMetaData*> RallyPoint::_metaDataMap;
...@@ -63,9 +63,7 @@ RallyPoint::~RallyPoint() ...@@ -63,9 +63,7 @@ RallyPoint::~RallyPoint()
void RallyPoint::_factSetup(void) void RallyPoint::_factSetup(void)
{ {
if (_metaDataMap.isEmpty()) { _cacheFactMetadata();
_metaDataMap = FactMetaData::createMapFromJsonFile(QStringLiteral(":/json/RallyPoint.FactMetaData.json"), nullptr /* metaDataParent */);
}
_longitudeFact.setMetaData(_metaDataMap[_longitudeFactName]); _longitudeFact.setMetaData(_metaDataMap[_longitudeFactName]);
_latitudeFact.setMetaData(_metaDataMap[_latitudeFactName]); _latitudeFact.setMetaData(_metaDataMap[_latitudeFactName]);
...@@ -80,6 +78,12 @@ void RallyPoint::_factSetup(void) ...@@ -80,6 +78,12 @@ void RallyPoint::_factSetup(void)
connect(&_altitudeFact, &Fact::valueChanged, this, &RallyPoint::_sendCoordinateChanged); connect(&_altitudeFact, &Fact::valueChanged, this, &RallyPoint::_sendCoordinateChanged);
} }
void RallyPoint::_cacheFactMetadata() {
if (_metaDataMap.isEmpty()) {
_metaDataMap = FactMetaData::createMapFromJsonFile(QStringLiteral(":/json/RallyPoint.FactMetaData.json"), nullptr /* metaDataParent */);
}
}
void RallyPoint::setCoordinate(const QGeoCoordinate& coordinate) void RallyPoint::setCoordinate(const QGeoCoordinate& coordinate)
{ {
if (coordinate != this->coordinate()) { if (coordinate != this->coordinate()) {
...@@ -99,6 +103,15 @@ void RallyPoint::setDirty(bool dirty) ...@@ -99,6 +103,15 @@ void RallyPoint::setDirty(bool dirty)
} }
} }
double RallyPoint::getDefaultFactAltitude() {
_cacheFactMetadata();
auto it = _metaDataMap.find(QString(_altitudeFactName));
if(it != _metaDataMap.end() && (*it)->defaultValueAvailable()) {
return (*it)->rawDefaultValue().toDouble();
}
return 0.0;
}
QGeoCoordinate RallyPoint::coordinate(void) const QGeoCoordinate RallyPoint::coordinate(void) const
{ {
return QGeoCoordinate(_latitudeFact.rawValue().toDouble(), _longitudeFact.rawValue().toDouble(), _altitudeFact.rawValue().toDouble()); return QGeoCoordinate(_latitudeFact.rawValue().toDouble(), _longitudeFact.rawValue().toDouble(), _altitudeFact.rawValue().toDouble());
......
...@@ -39,6 +39,8 @@ public: ...@@ -39,6 +39,8 @@ public:
bool dirty(void) const { return _dirty; } bool dirty(void) const { return _dirty; }
void setDirty(bool dirty); void setDirty(bool dirty);
static double getDefaultFactAltitude();
signals: signals:
void coordinateChanged (const QGeoCoordinate& coordinate); void coordinateChanged (const QGeoCoordinate& coordinate);
void dirtyChanged (bool dirty); void dirtyChanged (bool dirty);
...@@ -48,6 +50,7 @@ private slots: ...@@ -48,6 +50,7 @@ private slots:
private: private:
void _factSetup(void); void _factSetup(void);
static void _cacheFactMetadata();
bool _dirty; bool _dirty;
Fact _longitudeFact; Fact _longitudeFact;
......
...@@ -243,7 +243,12 @@ void RallyPointController::addPoint(QGeoCoordinate point) ...@@ -243,7 +243,12 @@ void RallyPointController::addPoint(QGeoCoordinate point)
if (_points.count()) { if (_points.count()) {
defaultAlt = qobject_cast<RallyPoint*>(_points[_points.count() - 1])->coordinate().altitude(); defaultAlt = qobject_cast<RallyPoint*>(_points[_points.count() - 1])->coordinate().altitude();
} else { } else {
defaultAlt = qgcApp()->toolbox()->settingsManager()->appSettings()->defaultMissionItemAltitude()->rawValue().toDouble(); if(_masterController->controllerVehicle()->fixedWing()) {
defaultAlt = qgcApp()->toolbox()->settingsManager()->appSettings()->defaultMissionItemAltitude()->rawValue().toDouble();
}
else {
defaultAlt = RallyPoint::getDefaultFactAltitude();
}
} }
point.setAltitude(defaultAlt); point.setAltitude(defaultAlt);
RallyPoint* newPoint = new RallyPoint(point, this); RallyPoint* newPoint = new RallyPoint(point, this);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment