##// END OF EJS Templates
Adds "number of operations" and "number of variables" properties for the tests
Adds "number of operations" and "number of variables" properties for the tests

File last commit:

r1009:761051f0c06c
r1170:3da18e6983d5
Show More
PlottablesRenderingUtils.cpp
122 lines | 4.1 KiB | text/x-c | CppLexer
/ gui / src / Visualization / PlottablesRenderingUtils.cpp
Alexandre Leroux
Handles rendering of plottables (1)...
r917 #include "Visualization/PlottablesRenderingUtils.h"
Alexandre Leroux
Handles rendering of plottables (2)...
r918 #include <Common/ColorUtils.h>
Alexandre Leroux
Handles rendering of plottables (1)...
r917 #include <Data/ScalarSeries.h>
Alexandre Leroux
Handles rendering properties for spectrograms...
r921 #include <Data/SpectrogramSeries.h>
Alexandre Leroux
Handles rendering of plottables (1)...
r917 #include <Data/VectorSeries.h>
#include <Visualization/qcustomplot.h>
Alexandre Leroux
Adds logs to axe and plottable rendering utils
r928 Q_LOGGING_CATEGORY(LOG_PlottablesRenderingUtils, "PlottablesRenderingUtils")
Alexandre Leroux
Handles rendering of plottables (1)...
r917 namespace {
/**
* Delegate used to set plottables properties
*/
template <typename T, typename Enabled = void>
struct PlottablesSetter {
static void setProperties(T &, PlottablesMap &)
{
// Default implementation does nothing
Alexandre Leroux
Adds logs to axe and plottable rendering utils
r928 qCCritical(LOG_PlottablesRenderingUtils())
<< "Can't set plottables properties: unmanaged type of data";
Alexandre Leroux
Handles rendering of plottables (1)...
r917 }
};
/**
* Specialization of PlottablesSetter for scalars and vectors
* @sa ScalarSeries
* @sa VectorSeries
*/
template <typename T>
struct PlottablesSetter<T, typename std::enable_if_t<std::is_base_of<ScalarSeries, T>::value
or std::is_base_of<VectorSeries, T>::value> > {
static void setProperties(T &dataSeries, PlottablesMap &plottables)
{
Alexandre Leroux
Handles rendering of plottables (2)...
r918 // Gets the number of components of the data series
dataSeries.lockRead();
auto componentCount = dataSeries.valuesData()->componentCount();
dataSeries.unlock();
// Generates colors for each component
auto colors = ColorUtils::colors(Qt::blue, Qt::red, componentCount);
// For each component of the data series, creates a QCPGraph to add to the plot
for (auto i = 0; i < componentCount; ++i) {
auto graph = plottables.at(i);
graph->setPen(QPen{colors.at(i)});
}
Alexandre Leroux
Handles rendering of plottables (1)...
r917 }
};
Alexandre Leroux
Handles rendering properties for spectrograms...
r921 /**
* Specialization of PlottablesSetter for spectrograms
* @sa SpectrogramSeries
*/
template <typename T>
struct PlottablesSetter<T,
typename std::enable_if_t<std::is_base_of<SpectrogramSeries, T>::value> > {
static void setProperties(T &, PlottablesMap &plottables)
{
// Checks that for a spectrogram there is only one plottable, that is a colormap
if (plottables.size() != 1) {
return;
}
if (auto colormap = dynamic_cast<QCPColorMap *>(plottables.begin()->second)) {
colormap->setInterpolate(false); // No value interpolation
colormap->setTightBoundary(true);
// Finds color scale in the colormap's plot to associate with it
auto plot = colormap->parentPlot();
auto plotElements = plot->plotLayout()->elements(false);
for (auto plotElement : plotElements) {
if (auto colorScale = dynamic_cast<QCPColorScale *>(plotElement)) {
colormap->setColorScale(colorScale);
}
}
colormap->rescaleDataRange();
}
Alexandre Leroux
Adds logs to axe and plottable rendering utils
r928 else {
qCCritical(LOG_PlottablesRenderingUtils()) << "Can't get colormap of the spectrogram";
}
Alexandre Leroux
Handles rendering properties for spectrograms...
r921 }
};
Alexandre Leroux
Handles rendering of plottables (1)...
r917 /**
* Default implementation of IPlottablesHelper, which takes data series to set plottables properties
* @tparam T the data series' type
*/
template <typename T>
struct PlottablesHelper : public IPlottablesHelper {
explicit PlottablesHelper(T &dataSeries) : m_DataSeries{dataSeries} {}
void setProperties(PlottablesMap &plottables) override
{
PlottablesSetter<T>::setProperties(m_DataSeries, plottables);
}
T &m_DataSeries;
};
} // namespace
std::unique_ptr<IPlottablesHelper>
IPlottablesHelperFactory::create(std::shared_ptr<IDataSeries> dataSeries) noexcept
{
if (auto scalarSeries = std::dynamic_pointer_cast<ScalarSeries>(dataSeries)) {
return std::make_unique<PlottablesHelper<ScalarSeries> >(*scalarSeries);
}
Alexandre Leroux
Handles rendering properties for spectrograms...
r921 else if (auto spectrogramSeries = std::dynamic_pointer_cast<SpectrogramSeries>(dataSeries)) {
return std::make_unique<PlottablesHelper<SpectrogramSeries> >(*spectrogramSeries);
}
Alexandre Leroux
Handles rendering of plottables (1)...
r917 else if (auto vectorSeries = std::dynamic_pointer_cast<VectorSeries>(dataSeries)) {
return std::make_unique<PlottablesHelper<VectorSeries> >(*vectorSeries);
}
else {
return std::make_unique<PlottablesHelper<IDataSeries> >(*dataSeries);
}
}