Commit 1b04f783 authored by Don Gagne's avatar Don Gagne

Support user configurable unit conversion

parent dcd55081
......@@ -534,3 +534,47 @@ void FactMetaData::setAppSettingsTranslators(void)
}
}
}
const FactMetaData::AppSettingsTranslation_s* FactMetaData::_findAppSettingsDistanceUnitsTranslation(const QString& rawUnits)
{
for (size_t i=0; i<sizeof(_rgAppSettingsTranslations)/sizeof(_rgAppSettingsTranslations[0]); i++) {
const AppSettingsTranslation_s* pAppSettingsTranslation = &_rgAppSettingsTranslations[i];
if (pAppSettingsTranslation->rawUnits == 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");
}
}
......@@ -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[];
};
......
......@@ -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)
}
}
}
......@@ -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) : ""
......
......@@ -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; }
......
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