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