@@ -0,0 +1,31 | |||
|
1 | #ifndef SCIQLOP_AXISRENDERINGUTILS_H | |
|
2 | #define SCIQLOP_AXISRENDERINGUTILS_H | |
|
3 | ||
|
4 | #include <memory> | |
|
5 | ||
|
6 | #include <QtCore/QString> | |
|
7 | ||
|
8 | class IDataSeries; | |
|
9 | class QCPAxis; | |
|
10 | class QCPColorScale; | |
|
11 | class QCustomPlot; | |
|
12 | ||
|
13 | /** | |
|
14 | * Helper used to handle axes rendering | |
|
15 | */ | |
|
16 | struct IAxisHelper { | |
|
17 | virtual ~IAxisHelper() noexcept = default; | |
|
18 | ||
|
19 | /// Set properties of the plot's axes and the color scale associated to plot passed as | |
|
20 | /// parameters | |
|
21 | /// @param plot the plot for which to set axe properties | |
|
22 | /// @param colorScale the color scale for which to set properties | |
|
23 | virtual void setProperties(QCustomPlot &plot, QCPColorScale &colorScale) = 0; | |
|
24 | }; | |
|
25 | ||
|
26 | struct IAxisHelperFactory { | |
|
27 | /// Creates IAxisHelper according to a data series | |
|
28 | static std::unique_ptr<IAxisHelper> create(std::shared_ptr<IDataSeries> dataSeries) noexcept; | |
|
29 | }; | |
|
30 | ||
|
31 | #endif // SCIQLOP_AXISRENDERINGUTILS_H |
@@ -0,0 +1,65 | |||
|
1 | #include "Visualization/AxisRenderingUtils.h" | |
|
2 | ||
|
3 | #include <Data/ScalarSeries.h> | |
|
4 | #include <Data/VectorSeries.h> | |
|
5 | ||
|
6 | #include <Visualization/qcustomplot.h> | |
|
7 | ||
|
8 | namespace { | |
|
9 | ||
|
10 | /** | |
|
11 | * Delegate used to set axes properties | |
|
12 | */ | |
|
13 | template <typename T, typename Enabled = void> | |
|
14 | struct AxisSetter { | |
|
15 | static void setProperties(T &, QCustomPlot &, QCPColorScale &) | |
|
16 | { | |
|
17 | // Default implementation does nothing | |
|
18 | } | |
|
19 | }; | |
|
20 | ||
|
21 | /** | |
|
22 | * Specialization of AxisSetter for scalars and vectors | |
|
23 | * @sa ScalarSeries | |
|
24 | * @sa VectorSeries | |
|
25 | */ | |
|
26 | template <typename T> | |
|
27 | struct AxisSetter<T, typename std::enable_if_t<std::is_base_of<ScalarSeries, T>::value | |
|
28 | or std::is_base_of<VectorSeries, T>::value> > { | |
|
29 | static void setProperties(T &dataSeries, QCustomPlot &plot, QCPColorScale &) | |
|
30 | { | |
|
31 | /// @todo ALX | |
|
32 | } | |
|
33 | }; | |
|
34 | ||
|
35 | /** | |
|
36 | * Default implementation of IAxisHelper, which takes data series to set axes properties | |
|
37 | * @tparam T the data series' type | |
|
38 | */ | |
|
39 | template <typename T> | |
|
40 | struct AxisHelper : public IAxisHelper { | |
|
41 | explicit AxisHelper(T &dataSeries) : m_DataSeries{dataSeries} {} | |
|
42 | ||
|
43 | void setProperties(QCustomPlot &plot, QCPColorScale &colorScale) override | |
|
44 | { | |
|
45 | AxisSetter<T>::setProperties(m_DataSeries, plot, colorScale); | |
|
46 | } | |
|
47 | ||
|
48 | T &m_DataSeries; | |
|
49 | }; | |
|
50 | ||
|
51 | } // namespace | |
|
52 | ||
|
53 | std::unique_ptr<IAxisHelper> | |
|
54 | IAxisHelperFactory::create(std::shared_ptr<IDataSeries> dataSeries) noexcept | |
|
55 | { | |
|
56 | if (auto scalarSeries = std::dynamic_pointer_cast<ScalarSeries>(dataSeries)) { | |
|
57 | return std::make_unique<AxisHelper<ScalarSeries> >(*scalarSeries); | |
|
58 | } | |
|
59 | else if (auto vectorSeries = std::dynamic_pointer_cast<VectorSeries>(dataSeries)) { | |
|
60 | return std::make_unique<AxisHelper<VectorSeries> >(*vectorSeries); | |
|
61 | } | |
|
62 | else { | |
|
63 | return std::make_unique<AxisHelper<IDataSeries> >(*dataSeries); | |
|
64 | } | |
|
65 | } |
@@ -77,6 +77,7 gui_sources = [ | |||
|
77 | 77 | 'src/Visualization/operations/RescaleAxeOperation.cpp', |
|
78 | 78 | 'src/Visualization/VisualizationDragDropContainer.cpp', |
|
79 | 79 | 'src/Visualization/VisualizationDragWidget.cpp' |
|
80 | 'src/Visualization/AxisRenderingUtils.cpp', | |
|
80 | 81 | ] |
|
81 | 82 | |
|
82 | 83 | gui_inc = include_directories(['include']) |
General Comments 0
You need to be logged in to leave comments.
Login now