Merge pull request #21921 from furgo16/add-prefcheckablegroupbox

Gui, Draft, BIM: Add PrefCheckableGroupBox, use it in IFC exporter preferences page
This commit is contained in:
Chris Hennes
2025-06-16 11:06:30 -05:00
committed by GitHub
6 changed files with 68 additions and 1 deletions

View File

@@ -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"

View File

@@ -26,6 +26,7 @@
#include <QCheckBox>
#include <QComboBox>
#include <QFontComboBox>
#include <QGroupBox>
#include <QRadioButton>
#include <QTextEdit>
@@ -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

View File

@@ -187,6 +187,7 @@ void PreferenceUiForm::loadSettings()
loadPrefWidgets<Gui::PrefColorButton *>();
loadPrefWidgets<Gui::PrefUnitSpinBox *>();
loadPrefWidgets<Gui::PrefQuantitySpinBox*>();
loadPrefWidgets<Gui::PrefCheckableGroupBox*>();
}
void PreferenceUiForm::saveSettings()
@@ -208,6 +209,7 @@ void PreferenceUiForm::saveSettings()
savePrefWidgets<Gui::PrefColorButton *>();
savePrefWidgets<Gui::PrefUnitSpinBox *>();
savePrefWidgets<Gui::PrefQuantitySpinBox*>();
savePrefWidgets<Gui::PrefCheckableGroupBox*>();
}
QWidget* Gui::Dialog::PreferenceUiForm::form()

View File

@@ -115,6 +115,7 @@ WidgetFactorySupplier::WidgetFactorySupplier()
new WidgetProducer<Gui::PrefComboBox>;
new WidgetProducer<Gui::PrefFontBox>;
new WidgetProducer<Gui::PrefCheckBox>;
new WidgetProducer<Gui::PrefCheckableGroupBox>;
new WidgetProducer<Gui::PrefRadioButton>;
new WidgetProducer<Gui::PrefSlider>;
new WidgetProducer<Gui::PrefFileChooser>;

View File

@@ -407,7 +407,7 @@ However, at FreeCAD, we believe having a building should not be mandatory, and t
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_ExportFreeCADGroups">
<widget class="Gui::PrefCheckableGroupBox" name="groupBox_ExportFreeCADGroups">
<property name="toolTip">
<string>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.</string>
</property>

View File

@@ -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 <property name="checked">.
path, entry, value = _param_from_PrefCheckBox(widget)
typ = "bool"
if path is not None:
if path in param_dict: