##// END OF EJS Templates
Inits gradient combobox
Alexandre Leroux -
r1046:b02b27914540
parent child
Show More
@@ -1,66 +1,89
1 #include "Visualization/ColorScaleEditor.h"
1 #include "Visualization/ColorScaleEditor.h"
2
2
3 #include "ui_ColorScaleEditor.h"
3 #include "ui_ColorScaleEditor.h"
4
4
5 namespace {
6
7 const auto GRADIENTS = QVariantMap{{"Candy", QCPColorGradient::gpCandy},
8 {"Cold", QCPColorGradient::gpCold},
9 {"Geography", QCPColorGradient::gpGeography},
10 {"Grayscale", QCPColorGradient::gpGrayscale},
11 {"Hot", QCPColorGradient::gpHot},
12 {"Hues", QCPColorGradient::gpHues},
13 {"Ion", QCPColorGradient::gpIon},
14 {"Jet", QCPColorGradient::gpJet},
15 {"Night", QCPColorGradient::gpNight},
16 {"Polar", QCPColorGradient::gpPolar},
17 {"Spectrum", QCPColorGradient::gpSpectrum},
18 {"Thermal", QCPColorGradient::gpThermal}};
19
20 } // namespace
21
5 ColorScaleEditor::ColorScaleEditor(QWidget *parent)
22 ColorScaleEditor::ColorScaleEditor(QWidget *parent)
6 : QDialog{parent}, ui{new Ui::ColorScaleEditor}, m_ThresholdGroup{new QButtonGroup{this}}
23 : QDialog{parent}, ui{new Ui::ColorScaleEditor}, m_ThresholdGroup{new QButtonGroup{this}}
7 {
24 {
8 ui->setupUi(this);
25 ui->setupUi(this);
26
27 // Inits gradient combobox content
28 for (auto it = GRADIENTS.begin(), end = GRADIENTS.end(); it != end; ++it) {
29 ui->gradientComboBox->addItem(it.key(), it.value());
30 }
31
9 // Creates threshold group
32 // Creates threshold group
10 m_ThresholdGroup->addButton(ui->thresholdAutoButton);
33 m_ThresholdGroup->addButton(ui->thresholdAutoButton);
11 m_ThresholdGroup->addButton(ui->thresholdManualButton);
34 m_ThresholdGroup->addButton(ui->thresholdManualButton);
12
35
13 // Inits min/max spinboxes' properties
36 // Inits min/max spinboxes' properties
14 auto setSpinBoxProperties = [](auto &spinBox) {
37 auto setSpinBoxProperties = [](auto &spinBox) {
15 spinBox.setDecimals(3);
38 spinBox.setDecimals(3);
16 spinBox.setMinimum(-std::numeric_limits<double>::max());
39 spinBox.setMinimum(-std::numeric_limits<double>::max());
17 spinBox.setMaximum(std::numeric_limits<double>::max());
40 spinBox.setMaximum(std::numeric_limits<double>::max());
18 };
41 };
19 setSpinBoxProperties(*ui->minSpinBox);
42 setSpinBoxProperties(*ui->minSpinBox);
20 setSpinBoxProperties(*ui->maxSpinBox);
43 setSpinBoxProperties(*ui->maxSpinBox);
21
44
22 // Inits connections
45 // Inits connections
23 connect(ui->thresholdAutoButton, SIGNAL(toggled(bool)), this, SLOT(onThresholdChanged(bool)));
46 connect(ui->thresholdAutoButton, SIGNAL(toggled(bool)), this, SLOT(onThresholdChanged(bool)));
24 connect(ui->thresholdManualButton, SIGNAL(toggled(bool)), this, SLOT(onThresholdChanged(bool)));
47 connect(ui->thresholdManualButton, SIGNAL(toggled(bool)), this, SLOT(onThresholdChanged(bool)));
25 connect(ui->minSpinBox, SIGNAL(editingFinished()), this, SLOT(onMinChanged()));
48 connect(ui->minSpinBox, SIGNAL(editingFinished()), this, SLOT(onMinChanged()));
26 connect(ui->maxSpinBox, SIGNAL(editingFinished()), this, SLOT(onMaxChanged()));
49 connect(ui->maxSpinBox, SIGNAL(editingFinished()), this, SLOT(onMaxChanged()));
27
50
28 // First update
51 // First update
29 onThresholdChanged(true);
52 onThresholdChanged(true);
30 }
53 }
31
54
32 ColorScaleEditor::~ColorScaleEditor() noexcept
55 ColorScaleEditor::~ColorScaleEditor() noexcept
33 {
56 {
34 delete ui;
57 delete ui;
35 }
58 }
36
59
37 void ColorScaleEditor::onMaxChanged()
60 void ColorScaleEditor::onMaxChanged()
38 {
61 {
39 // Ensures that max >= min
62 // Ensures that max >= min
40 auto maxValue = ui->maxSpinBox->value();
63 auto maxValue = ui->maxSpinBox->value();
41 if (maxValue < ui->minSpinBox->value()) {
64 if (maxValue < ui->minSpinBox->value()) {
42 ui->minSpinBox->setValue(maxValue);
65 ui->minSpinBox->setValue(maxValue);
43 }
66 }
44
67
45 }
68 }
46
69
47 void ColorScaleEditor::onMinChanged()
70 void ColorScaleEditor::onMinChanged()
48 {
71 {
49 // Ensures that min <= max
72 // Ensures that min <= max
50 auto minValue = ui->minSpinBox->value();
73 auto minValue = ui->minSpinBox->value();
51 if (minValue > ui->maxSpinBox->value()) {
74 if (minValue > ui->maxSpinBox->value()) {
52 ui->maxSpinBox->setValue(minValue);
75 ui->maxSpinBox->setValue(minValue);
53 }
76 }
54
77
55 }
78 }
56
79
57 void ColorScaleEditor::onThresholdChanged(bool checked)
80 void ColorScaleEditor::onThresholdChanged(bool checked)
58 {
81 {
59 if (checked) {
82 if (checked) {
60 auto isAutomatic = ui->thresholdAutoButton == m_ThresholdGroup->checkedButton();
83 auto isAutomatic = ui->thresholdAutoButton == m_ThresholdGroup->checkedButton();
61
84
62 ui->minSpinBox->setEnabled(!isAutomatic);
85 ui->minSpinBox->setEnabled(!isAutomatic);
63 ui->maxSpinBox->setEnabled(!isAutomatic);
86 ui->maxSpinBox->setEnabled(!isAutomatic);
64 }
87 }
65 }
88 }
66
89
General Comments 0
You need to be logged in to leave comments. Login now