From b92a8e838f6ec805d134de02482ef466ae87e63d 2017-11-10 08:42:51 From: Alexandre Leroux Date: 2017-11-10 08:42:51 Subject: [PATCH] Refactoring handling of axes properties (1) Creates helper used to determine which properties to set for the graph axes, depending on the type of the data hold (properties will be different if it's scalars/vectors or spectrograms) --- diff --git a/gui/include/Visualization/AxisRenderingUtils.h b/gui/include/Visualization/AxisRenderingUtils.h new file mode 100644 index 0000000..f64e43c --- /dev/null +++ b/gui/include/Visualization/AxisRenderingUtils.h @@ -0,0 +1,31 @@ +#ifndef SCIQLOP_AXISRENDERINGUTILS_H +#define SCIQLOP_AXISRENDERINGUTILS_H + +#include + +#include + +class IDataSeries; +class QCPAxis; +class QCPColorScale; +class QCustomPlot; + +/** + * Helper used to handle axes rendering + */ +struct IAxisHelper { + virtual ~IAxisHelper() noexcept = default; + + /// Set properties of the plot's axes and the color scale associated to plot passed as + /// parameters + /// @param plot the plot for which to set axe properties + /// @param colorScale the color scale for which to set properties + virtual void setProperties(QCustomPlot &plot, QCPColorScale &colorScale) = 0; +}; + +struct IAxisHelperFactory { + /// Creates IAxisHelper according to a data series + static std::unique_ptr create(std::shared_ptr dataSeries) noexcept; +}; + +#endif // SCIQLOP_AXISRENDERINGUTILS_H diff --git a/gui/meson.build b/gui/meson.build index 6520ba3..31c7e80 100644 --- a/gui/meson.build +++ b/gui/meson.build @@ -77,6 +77,7 @@ gui_sources = [ 'src/Visualization/operations/RescaleAxeOperation.cpp', 'src/Visualization/VisualizationDragDropContainer.cpp', 'src/Visualization/VisualizationDragWidget.cpp' + 'src/Visualization/AxisRenderingUtils.cpp', ] gui_inc = include_directories(['include']) diff --git a/gui/src/Visualization/AxisRenderingUtils.cpp b/gui/src/Visualization/AxisRenderingUtils.cpp new file mode 100644 index 0000000..bbdb842 --- /dev/null +++ b/gui/src/Visualization/AxisRenderingUtils.cpp @@ -0,0 +1,65 @@ +#include "Visualization/AxisRenderingUtils.h" + +#include +#include + +#include + +namespace { + +/** + * Delegate used to set axes properties + */ +template +struct AxisSetter { + static void setProperties(T &, QCustomPlot &, QCPColorScale &) + { + // Default implementation does nothing + } +}; + +/** + * Specialization of AxisSetter for scalars and vectors + * @sa ScalarSeries + * @sa VectorSeries + */ +template +struct AxisSetter::value + or std::is_base_of::value> > { + static void setProperties(T &dataSeries, QCustomPlot &plot, QCPColorScale &) + { + /// @todo ALX + } +}; + +/** + * Default implementation of IAxisHelper, which takes data series to set axes properties + * @tparam T the data series' type + */ +template +struct AxisHelper : public IAxisHelper { + explicit AxisHelper(T &dataSeries) : m_DataSeries{dataSeries} {} + + void setProperties(QCustomPlot &plot, QCPColorScale &colorScale) override + { + AxisSetter::setProperties(m_DataSeries, plot, colorScale); + } + + T &m_DataSeries; +}; + +} // namespace + +std::unique_ptr +IAxisHelperFactory::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); + } +}