SqpColorScale.cpp
63 lines
| 1.8 KiB
| text/x-c
|
CppLexer
Alexandre Leroux
|
r1008 | #include "Visualization/SqpColorScale.h" | ||
Alexandre Leroux
|
r1018 | #include <Visualization/QCPColorMapIterator.h> | ||
Q_LOGGING_CATEGORY(LOG_SqpColorScale, "SqpColorScale") | ||||
r1422 | namespace | |||
{ | ||||
Alexandre Leroux
|
r1008 | |||
const auto DEFAULT_GRADIENT_PRESET = QCPColorGradient::gpJet; | ||||
r1422 | const auto DEFAULT_RANGE = QCPRange { 1.0e3, 1.7e7 }; | |||
Alexandre Leroux
|
r1008 | |||
} // namespace | ||||
r1422 | std::pair<double, double> SqpColorScale::computeThresholds(const SqpColorScale& scale) | |||
Alexandre Leroux
|
r1018 | { | ||
auto qcpScale = scale.m_Scale; | ||||
auto colorMaps = qcpScale->colorMaps(); | ||||
r1422 | if (colorMaps.size() != 1) | |||
{ | ||||
return { std::numeric_limits<double>::quiet_NaN(), | ||||
std::numeric_limits<double>::quiet_NaN() }; | ||||
Alexandre Leroux
|
r1018 | } | ||
// Computes thresholds | ||||
auto isLogarithmicScale = qcpScale->dataScaleType() == QCPAxis::stLogarithmic; | ||||
auto colorMapData = colorMaps.first()->data(); | ||||
r1422 | QCPColorMapIterator begin { colorMapData, true }; | |||
QCPColorMapIterator end { colorMapData, false }; | ||||
Alexandre Leroux
|
r1018 | |||
r1422 | return {}; // DataSeriesUtils::thresholds(begin, end, isLogarithmicScale); | |||
Alexandre Leroux
|
r1018 | } | ||
r1422 | SqpColorScale::SqpColorScale(QCustomPlot& plot) | |||
: m_Scale { new QCPColorScale { &plot } } | ||||
, m_AutomaticThreshold { false } | ||||
, m_GradientPreset { DEFAULT_GRADIENT_PRESET } | ||||
Alexandre Leroux
|
r1008 | { | ||
m_Scale->setGradient(m_GradientPreset); | ||||
m_Scale->setDataRange(DEFAULT_RANGE); | ||||
} | ||||
Alexandre Leroux
|
r1019 | |||
void SqpColorScale::updateDataRange() noexcept | ||||
{ | ||||
// Updates data range only if mode is automatic | ||||
r1422 | if (!m_AutomaticThreshold) | |||
{ | ||||
Alexandre Leroux
|
r1019 | return; | ||
} | ||||
double minThreshold, maxThreshold; | ||||
std::tie(minThreshold, maxThreshold) = computeThresholds(*this); | ||||
r1422 | if (std::isnan(minThreshold) || std::isnan(maxThreshold)) | |||
{ | ||||
Alexandre Leroux
|
r1019 | qCCritical(LOG_SqpColorScale()) | ||
<< "Can't update data range of color scale: thresholds computed are invalid"; | ||||
return; | ||||
} | ||||
// Updates thresholds | ||||
r1422 | m_Scale->setDataRange({ minThreshold, maxThreshold }); | |||
Alexandre Leroux
|
r1019 | } | ||