##// END OF EJS Templates
Separate the initialization of the properties of the graph of the update of the units of the graph....
Separate the initialization of the properties of the graph of the update of the units of the graph. The initialization of the properties is carried out when adding a variable in the graph, the update of the units is carried out when loading the data of this variable

File last commit:

r1307:a119058eb032
r1308:41b7c6aab8be
Show More
PlottablesRenderingUtils.cpp
126 lines | 4.1 KiB | text/x-c | CppLexer
/ gui / src / Visualization / PlottablesRenderingUtils.cpp
Alexandre Leroux
Handles rendering of plottables (1)...
r918 #include "Visualization/PlottablesRenderingUtils.h"
Alexandre Leroux
Handles rendering of plottables (2)...
r919 #include <Common/ColorUtils.h>
Alexandre Leroux
Handles rendering of plottables (1)...
r918 #include <Data/ScalarSeries.h>
Alexandre Leroux
Handles rendering properties for spectrograms...
r922 #include <Data/SpectrogramSeries.h>
Alexandre Leroux
Handles rendering of plottables (1)...
r918 #include <Data/VectorSeries.h>
Alexandre Leroux
Updates PlottablesRenderingUtils to use variable's type instead of dataseries
r1307 #include <Variable/Variable.h>
Alexandre Leroux
Handles rendering of plottables (1)...
r918 #include <Visualization/qcustomplot.h>
Alexandre Leroux
Adds logs to axe and plottable rendering utils
r927 Q_LOGGING_CATEGORY(LOG_PlottablesRenderingUtils, "PlottablesRenderingUtils")
Alexandre Leroux
Handles rendering of plottables (1)...
r918 namespace {
/**
* Delegate used to set plottables properties
*/
template <typename T, typename Enabled = void>
struct PlottablesSetter {
Alexandre Leroux
Updates PlottablesRenderingUtils to use variable's type instead of dataseries
r1307 static void setProperties(PlottablesMap &)
Alexandre Leroux
Handles rendering of plottables (1)...
r918 {
// Default implementation does nothing
Alexandre Leroux
Adds logs to axe and plottable rendering utils
r927 qCCritical(LOG_PlottablesRenderingUtils())
<< "Can't set plottables properties: unmanaged type of data";
Alexandre Leroux
Handles rendering of plottables (1)...
r918 }
};
/**
* 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> > {
Alexandre Leroux
Updates PlottablesRenderingUtils to use variable's type instead of dataseries
r1307 static void setProperties(PlottablesMap &plottables)
Alexandre Leroux
Handles rendering of plottables (1)...
r918 {
Alexandre Leroux
Updates PlottablesRenderingUtils to use variable's type instead of dataseries
r1307 // Finds the plottable with the highest index to determine the number of colors to generate
auto end = plottables.cend();
auto maxPlottableIndexIt
= std::max_element(plottables.cbegin(), end, [](const auto &it1, const auto &it2) {
return it1.first < it2.first;
});
auto componentCount = maxPlottableIndexIt != end ? maxPlottableIndexIt->first + 1 : 0;
Alexandre Leroux
Handles rendering of plottables (2)...
r919
// 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) {
Alexandre Leroux
Updates PlottablesRenderingUtils to use variable's type instead of dataseries
r1307 auto graphIt = plottables.find(i);
if (graphIt != end) {
graphIt->second->setPen(QPen{colors.at(i)});
}
Alexandre Leroux
Handles rendering of plottables (2)...
r919 }
Alexandre Leroux
Handles rendering of plottables (1)...
r918 }
};
Alexandre Leroux
Handles rendering properties for spectrograms...
r922 /**
* 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> > {
Alexandre Leroux
Updates PlottablesRenderingUtils to use variable's type instead of dataseries
r1307 static void setProperties(PlottablesMap &plottables)
Alexandre Leroux
Handles rendering properties for spectrograms...
r922 {
// 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
r927 else {
qCCritical(LOG_PlottablesRenderingUtils()) << "Can't get colormap of the spectrogram";
}
Alexandre Leroux
Handles rendering properties for spectrograms...
r922 }
};
Alexandre Leroux
Handles rendering of plottables (1)...
r918 /**
* 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 {
void setProperties(PlottablesMap &plottables) override
{
Alexandre Leroux
Updates PlottablesRenderingUtils to use variable's type instead of dataseries
r1307 PlottablesSetter<T>::setProperties(plottables);
Alexandre Leroux
Handles rendering of plottables (1)...
r918 }
};
} // namespace
std::unique_ptr<IPlottablesHelper>
Alexandre Leroux
Updates PlottablesRenderingUtils to use variable's type instead of dataseries
r1307 IPlottablesHelperFactory::create(const Variable &variable) noexcept
Alexandre Leroux
Handles rendering of plottables (1)...
r918 {
Alexandre Leroux
Updates PlottablesRenderingUtils to use variable's type instead of dataseries
r1307 switch (variable.type()) {
case DataSeriesType::SCALAR:
return std::make_unique<PlottablesHelper<ScalarSeries> >();
case DataSeriesType::SPECTROGRAM:
return std::make_unique<PlottablesHelper<SpectrogramSeries> >();
case DataSeriesType::VECTOR:
return std::make_unique<PlottablesHelper<VectorSeries> >();
default:
// Returns default helper
break;
Alexandre Leroux
Handles rendering of plottables (1)...
r918 }
Alexandre Leroux
Updates PlottablesRenderingUtils to use variable's type instead of dataseries
r1307
return std::make_unique<PlottablesHelper<IDataSeries> >();
Alexandre Leroux
Handles rendering of plottables (1)...
r918 }