##// END OF EJS Templates
Inits min/max spinboxes...
Alexandre Leroux -
r1045:26696cd83a3b
parent child
Show More
@@ -1,30 +1,34
1 1 #ifndef SCIQLOP_COLORSCALEEDITOR_H
2 2 #define SCIQLOP_COLORSCALEEDITOR_H
3 3
4 4 #include <QButtonGroup>
5 5 #include <QDialog>
6 6
7 7 namespace Ui {
8 8 class ColorScaleEditor;
9 9 } // Ui
10 10
11 11 /**
12 12 * @brief The ColorScaleEditor class represents the widget to set properties of color scale's graphs
13 13 */
14 14 class ColorScaleEditor : public QDialog {
15 15 Q_OBJECT
16 16
17 17 public:
18 18 explicit ColorScaleEditor(QWidget *parent = 0);
19 19 virtual ~ColorScaleEditor() noexcept;
20 20
21 21 private:
22 22 Ui::ColorScaleEditor *ui;
23 23 QButtonGroup *m_ThresholdGroup;
24 24
25 25 private slots:
26 /// Slot called when max threshold value changes
27 void onMaxChanged();
28 /// Slot called when min threshold value changes
29 void onMinChanged();
26 30 /// Slot called when the threshold mode (auto or manual) changes
27 31 void onThresholdChanged(bool checked);
28 32 };
29 33
30 34 #endif // SCIQLOP_COLORSCALEEDITOR_H
@@ -1,34 +1,66
1 1 #include "Visualization/ColorScaleEditor.h"
2 2
3 3 #include "ui_ColorScaleEditor.h"
4 4
5 5 ColorScaleEditor::ColorScaleEditor(QWidget *parent)
6 6 : QDialog{parent}, ui{new Ui::ColorScaleEditor}, m_ThresholdGroup{new QButtonGroup{this}}
7 7 {
8 8 ui->setupUi(this);
9 9 // Creates threshold group
10 10 m_ThresholdGroup->addButton(ui->thresholdAutoButton);
11 11 m_ThresholdGroup->addButton(ui->thresholdManualButton);
12 12
13 // Inits min/max spinboxes' properties
14 auto setSpinBoxProperties = [](auto &spinBox) {
15 spinBox.setDecimals(3);
16 spinBox.setMinimum(-std::numeric_limits<double>::max());
17 spinBox.setMaximum(std::numeric_limits<double>::max());
18 };
19 setSpinBoxProperties(*ui->minSpinBox);
20 setSpinBoxProperties(*ui->maxSpinBox);
21
13 22 // Inits connections
14 23 connect(ui->thresholdAutoButton, SIGNAL(toggled(bool)), this, SLOT(onThresholdChanged(bool)));
15 24 connect(ui->thresholdManualButton, SIGNAL(toggled(bool)), this, SLOT(onThresholdChanged(bool)));
25 connect(ui->minSpinBox, SIGNAL(editingFinished()), this, SLOT(onMinChanged()));
26 connect(ui->maxSpinBox, SIGNAL(editingFinished()), this, SLOT(onMaxChanged()));
16 27
17 28 // First update
18 29 onThresholdChanged(true);
19 30 }
20 31
21 32 ColorScaleEditor::~ColorScaleEditor() noexcept
22 33 {
23 34 delete ui;
24 35 }
36
37 void ColorScaleEditor::onMaxChanged()
38 {
39 // Ensures that max >= min
40 auto maxValue = ui->maxSpinBox->value();
41 if (maxValue < ui->minSpinBox->value()) {
42 ui->minSpinBox->setValue(maxValue);
43 }
44
45 }
46
47 void ColorScaleEditor::onMinChanged()
48 {
49 // Ensures that min <= max
50 auto minValue = ui->minSpinBox->value();
51 if (minValue > ui->maxSpinBox->value()) {
52 ui->maxSpinBox->setValue(minValue);
53 }
54
55 }
56
25 57 void ColorScaleEditor::onThresholdChanged(bool checked)
26 58 {
27 59 if (checked) {
28 60 auto isAutomatic = ui->thresholdAutoButton == m_ThresholdGroup->checkedButton();
29 61
30 62 ui->minSpinBox->setEnabled(!isAutomatic);
31 63 ui->maxSpinBox->setEnabled(!isAutomatic);
32 64 }
33 65 }
34 66
General Comments 0
You need to be logged in to leave comments. Login now