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