@@ -13,13 +13,19 class SqpSettingsDialog; | |||||
13 | * @brief The SqpSettingsDialog class represents the dialog in which the parameters of SciQlop are |
|
13 | * @brief The SqpSettingsDialog class represents the dialog in which the parameters of SciQlop are | |
14 | * set |
|
14 | * set | |
15 | */ |
|
15 | */ | |
16 | class SqpSettingsDialog : public QDialog { |
|
16 | class SqpSettingsDialog : public QDialog, public ISqpSettingsBindable { | |
17 | Q_OBJECT |
|
17 | Q_OBJECT | |
18 |
|
18 | |||
19 | public: |
|
19 | public: | |
20 | explicit SqpSettingsDialog(QWidget *parent = 0); |
|
20 | explicit SqpSettingsDialog(QWidget *parent = 0); | |
21 | virtual ~SqpSettingsDialog() noexcept; |
|
21 | virtual ~SqpSettingsDialog() noexcept; | |
22 |
|
22 | |||
|
23 | /// @sa ISqpSettingsBindable::loadSettings() | |||
|
24 | void loadSettings() override final; | |||
|
25 | ||||
|
26 | /// @sa ISqpSettingsBindable::saveSettings() | |||
|
27 | void saveSettings() const override final; | |||
|
28 | ||||
23 | /** |
|
29 | /** | |
24 | * Registers a widget into the dialog |
|
30 | * Registers a widget into the dialog | |
25 | * @param name the name under which the widget will appear in the dialog |
|
31 | * @param name the name under which the widget will appear in the dialog |
@@ -1,6 +1,28 | |||||
1 | #include "Settings/SqpSettingsDialog.h" |
|
1 | #include "Settings/SqpSettingsDialog.h" | |
2 | #include "ui_SqpSettingsDialog.h" |
|
2 | #include "ui_SqpSettingsDialog.h" | |
3 |
|
3 | |||
|
4 | namespace { | |||
|
5 | ||||
|
6 | /** | |||
|
7 | * Performs a bind operation on widgets that can be binded to SciQlop settings | |||
|
8 | * @param widgets | |||
|
9 | * @param bind the bind operation | |||
|
10 | * @sa ISqpSettingsBindable | |||
|
11 | */ | |||
|
12 | template <typename BindMethod> | |||
|
13 | void processBind(const QStackedWidget &widgets, BindMethod bind) | |||
|
14 | { | |||
|
15 | auto count = widgets.count(); | |||
|
16 | for (auto i = 0; i < count; ++i) { | |||
|
17 | // Performs operation if widget is an ISqpSettingsBindable | |||
|
18 | if (auto sqpSettingsWidget = dynamic_cast<ISqpSettingsBindable *>(widgets.widget(i))) { | |||
|
19 | bind(*sqpSettingsWidget); | |||
|
20 | } | |||
|
21 | } | |||
|
22 | } | |||
|
23 | ||||
|
24 | } // namespace | |||
|
25 | ||||
4 | SqpSettingsDialog::SqpSettingsDialog(QWidget *parent) |
|
26 | SqpSettingsDialog::SqpSettingsDialog(QWidget *parent) | |
5 | : QDialog{parent}, ui{new Ui::SqpSettingsDialog} |
|
27 | : QDialog{parent}, ui{new Ui::SqpSettingsDialog} | |
6 | { |
|
28 | { | |
@@ -15,6 +37,21 SqpSettingsDialog::~SqpSettingsDialog() noexcept | |||||
15 | { |
|
37 | { | |
16 | delete ui; |
|
38 | delete ui; | |
17 | } |
|
39 | } | |
|
40 | ||||
|
41 | void SqpSettingsDialog::loadSettings() | |||
|
42 | { | |||
|
43 | // Performs load on all widgets that can be binded to SciQlop settings | |||
|
44 | processBind(*ui->stackedWidget, | |||
|
45 | [](ISqpSettingsBindable &bindable) { bindable.loadSettings(); }); | |||
|
46 | } | |||
|
47 | ||||
|
48 | void SqpSettingsDialog::saveSettings() const | |||
|
49 | { | |||
|
50 | // Performs save on all widgets that can be binded to SciQlop settings | |||
|
51 | processBind(*ui->stackedWidget, | |||
|
52 | [](ISqpSettingsBindable &bindable) { bindable.saveSettings(); }); | |||
|
53 | } | |||
|
54 | ||||
18 | void SqpSettingsDialog::registerWidget(const QString &name, QWidget *widget) noexcept |
|
55 | void SqpSettingsDialog::registerWidget(const QString &name, QWidget *widget) noexcept | |
19 | { |
|
56 | { | |
20 | auto newItem = new QListWidgetItem{ui->listWidget}; |
|
57 | auto newItem = new QListWidgetItem{ui->listWidget}; |
General Comments 0
You need to be logged in to leave comments.
Login now