Who manage the delete of the color scale ?
@@ -1,6 +1,7 | |||
|
1 | 1 | #include "Visualization/AxisRenderingUtils.h" |
|
2 | 2 | |
|
3 | 3 | #include <Data/ScalarSeries.h> |
|
4 | #include <Data/SpectrogramSeries.h> | |
|
4 | 5 | #include <Data/VectorSeries.h> |
|
5 | 6 | |
|
6 | 7 | #include <Visualization/qcustomplot.h> |
@@ -80,6 +81,42 struct AxisSetter<T, typename std::enable_if_t<std::is_base_of<ScalarSeries, T>: | |||
|
80 | 81 | }; |
|
81 | 82 | |
|
82 | 83 | /** |
|
84 | * Specialization of AxisSetter for spectrograms | |
|
85 | * @sa SpectrogramSeries | |
|
86 | */ | |
|
87 | template <typename T> | |
|
88 | struct AxisSetter<T, typename std::enable_if_t<std::is_base_of<SpectrogramSeries, T>::value> > { | |
|
89 | static void setProperties(T &dataSeries, QCustomPlot &plot, QCPColorScale &colorScale) | |
|
90 | { | |
|
91 | dataSeries.lockRead(); | |
|
92 | auto xAxisUnit = dataSeries.xAxisUnit(); | |
|
93 | /// @todo ALX: use iterators here | |
|
94 | auto yAxisUnit = dataSeries.yAxis().unit(); | |
|
95 | auto valuesUnit = dataSeries.valuesUnit(); | |
|
96 | dataSeries.unlock(); | |
|
97 | ||
|
98 | setAxisProperties(*plot.xAxis, xAxisUnit); | |
|
99 | setAxisProperties(*plot.yAxis, yAxisUnit); | |
|
100 | ||
|
101 | // Displays color scale in plot | |
|
102 | plot.plotLayout()->insertRow(0); | |
|
103 | plot.plotLayout()->addElement(0, 0, &colorScale); | |
|
104 | colorScale.setType(QCPAxis::atTop); | |
|
105 | colorScale.setMinimumMargins(QMargins{0, 0, 0, 0}); | |
|
106 | ||
|
107 | // Aligns color scale with axes | |
|
108 | auto marginGroups = plot.axisRect()->marginGroups(); | |
|
109 | for (auto it = marginGroups.begin(), end = marginGroups.end(); it != end; ++it) { | |
|
110 | colorScale.setMarginGroup(it.key(), it.value()); | |
|
111 | } | |
|
112 | ||
|
113 | // Set color scale properties | |
|
114 | colorScale.setLabel(valuesUnit.m_Name); | |
|
115 | colorScale.setDataScaleType(QCPAxis::stLogarithmic); // Logarithmic scale | |
|
116 | } | |
|
117 | }; | |
|
118 | ||
|
119 | /** | |
|
83 | 120 | * Default implementation of IAxisHelper, which takes data series to set axes properties |
|
84 | 121 | * @tparam T the data series' type |
|
85 | 122 | */ |
@@ -114,6 +151,9 IAxisHelperFactory::create(std::shared_ptr<IDataSeries> dataSeries) noexcept | |||
|
114 | 151 | if (auto scalarSeries = std::dynamic_pointer_cast<ScalarSeries>(dataSeries)) { |
|
115 | 152 | return std::make_unique<AxisHelper<ScalarSeries> >(*scalarSeries); |
|
116 | 153 | } |
|
154 | else if (auto spectrogramSeries = std::dynamic_pointer_cast<SpectrogramSeries>(dataSeries)) { | |
|
155 | return std::make_unique<AxisHelper<SpectrogramSeries> >(*spectrogramSeries); | |
|
156 | } | |
|
117 | 157 | else if (auto vectorSeries = std::dynamic_pointer_cast<VectorSeries>(dataSeries)) { |
|
118 | 158 | return std::make_unique<AxisHelper<VectorSeries> >(*vectorSeries); |
|
119 | 159 | } |
@@ -101,7 +101,8 struct VisualizationGraphRenderingDelegate::VisualizationGraphRenderingDelegateP | |||
|
101 | 101 | m_TitleText{new QCPItemText{&m_Plot}}, |
|
102 | 102 | m_XAxisPixmap{new QCPItemPixmap{&m_Plot}}, |
|
103 | 103 | m_ShowXAxis{true}, |
|
104 | m_XAxisLabel{} | |
|
104 | m_XAxisLabel{}, | |
|
105 |
m_ColorScale{new QCPColorScale{&m_Plot}}
|
|
|
105 | 106 | { |
|
106 | 107 | initPointTracerStyle(*m_PointTracer); |
|
107 | 108 | |
@@ -162,6 +163,7 struct VisualizationGraphRenderingDelegate::VisualizationGraphRenderingDelegateP | |||
|
162 | 163 | QCPItemPixmap *m_XAxisPixmap; |
|
163 | 164 | bool m_ShowXAxis; /// X-axis properties are shown or hidden |
|
164 | 165 | QString m_XAxisLabel; |
|
166 | QCPColorScale *m_ColorScale; /// Color scale used for some types of graphs (as spectrograms) | |
|
165 | 167 | }; |
|
166 | 168 | |
|
167 | 169 | VisualizationGraphRenderingDelegate::VisualizationGraphRenderingDelegate( |
General Comments 0
You need to be logged in to leave comments.
Login now