From 3d029739511fd72723b25843aac9c816a00ad080 Mon Sep 17 00:00:00 2001 From: Furgo <148809153+furgo16@users.noreply.github.com> Date: Wed, 11 Jun 2025 01:51:40 +0200 Subject: [PATCH 1/3] Gui: add new PrefCheckableGroupBox widget --- src/Gui/PrefWidgets.cpp | 33 +++++++++++++++++++++++++++++++++ src/Gui/PrefWidgets.h | 26 ++++++++++++++++++++++++++ src/Gui/PropertyPage.cpp | 2 ++ src/Gui/resource.cpp | 1 + 4 files changed, 62 insertions(+) diff --git a/src/Gui/PrefWidgets.cpp b/src/Gui/PrefWidgets.cpp index 66dbeaa839..5f71f0f19b 100644 --- a/src/Gui/PrefWidgets.cpp +++ b/src/Gui/PrefWidgets.cpp @@ -864,4 +864,37 @@ void PrefFontBox::savePreferences() getWindowParameter()->SetASCII(entryName(), currName.toUtf8()); } +// -------------------------------------------------------------------- + +PrefCheckableGroupBox::PrefCheckableGroupBox(QWidget* parent) + : QGroupBox(parent), PrefWidget() +{ +} + +PrefCheckableGroupBox::~PrefCheckableGroupBox() = default; + +void PrefCheckableGroupBox::restorePreferences() +{ + if (getWindowParameter().isNull() || entryName().isEmpty()) { + failedToRestore(objectName()); + return; + } + + // Default value is the current state of the checkbox (usually from .ui on first load) + bool defaultValueInUi = isChecked(); + bool actualValue = getWindowParameter()->GetBool(entryName(), defaultValueInUi); + setChecked(actualValue); +} + +void PrefCheckableGroupBox::savePreferences() +{ + if (getWindowParameter().isNull() || entryName().isEmpty()) + { + failedToSave(objectName()); + return; + } + + getWindowParameter()->SetBool(entryName(), isChecked()); +} + #include "moc_PrefWidgets.cpp" diff --git a/src/Gui/PrefWidgets.h b/src/Gui/PrefWidgets.h index c805f7d063..8f69406d2c 100644 --- a/src/Gui/PrefWidgets.h +++ b/src/Gui/PrefWidgets.h @@ -26,6 +26,7 @@ #include #include #include +#include #include #include @@ -426,6 +427,31 @@ protected: void savePreferences() override; }; +/** + * The PrefCheckableGroupBox class allows a QGroupBox to act as a boolean preference. + * Its 'checked' state is saved to and restored from the FreeCAD parameter system + * using the 'prefEntry' and 'prefPath' dynamic properties set in the .ui file. + * When the GroupBox is checked, its children are enabled; when unchecked, disabled (standard + * QGroupBox behavior). + */ +class GuiExport PrefCheckableGroupBox : public QGroupBox, public PrefWidget +{ + Q_OBJECT + + Q_PROPERTY(QByteArray prefEntry READ entryName WRITE setEntryName) // clazy:exclude=qproperty-without-notify + Q_PROPERTY(QByteArray prefPath READ paramGrpPath WRITE setParamGrpPath) // clazy:exclude=qproperty-without-notify + +public: + explicit PrefCheckableGroupBox(QWidget* parent = nullptr); + ~PrefCheckableGroupBox() override; + +protected: + // restore from/save to parameters + void restorePreferences() override; + void savePreferences() override; + +}; + } // namespace Gui #endif // GUI_PREFWIDGETS_H diff --git a/src/Gui/PropertyPage.cpp b/src/Gui/PropertyPage.cpp index 08c8407720..09da2764b5 100644 --- a/src/Gui/PropertyPage.cpp +++ b/src/Gui/PropertyPage.cpp @@ -187,6 +187,7 @@ void PreferenceUiForm::loadSettings() loadPrefWidgets(); loadPrefWidgets(); loadPrefWidgets(); + loadPrefWidgets(); } void PreferenceUiForm::saveSettings() @@ -208,6 +209,7 @@ void PreferenceUiForm::saveSettings() savePrefWidgets(); savePrefWidgets(); savePrefWidgets(); + savePrefWidgets(); } QWidget* Gui::Dialog::PreferenceUiForm::form() diff --git a/src/Gui/resource.cpp b/src/Gui/resource.cpp index f0d630a281..9239a9b24b 100644 --- a/src/Gui/resource.cpp +++ b/src/Gui/resource.cpp @@ -115,6 +115,7 @@ WidgetFactorySupplier::WidgetFactorySupplier() new WidgetProducer; new WidgetProducer; new WidgetProducer; + new WidgetProducer; new WidgetProducer; new WidgetProducer; new WidgetProducer; From cf5cf2babf9101f16e9447da7cda78e9339278fd Mon Sep 17 00:00:00 2001 From: Furgo <148809153+furgo16@users.noreply.github.com> Date: Tue, 10 Jun 2025 23:56:36 +0200 Subject: [PATCH 2/3] Draft: handle reading defaults from PrefCheckableGroupBox --- src/Mod/Draft/draftutils/params.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Mod/Draft/draftutils/params.py b/src/Mod/Draft/draftutils/params.py index a960935f93..ad49b2b7bf 100644 --- a/src/Mod/Draft/draftutils/params.py +++ b/src/Mod/Draft/draftutils/params.py @@ -696,6 +696,11 @@ def _get_param_dictionary(): elif att_class == "Gui::PrefFontBox": path, entry, value = _param_from_PrefFontBox(widget) typ = "string" + elif att_class == "Gui::PrefCheckableGroupBox": + # It's a boolean preference, so we can reuse the parsing logic + # from _param_from_PrefCheckBox, which looks for . + path, entry, value = _param_from_PrefCheckBox(widget) + typ = "bool" if path is not None: if path in param_dict: From f1aa692b716dc245a9d020cfce617b310691fb23 Mon Sep 17 00:00:00 2001 From: Furgo <148809153+furgo16@users.noreply.github.com> Date: Wed, 11 Jun 2025 01:54:50 +0200 Subject: [PATCH 3/3] BIM: Use PrefCheckableGroupBox in IFC exporter preferences page --- src/Mod/BIM/Resources/ui/preferences-ifc-export.ui | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Mod/BIM/Resources/ui/preferences-ifc-export.ui b/src/Mod/BIM/Resources/ui/preferences-ifc-export.ui index 255eb65040..3565343523 100644 --- a/src/Mod/BIM/Resources/ui/preferences-ifc-export.ui +++ b/src/Mod/BIM/Resources/ui/preferences-ifc-export.ui @@ -407,7 +407,7 @@ However, at FreeCAD, we believe having a building should not be mandatory, and t - + If not checked, standard FreeCAD groups (App::DocumentObjectGroup) will not be exported as IfcGroup or IfcElementAssembly.\nTheir children will be re-parented to the container of the skipped group in the IFC structure.