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