@@ -1,6 +1,8 | |||
|
1 | 1 | #ifndef SCIQLOP_SQPSETTINGSGENERALWIDGET_H |
|
2 | 2 | #define SCIQLOP_SQPSETTINGSGENERALWIDGET_H |
|
3 | 3 | |
|
4 | #include "Settings/ISqpSettingsBindable.h" | |
|
5 | ||
|
4 | 6 | #include <QWidget> |
|
5 | 7 | |
|
6 | 8 | namespace Ui { |
@@ -10,13 +12,19 class SqpSettingsGeneralWidget; | |||
|
10 | 12 | /** |
|
11 | 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 | 16 | Q_OBJECT |
|
15 | 17 | |
|
16 | 18 | public: |
|
17 | 19 | explicit SqpSettingsGeneralWidget(QWidget *parent = 0); |
|
18 | 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 | 28 | private: |
|
21 | 29 | Ui::SqpSettingsGeneralWidget *ui; |
|
22 | 30 | }; |
@@ -1,5 +1,7 | |||
|
1 | 1 | #include "Settings/SqpSettingsGeneralWidget.h" |
|
2 | 2 | |
|
3 | #include "Settings/SqpSettingsDefs.h" | |
|
4 | ||
|
3 | 5 | #include "ui_SqpSettingsGeneralWidget.h" |
|
4 | 6 | |
|
5 | 7 | SqpSettingsGeneralWidget::SqpSettingsGeneralWidget(QWidget *parent) |
@@ -12,3 +14,32 SqpSettingsGeneralWidget::~SqpSettingsGeneralWidget() noexcept | |||
|
12 | 14 | { |
|
13 | 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