From 8264fa4b2aa2e945dda51f9a1aab8fd019e48539 2017-11-10 08:42:52 From: Alexandre Leroux Date: 2017-11-10 08:42:52 Subject: [PATCH] Handles rendering of plottables (1) As for the axes properties, we create a helper used to set rendering properties of the plottables depending on the type of the data series used to create these plottables. Rendering properties will be, for example: - the color of each component for a scalar or a vector - the color scale management for a spectrogram --- diff --git a/gui/include/Visualization/PlottablesRenderingUtils.h b/gui/include/Visualization/PlottablesRenderingUtils.h new file mode 100644 index 0000000..ddc9b2e --- /dev/null +++ b/gui/include/Visualization/PlottablesRenderingUtils.h @@ -0,0 +1,29 @@ +#ifndef SCIQLOP_PLOTTABLESRENDERINGUTILS_H +#define SCIQLOP_PLOTTABLESRENDERINGUTILS_H + +#include + +#include + +class IDataSeries; +class QCPColorScale; +class QCustomPlot; + +/** + * Helper used to handle plottables rendering + */ +struct IPlottablesHelper { + virtual ~IPlottablesHelper() noexcept = default; + + /// Set properties of the plottables passed as parameter + /// @param plottables the plottables for which to set properties + virtual void setProperties(PlottablesMap &plottables) = 0; +}; + +struct IPlottablesHelperFactory { + /// Creates IPlottablesHelper according to a data series + static std::unique_ptr + create(std::shared_ptr dataSeries) noexcept; +}; + +#endif // SCIQLOP_PLOTTABLESRENDERINGUTILS_H diff --git a/gui/meson.build b/gui/meson.build index 31c7e80..87208a6 100644 --- a/gui/meson.build +++ b/gui/meson.build @@ -78,6 +78,7 @@ gui_sources = [ 'src/Visualization/VisualizationDragDropContainer.cpp', 'src/Visualization/VisualizationDragWidget.cpp' 'src/Visualization/AxisRenderingUtils.cpp', + 'src/Visualization/PlottablesRenderingUtils.cpp' ] gui_inc = include_directories(['include']) diff --git a/gui/src/Visualization/PlottablesRenderingUtils.cpp b/gui/src/Visualization/PlottablesRenderingUtils.cpp new file mode 100644 index 0000000..c9b90d6 --- /dev/null +++ b/gui/src/Visualization/PlottablesRenderingUtils.cpp @@ -0,0 +1,65 @@ +#include "Visualization/PlottablesRenderingUtils.h" + +#include +#include + +#include + +namespace { + +/** + * Delegate used to set plottables properties + */ +template +struct PlottablesSetter { + static void setProperties(T &, PlottablesMap &) + { + // Default implementation does nothing + } +}; + +/** + * Specialization of PlottablesSetter for scalars and vectors + * @sa ScalarSeries + * @sa VectorSeries + */ +template +struct PlottablesSetter::value + or std::is_base_of::value> > { + static void setProperties(T &dataSeries, PlottablesMap &plottables) + { + /// @todo ALX + } +}; + +/** + * Default implementation of IPlottablesHelper, which takes data series to set plottables properties + * @tparam T the data series' type + */ +template +struct PlottablesHelper : public IPlottablesHelper { + explicit PlottablesHelper(T &dataSeries) : m_DataSeries{dataSeries} {} + + void setProperties(PlottablesMap &plottables) override + { + PlottablesSetter::setProperties(m_DataSeries, plottables); + } + + T &m_DataSeries; +}; + +} // namespace + +std::unique_ptr +IPlottablesHelperFactory::create(std::shared_ptr dataSeries) noexcept +{ + if (auto scalarSeries = std::dynamic_pointer_cast(dataSeries)) { + return std::make_unique >(*scalarSeries); + } + else if (auto vectorSeries = std::dynamic_pointer_cast(dataSeries)) { + return std::make_unique >(*vectorSeries); + } + else { + return std::make_unique >(*dataSeries); + } +}