diff options
author | Andreas Hartmetz <andreas.hartmetz@kdab.com> | 2016-12-02 16:42:19 +0100 |
---|---|---|
committer | Andreas Hartmetz <andreas.hartmetz@kdab.com> | 2016-12-07 17:14:03 +0000 |
commit | a210e423a334e33acd9b5c9d9fcdc13ed1a1a9ca (patch) | |
tree | d0a21a16c87fbcb131e677944265ba35f21a797f | |
parent | fc298ccec2ef0186cba29b0c7e565ee23e733628 (diff) |
Ventilation item: fix changes by more than one step
Previously, two things did not work:
- Changing by more than one level by directly tapping on the
desired level. This was apparently intended to work but
didn't, from looking at the code.
- Changing by more than one level from the backend
In both cases, the NumberAnimation on the view's index which was
aliased to the ventilation level caused a changed signal for
every step change, which, because it was the most recent change,
became *the* change and caused the final value to fall short of
the actual target value.
After the core fix, a similar fix to the previous one is needed
to make the backend to UI propagation work at all again. But
then it works right.
Change-Id: I31d7f247203cf25b17d06d0eb4edc7af81af4334
Reviewed-by: Nedim Hadzic <nedim.hadzic@pelagicore.com>
-rw-r--r-- | imports/shared/service/climate/ClimateService.qml | 5 | ||||
-rw-r--r-- | sysui/Climate/ClimateBar.qml | 4 | ||||
-rw-r--r-- | sysui/Climate/Ventilation.qml | 26 |
3 files changed, 28 insertions, 7 deletions
diff --git a/imports/shared/service/climate/ClimateService.qml b/imports/shared/service/climate/ClimateService.qml index 6d7a3cd..869b20c 100644 --- a/imports/shared/service/climate/ClimateService.qml +++ b/imports/shared/service/climate/ClimateService.qml @@ -127,7 +127,12 @@ QtObject { property int ventilation: climateControl.fanSpeedLevel.value property string tempSuffix: SettingsService.metric ? "°C" : "°F" property int ventilationLevels: 7 // 6 + off (0) + onVentilationChanged: climateControl.fanSpeedLevel.value = ventilation + property Connections fanSpeedLevelConnections: Connections { + target: climateControl.fanSpeedLevel + onValueChanged: ventilation = climateControl.fanSpeedLevel.value + } property QtObject stateMachine: ClimateStateMachine { climateControl: root.climateControl diff --git a/sysui/Climate/ClimateBar.qml b/sysui/Climate/ClimateBar.qml index 3a9c2c7..f391b6c 100644 --- a/sysui/Climate/ClimateBar.qml +++ b/sysui/Climate/ClimateBar.qml @@ -162,6 +162,10 @@ UIElement { levels: ClimateService.ventilationLevels currentLevel: ClimateService.ventilation onCurrentLevelChanged: ClimateService.ventilation = currentLevel + Connections { + target: ClimateService + onVentilationChanged: ventilation.currentLevel = ClimateService.ventilation + } } Spacer { diff --git a/sysui/Climate/Ventilation.qml b/sysui/Climate/Ventilation.qml index dffed44..c6f4bfa 100644 --- a/sysui/Climate/Ventilation.qml +++ b/sysui/Climate/Ventilation.qml @@ -38,19 +38,31 @@ UIElement { // Number of levels including zero which means 'off'. 7 equals 6 levels + off property int levels - property alias currentLevel: view.currentIndex + property int currentLevel + + property bool _updateInProgress: false + + onCurrentLevelChanged: if (!_updateInProgress) updateLevelInternal(currentLevel); + + function updateLevelInternal(newLevel) { + var boundedLevel = Math.max(0, Math.min(levels - 1, newLevel)); + _updateInProgress = true; + currentLevel = boundedLevel; + _updateInProgress = false; + view.currentIndex = boundedLevel; + } MouseArea { anchors.fill: view anchors.leftMargin: Style.hspan(2) anchors.rightMargin: Style.hspan(2) - onClicked: updateIndex(mouse.x, mouse.y) - onPositionChanged: updateIndex(mouse.x, mouse.y) + onClicked: updateLevelFromMousePosition(mouse.x, mouse.y) + onPositionChanged: updateLevelFromMousePosition(mouse.x, mouse.y) - function updateIndex(x, y) { + function updateLevelFromMousePosition(x, y) { var index = view.indexAt(x, y) if (index > 0) { - view.currentIndex = Math.min(index, view.count-1) + root.updateLevelInternal(index) } } } @@ -76,7 +88,7 @@ UIElement { size: Style.symbolSizeS MouseArea { anchors.fill: parent - onClicked: view.decrementCurrentIndex() + onClicked: root.updateLevelInternal(root.currentLevel - 1) } } @@ -87,7 +99,7 @@ UIElement { size: Style.symbolSizeM MouseArea { anchors.fill: parent - onClicked: view.incrementCurrentIndex() + onClicked: root.updateLevelInternal(root.currentLevel + 1) } } |