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