From e65202cfbedc287f9cf71e8a36a008b92ea1cd06 Mon Sep 17 00:00:00 2001 From: miruka Date: Wed, 16 Sep 2020 07:42:59 -0400 Subject: [PATCH] Fix checkbox update when default state changes Make sure to update checkboxes when their default value changes and the user hasn't already changed the value themselves. This fixes a dangerous issue with new room switching and room settings checkboxes keeping their value from the previous room. --- src/gui/Base/HCheckBox.qml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/gui/Base/HCheckBox.qml b/src/gui/Base/HCheckBox.qml index 22e34e88..471a3eaf 100644 --- a/src/gui/Base/HCheckBox.qml +++ b/src/gui/Base/HCheckBox.qml @@ -12,6 +12,8 @@ CheckBox { property bool defaultChecked: false readonly property bool changed: checked !== defaultChecked + property bool previousDefaultChecked: false // private + function reset() { checked = defaultChecked } @@ -92,5 +94,15 @@ CheckBox { } } + onDefaultCheckedChanged: { + if (checked === previousDefaultChecked) + checked = Qt.binding(() => defaultChecked) + + previousDefaultChecked = defaultChecked + } + + // Break binding + Component.onCompleted: previousDefaultChecked = previousDefaultChecked + Behavior on opacity { HNumberAnimation { factor: 2 } } }