diff --git a/src/FactSystem/FactMetaData.cc b/src/FactSystem/FactMetaData.cc index d350835d0fdf9203d919f7d281bef9764e119dab..4fa029eb41420b01b8f3889a9eccb59312c35520 100644 --- a/src/FactSystem/FactMetaData.cc +++ b/src/FactSystem/FactMetaData.cc @@ -534,3 +534,47 @@ void FactMetaData::setAppSettingsTranslators(void) } } } + +const FactMetaData::AppSettingsTranslation_s* FactMetaData::_findAppSettingsDistanceUnitsTranslation(const QString& rawUnits) +{ + for (size_t i=0; irawUnits == rawUnits && + (!pAppSettingsTranslation->speed && pAppSettingsTranslation->speedOrDistanceUnits == QGroundControlQmlGlobal::distanceUnits()->rawValue().toUInt())) { + return pAppSettingsTranslation; + } + } + + return NULL; +} + +QVariant FactMetaData::metersToAppSettingsDistanceUnits(const QVariant& meters) +{ + const AppSettingsTranslation_s* pAppSettingsTranslation = _findAppSettingsDistanceUnitsTranslation("m"); + if (pAppSettingsTranslation) { + return pAppSettingsTranslation->rawTranslator(meters); + } else { + return meters; + } +} + +QVariant FactMetaData::appSettingsDistanceUnitsToMeters(const QVariant& distance) +{ + const AppSettingsTranslation_s* pAppSettingsTranslation = _findAppSettingsDistanceUnitsTranslation("m"); + if (pAppSettingsTranslation) { + return pAppSettingsTranslation->cookedTranslator(distance); + } else { + return distance; + } +} + +QString FactMetaData::appSettingsDistanceUnitsString(void) +{ + const AppSettingsTranslation_s* pAppSettingsTranslation = _findAppSettingsDistanceUnitsTranslation("m"); + if (pAppSettingsTranslation) { + return pAppSettingsTranslation->cookedUnits; + } else { + return QStringLiteral("m"); + } +} diff --git a/src/FactSystem/FactMetaData.h b/src/FactSystem/FactMetaData.h index 14cc9a9c2561a8fb08c1c000f7c82390de8b78a8..e13484c9423178f3689739fa915a35ba312f760b 100644 --- a/src/FactSystem/FactMetaData.h +++ b/src/FactSystem/FactMetaData.h @@ -61,6 +61,15 @@ public: const FactMetaData& operator=(const FactMetaData& other); + /// Converts from meters to the user specified distance unit + static QVariant metersToAppSettingsDistanceUnits(const QVariant& meters); + + /// Converts from user specified distance unit to meters + static QVariant appSettingsDistanceUnitsToMeters(const QVariant& distance); + + /// Returns the string for distance units which has configued by user + static QString appSettingsDistanceUnitsString(void); + int decimalPlaces (void) const { return _decimalPlaces; } QVariant rawDefaultValue (void) const; QVariant cookedDefaultValue (void) const { return _rawTranslator(rawDefaultValue()); } @@ -154,6 +163,18 @@ private: static QVariant _metersPerSecondToKnots(const QVariant& metersPerSecond); static QVariant _knotsToMetersPerSecond(const QVariant& knots); + struct AppSettingsTranslation_s { + const char* rawUnits; + const char* cookedUnits; + bool speed; + uint32_t speedOrDistanceUnits; + Translator rawTranslator; + Translator cookedTranslator; + + }; + + static const AppSettingsTranslation_s* _findAppSettingsDistanceUnitsTranslation(const QString& rawUnits); + ValueType_t _type; // must be first for correct constructor init int _decimalPlaces; QVariant _rawDefaultValue; @@ -186,15 +207,6 @@ private: }; static const BuiltInTranslation_s _rgBuiltInTranslations[]; - struct AppSettingsTranslation_s { - const char* rawUnits; - const char* cookedUnits; - bool speed; - uint32_t speedOrDistanceUnits; - Translator rawTranslator; - Translator cookedTranslator; - - }; static const AppSettingsTranslation_s _rgAppSettingsTranslations[]; }; diff --git a/src/FlightDisplay/FlightDisplayViewWidgets.qml b/src/FlightDisplay/FlightDisplayViewWidgets.qml index 371ffcf17dc995486475f19dd7bfa2c2659c4dc5..20b36bd7970d3cd713c8ad3b9e0b583d5ed24810 100644 --- a/src/FlightDisplay/FlightDisplayViewWidgets.qml +++ b/src/FlightDisplay/FlightDisplayViewWidgets.qml @@ -341,7 +341,7 @@ Item { break; case confirmTakeoff: altitudeSlider.visible = true - altitudeSlider.initialValue = 10 + altitudeSlider.setInitialValueMeters(10) _guidedModeBar.confirmText = "takeoff" break; case confirmLand: @@ -349,7 +349,7 @@ Item { break; case confirmChangeAlt: altitudeSlider.visible = true - altitudeSlider.initialValue = _activeVehicle.altitudeAMSL.value + altitudeSlider.setInitialValueAppSettingsDistanceUnits(_activeVehicle.altitudeAMSL.value) _guidedModeBar.confirmText = "altitude change" break; case confirmGoTo: @@ -444,14 +444,24 @@ Item { opacity: 0.8 visible: false - property alias initialValue: altSlider.value + function setInitialValueMeters(meters) { + altSlider.value = QGroundControl.metersToAppSettingsDistanceUnits(meters) + } + + function setInitialValueAppSettingsDistanceUnits(height) { + altSlider.value = height + } /// Returns NaN for bad value function getValue() { - return parseFloat(altField.text) + var value = parseFloat(altField.text) + if (!isNaN(value)) { + return QGroundControl.appSettingsDistanceUnitsToMeters(value); + } else { + return value; + } } - Column { id: headerColumn anchors.margins: _margins @@ -461,12 +471,12 @@ Item { QGCLabel { anchors.horizontalCenter: parent.horizontalCenter - text: "Altitude" + text: "Alt (rel)" } QGCLabel { anchors.horizontalCenter: parent.horizontalCenter - text: "meters (rel)" + text: QGroundControl.appSettingsDistanceUnitsString } QGCTextField { @@ -486,9 +496,7 @@ Item { anchors.right: parent.right orientation: Qt.Vertical minimumValue: 0 - maximumValue: 100 - value: 30 - //anchors.horizontalCenter: parent.horizontalCenter + maximumValue: QGroundControl.metersToAppSettingsDistanceUnits(100) } } } diff --git a/src/MissionEditor/MissionItemStatus.qml b/src/MissionEditor/MissionItemStatus.qml index ced1b401e15cb2470c60be6b0538f880cda930b6..b8436ae073a05747de951937763d3784032b7b0a 100644 --- a/src/MissionEditor/MissionItemStatus.qml +++ b/src/MissionEditor/MissionItemStatus.qml @@ -27,6 +27,7 @@ import QtQuick.Controls 1.3 import QGroundControl.ScreenTools 1.0 import QGroundControl.Controls 1.0 import QGroundControl.Palette 1.0 +import QGroundControl 1.0 Rectangle { property var currentMissionItem ///< Mission item to display status for @@ -50,8 +51,8 @@ Rectangle { property real _gradientPercent: isNaN(_gradient) ? 0 : _gradient * 100 property real _azimuth: _statusValid ? _currentMissionItem.azimuth : -1 property bool _statusValid: currentMissionItem != undefined - property string _distanceText: _statusValid ? _distance.toFixed(2) + " m" : "" - property string _altText: _statusValid ? _altDifference.toFixed(2) + " m" : "" + property string _distanceText: _statusValid ? QGroundControl.metersToAppSettingsDistanceUnits(_distance).toFixed(2) + " " + QGroundControl.appSettingsDistanceUnitsString : "" + property string _altText: _statusValid ? QGroundControl.metersToAppSettingsDistanceUnits(_altDifference).toFixed(2) + " " + QGroundControl.appSettingsDistanceUnitsString : "" property string _gradientText: _statusValid ? _gradientPercent.toFixed(0) + "%" : "" property string _azimuthText: _statusValid ? Math.round(_azimuth) : "" diff --git a/src/QmlControls/QGroundControlQmlGlobal.h b/src/QmlControls/QGroundControlQmlGlobal.h index 5c1dbdd0f145eba98b4c5b33bba633b73022a25a..adc91f9586ba810dd936f1f6f9f65724e24f3c59 100644 --- a/src/QmlControls/QGroundControlQmlGlobal.h +++ b/src/QmlControls/QGroundControlQmlGlobal.h @@ -34,6 +34,7 @@ #include "FlightMapSettings.h" #include "MissionCommands.h" #include "SettingsFact.h" +#include "FactMetaData.h" #ifdef QT_DEBUG #include "MockLink.h" @@ -104,6 +105,9 @@ public: /// @ return: true: experimental survey ip code is turned on Q_PROPERTY(bool experimentalSurvey READ experimentalSurvey WRITE setExperimentalSurvey NOTIFY experimentalSurveyChanged) + /// Returns the string for distance units which has configued by user + Q_PROPERTY(QString appSettingsDistanceUnitsString READ appSettingsDistanceUnitsString CONSTANT) + Q_INVOKABLE void saveGlobalSetting (const QString& key, const QString& value); Q_INVOKABLE QString loadGlobalSetting (const QString& key, const QString& defaultValue); Q_INVOKABLE void saveBoolGlobalSetting (const QString& key, bool value); @@ -118,6 +122,14 @@ public: Q_INVOKABLE void startAPMArduPlaneMockLink (bool sendStatusText); Q_INVOKABLE void stopAllMockLinks (void); + /// Converts from meters to the user specified distance unit + Q_INVOKABLE QVariant metersToAppSettingsDistanceUnits(const QVariant& meters) const { return FactMetaData::metersToAppSettingsDistanceUnits(meters); } + + /// Converts from user specified distance unit to meters + Q_INVOKABLE QVariant appSettingsDistanceUnitsToMeters(const QVariant& distance) const { return FactMetaData::appSettingsDistanceUnitsToMeters(distance); } + + QString appSettingsDistanceUnitsString(void) const { return FactMetaData::appSettingsDistanceUnitsString(); } + // Property accesors FlightMapSettings* flightMapSettings () { return _flightMapSettings; }