##// END OF EJS Templates
Many synchronization fixes, most operations works, only product drag from tree is broken...
Many synchronization fixes, most operations works, only product drag from tree is broken Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>

File last commit:

r1315:b20dcec1c57b
r1377:0f6ffbe66d5f
Show More
AxisRenderingUtils.cpp
205 lines | 6.6 KiB | text/x-c | CppLexer
/ gui / src / Visualization / AxisRenderingUtils.cpp
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915 #include "Visualization/AxisRenderingUtils.h"
#include <Data/ScalarSeries.h>
Alexandre Leroux
Handles axes properties for spectrograms...
r920 #include <Data/SpectrogramSeries.h>
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915 #include <Data/VectorSeries.h>
Alexandre Leroux
Updates AxisRenderingUtils to use variable's type instead of dataseries
r1281 #include <Variable/Variable.h>
Alexandre Leroux
Uses SciQlop color scale in graphs
r1009 #include <Visualization/SqpColorScale.h>
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915 #include <Visualization/qcustomplot.h>
Alexandre Leroux
Adds logs to axe and plottable rendering utils
r928 Q_LOGGING_CATEGORY(LOG_AxisRenderingUtils, "AxisRenderingUtils")
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915 namespace {
Alexandre Leroux
Refactoring handling of axes properties (2)...
r916 /// Format for datetimes on a axis
const auto DATETIME_TICKER_FORMAT = QStringLiteral("yyyy/MM/dd \nhh:mm:ss");
Alexandre Leroux
Tooltip for spectrograms (4)...
r1027 const auto NUMBER_FORMAT = 'g';
const auto NUMBER_PRECISION = 9;
Alexandre Leroux
Refactoring handling of axes properties (2)...
r916 /// Generates the appropriate ticker for an axis, depending on whether the axis displays time or
/// non-time data
Alexandre Leroux
Handles log scales for y-axis and color scale
r929 QSharedPointer<QCPAxisTicker> axisTicker(bool isTimeAxis, QCPAxis::ScaleType scaleType)
Alexandre Leroux
Refactoring handling of axes properties (2)...
r916 {
if (isTimeAxis) {
auto dateTicker = QSharedPointer<QCPAxisTickerDateTime>::create();
dateTicker->setDateTimeFormat(DATETIME_TICKER_FORMAT);
dateTicker->setDateTimeSpec(Qt::UTC);
return dateTicker;
}
Alexandre Leroux
Handles log scales for y-axis and color scale
r929 else if (scaleType == QCPAxis::stLogarithmic) {
return QSharedPointer<QCPAxisTickerLog>::create();
}
Alexandre Leroux
Refactoring handling of axes properties (2)...
r916 else {
// default ticker
return QSharedPointer<QCPAxisTicker>::create();
}
}
/**
* Sets properties of the axis passed as parameter
* @param axis the axis to set
* @param unit the unit to set for the axis
* @param scaleType the scale type to set for the axis
*/
void setAxisProperties(QCPAxis &axis, const Unit &unit,
QCPAxis::ScaleType scaleType = QCPAxis::stLinear)
{
// label (unit name)
axis.setLabel(unit.m_Name);
// scale type
axis.setScaleType(scaleType);
Alexandre Leroux
Handles log scales for y-axis and color scale
r929 if (scaleType == QCPAxis::stLogarithmic) {
// Scientific notation
axis.setNumberPrecision(0);
axis.setNumberFormat("eb");
}
Alexandre Leroux
Refactoring handling of axes properties (2)...
r916
// ticker (depending on the type of unit)
Alexandre Leroux
Handles log scales for y-axis and color scale
r929 axis.setTicker(axisTicker(unit.m_TimeUnit, scaleType));
Alexandre Leroux
Refactoring handling of axes properties (2)...
r916 }
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915 /**
* Delegate used to set axes properties
*/
template <typename T, typename Enabled = void>
struct AxisSetter {
Alexandre Leroux
Updates AxisRenderingUtils to use variable's type instead of dataseries
r1281 static void setProperties(QCustomPlot &, SqpColorScale &)
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915 {
// Default implementation does nothing
Alexandre Leroux
Adds logs to axe and plottable rendering utils
r928 qCCritical(LOG_AxisRenderingUtils()) << "Can't set axis properties: unmanaged type of data";
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915 }
Alexandre Leroux
Updates AxisRenderingUtils to use variable's type instead of dataseries
r1281
static void setUnits(T &, QCustomPlot &, SqpColorScale &)
{
// Default implementation does nothing
qCCritical(LOG_AxisRenderingUtils()) << "Can't set axis units: unmanaged type of data";
}
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915 };
/**
* Specialization of AxisSetter for scalars and vectors
* @sa ScalarSeries
* @sa VectorSeries
*/
template <typename T>
struct AxisSetter<T, typename std::enable_if_t<std::is_base_of<ScalarSeries, T>::value
or std::is_base_of<VectorSeries, T>::value> > {
Alexandre Leroux
Updates AxisRenderingUtils to use variable's type instead of dataseries
r1281 static void setProperties(QCustomPlot &, SqpColorScale &)
{
// Nothing to do
}
static void setUnits(T &dataSeries, QCustomPlot &plot, SqpColorScale &)
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915 {
Alexandre Leroux
Refactoring handling of axes properties (2)...
r916 dataSeries.lockRead();
auto xAxisUnit = dataSeries.xAxisUnit();
auto valuesUnit = dataSeries.valuesUnit();
dataSeries.unlock();
setAxisProperties(*plot.xAxis, xAxisUnit);
setAxisProperties(*plot.yAxis, valuesUnit);
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915 }
};
Alexandre Leroux
Handles axes properties for spectrograms...
r920 /**
* Specialization of AxisSetter for spectrograms
* @sa SpectrogramSeries
*/
template <typename T>
struct AxisSetter<T, typename std::enable_if_t<std::is_base_of<SpectrogramSeries, T>::value> > {
Alexandre Leroux
Updates AxisRenderingUtils to use variable's type instead of dataseries
r1281 static void setProperties(QCustomPlot &plot, SqpColorScale &colorScale)
Alexandre Leroux
Handles axes properties for spectrograms...
r920 {
// Displays color scale in plot
plot.plotLayout()->insertRow(0);
Alexandre Leroux
Uses SciQlop color scale in graphs
r1009 plot.plotLayout()->addElement(0, 0, colorScale.m_Scale);
colorScale.m_Scale->setType(QCPAxis::atTop);
colorScale.m_Scale->setMinimumMargins(QMargins{0, 0, 0, 0});
Alexandre Leroux
Handles axes properties for spectrograms...
r920
// Aligns color scale with axes
auto marginGroups = plot.axisRect()->marginGroups();
for (auto it = marginGroups.begin(), end = marginGroups.end(); it != end; ++it) {
Alexandre Leroux
Uses SciQlop color scale in graphs
r1009 colorScale.m_Scale->setMarginGroup(it.key(), it.value());
Alexandre Leroux
Handles axes properties for spectrograms...
r920 }
// Set color scale properties
Alexandre Leroux
Minor fix...
r1110 colorScale.m_AutomaticThreshold = true;
Alexandre Leroux
Handles axes properties for spectrograms...
r920 }
Alexandre Leroux
Updates AxisRenderingUtils to use variable's type instead of dataseries
r1281
static void setUnits(T &dataSeries, QCustomPlot &plot, SqpColorScale &colorScale)
{
dataSeries.lockRead();
auto xAxisUnit = dataSeries.xAxisUnit();
auto yAxisUnit = dataSeries.yAxisUnit();
auto valuesUnit = dataSeries.valuesUnit();
dataSeries.unlock();
setAxisProperties(*plot.xAxis, xAxisUnit);
setAxisProperties(*plot.yAxis, yAxisUnit, QCPAxis::stLogarithmic);
setAxisProperties(*colorScale.m_Scale->axis(), valuesUnit, QCPAxis::stLogarithmic);
}
Alexandre Leroux
Handles axes properties for spectrograms...
r920 };
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915 /**
* Default implementation of IAxisHelper, which takes data series to set axes properties
* @tparam T the data series' type
*/
template <typename T>
struct AxisHelper : public IAxisHelper {
Alexandre Leroux
Updates AxisRenderingUtils to use variable's type instead of dataseries
r1281 explicit AxisHelper(std::shared_ptr<T> dataSeries) : m_DataSeries{dataSeries} {}
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915
Alexandre Leroux
Uses SciQlop color scale in graphs
r1009 void setProperties(QCustomPlot &plot, SqpColorScale &colorScale) override
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915 {
Alexandre Leroux
Updates AxisRenderingUtils to use variable's type instead of dataseries
r1281 AxisSetter<T>::setProperties(plot, colorScale);
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915 }
Alexandre Leroux
Updates AxisRenderingUtils to use variable's type instead of dataseries
r1281 void setUnits(QCustomPlot &plot, SqpColorScale &colorScale) override
{
if (m_DataSeries) {
AxisSetter<T>::setUnits(*m_DataSeries, plot, colorScale);
}
else {
qCCritical(LOG_AxisRenderingUtils()) << "Can't set units: inconsistency between the "
"type of data series and the type supposed";
}
}
std::shared_ptr<T> m_DataSeries;
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915 };
} // namespace
Alexandre Leroux
Refactoring handling of axes properties (2)...
r916 QString formatValue(double value, const QCPAxis &axis)
{
// If the axis is a time axis, formats the value as a date
if (auto axisTicker = qSharedPointerDynamicCast<QCPAxisTickerDateTime>(axis.ticker())) {
return DateUtils::dateTime(value, axisTicker->dateTimeSpec()).toString(DATETIME_FORMAT);
}
else {
Alexandre Leroux
Tooltip for spectrograms (4)...
r1027 return QString::number(value, NUMBER_FORMAT, NUMBER_PRECISION);
Alexandre Leroux
Refactoring handling of axes properties (2)...
r916 }
}
Alexandre Leroux
Updates AxisRenderingUtils to use variable's type instead of dataseries
r1281 std::unique_ptr<IAxisHelper> IAxisHelperFactory::create(const Variable &variable) noexcept
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915 {
Alexandre Leroux
Updates AxisRenderingUtils to use variable's type instead of dataseries
r1281 switch (variable.type()) {
case DataSeriesType::SCALAR:
return std::make_unique<AxisHelper<ScalarSeries> >(
std::dynamic_pointer_cast<ScalarSeries>(variable.dataSeries()));
case DataSeriesType::SPECTROGRAM:
return std::make_unique<AxisHelper<SpectrogramSeries> >(
std::dynamic_pointer_cast<SpectrogramSeries>(variable.dataSeries()));
case DataSeriesType::VECTOR:
return std::make_unique<AxisHelper<VectorSeries> >(
std::dynamic_pointer_cast<VectorSeries>(variable.dataSeries()));
default:
// Creates default helper
break;
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915 }
Alexandre Leroux
Updates AxisRenderingUtils to use variable's type instead of dataseries
r1281
return std::make_unique<AxisHelper<IDataSeries> >(nullptr);
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915 }