@@ -1,6 +1,8 | |||||
1 | #ifndef SCIQLOP_SQPSETTINGSGENERALWIDGET_H |
|
1 | #ifndef SCIQLOP_SQPSETTINGSGENERALWIDGET_H | |
2 | #define SCIQLOP_SQPSETTINGSGENERALWIDGET_H |
|
2 | #define SCIQLOP_SQPSETTINGSGENERALWIDGET_H | |
3 |
|
3 | |||
|
4 | #include "Settings/ISqpSettingsBindable.h" | |||
|
5 | ||||
4 | #include <QWidget> |
|
6 | #include <QWidget> | |
5 |
|
7 | |||
6 | namespace Ui { |
|
8 | namespace Ui { | |
@@ -10,13 +12,19 class SqpSettingsGeneralWidget; | |||||
10 | /** |
|
12 | /** | |
11 | * @brief The SqpSettingsGeneralWidget class represents the general settings of SciQlop |
|
13 | * @brief The SqpSettingsGeneralWidget class represents the general settings of SciQlop | |
12 | */ |
|
14 | */ | |
13 | class SqpSettingsGeneralWidget : public QWidget { |
|
15 | class SqpSettingsGeneralWidget : public QWidget, public ISqpSettingsBindable { | |
14 | Q_OBJECT |
|
16 | Q_OBJECT | |
15 |
|
17 | |||
16 | public: |
|
18 | public: | |
17 | explicit SqpSettingsGeneralWidget(QWidget *parent = 0); |
|
19 | explicit SqpSettingsGeneralWidget(QWidget *parent = 0); | |
18 | virtual ~SqpSettingsGeneralWidget() noexcept; |
|
20 | virtual ~SqpSettingsGeneralWidget() noexcept; | |
19 |
|
21 | |||
|
22 | /// @sa ISqpSettingsBindable::loadSettings() | |||
|
23 | void loadSettings() override final; | |||
|
24 | ||||
|
25 | /// @sa ISqpSettingsBindable::saveSettings() | |||
|
26 | void saveSettings() const override final; | |||
|
27 | ||||
20 | private: |
|
28 | private: | |
21 | Ui::SqpSettingsGeneralWidget *ui; |
|
29 | Ui::SqpSettingsGeneralWidget *ui; | |
22 | }; |
|
30 | }; |
@@ -1,5 +1,7 | |||||
1 | #include "Settings/SqpSettingsGeneralWidget.h" |
|
1 | #include "Settings/SqpSettingsGeneralWidget.h" | |
2 |
|
2 | |||
|
3 | #include "Settings/SqpSettingsDefs.h" | |||
|
4 | ||||
3 | #include "ui_SqpSettingsGeneralWidget.h" |
|
5 | #include "ui_SqpSettingsGeneralWidget.h" | |
4 |
|
6 | |||
5 | SqpSettingsGeneralWidget::SqpSettingsGeneralWidget(QWidget *parent) |
|
7 | SqpSettingsGeneralWidget::SqpSettingsGeneralWidget(QWidget *parent) | |
@@ -12,3 +14,32 SqpSettingsGeneralWidget::~SqpSettingsGeneralWidget() noexcept | |||||
12 | { |
|
14 | { | |
13 | delete ui; |
|
15 | delete ui; | |
14 | } |
|
16 | } | |
|
17 | ||||
|
18 | void SqpSettingsGeneralWidget::loadSettings() | |||
|
19 | { | |||
|
20 | QSettings settings{}; | |||
|
21 | ||||
|
22 | auto loadTolerance = [&settings](const QString &key, double defaultValue) { | |||
|
23 | // Tolerance is converted to percent | |||
|
24 | auto toleranceValue = settings.value(key, defaultValue).toDouble(); | |||
|
25 | return toleranceValue * 100.; | |||
|
26 | }; | |||
|
27 | ||||
|
28 | ui->toleranceInitSpinBox->setValue( | |||
|
29 | loadTolerance(GENERAL_TOLERANCE_AT_INIT_KEY, GENERAL_TOLERANCE_AT_INIT_DEFAULT_VALUE)); | |||
|
30 | ui->toleranceUpdateSpinBox->setValue( | |||
|
31 | loadTolerance(GENERAL_TOLERANCE_AT_UPDATE_KEY, GENERAL_TOLERANCE_AT_UPDATE_DEFAULT_VALUE)); | |||
|
32 | } | |||
|
33 | ||||
|
34 | void SqpSettingsGeneralWidget::saveSettings() const | |||
|
35 | { | |||
|
36 | QSettings settings{}; | |||
|
37 | ||||
|
38 | auto saveTolerance = [&settings](const QString &key, double value) { | |||
|
39 | // Tolerance is converted from percent | |||
|
40 | settings.setValue(key, value * 0.01); | |||
|
41 | }; | |||
|
42 | ||||
|
43 | saveTolerance(GENERAL_TOLERANCE_AT_INIT_KEY, ui->toleranceInitSpinBox->value()); | |||
|
44 | saveTolerance(GENERAL_TOLERANCE_AT_UPDATE_KEY, ui->toleranceUpdateSpinBox->value()); | |||
|
45 | } |
General Comments 0
You need to be logged in to leave comments.
Login now