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