Some fixes for units (pressure mostly)
This commit is contained in:
parent
c478310c52
commit
6c47341019
@ -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;
|
||||
}
|
||||
|
||||
@ -117,6 +117,7 @@ public:
|
||||
UnitMile,
|
||||
UnitFootPerSecond,
|
||||
UnitMilePerHour,
|
||||
UnitPoundsPerSquareInch
|
||||
};
|
||||
Q_ENUM(Unit)
|
||||
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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");
|
||||
|
||||
Reference in New Issue
Block a user