##// END OF EJS Templates
Settings binding (3)...
Alexandre Leroux -
r468:4682fc2670df
parent child
Show More
@@ -1,34 +1,40
1 1 #ifndef SCIQLOP_SQPSETTINGSDIALOG_H
2 2 #define SCIQLOP_SQPSETTINGSDIALOG_H
3 3
4 4 #include "Settings/ISqpSettingsBindable.h"
5 5
6 6 #include <QDialog>
7 7
8 8 namespace Ui {
9 9 class SqpSettingsDialog;
10 10 } // Ui
11 11
12 12 /**
13 13 * @brief The SqpSettingsDialog class represents the dialog in which the parameters of SciQlop are
14 14 * set
15 15 */
16 class SqpSettingsDialog : public QDialog {
16 class SqpSettingsDialog : public QDialog, public ISqpSettingsBindable {
17 17 Q_OBJECT
18 18
19 19 public:
20 20 explicit SqpSettingsDialog(QWidget *parent = 0);
21 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 30 * Registers a widget into the dialog
25 31 * @param name the name under which the widget will appear in the dialog
26 32 * @param widget the widget to register
27 33 */
28 34 void registerWidget(const QString &name, QWidget *widget) noexcept;
29 35
30 36 private:
31 37 Ui::SqpSettingsDialog *ui;
32 38 };
33 39
34 40 #endif // SCIQLOP_SQPSETTINGSDIALOG_H
@@ -1,29 +1,66
1 1 #include "Settings/SqpSettingsDialog.h"
2 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 26 SqpSettingsDialog::SqpSettingsDialog(QWidget *parent)
5 27 : QDialog{parent}, ui{new Ui::SqpSettingsDialog}
6 28 {
7 29 ui->setupUi(this);
8 30
9 31 // Connection to change the current page to the selection of an entry in the list
10 32 connect(ui->listWidget, &QListWidget::currentRowChanged, ui->stackedWidget,
11 33 &QStackedWidget::setCurrentIndex);
12 34 }
13 35
14 36 SqpSettingsDialog::~SqpSettingsDialog() noexcept
15 37 {
16 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 55 void SqpSettingsDialog::registerWidget(const QString &name, QWidget *widget) noexcept
19 56 {
20 57 auto newItem = new QListWidgetItem{ui->listWidget};
21 58 newItem->setText(name);
22 59
23 60 ui->stackedWidget->addWidget(widget);
24 61
25 62 // Selects widget if it's the first in the dialog
26 63 if (ui->listWidget->count() == 1) {
27 64 ui->listWidget->setCurrentItem(newItem);
28 65 }
29 66 }
General Comments 0
You need to be logged in to leave comments. Login now