##// END OF EJS Templates
Adds the color scale in edting in color scale editor
Alexandre Leroux -
r1051:9df64e6c645d
parent child
Show More
@@ -1,40 +1,46
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 QCPColorScale;
12 class QCPColorScale;
12
13
13 /**
14 /**
14 * @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
15 */
16 */
16 class ColorScaleEditor : public QDialog {
17 class ColorScaleEditor : public QDialog {
17 Q_OBJECT
18 Q_OBJECT
18
19
19 public:
20 public:
20 explicit ColorScaleEditor(QWidget *parent = 0);
21 explicit ColorScaleEditor(SqpColorScale &scale, QWidget *parent = 0);
21 virtual ~ColorScaleEditor() noexcept;
22 virtual ~ColorScaleEditor() noexcept;
22
23
23 private:
24 private:
24 Ui::ColorScaleEditor *ui;
25 Ui::ColorScaleEditor *ui;
25 QButtonGroup *m_ThresholdGroup;
26 QButtonGroup *m_ThresholdGroup;
26 QCPColorScale *m_PreviewScale; ///< Scale shown as preview
27 /// Scale in editing
28 /// @remarks reference must remain valid throughout the existence of the ColorScaleEditor
29 /// instance
30 SqpColorScale &m_Scale;
31 /// Scale shown as preview
32 QCPColorScale *m_PreviewScale;
27
33
28 private slots:
34 private slots:
29 /// Slot called when max threshold value changes
35 /// Slot called when max threshold value changes
30 void onMaxChanged();
36 void onMaxChanged();
31 /// Slot called when min threshold value changes
37 /// Slot called when min threshold value changes
32 void onMinChanged();
38 void onMinChanged();
33 /// Slot called when the threshold mode (auto or manual) changes
39 /// Slot called when the threshold mode (auto or manual) changes
34 void onThresholdChanged(bool checked);
40 void onThresholdChanged(bool checked);
35
41
36 /// Slot called when a property of the color scale changed
42 /// Slot called when a property of the color scale changed
37 void updatePreview();
43 void updatePreview();
38 };
44 };
39
45
40 #endif // SCIQLOP_COLORSCALEEDITOR_H
46 #endif // SCIQLOP_COLORSCALEEDITOR_H
@@ -1,116 +1,119
1 #include "Visualization/ColorScaleEditor.h"
1 #include "Visualization/ColorScaleEditor.h"
2 #include "Visualization/qcustomplot.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(QWidget *parent)
23 ColorScaleEditor::ColorScaleEditor(SqpColorScale &scale, QWidget *parent)
24 : QDialog{parent}, ui{new Ui::ColorScaleEditor}, m_ThresholdGroup{new QButtonGroup{this}}
24 : QDialog{parent},
25 ui{new Ui::ColorScaleEditor},
26 m_Scale{scale},
27 m_ThresholdGroup{new QButtonGroup{this}}
25 {
28 {
26 ui->setupUi(this);
29 ui->setupUi(this);
27
30
28 // Inits gradient combobox content
31 // Inits gradient combobox content
29 for (auto it = GRADIENTS.begin(), end = GRADIENTS.end(); it != end; ++it) {
32 for (auto it = GRADIENTS.begin(), end = GRADIENTS.end(); it != end; ++it) {
30 ui->gradientComboBox->addItem(it.key(), it.value());
33 ui->gradientComboBox->addItem(it.key(), it.value());
31 }
34 }
32
35
33 // Creates threshold group
36 // Creates threshold group
34 m_ThresholdGroup->addButton(ui->thresholdAutoButton);
37 m_ThresholdGroup->addButton(ui->thresholdAutoButton);
35 m_ThresholdGroup->addButton(ui->thresholdManualButton);
38 m_ThresholdGroup->addButton(ui->thresholdManualButton);
36
39
37 // Inits min/max spinboxes' properties
40 // Inits min/max spinboxes' properties
38 auto setSpinBoxProperties = [](auto &spinBox) {
41 auto setSpinBoxProperties = [](auto &spinBox) {
39 spinBox.setDecimals(3);
42 spinBox.setDecimals(3);
40 spinBox.setMinimum(-std::numeric_limits<double>::max());
43 spinBox.setMinimum(-std::numeric_limits<double>::max());
41 spinBox.setMaximum(std::numeric_limits<double>::max());
44 spinBox.setMaximum(std::numeric_limits<double>::max());
42 };
45 };
43 setSpinBoxProperties(*ui->minSpinBox);
46 setSpinBoxProperties(*ui->minSpinBox);
44 setSpinBoxProperties(*ui->maxSpinBox);
47 setSpinBoxProperties(*ui->maxSpinBox);
45
48
46 // Creates color scale preview
49 // Creates color scale preview
47 m_PreviewScale = new QCPColorScale{ui->plot};
50 m_PreviewScale = new QCPColorScale{ui->plot};
48 m_PreviewScale->setType(QCPAxis::atTop);
51 m_PreviewScale->setType(QCPAxis::atTop);
49 m_PreviewScale->setMinimumMargins(QMargins{5, 5, 5, 5});
52 m_PreviewScale->setMinimumMargins(QMargins{5, 5, 5, 5});
50 m_PreviewScale->axis()->setScaleType(QCPAxis::stLogarithmic);
53 m_PreviewScale->axis()->setScaleType(QCPAxis::stLogarithmic);
51 m_PreviewScale->axis()->setNumberPrecision(0);
54 m_PreviewScale->axis()->setNumberPrecision(0);
52 m_PreviewScale->axis()->setNumberFormat("eb");
55 m_PreviewScale->axis()->setNumberFormat("eb");
53 m_PreviewScale->axis()->setTicker(QSharedPointer<QCPAxisTickerLog>::create());
56 m_PreviewScale->axis()->setTicker(QSharedPointer<QCPAxisTickerLog>::create());
54 m_PreviewScale->setGradient(QCPColorGradient{QCPColorGradient::gpJet});
57 m_PreviewScale->setGradient(QCPColorGradient{QCPColorGradient::gpJet});
55
58
56 ui->plot->plotLayout()->clear();
59 ui->plot->plotLayout()->clear();
57 ui->plot->plotLayout()->insertRow(0);
60 ui->plot->plotLayout()->insertRow(0);
58 ui->plot->plotLayout()->addElement(0, 0, m_PreviewScale);
61 ui->plot->plotLayout()->addElement(0, 0, m_PreviewScale);
59
62
60 // Inits connections
63 // Inits connections
61 connect(ui->gradientComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updatePreview()));
64 connect(ui->gradientComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updatePreview()));
62 connect(ui->thresholdAutoButton, SIGNAL(toggled(bool)), this, SLOT(onThresholdChanged(bool)));
65 connect(ui->thresholdAutoButton, SIGNAL(toggled(bool)), this, SLOT(onThresholdChanged(bool)));
63 connect(ui->thresholdManualButton, SIGNAL(toggled(bool)), this, SLOT(onThresholdChanged(bool)));
66 connect(ui->thresholdManualButton, SIGNAL(toggled(bool)), this, SLOT(onThresholdChanged(bool)));
64 connect(ui->minSpinBox, SIGNAL(editingFinished()), this, SLOT(onMinChanged()));
67 connect(ui->minSpinBox, SIGNAL(editingFinished()), this, SLOT(onMinChanged()));
65 connect(ui->maxSpinBox, SIGNAL(editingFinished()), this, SLOT(onMaxChanged()));
68 connect(ui->maxSpinBox, SIGNAL(editingFinished()), this, SLOT(onMaxChanged()));
66
69
67 // First update
70 // First update
68 onThresholdChanged(true);
71 onThresholdChanged(true);
69 updatePreview();
72 updatePreview();
70 }
73 }
71
74
72 ColorScaleEditor::~ColorScaleEditor() noexcept
75 ColorScaleEditor::~ColorScaleEditor() noexcept
73 {
76 {
74 delete ui;
77 delete ui;
75 }
78 }
76
79
77 void ColorScaleEditor::onMaxChanged()
80 void ColorScaleEditor::onMaxChanged()
78 {
81 {
79 // Ensures that max >= min
82 // Ensures that max >= min
80 auto maxValue = ui->maxSpinBox->value();
83 auto maxValue = ui->maxSpinBox->value();
81 if (maxValue < ui->minSpinBox->value()) {
84 if (maxValue < ui->minSpinBox->value()) {
82 ui->minSpinBox->setValue(maxValue);
85 ui->minSpinBox->setValue(maxValue);
83 }
86 }
84
87
85 updatePreview();
88 updatePreview();
86 }
89 }
87
90
88 void ColorScaleEditor::onMinChanged()
91 void ColorScaleEditor::onMinChanged()
89 {
92 {
90 // Ensures that min <= max
93 // Ensures that min <= max
91 auto minValue = ui->minSpinBox->value();
94 auto minValue = ui->minSpinBox->value();
92 if (minValue > ui->maxSpinBox->value()) {
95 if (minValue > ui->maxSpinBox->value()) {
93 ui->maxSpinBox->setValue(minValue);
96 ui->maxSpinBox->setValue(minValue);
94 }
97 }
95
98
96 updatePreview();
99 updatePreview();
97 }
100 }
98
101
99 void ColorScaleEditor::onThresholdChanged(bool checked)
102 void ColorScaleEditor::onThresholdChanged(bool checked)
100 {
103 {
101 if (checked) {
104 if (checked) {
102 auto isAutomatic = ui->thresholdAutoButton == m_ThresholdGroup->checkedButton();
105 auto isAutomatic = ui->thresholdAutoButton == m_ThresholdGroup->checkedButton();
103
106
104 ui->minSpinBox->setEnabled(!isAutomatic);
107 ui->minSpinBox->setEnabled(!isAutomatic);
105 ui->maxSpinBox->setEnabled(!isAutomatic);
108 ui->maxSpinBox->setEnabled(!isAutomatic);
106 }
109 }
107 }
110 }
108
111
109 void ColorScaleEditor::updatePreview()
112 void ColorScaleEditor::updatePreview()
110 {
113 {
111 m_PreviewScale->setDataRange(QCPRange{ui->minSpinBox->value(), ui->maxSpinBox->value()});
114 m_PreviewScale->setDataRange(QCPRange{ui->minSpinBox->value(), ui->maxSpinBox->value()});
112 m_PreviewScale->setGradient(
115 m_PreviewScale->setGradient(
113 ui->gradientComboBox->currentData().value<QCPColorGradient::GradientPreset>());
116 ui->gradientComboBox->currentData().value<QCPColorGradient::GradientPreset>());
114
117
115 ui->plot->replot();
118 ui->plot->replot();
116 }
119 }
General Comments 0
You need to be logged in to leave comments. Login now