From 271c446493a0c64f0ba07f35fcd2807048ab95a6 Mon Sep 17 00:00:00 2001 From: GS-GOAT <86884129+GS-GOAT@users.noreply.github.com> Date: Wed, 12 Feb 2025 00:40:53 +0530 Subject: [PATCH] Measurement: save 'Show Delta' state between commands #19204 (#19430) * Measurement: save 'Show Delta' state between commands #19204 When users set Show Delta option to off in the Measure tool, the setting was not being preserved when the tool was invoked again. This was due to using an uninitialized value as the default when loading the preference. Changes staged in: FreeCAD\src\Mod\Measure\Gui\TaskMeasure.cpp Fixed by: - Using explicit 'true' as default value when loading Show Delta preference - Maintains existing save functionality - Ensures consistent behavior on first use Fixes #19204 * Changed few things to ensure the delta state is saved #19204 added changes:- 1. settings.endGroup() When we call beginGroup(), it creates a prefix for all subsequent settings operations, All settings will be stored under the "TaskMeasure" group. endGroup() is needed to close this grouping scope Without it, subsequent settings operations would still use the "TaskMeasure" prefix 2. settings.sync() By default, QSettings caches changes in memory and writes them to disk later sync() makes an immediate write to the settings file This ensures the setting is saved right away rather than waiting for Qt to decide when to save. Makes the setting change immediately available for future commands. -Fixes Measurement: save 'Show Delta' state between commands #19204 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Added proposed changes to autoSaveChanged() and newMeasurementBehaviourChanged() functions #19204 #19430 Added settings.endGroup() to the following functions:- 1.autoSaveChanged() 2.newMeasurementBehaviourChanged() Each beginGroup() should be followed by endGroup(). No need for explicitily calling sync() as it is called automatically from QSettings's destructor and by the event loop at regular intervals.(Refer documentation for more info) -Fixes Measurement: save 'Show Delta' state between commands #19204 #19430 --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- src/Mod/Measure/Gui/TaskMeasure.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Mod/Measure/Gui/TaskMeasure.cpp b/src/Mod/Measure/Gui/TaskMeasure.cpp index 0ad94adbd1..b5234d62d2 100644 --- a/src/Mod/Measure/Gui/TaskMeasure.cpp +++ b/src/Mod/Measure/Gui/TaskMeasure.cpp @@ -72,7 +72,7 @@ TaskMeasure::TaskMeasure() QSettings settings; settings.beginGroup(QLatin1String(taskMeasureSettingsGroup)); - delta = settings.value(QLatin1String(taskMeasureShowDeltaSettingsName), delta).toBool(); + delta = settings.value(QLatin1String(taskMeasureShowDeltaSettingsName), true).toBool(); mAutoSave = settings.value(QLatin1String(taskMeasureAutoSaveSettingsName), mAutoSave).toBool(); if (settings.value(QLatin1String(taskMeasureGreedySelection), false).toBool()) { Gui::Selection().setSelectionStyle(SelectionStyle::GreedySelection); @@ -80,6 +80,7 @@ TaskMeasure::TaskMeasure() else { Gui::Selection().setSelectionStyle(SelectionStyle::NormalSelection); } + settings.endGroup(); showDelta = new QCheckBox(); showDelta->setChecked(delta); @@ -526,6 +527,8 @@ void TaskMeasure::showDeltaChanged(int checkState) QSettings settings; settings.beginGroup(QLatin1String(taskMeasureSettingsGroup)); settings.setValue(QLatin1String(taskMeasureShowDeltaSettingsName), delta); + settings.endGroup(); + settings.sync(); // immediate write to the settings file this->update(); } @@ -537,6 +540,7 @@ void TaskMeasure::autoSaveChanged(bool checked) QSettings settings; settings.beginGroup(QLatin1String(taskMeasureSettingsGroup)); settings.setValue(QLatin1String(taskMeasureAutoSaveSettingsName), mAutoSave); + settings.endGroup(); } void TaskMeasure::newMeasurementBehaviourChanged(bool checked) @@ -551,6 +555,7 @@ void TaskMeasure::newMeasurementBehaviourChanged(bool checked) Gui::Selection().setSelectionStyle(SelectionStyle::GreedySelection); settings.setValue(QLatin1String(taskMeasureGreedySelection), true); } + settings.endGroup(); } void TaskMeasure::setModeSilent(App::MeasureType* mode)