##// END OF EJS Templates
Implements color scale loading when the editor is open
Alexandre Leroux -
r1052:9104d7a70c66
parent child
Show More
@@ -1,46 +1,48
1 #ifndef SCIQLOP_COLORSCALEEDITOR_H
1 #ifndef SCIQLOP_COLORSCALEEDITOR_H
2 #define SCIQLOP_COLORSCALEEDITOR_H
2 #define SCIQLOP_COLORSCALEEDITOR_H
3
3
4 #include <QButtonGroup>
4 #include <QButtonGroup>
5 #include <QDialog>
5 #include <QDialog>
6
6
7 namespace Ui {
7 namespace Ui {
8 class ColorScaleEditor;
8 class ColorScaleEditor;
9 } // Ui
9 } // Ui
10
10
11 class SqpColorScale;
11 class SqpColorScale;
12 class QCPColorScale;
12 class QCPColorScale;
13
13
14 /**
14 /**
15 * @brief The ColorScaleEditor class represents the widget to set properties of color scale's graphs
15 * @brief The ColorScaleEditor class represents the widget to set properties of color scale's graphs
16 */
16 */
17 class ColorScaleEditor : public QDialog {
17 class ColorScaleEditor : public QDialog {
18 Q_OBJECT
18 Q_OBJECT
19
19
20 public:
20 public:
21 explicit ColorScaleEditor(SqpColorScale &scale, QWidget *parent = 0);
21 explicit ColorScaleEditor(SqpColorScale &scale, QWidget *parent = 0);
22 virtual ~ColorScaleEditor() noexcept;
22 virtual ~ColorScaleEditor() noexcept;
23
23
24 private:
24 private:
25 /// Fills the editor fields from color scale data
26 void loadScale();
25 Ui::ColorScaleEditor *ui;
27 Ui::ColorScaleEditor *ui;
26 QButtonGroup *m_ThresholdGroup;
28 QButtonGroup *m_ThresholdGroup;
27 /// Scale in editing
29 /// Scale in editing
28 /// @remarks reference must remain valid throughout the existence of the ColorScaleEditor
30 /// @remarks reference must remain valid throughout the existence of the ColorScaleEditor
29 /// instance
31 /// instance
30 SqpColorScale &m_Scale;
32 SqpColorScale &m_Scale;
31 /// Scale shown as preview
33 /// Scale shown as preview
32 QCPColorScale *m_PreviewScale;
34 QCPColorScale *m_PreviewScale;
33
35
34 private slots:
36 private slots:
35 /// Slot called when max threshold value changes
37 /// Slot called when max threshold value changes
36 void onMaxChanged();
38 void onMaxChanged();
37 /// Slot called when min threshold value changes
39 /// Slot called when min threshold value changes
38 void onMinChanged();
40 void onMinChanged();
39 /// Slot called when the threshold mode (auto or manual) changes
41 /// Slot called when the threshold mode (auto or manual) changes
40 void onThresholdChanged(bool checked);
42 void onThresholdChanged(bool checked);
41
43
42 /// Slot called when a property of the color scale changed
44 /// Slot called when a property of the color scale changed
43 void updatePreview();
45 void updatePreview();
44 };
46 };
45
47
46 #endif // SCIQLOP_COLORSCALEEDITOR_H
48 #endif // SCIQLOP_COLORSCALEEDITOR_H
@@ -1,119 +1,137
1 #include "Visualization/ColorScaleEditor.h"
1 #include "Visualization/ColorScaleEditor.h"
2 #include "Visualization/SqpColorScale.h"
2 #include "Visualization/SqpColorScale.h"
3
3
4 #include "ui_ColorScaleEditor.h"
4 #include "ui_ColorScaleEditor.h"
5
5
6 namespace {
6 namespace {
7
7
8 const auto GRADIENTS = QVariantMap{{"Candy", QCPColorGradient::gpCandy},
8 const auto GRADIENTS = QVariantMap{{"Candy", QCPColorGradient::gpCandy},
9 {"Cold", QCPColorGradient::gpCold},
9 {"Cold", QCPColorGradient::gpCold},
10 {"Geography", QCPColorGradient::gpGeography},
10 {"Geography", QCPColorGradient::gpGeography},
11 {"Grayscale", QCPColorGradient::gpGrayscale},
11 {"Grayscale", QCPColorGradient::gpGrayscale},
12 {"Hot", QCPColorGradient::gpHot},
12 {"Hot", QCPColorGradient::gpHot},
13 {"Hues", QCPColorGradient::gpHues},
13 {"Hues", QCPColorGradient::gpHues},
14 {"Ion", QCPColorGradient::gpIon},
14 {"Ion", QCPColorGradient::gpIon},
15 {"Jet", QCPColorGradient::gpJet},
15 {"Jet", QCPColorGradient::gpJet},
16 {"Night", QCPColorGradient::gpNight},
16 {"Night", QCPColorGradient::gpNight},
17 {"Polar", QCPColorGradient::gpPolar},
17 {"Polar", QCPColorGradient::gpPolar},
18 {"Spectrum", QCPColorGradient::gpSpectrum},
18 {"Spectrum", QCPColorGradient::gpSpectrum},
19 {"Thermal", QCPColorGradient::gpThermal}};
19 {"Thermal", QCPColorGradient::gpThermal}};
20
20
21 } // namespace
21 } // namespace
22
22
23 ColorScaleEditor::ColorScaleEditor(SqpColorScale &scale, QWidget *parent)
23 ColorScaleEditor::ColorScaleEditor(SqpColorScale &scale, QWidget *parent)
24 : QDialog{parent},
24 : QDialog{parent},
25 ui{new Ui::ColorScaleEditor},
25 ui{new Ui::ColorScaleEditor},
26 m_Scale{scale},
26 m_Scale{scale},
27 m_ThresholdGroup{new QButtonGroup{this}}
27 m_ThresholdGroup{new QButtonGroup{this}}
28 {
28 {
29 ui->setupUi(this);
29 ui->setupUi(this);
30
30
31 // Inits gradient combobox content
31 // Inits gradient combobox content
32 for (auto it = GRADIENTS.begin(), end = GRADIENTS.end(); it != end; ++it) {
32 for (auto it = GRADIENTS.begin(), end = GRADIENTS.end(); it != end; ++it) {
33 ui->gradientComboBox->addItem(it.key(), it.value());
33 ui->gradientComboBox->addItem(it.key(), it.value());
34 }
34 }
35
35
36 // Creates threshold group
36 // Creates threshold group
37 m_ThresholdGroup->addButton(ui->thresholdAutoButton);
37 m_ThresholdGroup->addButton(ui->thresholdAutoButton);
38 m_ThresholdGroup->addButton(ui->thresholdManualButton);
38 m_ThresholdGroup->addButton(ui->thresholdManualButton);
39
39
40 // Inits min/max spinboxes' properties
40 // Inits min/max spinboxes' properties
41 auto setSpinBoxProperties = [](auto &spinBox) {
41 auto setSpinBoxProperties = [](auto &spinBox) {
42 spinBox.setDecimals(3);
42 spinBox.setDecimals(3);
43 spinBox.setMinimum(-std::numeric_limits<double>::max());
43 spinBox.setMinimum(-std::numeric_limits<double>::max());
44 spinBox.setMaximum(std::numeric_limits<double>::max());
44 spinBox.setMaximum(std::numeric_limits<double>::max());
45 };
45 };
46 setSpinBoxProperties(*ui->minSpinBox);
46 setSpinBoxProperties(*ui->minSpinBox);
47 setSpinBoxProperties(*ui->maxSpinBox);
47 setSpinBoxProperties(*ui->maxSpinBox);
48
48
49 // Creates color scale preview
49 // Creates color scale preview
50 m_PreviewScale = new QCPColorScale{ui->plot};
50 m_PreviewScale = new QCPColorScale{ui->plot};
51 m_PreviewScale->setType(QCPAxis::atTop);
51 m_PreviewScale->setType(QCPAxis::atTop);
52 m_PreviewScale->setMinimumMargins(QMargins{5, 5, 5, 5});
52 m_PreviewScale->setMinimumMargins(QMargins{5, 5, 5, 5});
53 m_PreviewScale->axis()->setScaleType(QCPAxis::stLogarithmic);
53 m_PreviewScale->axis()->setScaleType(QCPAxis::stLogarithmic);
54 m_PreviewScale->axis()->setNumberPrecision(0);
54 m_PreviewScale->axis()->setNumberPrecision(0);
55 m_PreviewScale->axis()->setNumberFormat("eb");
55 m_PreviewScale->axis()->setNumberFormat("eb");
56 m_PreviewScale->axis()->setTicker(QSharedPointer<QCPAxisTickerLog>::create());
56 m_PreviewScale->axis()->setTicker(QSharedPointer<QCPAxisTickerLog>::create());
57 m_PreviewScale->setGradient(QCPColorGradient{QCPColorGradient::gpJet});
57 m_PreviewScale->setGradient(QCPColorGradient{QCPColorGradient::gpJet});
58
58
59 ui->plot->plotLayout()->clear();
59 ui->plot->plotLayout()->clear();
60 ui->plot->plotLayout()->insertRow(0);
60 ui->plot->plotLayout()->insertRow(0);
61 ui->plot->plotLayout()->addElement(0, 0, m_PreviewScale);
61 ui->plot->plotLayout()->addElement(0, 0, m_PreviewScale);
62
62
63 // Inits connections
63 // Inits connections
64 connect(ui->gradientComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updatePreview()));
64 connect(ui->gradientComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updatePreview()));
65 connect(ui->thresholdAutoButton, SIGNAL(toggled(bool)), this, SLOT(onThresholdChanged(bool)));
65 connect(ui->thresholdAutoButton, SIGNAL(toggled(bool)), this, SLOT(onThresholdChanged(bool)));
66 connect(ui->thresholdManualButton, SIGNAL(toggled(bool)), this, SLOT(onThresholdChanged(bool)));
66 connect(ui->thresholdManualButton, SIGNAL(toggled(bool)), this, SLOT(onThresholdChanged(bool)));
67 connect(ui->minSpinBox, SIGNAL(editingFinished()), this, SLOT(onMinChanged()));
67 connect(ui->minSpinBox, SIGNAL(editingFinished()), this, SLOT(onMinChanged()));
68 connect(ui->maxSpinBox, SIGNAL(editingFinished()), this, SLOT(onMaxChanged()));
68 connect(ui->maxSpinBox, SIGNAL(editingFinished()), this, SLOT(onMaxChanged()));
69
69
70 // First update
70 // Loads color scale
71 onThresholdChanged(true);
71 loadScale();
72 updatePreview();
73 }
72 }
74
73
75 ColorScaleEditor::~ColorScaleEditor() noexcept
74 ColorScaleEditor::~ColorScaleEditor() noexcept
76 {
75 {
77 delete ui;
76 delete ui;
78 }
77 }
79
78
79 void ColorScaleEditor::loadScale()
80 {
81 // Gradient
82 auto gradientPresetIndex = ui->gradientComboBox->findData(m_Scale.m_GradientPreset);
83 ui->gradientComboBox->setCurrentIndex(gradientPresetIndex);
84
85 // Threshold mode
86 (m_Scale.m_AutomaticThreshold ? ui->thresholdAutoButton : ui->thresholdManualButton)
87 ->setChecked(true);
88
89 // Min/max
90 auto qcpColorScale = m_Scale.m_Scale;
91 auto range = qcpColorScale->dataRange();
92 ui->minSpinBox->setValue(range.lower);
93 ui->maxSpinBox->setValue(range.upper);
94
95 updatePreview();
96 }
97
80 void ColorScaleEditor::onMaxChanged()
98 void ColorScaleEditor::onMaxChanged()
81 {
99 {
82 // Ensures that max >= min
100 // Ensures that max >= min
83 auto maxValue = ui->maxSpinBox->value();
101 auto maxValue = ui->maxSpinBox->value();
84 if (maxValue < ui->minSpinBox->value()) {
102 if (maxValue < ui->minSpinBox->value()) {
85 ui->minSpinBox->setValue(maxValue);
103 ui->minSpinBox->setValue(maxValue);
86 }
104 }
87
105
88 updatePreview();
106 updatePreview();
89 }
107 }
90
108
91 void ColorScaleEditor::onMinChanged()
109 void ColorScaleEditor::onMinChanged()
92 {
110 {
93 // Ensures that min <= max
111 // Ensures that min <= max
94 auto minValue = ui->minSpinBox->value();
112 auto minValue = ui->minSpinBox->value();
95 if (minValue > ui->maxSpinBox->value()) {
113 if (minValue > ui->maxSpinBox->value()) {
96 ui->maxSpinBox->setValue(minValue);
114 ui->maxSpinBox->setValue(minValue);
97 }
115 }
98
116
99 updatePreview();
117 updatePreview();
100 }
118 }
101
119
102 void ColorScaleEditor::onThresholdChanged(bool checked)
120 void ColorScaleEditor::onThresholdChanged(bool checked)
103 {
121 {
104 if (checked) {
122 if (checked) {
105 auto isAutomatic = ui->thresholdAutoButton == m_ThresholdGroup->checkedButton();
123 auto isAutomatic = ui->thresholdAutoButton == m_ThresholdGroup->checkedButton();
106
124
107 ui->minSpinBox->setEnabled(!isAutomatic);
125 ui->minSpinBox->setEnabled(!isAutomatic);
108 ui->maxSpinBox->setEnabled(!isAutomatic);
126 ui->maxSpinBox->setEnabled(!isAutomatic);
109 }
127 }
110 }
128 }
111
129
112 void ColorScaleEditor::updatePreview()
130 void ColorScaleEditor::updatePreview()
113 {
131 {
114 m_PreviewScale->setDataRange(QCPRange{ui->minSpinBox->value(), ui->maxSpinBox->value()});
132 m_PreviewScale->setDataRange(QCPRange{ui->minSpinBox->value(), ui->maxSpinBox->value()});
115 m_PreviewScale->setGradient(
133 m_PreviewScale->setGradient(
116 ui->gradientComboBox->currentData().value<QCPColorGradient::GradientPreset>());
134 ui->gradientComboBox->currentData().value<QCPColorGradient::GradientPreset>());
117
135
118 ui->plot->replot();
136 ui->plot->replot();
119 }
137 }
General Comments 0
You need to be logged in to leave comments. Login now