From 0a8936644e1dbd48c6f9adefba50448d69c608fc Mon Sep 17 00:00:00 2001 From: Kacper Donat Date: Mon, 6 Nov 2023 19:16:50 +0100 Subject: [PATCH] Gui: Move reset logic to PreferencePage --- src/Gui/DlgPreferencesImp.cpp | 16 ++-------------- src/Gui/PrefWidgets.cpp | 2 +- src/Gui/PropertyPage.cpp | 19 +++++++++++++++++++ src/Gui/PropertyPage.h | 1 + 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/Gui/DlgPreferencesImp.cpp b/src/Gui/DlgPreferencesImp.cpp index e54f4bf50e..baa741cbb2 100644 --- a/src/Gui/DlgPreferencesImp.cpp +++ b/src/Gui/DlgPreferencesImp.cpp @@ -725,20 +725,8 @@ void DlgPreferencesImp::restorePageDefaults(PreferencesPageItem* item) auto* page = qobject_cast(item->getWidget()); auto prefs = page->findChildren(); - for (const auto& pref : prefs) { - if (!pref->property("prefPath").isNull() && !pref->property("prefEntry").isNull()) { - std::string path = pref->property("prefPath").toString().toStdString(); - std::string entry = pref->property("prefEntry").toString().toStdString(); - - ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath( - std::string("User parameter:BaseApp/Preferences/" + path).c_str()); - - for (const auto& pn : hGrp->GetParameterNames(entry.c_str())) { - hGrp->RemoveAttribute(pn.first, pn.second.c_str()); - } - } - } - + page->resetSettingsToDefaults(); + std::string pageName = page->property(PageNameProperty).toString().toStdString(); std::string groupName = page->property(GroupNameProperty).toString().toStdString(); diff --git a/src/Gui/PrefWidgets.cpp b/src/Gui/PrefWidgets.cpp index 314380b311..445392c041 100644 --- a/src/Gui/PrefWidgets.cpp +++ b/src/Gui/PrefWidgets.cpp @@ -815,7 +815,7 @@ void PrefFontBox::savePreferences() QFont currFont = currentFont(); QString currName = currFont.family(); - getWindowParameter()->SetASCII( entryName() , currName.toUtf8() ); + getWindowParameter()->SetASCII(entryName(), currName.toUtf8()); } #include "moc_PrefWidgets.cpp" diff --git a/src/Gui/PropertyPage.cpp b/src/Gui/PropertyPage.cpp index 26123473f2..2526ad8967 100644 --- a/src/Gui/PropertyPage.cpp +++ b/src/Gui/PropertyPage.cpp @@ -28,6 +28,7 @@ #endif #include +#include #include "PropertyPage.h" #include "PrefWidgets.h" @@ -209,6 +210,24 @@ void PreferenceUiForm::saveSettings() savePrefWidgets(); } +void PreferencePage::resetSettingsToDefaults() +{ + auto prefs = this->findChildren(); + + for (const auto& pref : prefs) { + if (!pref->property("prefPath").isNull() && !pref->property("prefEntry").isNull()) { + std::string path = pref->property("prefPath").toString().toStdString(); + std::string entry = pref->property("prefEntry").toString().toStdString(); + + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath( + std::string("User parameter:BaseApp/Preferences/" + path).c_str()); + + for (const auto& pn : hGrp->GetParameterNames(entry.c_str())) { + hGrp->RemoveAttribute(pn.first, pn.second.c_str()); + } + } + } +} // ---------------------------------------------------------------- /** Construction */ diff --git a/src/Gui/PropertyPage.h b/src/Gui/PropertyPage.h index 5d17f3bf8f..9fbf03e0b5 100644 --- a/src/Gui/PropertyPage.h +++ b/src/Gui/PropertyPage.h @@ -79,6 +79,7 @@ public: public Q_SLOTS: virtual void loadSettings()=0; virtual void saveSettings()=0; + virtual void resetSettingsToDefaults(); protected: void changeEvent(QEvent* event) override = 0;