From 7e698ba537166331d8777656221339677fb67f10 Mon Sep 17 00:00:00 2001 From: wmayer Date: Tue, 19 Mar 2024 21:00:35 +0100 Subject: [PATCH] Fixes #11861: Gui::PrefUnitSpinBox requires restart after unit system change This fixes a regression of PR #11266 that dropped the case where neither the option 'Ignore project unit system and use the default' is set nor an active document exists. In this case nothing happens even if the user changed the unit system. --- .../PreferencePages/DlgSettingsGeneral.cpp | 35 +++++++++++-------- src/Gui/PreferencePages/DlgSettingsGeneral.h | 1 + 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/src/Gui/PreferencePages/DlgSettingsGeneral.cpp b/src/Gui/PreferencePages/DlgSettingsGeneral.cpp index d78f4c1bec..24c632801a 100644 --- a/src/Gui/PreferencePages/DlgSettingsGeneral.cpp +++ b/src/Gui/PreferencePages/DlgSettingsGeneral.cpp @@ -180,13 +180,8 @@ void DlgSettingsGeneral::setDecimalPointConversion(bool on) } } -void DlgSettingsGeneral::saveSettings() +void DlgSettingsGeneral::saveUnitSystemSettings() { - // must be done as very first because we create a new instance of NavigatorStyle - // where we set some attributes afterwards - int FracInch; // minimum fractional inch to display - int viewSystemIndex; // currently selected View System (unit system) - ParameterGrp::handle hGrpu = App::GetApplication().GetParameterGroupByPath ("User parameter:BaseApp/Preferences/Units"); hGrpu->SetInt("UserSchema", ui->comboBox_UnitSystem->currentIndex()); @@ -202,25 +197,37 @@ void DlgSettingsGeneral::saveSettings() // // The inverse conversion is done when loaded. That way only one thing (the // numerical fractional inch value) needs to be stored. - FracInch = std::pow(2, ui->comboBox_FracInch->currentIndex() + 1); + + // minimum fractional inch to display + int FracInch = std::pow(2, ui->comboBox_FracInch->currentIndex() + 1); hGrpu->SetInt("FracInch", FracInch); // Set the actual format value Base::QuantityFormat::setDefaultDenominator(FracInch); // Set and save the Unit System - if ( ui->checkBox_projectUnitSystemIgnore->isChecked() ) { - viewSystemIndex = ui->comboBox_UnitSystem->currentIndex(); + if (ui->checkBox_projectUnitSystemIgnore->isChecked()) { + // currently selected View System (unit system) + int viewSystemIndex = ui->comboBox_UnitSystem->currentIndex(); + UnitsApi::setSchema(static_cast(viewSystemIndex)); + } + else if (App::Document* doc = App::GetApplication().getActiveDocument()) { + UnitsApi::setSchema(static_cast(doc->UnitSystem.getValue())); + } + else { + // if there is no existing document then the unit must still be set + int viewSystemIndex = ui->comboBox_UnitSystem->currentIndex(); UnitsApi::setSchema(static_cast(viewSystemIndex)); - } else { - App::Document* doc = App::GetApplication().getActiveDocument(); - if ( doc != nullptr ) { - UnitsApi::setSchema(static_cast(doc->UnitSystem.getValue())); - } } ui->SubstituteDecimal->onSave(); ui->UseLocaleFormatting->onSave(); +} + +void DlgSettingsGeneral::saveSettings() +{ + saveUnitSystemSettings(); + ui->RecentFiles->onSave(); ui->EnableCursorBlinking->onSave(); ui->SplashScreen->onSave(); diff --git a/src/Gui/PreferencePages/DlgSettingsGeneral.h b/src/Gui/PreferencePages/DlgSettingsGeneral.h index cab67e4716..0cb072a253 100644 --- a/src/Gui/PreferencePages/DlgSettingsGeneral.h +++ b/src/Gui/PreferencePages/DlgSettingsGeneral.h @@ -75,6 +75,7 @@ public Q_SLOTS: void onUnitSystemIndexChanged(int index); private: + void saveUnitSystemSettings(); void saveDockWindowVisibility(); void loadDockWindowVisibility(); void setRecentFileSize();