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