##// END OF EJS Templates
Updates AxisRenderingUtils to use variable's type instead of dataseries
Alexandre Leroux -
r1335:89a3f92d2fbb
parent child
Show More
@@ -12,6 +12,7 class IDataSeries;
12 12 class QCPAxis;
13 13 class QCustomPlot;
14 14 class SqpColorScale;
15 class Variable;
15 16
16 17 /// Formats a data value according to the axis on which it is present
17 18 QString formatValue(double value, const QCPAxis &axis);
@@ -27,11 +28,17 struct IAxisHelper {
27 28 /// @param plot the plot for which to set axe properties
28 29 /// @param colorScale the color scale for which to set properties
29 30 virtual void setProperties(QCustomPlot &plot, SqpColorScale &colorScale) = 0;
31
32 /// Set the units of the plot's axes and the color scale associated to plot passed as
33 /// parameters
34 /// @param plot the plot for which to set axe units
35 /// @param colorScale the color scale for which to set unit
36 virtual void setUnits(QCustomPlot &plot, SqpColorScale &colorScale) = 0;
30 37 };
31 38
32 39 struct IAxisHelperFactory {
33 /// Creates IAxisHelper according to a data series
34 static std::unique_ptr<IAxisHelper> create(std::shared_ptr<IDataSeries> dataSeries) noexcept;
40 /// Creates IPlottablesHelper according to the type of data series a variable holds
41 static std::unique_ptr<IAxisHelper> create(const Variable &variable) noexcept;
35 42 };
36 43
37 44 #endif // SCIQLOP_AXISRENDERINGUTILS_H
@@ -4,6 +4,8
4 4 #include <Data/SpectrogramSeries.h>
5 5 #include <Data/VectorSeries.h>
6 6
7 #include <Variable/Variable.h>
8
7 9 #include <Visualization/SqpColorScale.h>
8 10 #include <Visualization/qcustomplot.h>
9 11
@@ -68,11 +70,17 void setAxisProperties(QCPAxis &axis, const Unit &unit,
68 70 */
69 71 template <typename T, typename Enabled = void>
70 72 struct AxisSetter {
71 static void setProperties(T &, QCustomPlot &, SqpColorScale &)
73 static void setProperties(QCustomPlot &, SqpColorScale &)
72 74 {
73 75 // Default implementation does nothing
74 76 qCCritical(LOG_AxisRenderingUtils()) << "Can't set axis properties: unmanaged type of data";
75 77 }
78
79 static void setUnits(T &, QCustomPlot &, SqpColorScale &)
80 {
81 // Default implementation does nothing
82 qCCritical(LOG_AxisRenderingUtils()) << "Can't set axis units: unmanaged type of data";
83 }
76 84 };
77 85
78 86 /**
@@ -83,7 +91,12 struct AxisSetter {
83 91 template <typename T>
84 92 struct AxisSetter<T, typename std::enable_if_t<std::is_base_of<ScalarSeries, T>::value
85 93 or std::is_base_of<VectorSeries, T>::value> > {
86 static void setProperties(T &dataSeries, QCustomPlot &plot, SqpColorScale &)
94 static void setProperties(QCustomPlot &, SqpColorScale &)
95 {
96 // Nothing to do
97 }
98
99 static void setUnits(T &dataSeries, QCustomPlot &plot, SqpColorScale &)
87 100 {
88 101 dataSeries.lockRead();
89 102 auto xAxisUnit = dataSeries.xAxisUnit();
@@ -101,17 +114,8 struct AxisSetter<T, typename std::enable_if_t<std::is_base_of<ScalarSeries, T>:
101 114 */
102 115 template <typename T>
103 116 struct AxisSetter<T, typename std::enable_if_t<std::is_base_of<SpectrogramSeries, T>::value> > {
104 static void setProperties(T &dataSeries, QCustomPlot &plot, SqpColorScale &colorScale)
117 static void setProperties(QCustomPlot &plot, SqpColorScale &colorScale)
105 118 {
106 dataSeries.lockRead();
107 auto xAxisUnit = dataSeries.xAxisUnit();
108 auto yAxisUnit = dataSeries.yAxisUnit();
109 auto valuesUnit = dataSeries.valuesUnit();
110 dataSeries.unlock();
111
112 setAxisProperties(*plot.xAxis, xAxisUnit);
113 setAxisProperties(*plot.yAxis, yAxisUnit, QCPAxis::stLogarithmic);
114
115 119 // Displays color scale in plot
116 120 plot.plotLayout()->insertRow(0);
117 121 plot.plotLayout()->addElement(0, 0, colorScale.m_Scale);
@@ -125,9 +129,21 struct AxisSetter<T, typename std::enable_if_t<std::is_base_of<SpectrogramSeries
125 129 }
126 130
127 131 // Set color scale properties
128 setAxisProperties(*colorScale.m_Scale->axis(), valuesUnit, QCPAxis::stLogarithmic);
129 132 colorScale.m_AutomaticThreshold = true;
130 133 }
134
135 static void setUnits(T &dataSeries, QCustomPlot &plot, SqpColorScale &colorScale)
136 {
137 dataSeries.lockRead();
138 auto xAxisUnit = dataSeries.xAxisUnit();
139 auto yAxisUnit = dataSeries.yAxisUnit();
140 auto valuesUnit = dataSeries.valuesUnit();
141 dataSeries.unlock();
142
143 setAxisProperties(*plot.xAxis, xAxisUnit);
144 setAxisProperties(*plot.yAxis, yAxisUnit, QCPAxis::stLogarithmic);
145 setAxisProperties(*colorScale.m_Scale->axis(), valuesUnit, QCPAxis::stLogarithmic);
146 }
131 147 };
132 148
133 149 /**
@@ -136,14 +152,25 struct AxisSetter<T, typename std::enable_if_t<std::is_base_of<SpectrogramSeries
136 152 */
137 153 template <typename T>
138 154 struct AxisHelper : public IAxisHelper {
139 explicit AxisHelper(T &dataSeries) : m_DataSeries{dataSeries} {}
155 explicit AxisHelper(std::shared_ptr<T> dataSeries) : m_DataSeries{dataSeries} {}
140 156
141 157 void setProperties(QCustomPlot &plot, SqpColorScale &colorScale) override
142 158 {
143 AxisSetter<T>::setProperties(m_DataSeries, plot, colorScale);
159 AxisSetter<T>::setProperties(plot, colorScale);
160 }
161
162 void setUnits(QCustomPlot &plot, SqpColorScale &colorScale) override
163 {
164 if (m_DataSeries) {
165 AxisSetter<T>::setUnits(*m_DataSeries, plot, colorScale);
166 }
167 else {
168 qCCritical(LOG_AxisRenderingUtils()) << "Can't set units: inconsistency between the "
169 "type of data series and the type supposed";
170 }
144 171 }
145 172
146 T &m_DataSeries;
173 std::shared_ptr<T> m_DataSeries;
147 174 };
148 175
149 176 } // namespace
@@ -159,19 +186,22 QString formatValue(double value, const QCPAxis &axis)
159 186 }
160 187 }
161 188
162 std::unique_ptr<IAxisHelper>
163 IAxisHelperFactory::create(std::shared_ptr<IDataSeries> dataSeries) noexcept
189 std::unique_ptr<IAxisHelper> IAxisHelperFactory::create(const Variable &variable) noexcept
164 190 {
165 if (auto scalarSeries = std::dynamic_pointer_cast<ScalarSeries>(dataSeries)) {
166 return std::make_unique<AxisHelper<ScalarSeries> >(*scalarSeries);
167 }
168 else if (auto spectrogramSeries = std::dynamic_pointer_cast<SpectrogramSeries>(dataSeries)) {
169 return std::make_unique<AxisHelper<SpectrogramSeries> >(*spectrogramSeries);
170 }
171 else if (auto vectorSeries = std::dynamic_pointer_cast<VectorSeries>(dataSeries)) {
172 return std::make_unique<AxisHelper<VectorSeries> >(*vectorSeries);
173 }
174 else {
175 return std::make_unique<AxisHelper<IDataSeries> >(*dataSeries);
176 }
191 switch (variable.type()) {
192 case DataSeriesType::SCALAR:
193 return std::make_unique<AxisHelper<ScalarSeries> >(
194 std::dynamic_pointer_cast<ScalarSeries>(variable.dataSeries()));
195 case DataSeriesType::SPECTROGRAM:
196 return std::make_unique<AxisHelper<SpectrogramSeries> >(
197 std::dynamic_pointer_cast<SpectrogramSeries>(variable.dataSeries()));
198 case DataSeriesType::VECTOR:
199 return std::make_unique<AxisHelper<VectorSeries> >(
200 std::dynamic_pointer_cast<VectorSeries>(variable.dataSeries()));
201 default:
202 // Creates default helper
203 break;
204 }
205
206 return std::make_unique<AxisHelper<IDataSeries> >(nullptr);
177 207 }
General Comments 0
You need to be logged in to leave comments. Login now