##// END OF EJS Templates
Implements color scale save when the editor is closed
Alexandre Leroux -
r1012:18abbd5ba9c1
parent child
Show More
@@ -1,48 +1,54
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
25 /// Fills the editor fields from color scale data
26 void loadScale();
26 void loadScale();
27 /// Updates the color scale from editor fields
28 void saveScale();
29
27 Ui::ColorScaleEditor *ui;
30 Ui::ColorScaleEditor *ui;
28 QButtonGroup *m_ThresholdGroup;
31 QButtonGroup *m_ThresholdGroup;
29 /// Scale in editing
32 /// Scale in editing
30 /// @remarks reference must remain valid throughout the existence of the ColorScaleEditor
33 /// @remarks reference must remain valid throughout the existence of the ColorScaleEditor
31 /// instance
34 /// instance
32 SqpColorScale &m_Scale;
35 SqpColorScale &m_Scale;
33 /// Scale shown as preview
36 /// Scale shown as preview
34 QCPColorScale *m_PreviewScale;
37 QCPColorScale *m_PreviewScale;
35
38
36 private slots:
39 private slots:
40 /// @sa QDialog::accept()
41 void accept() override;
42
37 /// Slot called when max threshold value changes
43 /// Slot called when max threshold value changes
38 void onMaxChanged();
44 void onMaxChanged();
39 /// Slot called when min threshold value changes
45 /// Slot called when min threshold value changes
40 void onMinChanged();
46 void onMinChanged();
41 /// Slot called when the threshold mode (auto or manual) changes
47 /// Slot called when the threshold mode (auto or manual) changes
42 void onThresholdChanged(bool checked);
48 void onThresholdChanged(bool checked);
43
49
44 /// Slot called when a property of the color scale changed
50 /// Slot called when a property of the color scale changed
45 void updatePreview();
51 void updatePreview();
46 };
52 };
47
53
48 #endif // SCIQLOP_COLORSCALEEDITOR_H
54 #endif // SCIQLOP_COLORSCALEEDITOR_H
@@ -1,137 +1,164
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 // OK/cancel buttons
71 connect(ui->okButton, SIGNAL(clicked(bool)), this, SLOT(accept()));
72 connect(ui->cancelButton, SIGNAL(clicked(bool)), this, SLOT(reject()));
73
70 // Loads color scale
74 // Loads color scale
71 loadScale();
75 loadScale();
72 }
76 }
73
77
74 ColorScaleEditor::~ColorScaleEditor() noexcept
78 ColorScaleEditor::~ColorScaleEditor() noexcept
75 {
79 {
76 delete ui;
80 delete ui;
77 }
81 }
78
82
79 void ColorScaleEditor::loadScale()
83 void ColorScaleEditor::loadScale()
80 {
84 {
81 // Gradient
85 // Gradient
82 auto gradientPresetIndex = ui->gradientComboBox->findData(m_Scale.m_GradientPreset);
86 auto gradientPresetIndex = ui->gradientComboBox->findData(m_Scale.m_GradientPreset);
83 ui->gradientComboBox->setCurrentIndex(gradientPresetIndex);
87 ui->gradientComboBox->setCurrentIndex(gradientPresetIndex);
84
88
85 // Threshold mode
89 // Threshold mode
86 (m_Scale.m_AutomaticThreshold ? ui->thresholdAutoButton : ui->thresholdManualButton)
90 (m_Scale.m_AutomaticThreshold ? ui->thresholdAutoButton : ui->thresholdManualButton)
87 ->setChecked(true);
91 ->setChecked(true);
88
92
89 // Min/max
93 // Min/max
90 auto qcpColorScale = m_Scale.m_Scale;
94 auto qcpColorScale = m_Scale.m_Scale;
91 auto range = qcpColorScale->dataRange();
95 auto range = qcpColorScale->dataRange();
92 ui->minSpinBox->setValue(range.lower);
96 ui->minSpinBox->setValue(range.lower);
93 ui->maxSpinBox->setValue(range.upper);
97 ui->maxSpinBox->setValue(range.upper);
94
98
95 updatePreview();
99 updatePreview();
96 }
100 }
97
101
102 void ColorScaleEditor::saveScale()
103 {
104 auto qcpColorScale = m_Scale.m_Scale;
105
106 // Gradient
107 auto gradientPreset
108 = ui->gradientComboBox->currentData().value<QCPColorGradient::GradientPreset>();
109 qcpColorScale->setGradient(gradientPreset);
110 m_Scale.m_GradientPreset = gradientPreset;
111
112 // Threshold mode
113 m_Scale.m_AutomaticThreshold = ui->thresholdAutoButton->isChecked();
114
115 // Min/max
116 qcpColorScale->setDataRange(QCPRange{ui->minSpinBox->value(), ui->maxSpinBox->value()});
117 }
118
119 void ColorScaleEditor::accept()
120 {
121 saveScale();
122 QDialog::accept();
123 }
124
98 void ColorScaleEditor::onMaxChanged()
125 void ColorScaleEditor::onMaxChanged()
99 {
126 {
100 // Ensures that max >= min
127 // Ensures that max >= min
101 auto maxValue = ui->maxSpinBox->value();
128 auto maxValue = ui->maxSpinBox->value();
102 if (maxValue < ui->minSpinBox->value()) {
129 if (maxValue < ui->minSpinBox->value()) {
103 ui->minSpinBox->setValue(maxValue);
130 ui->minSpinBox->setValue(maxValue);
104 }
131 }
105
132
106 updatePreview();
133 updatePreview();
107 }
134 }
108
135
109 void ColorScaleEditor::onMinChanged()
136 void ColorScaleEditor::onMinChanged()
110 {
137 {
111 // Ensures that min <= max
138 // Ensures that min <= max
112 auto minValue = ui->minSpinBox->value();
139 auto minValue = ui->minSpinBox->value();
113 if (minValue > ui->maxSpinBox->value()) {
140 if (minValue > ui->maxSpinBox->value()) {
114 ui->maxSpinBox->setValue(minValue);
141 ui->maxSpinBox->setValue(minValue);
115 }
142 }
116
143
117 updatePreview();
144 updatePreview();
118 }
145 }
119
146
120 void ColorScaleEditor::onThresholdChanged(bool checked)
147 void ColorScaleEditor::onThresholdChanged(bool checked)
121 {
148 {
122 if (checked) {
149 if (checked) {
123 auto isAutomatic = ui->thresholdAutoButton == m_ThresholdGroup->checkedButton();
150 auto isAutomatic = ui->thresholdAutoButton == m_ThresholdGroup->checkedButton();
124
151
125 ui->minSpinBox->setEnabled(!isAutomatic);
152 ui->minSpinBox->setEnabled(!isAutomatic);
126 ui->maxSpinBox->setEnabled(!isAutomatic);
153 ui->maxSpinBox->setEnabled(!isAutomatic);
127 }
154 }
128 }
155 }
129
156
130 void ColorScaleEditor::updatePreview()
157 void ColorScaleEditor::updatePreview()
131 {
158 {
132 m_PreviewScale->setDataRange(QCPRange{ui->minSpinBox->value(), ui->maxSpinBox->value()});
159 m_PreviewScale->setDataRange(QCPRange{ui->minSpinBox->value(), ui->maxSpinBox->value()});
133 m_PreviewScale->setGradient(
160 m_PreviewScale->setGradient(
134 ui->gradientComboBox->currentData().value<QCPColorGradient::GradientPreset>());
161 ui->gradientComboBox->currentData().value<QCPColorGradient::GradientPreset>());
135
162
136 ui->plot->replot();
163 ui->plot->replot();
137 }
164 }
General Comments 0
You need to be logged in to leave comments. Login now