From 6c4734101919b135162ac7ecd97ffe421ac1f4f9 Mon Sep 17 00:00:00 2001 From: Michael Zanetti Date: Tue, 26 Jan 2021 15:09:55 +0100 Subject: [PATCH] Some fixes for units (pressure mostly) --- libnymea-app/types/types.cpp | 12 +++++++++++- libnymea-app/types/types.h | 1 + nymea-app/ui/Nymea.qml | 5 ++++- nymea-app/ui/customviews/WeatherView.qml | 8 +++++--- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/libnymea-app/types/types.cpp b/libnymea-app/types/types.cpp index c5d8b432..e9618a00 100644 --- a/libnymea-app/types/types.cpp +++ b/libnymea-app/types/types.cpp @@ -90,6 +90,10 @@ QString Types::toUiUnit(Types::Unit unit) const case Types::UnitKiloMeterPerHour: uiUnit = Types::UnitMilePerHour; break; + case Types::UnitMilliBar: + case Types::UnitBar: + uiUnit = Types::UnitPoundsPerSquareInch; + break; default: uiUnit = unit; } @@ -217,6 +221,8 @@ QString Types::toUiUnit(Types::Unit unit) const return "fps"; case Types::UnitMilePerHour: return "mph"; + case Types::UnitPoundsPerSquareInch: + return "psi"; } return ""; @@ -242,8 +248,12 @@ QVariant Types::toUiValue(const QVariant &value, Types::Unit unit) const return value.toDouble() / 1.609; case Types::UnitMeterPerSecond: // To foot per second return value.toDouble() * 3.281; - case Types::UnitKiloMeterPerHour: + case Types::UnitKiloMeterPerHour: // To miles per hour return value.toDouble() / 1.609; + case Types::UnitMilliBar: // To pounds per square inch (psi) + return value.toDouble() * 0.01450377; + case Types::UnitBar: // To pounds per square inch (psi) + return value.toDouble() * 14.50377; default: return value; } diff --git a/libnymea-app/types/types.h b/libnymea-app/types/types.h index e5cc76a3..7d11107d 100644 --- a/libnymea-app/types/types.h +++ b/libnymea-app/types/types.h @@ -117,6 +117,7 @@ public: UnitMile, UnitFootPerSecond, UnitMilePerHour, + UnitPoundsPerSquareInch }; Q_ENUM(Unit) diff --git a/nymea-app/ui/Nymea.qml b/nymea-app/ui/Nymea.qml index 3cb99172..54a7027f 100644 --- a/nymea-app/ui/Nymea.qml +++ b/nymea-app/ui/Nymea.qml @@ -90,7 +90,10 @@ ApplicationWindow { property string cloudEnvironment: "Community" property bool showConnectionTabs: false property int tabCount: 1 - property string units: "metric" // or "imperial" + // FIXME: This shouldn't be needed... we should probably only use the system locale and not even provide a setting + // However, the topic is more complex, and in the long run we'd probably want to allow the user selecting the + // desired unit for particular interfaces/things/views. See https://github.com/nymea/nymea/issues/386 + property string units: Qt.locale().measurementSystem === Locale.MetricSystem ? "metric" : "imperial" } property string privacyPolicyUrl: "https://nymea.io/privacy-statement/en/nymea_privacy.html" diff --git a/nymea-app/ui/customviews/WeatherView.qml b/nymea-app/ui/customviews/WeatherView.qml index c509e34a..0b8b6cc4 100644 --- a/nymea-app/ui/customviews/WeatherView.qml +++ b/nymea-app/ui/customviews/WeatherView.qml @@ -49,6 +49,8 @@ Item { readonly property State windSpeedState: thing.stateByName("windSpeed") readonly property StateType temperatureStateType: thing.thingClass.stateTypes.findByName("temperature") + readonly property StateType pressureStateType: thing.thingClass.stateTypes.findByName("pressure") + readonly property StateType windSpeedStateType: thing.thingClass.stateTypes.findByName("windspeed") ColumnLayout { id: grid @@ -75,7 +77,7 @@ Item { color: app.interfaceToColor("temperaturesensor") } Label { - text: (temperatureState ? Math.round(Types.toUiValue(temperatureState.value, temperatureStateType.unit) * 10) / 10 : "N/A") + " °" + text: (temperatureState ? "%1 %2".arg(Math.round(Types.toUiValue(temperatureState.value, temperatureStateType.unit) * 10) / 10).arg(Types.toUiUnit(temperatureStateType.unit)) : "N/A") Layout.fillWidth: true horizontalAlignment: Text.AlignHCenter } @@ -115,7 +117,7 @@ Item { } Label { - text: (pressureState ? pressureState.value : "N/A") + " mBar" + text: (pressureState ? "%1 %2".arg(Types.toUiValue(pressureState.value, pressureStateType.unit)).arg(Types.toUiUnit(pressureStateType.unit)) : "N/A") } ColorIcon { name: "../images/weathericons/wind.svg" @@ -125,7 +127,7 @@ Item { } Label { - text: windSpeedState && windDirectionState ? "%1 km/h %2".arg(windSpeedState.value).arg(angleToOrientation(windDirectionState.value)) : "N/A" + text: windSpeedState && windDirectionState ? "%1 %2 %3".arg(Types.toUiValue(windSpeedState.value, windSpeedStateType.unit)).arg(Types.toUiUnit(windSpeedStateType.unit)).arg(angleToOrientation(windDirectionState.value)) : "N/A" function angleToOrientation(windAngle) { if (windAngle < 23) { return qsTr("N");