diff --git a/gui/include/Settings/SqpSettingsDialog.h b/gui/include/Settings/SqpSettingsDialog.h index c18ed47..a08b477 100644 --- a/gui/include/Settings/SqpSettingsDialog.h +++ b/gui/include/Settings/SqpSettingsDialog.h @@ -13,13 +13,19 @@ class SqpSettingsDialog; * @brief The SqpSettingsDialog class represents the dialog in which the parameters of SciQlop are * set */ -class SqpSettingsDialog : public QDialog { +class SqpSettingsDialog : public QDialog, public ISqpSettingsBindable { Q_OBJECT public: explicit SqpSettingsDialog(QWidget *parent = 0); virtual ~SqpSettingsDialog() noexcept; + /// @sa ISqpSettingsBindable::loadSettings() + void loadSettings() override final; + + /// @sa ISqpSettingsBindable::saveSettings() + void saveSettings() const override final; + /** * Registers a widget into the dialog * @param name the name under which the widget will appear in the dialog diff --git a/gui/src/Settings/SqpSettingsDialog.cpp b/gui/src/Settings/SqpSettingsDialog.cpp index 44098d5..95c236a 100644 --- a/gui/src/Settings/SqpSettingsDialog.cpp +++ b/gui/src/Settings/SqpSettingsDialog.cpp @@ -1,6 +1,28 @@ #include "Settings/SqpSettingsDialog.h" #include "ui_SqpSettingsDialog.h" +namespace { + +/** + * Performs a bind operation on widgets that can be binded to SciQlop settings + * @param widgets + * @param bind the bind operation + * @sa ISqpSettingsBindable + */ +template +void processBind(const QStackedWidget &widgets, BindMethod bind) +{ + auto count = widgets.count(); + for (auto i = 0; i < count; ++i) { + // Performs operation if widget is an ISqpSettingsBindable + if (auto sqpSettingsWidget = dynamic_cast(widgets.widget(i))) { + bind(*sqpSettingsWidget); + } + } +} + +} // namespace + SqpSettingsDialog::SqpSettingsDialog(QWidget *parent) : QDialog{parent}, ui{new Ui::SqpSettingsDialog} { @@ -15,6 +37,21 @@ SqpSettingsDialog::~SqpSettingsDialog() noexcept { delete ui; } + +void SqpSettingsDialog::loadSettings() +{ + // Performs load on all widgets that can be binded to SciQlop settings + processBind(*ui->stackedWidget, + [](ISqpSettingsBindable &bindable) { bindable.loadSettings(); }); +} + +void SqpSettingsDialog::saveSettings() const +{ + // Performs save on all widgets that can be binded to SciQlop settings + processBind(*ui->stackedWidget, + [](ISqpSettingsBindable &bindable) { bindable.saveSettings(); }); +} + void SqpSettingsDialog::registerWidget(const QString &name, QWidget *widget) noexcept { auto newItem = new QListWidgetItem{ui->listWidget};