@@ -1,66 +1,89 | |||
|
1 | 1 | #include "Visualization/ColorScaleEditor.h" |
|
2 | 2 | |
|
3 | 3 | #include "ui_ColorScaleEditor.h" |
|
4 | 4 | |
|
5 | namespace { | |
|
6 | ||
|
7 | const auto GRADIENTS = QVariantMap{{"Candy", QCPColorGradient::gpCandy}, | |
|
8 | {"Cold", QCPColorGradient::gpCold}, | |
|
9 | {"Geography", QCPColorGradient::gpGeography}, | |
|
10 | {"Grayscale", QCPColorGradient::gpGrayscale}, | |
|
11 | {"Hot", QCPColorGradient::gpHot}, | |
|
12 | {"Hues", QCPColorGradient::gpHues}, | |
|
13 | {"Ion", QCPColorGradient::gpIon}, | |
|
14 | {"Jet", QCPColorGradient::gpJet}, | |
|
15 | {"Night", QCPColorGradient::gpNight}, | |
|
16 | {"Polar", QCPColorGradient::gpPolar}, | |
|
17 | {"Spectrum", QCPColorGradient::gpSpectrum}, | |
|
18 | {"Thermal", QCPColorGradient::gpThermal}}; | |
|
19 | ||
|
20 | } // namespace | |
|
21 | ||
|
5 | 22 | ColorScaleEditor::ColorScaleEditor(QWidget *parent) |
|
6 | 23 | : QDialog{parent}, ui{new Ui::ColorScaleEditor}, m_ThresholdGroup{new QButtonGroup{this}} |
|
7 | 24 | { |
|
8 | 25 | ui->setupUi(this); |
|
26 | ||
|
27 | // Inits gradient combobox content | |
|
28 | for (auto it = GRADIENTS.begin(), end = GRADIENTS.end(); it != end; ++it) { | |
|
29 | ui->gradientComboBox->addItem(it.key(), it.value()); | |
|
30 | } | |
|
31 | ||
|
9 | 32 | // Creates threshold group |
|
10 | 33 | m_ThresholdGroup->addButton(ui->thresholdAutoButton); |
|
11 | 34 | m_ThresholdGroup->addButton(ui->thresholdManualButton); |
|
12 | 35 | |
|
13 | 36 | // Inits min/max spinboxes' properties |
|
14 | 37 | auto setSpinBoxProperties = [](auto &spinBox) { |
|
15 | 38 | spinBox.setDecimals(3); |
|
16 | 39 | spinBox.setMinimum(-std::numeric_limits<double>::max()); |
|
17 | 40 | spinBox.setMaximum(std::numeric_limits<double>::max()); |
|
18 | 41 | }; |
|
19 | 42 | setSpinBoxProperties(*ui->minSpinBox); |
|
20 | 43 | setSpinBoxProperties(*ui->maxSpinBox); |
|
21 | 44 | |
|
22 | 45 | // Inits connections |
|
23 | 46 | connect(ui->thresholdAutoButton, SIGNAL(toggled(bool)), this, SLOT(onThresholdChanged(bool))); |
|
24 | 47 | connect(ui->thresholdManualButton, SIGNAL(toggled(bool)), this, SLOT(onThresholdChanged(bool))); |
|
25 | 48 | connect(ui->minSpinBox, SIGNAL(editingFinished()), this, SLOT(onMinChanged())); |
|
26 | 49 | connect(ui->maxSpinBox, SIGNAL(editingFinished()), this, SLOT(onMaxChanged())); |
|
27 | 50 | |
|
28 | 51 | // First update |
|
29 | 52 | onThresholdChanged(true); |
|
30 | 53 | } |
|
31 | 54 | |
|
32 | 55 | ColorScaleEditor::~ColorScaleEditor() noexcept |
|
33 | 56 | { |
|
34 | 57 | delete ui; |
|
35 | 58 | } |
|
36 | 59 | |
|
37 | 60 | void ColorScaleEditor::onMaxChanged() |
|
38 | 61 | { |
|
39 | 62 | // Ensures that max >= min |
|
40 | 63 | auto maxValue = ui->maxSpinBox->value(); |
|
41 | 64 | if (maxValue < ui->minSpinBox->value()) { |
|
42 | 65 | ui->minSpinBox->setValue(maxValue); |
|
43 | 66 | } |
|
44 | 67 | |
|
45 | 68 | } |
|
46 | 69 | |
|
47 | 70 | void ColorScaleEditor::onMinChanged() |
|
48 | 71 | { |
|
49 | 72 | // Ensures that min <= max |
|
50 | 73 | auto minValue = ui->minSpinBox->value(); |
|
51 | 74 | if (minValue > ui->maxSpinBox->value()) { |
|
52 | 75 | ui->maxSpinBox->setValue(minValue); |
|
53 | 76 | } |
|
54 | 77 | |
|
55 | 78 | } |
|
56 | 79 | |
|
57 | 80 | void ColorScaleEditor::onThresholdChanged(bool checked) |
|
58 | 81 | { |
|
59 | 82 | if (checked) { |
|
60 | 83 | auto isAutomatic = ui->thresholdAutoButton == m_ThresholdGroup->checkedButton(); |
|
61 | 84 | |
|
62 | 85 | ui->minSpinBox->setEnabled(!isAutomatic); |
|
63 | 86 | ui->maxSpinBox->setEnabled(!isAutomatic); |
|
64 | 87 | } |
|
65 | 88 | } |
|
66 | 89 |
General Comments 0
You need to be logged in to leave comments.
Login now