##// END OF EJS Templates
Adds the ability to force an acquisition pending for an operation (3)...
Adds the ability to force an acquisition pending for an operation (3) Forces to wait acquisition when creating a variable

File last commit:

r1062:b014e09f2329
r1251:6cdc10030ad4
Show More
ColorScaleEditor.cpp
174 lines | 5.8 KiB | text/x-c | CppLexer
/ gui / src / Visualization / ColorScaleEditor.cpp
Alexandre Leroux
Inits color scale widget
r1042 #include "Visualization/ColorScaleEditor.h"
Alexandre Leroux
Adds the color scale in edting in color scale editor
r1051 #include "Visualization/SqpColorScale.h"
Alexandre Leroux
Inits color scale widget
r1042
#include "ui_ColorScaleEditor.h"
Alexandre Leroux
Inits gradient combobox
r1046 namespace {
const auto GRADIENTS = QVariantMap{{"Candy", QCPColorGradient::gpCandy},
{"Cold", QCPColorGradient::gpCold},
{"Geography", QCPColorGradient::gpGeography},
{"Grayscale", QCPColorGradient::gpGrayscale},
{"Hot", QCPColorGradient::gpHot},
{"Hues", QCPColorGradient::gpHues},
{"Ion", QCPColorGradient::gpIon},
{"Jet", QCPColorGradient::gpJet},
{"Night", QCPColorGradient::gpNight},
{"Polar", QCPColorGradient::gpPolar},
{"Spectrum", QCPColorGradient::gpSpectrum},
{"Thermal", QCPColorGradient::gpThermal}};
} // namespace
Alexandre Leroux
Adds the color scale in edting in color scale editor
r1051 ColorScaleEditor::ColorScaleEditor(SqpColorScale &scale, QWidget *parent)
: QDialog{parent},
ui{new Ui::ColorScaleEditor},
Alexandre Leroux
Fixes compilation warning
r1055 m_ThresholdGroup{new QButtonGroup{this}},
m_Scale{scale}
Alexandre Leroux
Inits color scale widget
r1042 {
ui->setupUi(this);
Alexandre Leroux
Inits gradient combobox
r1046
// Inits gradient combobox content
for (auto it = GRADIENTS.begin(), end = GRADIENTS.end(); it != end; ++it) {
ui->gradientComboBox->addItem(it.key(), it.value());
}
Alexandre Leroux
Inits threshold mode buttons (auto or manual)...
r1044 // Creates threshold group
m_ThresholdGroup->addButton(ui->thresholdAutoButton);
m_ThresholdGroup->addButton(ui->thresholdManualButton);
Alexandre Leroux
Inits min/max spinboxes...
r1045 // Inits min/max spinboxes' properties
auto setSpinBoxProperties = [](auto &spinBox) {
spinBox.setDecimals(3);
spinBox.setMinimum(-std::numeric_limits<double>::max());
spinBox.setMaximum(std::numeric_limits<double>::max());
};
setSpinBoxProperties(*ui->minSpinBox);
setSpinBoxProperties(*ui->maxSpinBox);
Alexandre Leroux
Inits color scale preview
r1047 // Creates color scale preview
m_PreviewScale = new QCPColorScale{ui->plot};
m_PreviewScale->setType(QCPAxis::atTop);
m_PreviewScale->setMinimumMargins(QMargins{5, 5, 5, 5});
m_PreviewScale->axis()->setScaleType(QCPAxis::stLogarithmic);
m_PreviewScale->axis()->setNumberPrecision(0);
m_PreviewScale->axis()->setNumberFormat("eb");
m_PreviewScale->axis()->setTicker(QSharedPointer<QCPAxisTickerLog>::create());
m_PreviewScale->setGradient(QCPColorGradient{QCPColorGradient::gpJet});
ui->plot->plotLayout()->clear();
ui->plot->plotLayout()->insertRow(0);
ui->plot->plotLayout()->addElement(0, 0, m_PreviewScale);
Alexandre Leroux
Inits threshold mode buttons (auto or manual)...
r1044 // Inits connections
Alexandre Leroux
Implements preview update...
r1048 connect(ui->gradientComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(updatePreview()));
Alexandre Leroux
Inits threshold mode buttons (auto or manual)...
r1044 connect(ui->thresholdAutoButton, SIGNAL(toggled(bool)), this, SLOT(onThresholdChanged(bool)));
connect(ui->thresholdManualButton, SIGNAL(toggled(bool)), this, SLOT(onThresholdChanged(bool)));
Alexandre Leroux
Inits min/max spinboxes...
r1045 connect(ui->minSpinBox, SIGNAL(editingFinished()), this, SLOT(onMinChanged()));
connect(ui->maxSpinBox, SIGNAL(editingFinished()), this, SLOT(onMaxChanged()));
Alexandre Leroux
Inits threshold mode buttons (auto or manual)...
r1044
Alexandre Leroux
Implements color scale save when the editor is closed
r1053 // OK/cancel buttons
connect(ui->okButton, SIGNAL(clicked(bool)), this, SLOT(accept()));
connect(ui->cancelButton, SIGNAL(clicked(bool)), this, SLOT(reject()));
Alexandre Leroux
Implements color scale loading when the editor is open
r1052 // Loads color scale
loadScale();
Alexandre Leroux
Inits color scale widget
r1042 }
ColorScaleEditor::~ColorScaleEditor() noexcept
{
delete ui;
}
Alexandre Leroux
Inits min/max spinboxes...
r1045
Alexandre Leroux
Implements color scale loading when the editor is open
r1052 void ColorScaleEditor::loadScale()
{
// Gradient
auto gradientPresetIndex = ui->gradientComboBox->findData(m_Scale.m_GradientPreset);
ui->gradientComboBox->setCurrentIndex(gradientPresetIndex);
// Threshold mode
(m_Scale.m_AutomaticThreshold ? ui->thresholdAutoButton : ui->thresholdManualButton)
->setChecked(true);
// Min/max
auto qcpColorScale = m_Scale.m_Scale;
auto range = qcpColorScale->dataRange();
ui->minSpinBox->setValue(range.lower);
ui->maxSpinBox->setValue(range.upper);
updatePreview();
}
Alexandre Leroux
Implements color scale save when the editor is closed
r1053 void ColorScaleEditor::saveScale()
{
auto qcpColorScale = m_Scale.m_Scale;
// Gradient
auto gradientPreset
= ui->gradientComboBox->currentData().value<QCPColorGradient::GradientPreset>();
qcpColorScale->setGradient(gradientPreset);
m_Scale.m_GradientPreset = gradientPreset;
// Threshold mode
m_Scale.m_AutomaticThreshold = ui->thresholdAutoButton->isChecked();
// Min/max
qcpColorScale->setDataRange(QCPRange{ui->minSpinBox->value(), ui->maxSpinBox->value()});
}
void ColorScaleEditor::accept()
{
saveScale();
QDialog::accept();
}
Alexandre Leroux
Inits min/max spinboxes...
r1045 void ColorScaleEditor::onMaxChanged()
{
// Ensures that max >= min
auto maxValue = ui->maxSpinBox->value();
if (maxValue < ui->minSpinBox->value()) {
ui->minSpinBox->setValue(maxValue);
}
Alexandre Leroux
Implements preview update...
r1048 updatePreview();
Alexandre Leroux
Inits min/max spinboxes...
r1045 }
void ColorScaleEditor::onMinChanged()
{
// Ensures that min <= max
auto minValue = ui->minSpinBox->value();
if (minValue > ui->maxSpinBox->value()) {
ui->maxSpinBox->setValue(minValue);
}
Alexandre Leroux
Implements preview update...
r1048 updatePreview();
Alexandre Leroux
Inits min/max spinboxes...
r1045 }
Alexandre Leroux
Inits threshold mode buttons (auto or manual)...
r1044 void ColorScaleEditor::onThresholdChanged(bool checked)
{
if (checked) {
auto isAutomatic = ui->thresholdAutoButton == m_ThresholdGroup->checkedButton();
ui->minSpinBox->setEnabled(!isAutomatic);
ui->maxSpinBox->setEnabled(!isAutomatic);
Alexandre Leroux
Call the calculation of the thresholds in the scale editor (with each click on the 'automatic' mode)
r1062
// Computes automatic thresholds
if (isAutomatic) {
double minThreshold, maxThreshold;
std::tie(minThreshold, maxThreshold) = SqpColorScale::computeThresholds(m_Scale);
ui->minSpinBox->setValue(minThreshold);
ui->maxSpinBox->setValue(maxThreshold);
updatePreview();
}
Alexandre Leroux
Inits threshold mode buttons (auto or manual)...
r1044 }
}
Alexandre Leroux
Implements preview update...
r1048 void ColorScaleEditor::updatePreview()
{
m_PreviewScale->setDataRange(QCPRange{ui->minSpinBox->value(), ui->maxSpinBox->value()});
m_PreviewScale->setGradient(
ui->gradientComboBox->currentData().value<QCPColorGradient::GradientPreset>());
ui->plot->replot();
}