##// END OF EJS Templates
Merge pull request 229 from SCIQLOP-Initialisation develop...
perrinel -
r588:aa5771ec396c merge
parent child
Show More
@@ -0,0 +1,19
1 #ifndef SCIQLOP_COLORUTILS_H
2 #define SCIQLOP_COLORUTILS_H
3
4 #include <vector>
5
6 class QColor;
7
8 /**
9 * Utility class with methods for colors
10 */
11 struct ColorUtils {
12 /// Generates a color scale from min / max values and a number of colors.
13 /// The algorithm uses the HSV color model to generate color variations (see
14 /// http://doc.qt.io/qt-4.8/qcolor.html#the-hsv-color-model)
15 static std::vector<QColor> colors(const QColor &minColor, const QColor &maxColor,
16 int nbColors) noexcept;
17 };
18
19 #endif // SCIQLOP_COLORUTILS_H
@@ -0,0 +1,10
1 #ifndef SCIQLOP_VISUALIZATIONDEFS_H
2 #define SCIQLOP_VISUALIZATIONDEFS_H
3
4 #include <map>
5
6 class QCPAbstractPlottable;
7
8 using PlottablesMap = std::map<int, QCPAbstractPlottable *>;
9
10 #endif // SCIQLOP_VISUALIZATIONDEFS_H
@@ -0,0 +1,29
1 #include "Common/ColorUtils.h"
2
3 #include <QtGui/QColor>
4
5 std::vector<QColor> ColorUtils::colors(const QColor &minColor, const QColor &maxColor,
6 int nbColors) noexcept
7 {
8 auto result = std::vector<QColor>{};
9
10 if (nbColors == 1) {
11 result.push_back(minColor);
12 }
13 else if (nbColors > 0) {
14 const auto nbSteps = static_cast<double>(nbColors - 1);
15
16 const auto colorHStep = (maxColor.hue() - minColor.hue()) / nbSteps;
17 const auto colorSStep = (maxColor.saturation() - minColor.saturation()) / nbSteps;
18 const auto colorVStep = (maxColor.value() - minColor.value()) / nbSteps;
19 const auto colorAStep = (maxColor.alpha() - minColor.alpha()) / nbSteps;
20
21 for (auto i = 0; i < nbColors; ++i) {
22 result.push_back(QColor::fromHsv(
23 minColor.hue() + i * colorHStep, minColor.saturation() + i * colorSStep,
24 minColor.value() + i * colorVStep, minColor.alpha() + i * colorAStep));
25 }
26 }
27
28 return result;
29 }
@@ -218,6 +218,8 public:
218 }
218 }
219 }
219 }
220
220
221 int componentCount() const noexcept { return m_Data.size(); }
222
221 /**
223 /**
222 * @return the data of a component
224 * @return the data of a component
223 * @param componentIndex the index of the component to retrieve the data
225 * @param componentIndex the index of the component to retrieve the data
@@ -208,11 +208,11 public:
208
208
209 auto lowerIt
209 auto lowerIt
210 = std::lower_bound(begin, end, min, [](const auto &itValue, const auto &value) {
210 = std::lower_bound(begin, end, min, [](const auto &itValue, const auto &value) {
211 return itValue.x() == value;
211 return itValue.x() < value;
212 });
212 });
213 auto upperIt
213 auto upperIt
214 = std::upper_bound(begin, end, max, [](const auto &value, const auto &itValue) {
214 = std::upper_bound(begin, end, max, [](const auto &value, const auto &itValue) {
215 return itValue.x() == value;
215 return value < itValue.x();
216 });
216 });
217
217
218 return std::make_pair(lowerIt, upperIt);
218 return std::make_pair(lowerIt, upperIt);
@@ -22,6 +22,13 private slots:
22
22
23 /// Tests merge of two data series
23 /// Tests merge of two data series
24 void testMerge();
24 void testMerge();
25
26 /// Input test data
27 /// @sa testSubdata()
28 void testSubdata_data();
29
30 /// Tests get subdata of two data series
31 void testSubdata();
25 };
32 };
26
33
27 void TestDataSeries::testCtor_data()
34 void TestDataSeries::testCtor_data()
@@ -160,5 +167,66 void TestDataSeries::testMerge()
160 seriesValuesData.cbegin()));
167 seriesValuesData.cbegin()));
161 }
168 }
162
169
170 void TestDataSeries::testSubdata_data()
171 {
172 // ////////////// //
173 // Test structure //
174 // ////////////// //
175
176 // Data series to get subdata
177 QTest::addColumn<std::shared_ptr<ScalarSeries> >("dataSeries");
178
179 // Min/max values
180 QTest::addColumn<double>("min");
181 QTest::addColumn<double>("max");
182
183 // Expected values after subdata
184 QTest::addColumn<QVector<double> >("expectedXAxisData");
185 QTest::addColumn<QVector<double> >("expectedValuesData");
186
187 // ////////// //
188 // Test cases //
189 // ////////// //
190
191 QTest::newRow("subData1") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
192 << -1. << 3.2 << QVector<double>{1., 2., 3.}
193 << QVector<double>{100., 200., 300.};
194 QTest::newRow("subData2") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
195 << 1. << 4. << QVector<double>{1., 2., 3., 4.}
196 << QVector<double>{100., 200., 300., 400.};
197 QTest::newRow("subData3") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
198 << 1. << 3.9 << QVector<double>{1., 2., 3.}
199 << QVector<double>{100., 200., 300.};
200 QTest::newRow("subData4") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
201 << 0. << 0.9 << QVector<double>{} << QVector<double>{};
202 QTest::newRow("subData5") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
203 << 0. << 1. << QVector<double>{1.} << QVector<double>{100.};
204 QTest::newRow("subData6") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
205 << 2.1 << 6. << QVector<double>{3., 4., 5.}
206 << QVector<double>{300., 400., 500.};
207 QTest::newRow("subData7") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
208 << 6. << 9. << QVector<double>{} << QVector<double>{};
209 QTest::newRow("subData8") << createSeries({1., 2., 3., 4., 5.}, {100., 200., 300., 400., 500.})
210 << 5. << 9. << QVector<double>{5.} << QVector<double>{500.};
211 }
212
213 void TestDataSeries::testSubdata()
214 {
215 QFETCH(std::shared_ptr<ScalarSeries>, dataSeries);
216 QFETCH(double, min);
217 QFETCH(double, max);
218
219 QFETCH(QVector<double>, expectedXAxisData);
220 QFETCH(QVector<double>, expectedValuesData);
221
222 auto bounds = dataSeries->subData(min, max);
223 QVERIFY(std::equal(bounds.first, bounds.second, expectedXAxisData.cbegin(),
224 expectedXAxisData.cend(),
225 [](const auto &it, const auto &expectedX) { return it.x() == expectedX; }));
226 QVERIFY(std::equal(
227 bounds.first, bounds.second, expectedValuesData.cbegin(), expectedValuesData.cend(),
228 [](const auto &it, const auto &expectedVal) { return it.value() == expectedVal; }));
229 }
230
163 QTEST_MAIN(TestDataSeries)
231 QTEST_MAIN(TestDataSeries)
164 #include "TestDataSeries.moc"
232 #include "TestDataSeries.moc"
@@ -1,6 +1,8
1 #ifndef SCIQLOP_VISUALIZATIONGRAPHHELPER_H
1 #ifndef SCIQLOP_VISUALIZATIONGRAPHHELPER_H
2 #define SCIQLOP_VISUALIZATIONGRAPHHELPER_H
2 #define SCIQLOP_VISUALIZATIONGRAPHHELPER_H
3
3
4 #include "Visualization/VisualizationDefs.h"
5
4 #include <Data/SqpRange.h>
6 #include <Data/SqpRange.h>
5
7
6 #include <QLoggingCategory>
8 #include <QLoggingCategory>
@@ -28,13 +30,10 struct VisualizationGraphHelper {
28 * components.
30 * components.
29 * @return the list of the components created
31 * @return the list of the components created
30 */
32 */
31 static QVector<QCPAbstractPlottable *> create(std::shared_ptr<Variable> variable,
33 static PlottablesMap create(std::shared_ptr<Variable> variable, QCustomPlot &plot) noexcept;
32 QCustomPlot &plot) noexcept;
33 static QVector<QCPAbstractPlottable *> createV2(std::shared_ptr<Variable> variable,
34 QCustomPlot &plot) noexcept;
35
34
36 static void updateData(QVector<QCPAbstractPlottable *> plotableVect,
35 static void updateData(PlottablesMap &plottables, std::shared_ptr<IDataSeries> dataSeries,
37 std::shared_ptr<IDataSeries> dataSeries, const SqpRange &dateTime);
36 const SqpRange &dateTime);
38 };
37 };
39
38
40 #endif // SCIQLOP_VISUALIZATIONGRAPHHELPER_H
39 #endif // SCIQLOP_VISUALIZATIONGRAPHHELPER_H
@@ -1,7 +1,10
1 #include "Visualization/VisualizationGraphHelper.h"
1 #include "Visualization/VisualizationGraphHelper.h"
2 #include "Visualization/qcustomplot.h"
2 #include "Visualization/qcustomplot.h"
3
3
4 #include <Common/ColorUtils.h>
5
4 #include <Data/ScalarSeries.h>
6 #include <Data/ScalarSeries.h>
7 #include <Data/VectorSeries.h>
5
8
6 #include <Variable/Variable.h>
9 #include <Variable/Variable.h>
7
10
@@ -35,45 +38,12 QSharedPointer<QCPAxisTicker> axisTicker(bool isTimeAxis)
35 }
38 }
36 }
39 }
37
40
38 void updateScalarData(QCPAbstractPlottable *component, std::shared_ptr<ScalarSeries> scalarSeries,
41 /// Sets axes properties according to the properties of a data series
39 const SqpRange &range)
42 template <int Dim>
40 {
43 void setAxesProperties(const DataSeries<Dim> &dataSeries, QCustomPlot &plot) noexcept
41 qCDebug(LOG_VisualizationGraphHelper()) << "TORM: updateScalarData"
42 << QThread::currentThread()->objectName();
43 if (auto qcpGraph = dynamic_cast<QCPGraph *>(component)) {
44 scalarSeries->lockRead();
45 {
44 {
46 auto sqpDataContainer = QSharedPointer<SqpDataContainer>::create();
47 qcpGraph->setData(sqpDataContainer);
48 auto bounds = scalarSeries->subData(range.m_TStart, range.m_TEnd);
49 for (auto it = bounds.first; it != bounds.second; ++it) {
50 sqpDataContainer->appendGraphData(QCPGraphData(it->x(), it->value()));
51 }
52
53 qCInfo(LOG_VisualizationGraphHelper()) << "TODEBUG: Current points displayed"
54 << sqpDataContainer->size();
55 }
56 scalarSeries->unlock();
57
58
59 // Display all data
60 component->parentPlot()->replot();
61 }
62 else {
63 /// @todo DEBUG
64 }
65 }
66
67 QCPAbstractPlottable *createScalarSeriesComponentV2(std::shared_ptr<ScalarSeries> scalarSeries,
68 QCustomPlot &plot)
69 {
70 auto component = plot.addGraph();
71
72 if (component) {
73 // Axes properties
74 /// @todo : for the moment, no control is performed on the axes: the units and the tickers
45 /// @todo : for the moment, no control is performed on the axes: the units and the tickers
75 /// are fixed for the default x-axis and y-axis of the plot, and according to the new graph
46 /// are fixed for the default x-axis and y-axis of the plot, and according to the new graph
76
77 auto setAxisProperties = [](auto axis, const auto &unit) {
47 auto setAxisProperties = [](auto axis, const auto &unit) {
78 // label (unit name)
48 // label (unit name)
79 axis->setLabel(unit.m_Name);
49 axis->setLabel(unit.m_Name);
@@ -81,115 +51,190 QCPAbstractPlottable *createScalarSeriesComponentV2(std::shared_ptr<ScalarSeries
81 // ticker (depending on the type of unit)
51 // ticker (depending on the type of unit)
82 axis->setTicker(axisTicker(unit.m_TimeUnit));
52 axis->setTicker(axisTicker(unit.m_TimeUnit));
83 };
53 };
84 setAxisProperties(plot.xAxis, scalarSeries->xAxisUnit());
54 setAxisProperties(plot.xAxis, dataSeries.xAxisUnit());
85 setAxisProperties(plot.yAxis, scalarSeries->valuesUnit());
55 setAxisProperties(plot.yAxis, dataSeries.valuesUnit());
86 }
56 }
87 return component;
57
58 /**
59 * Struct used to create plottables, depending on the type of the data series from which to create them
60 * @tparam T the data series' type
61 * @remarks Default implementation can't create plottables
62 */
63 template <typename T, typename Enabled = void>
64 struct PlottablesCreator {
65 static PlottablesMap createPlottables(T &, QCustomPlot &)
66 {
67 qCCritical(LOG_DataSeries())
68 << QObject::tr("Can't create plottables: unmanaged data series type");
69 return {};
88 }
70 }
71 };
89
72
90 QCPAbstractPlottable *createScalarSeriesComponent(std::shared_ptr<ScalarSeries> scalarSeries,
73 /**
91 QCustomPlot &plot, const SqpRange &dateTime)
74 * Specialization of PlottablesCreator for scalars and vectors
75 * @sa ScalarSeries
76 * @sa VectorSeries
77 */
78 template <typename T>
79 struct PlottablesCreator<T,
80 typename std::enable_if_t<std::is_base_of<ScalarSeries, T>::value
81 or std::is_base_of<VectorSeries, T>::value> > {
82 static PlottablesMap createPlottables(T &dataSeries, QCustomPlot &plot)
92 {
83 {
93 auto component = plot.addGraph();
84 PlottablesMap result{};
85
86 // Gets the number of components of the data series
87 auto componentCount = dataSeries.valuesData()->componentCount();
88
89 auto colors = ColorUtils::colors(Qt::blue, Qt::red, componentCount);
94
90
95 if (component) {
91 // For each component of the data series, creates a QCPGraph to add to the plot
96 // // Graph data
92 for (auto i = 0; i < componentCount; ++i) {
97 component->setData(scalarSeries->xAxisData()->data(), scalarSeries->valuesData()->data(),
93 auto graph = plot.addGraph();
98 true);
94 graph->setPen(QPen{colors.at(i)});
99
95
100 updateScalarData(component, scalarSeries, dateTime);
96 result.insert({i, graph});
97 }
101
98
102 // Axes properties
99 // Axes properties
103 /// @todo : for the moment, no control is performed on the axes: the units and the tickers
100 setAxesProperties(dataSeries, plot);
104 /// are fixed for the default x-axis and y-axis of the plot, and according to the new graph
105
101
106 auto setAxisProperties = [](auto axis, const auto &unit) {
102 plot.replot();
107 // label (unit name)
108 axis->setLabel(unit.m_Name);
109
103
110 // ticker (depending on the type of unit)
104 return result;
111 axis->setTicker(axisTicker(unit.m_TimeUnit));
105 }
112 };
106 };
113 setAxisProperties(plot.xAxis, scalarSeries->xAxisUnit());
114 setAxisProperties(plot.yAxis, scalarSeries->valuesUnit());
115
107
116 // Display all data
108 /**
117 component->rescaleAxes();
109 * Struct used to update plottables, depending on the type of the data series from which to update them
118 plot.replot();
110 * @tparam T the data series' type
111 * @remarks Default implementation can't update plottables
112 */
113 template <typename T, typename Enabled = void>
114 struct PlottablesUpdater {
115 static void updatePlottables(T &, PlottablesMap &, const SqpRange &, bool)
116 {
117 qCCritical(LOG_DataSeries())
118 << QObject::tr("Can't update plottables: unmanaged data series type");
119 }
120 };
121
122 /**
123 * Specialization of PlottablesUpdater for scalars and vectors
124 * @sa ScalarSeries
125 * @sa VectorSeries
126 */
127 template <typename T>
128 struct PlottablesUpdater<T,
129 typename std::enable_if_t<std::is_base_of<ScalarSeries, T>::value
130 or std::is_base_of<VectorSeries, T>::value> > {
131 static void updatePlottables(T &dataSeries, PlottablesMap &plottables, const SqpRange &range,
132 bool rescaleAxes)
133 {
134 dataSeries.lockRead();
135
136 // For each plottable to update, resets its data
137 std::map<int, QSharedPointer<SqpDataContainer> > dataContainers{};
138 for (const auto &plottable : plottables) {
139 if (auto graph = dynamic_cast<QCPGraph *>(plottable.second)) {
140 auto dataContainer = QSharedPointer<SqpDataContainer>::create();
141 graph->setData(dataContainer);
142
143 dataContainers.insert({plottable.first, dataContainer});
119 }
144 }
120 else {
121 qCDebug(LOG_VisualizationGraphHelper())
122 << QObject::tr("Can't create graph for the scalar series");
123 }
145 }
124
146
125 return component;
147 // - Gets the data of the series included in the current range
148 // - Updates each plottable by adding, for each data item, a point that takes x-axis data and value data. The correct value is retrieved according to the index of the component
149 auto subDataIts = dataSeries.subData(range.m_TStart, range.m_TEnd);
150 for (auto it = subDataIts.first; it != subDataIts.second; ++it) {
151 for (const auto &dataContainer : dataContainers) {
152 auto componentIndex = dataContainer.first;
153 dataContainer.second->appendGraphData(
154 QCPGraphData(it->x(), it->value(componentIndex)));
155 }
126 }
156 }
127
157
128 } // namespace
158 dataSeries.unlock();
129
159
130 QVector<QCPAbstractPlottable *>
160 if (!plottables.empty()) {
131 VisualizationGraphHelper::createV2(std::shared_ptr<Variable> variable, QCustomPlot &plot) noexcept
161 auto plot = plottables.begin()->second->parentPlot();
132 {
133 auto result = QVector<QCPAbstractPlottable *>{};
134
162
135 if (variable) {
163 if (rescaleAxes) {
136 // Gets the data series of the variable to call the creation of the right components
164 plot->rescaleAxes();
137 // according to its type
138 if (auto scalarSeries = std::dynamic_pointer_cast<ScalarSeries>(variable->dataSeries())) {
139 result.append(createScalarSeriesComponentV2(scalarSeries, plot));
140 }
141 else {
142 qCDebug(LOG_VisualizationGraphHelper())
143 << QObject::tr("Can't create graph plottables : unmanaged data series type");
144 }
165 }
166
167 plot->replot();
145 }
168 }
146 else {
147 qCDebug(LOG_VisualizationGraphHelper())
148 << QObject::tr("Can't create graph plottables : the variable is null");
149 }
169 }
170 };
150
171
151 return result;
172 /**
173 * Helper used to create/update plottables
174 */
175 struct IPlottablesHelper {
176 virtual ~IPlottablesHelper() noexcept = default;
177 virtual PlottablesMap create(QCustomPlot &plot) const = 0;
178 virtual void update(PlottablesMap &plottables, const SqpRange &range,
179 bool rescaleAxes = false) const = 0;
180 };
181
182 /**
183 * Default implementation of IPlottablesHelper, which takes data series to create/update plottables
184 * @tparam T the data series' type
185 */
186 template <typename T>
187 struct PlottablesHelper : public IPlottablesHelper {
188 explicit PlottablesHelper(T &dataSeries) : m_DataSeries{dataSeries} {}
189
190 PlottablesMap create(QCustomPlot &plot) const override
191 {
192 return PlottablesCreator<T>::createPlottables(m_DataSeries, plot);
152 }
193 }
153
194
154 QVector<QCPAbstractPlottable *> VisualizationGraphHelper::create(std::shared_ptr<Variable> variable,
195 void update(PlottablesMap &plottables, const SqpRange &range, bool rescaleAxes) const override
155 QCustomPlot &plot) noexcept
156 {
196 {
157 auto result = QVector<QCPAbstractPlottable *>{};
197 PlottablesUpdater<T>::updatePlottables(m_DataSeries, plottables, range, rescaleAxes);
198 }
158
199
159 if (variable) {
200 T &m_DataSeries;
160 // Gets the data series of the variable to call the creation of the right components
201 };
161 // according to its type
202
162 if (auto scalarSeries = std::dynamic_pointer_cast<ScalarSeries>(variable->dataSeries())) {
203 /// Creates IPlottablesHelper according to a data series
163 result.append(createScalarSeriesComponent(scalarSeries, plot, variable->range()));
204 std::unique_ptr<IPlottablesHelper> createHelper(std::shared_ptr<IDataSeries> dataSeries) noexcept
205 {
206 if (auto scalarSeries = std::dynamic_pointer_cast<ScalarSeries>(dataSeries)) {
207 return std::make_unique<PlottablesHelper<ScalarSeries> >(*scalarSeries);
208 }
209 else if (auto vectorSeries = std::dynamic_pointer_cast<VectorSeries>(dataSeries)) {
210 return std::make_unique<PlottablesHelper<VectorSeries> >(*vectorSeries);
164 }
211 }
165 else {
212 else {
166 qCDebug(LOG_VisualizationGraphHelper())
213 return std::make_unique<PlottablesHelper<IDataSeries> >(*dataSeries);
167 << QObject::tr("Can't create graph plottables : unmanaged data series type");
168 }
214 }
169 }
215 }
216
217 } // namespace
218
219 PlottablesMap VisualizationGraphHelper::create(std::shared_ptr<Variable> variable,
220 QCustomPlot &plot) noexcept
221 {
222 if (variable) {
223 auto helper = createHelper(variable->dataSeries());
224 auto plottables = helper->create(plot);
225 return plottables;
226 }
170 else {
227 else {
171 qCDebug(LOG_VisualizationGraphHelper())
228 qCDebug(LOG_VisualizationGraphHelper())
172 << QObject::tr("Can't create graph plottables : the variable is null");
229 << QObject::tr("Can't create graph plottables : the variable is null");
230 return PlottablesMap{};
173 }
231 }
174
175 return result;
176 }
232 }
177
233
178 void VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *> plotableVect,
234 void VisualizationGraphHelper::updateData(PlottablesMap &plottables,
179 std::shared_ptr<IDataSeries> dataSeries,
235 std::shared_ptr<IDataSeries> dataSeries,
180 const SqpRange &dateTime)
236 const SqpRange &dateTime)
181 {
237 {
182 if (auto scalarSeries = std::dynamic_pointer_cast<ScalarSeries>(dataSeries)) {
238 auto helper = createHelper(dataSeries);
183 if (plotableVect.size() == 1) {
239 helper->update(plottables, dateTime);
184 updateScalarData(plotableVect.at(0), scalarSeries, dateTime);
185 }
186 else {
187 qCCritical(LOG_VisualizationGraphHelper()) << QObject::tr(
188 "Can't update Data of a scalarSeries because there is not only one component "
189 "associated");
190 }
191 }
192 else {
193 /// @todo DEBUG
194 }
195 }
240 }
@@ -1,5 +1,6
1 #include "Visualization/VisualizationGraphWidget.h"
1 #include "Visualization/VisualizationGraphWidget.h"
2 #include "Visualization/IVisualizationWidgetVisitor.h"
2 #include "Visualization/IVisualizationWidgetVisitor.h"
3 #include "Visualization/VisualizationDefs.h"
3 #include "Visualization/VisualizationGraphHelper.h"
4 #include "Visualization/VisualizationGraphHelper.h"
4 #include "Visualization/VisualizationGraphRenderingDelegate.h"
5 #include "Visualization/VisualizationGraphRenderingDelegate.h"
5 #include "ui_VisualizationGraphWidget.h"
6 #include "ui_VisualizationGraphWidget.h"
@@ -33,7 +34,7 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate {
33 }
34 }
34
35
35 // 1 variable -> n qcpplot
36 // 1 variable -> n qcpplot
36 std::multimap<std::shared_ptr<Variable>, QCPAbstractPlottable *> m_VariableToPlotMultiMap;
37 std::map<std::shared_ptr<Variable>, PlottablesMap> m_VariableToPlotMultiMap;
37 bool m_DoAcquisition;
38 bool m_DoAcquisition;
38 bool m_IsCalibration;
39 bool m_IsCalibration;
39 QCPItemTracer *m_TextTracer;
40 QCPItemTracer *m_TextTracer;
@@ -99,11 +100,8 void VisualizationGraphWidget::enableAcquisition(bool enable)
99 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable, SqpRange range)
100 void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable, SqpRange range)
100 {
101 {
101 // Uses delegate to create the qcpplot components according to the variable
102 // Uses delegate to create the qcpplot components according to the variable
102 auto createdPlottables = VisualizationGraphHelper::createV2(variable, *ui->widget);
103 auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget);
103
104 impl->m_VariableToPlotMultiMap.insert({variable, std::move(createdPlottables)});
104 for (auto createdPlottable : qAsConst(createdPlottables)) {
105 impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable});
106 }
107
105
108 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
106 connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated()));
109
107
@@ -124,10 +122,17 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable
124 // Each component associated to the variable :
122 // Each component associated to the variable :
125 // - is removed from qcpplot (which deletes it)
123 // - is removed from qcpplot (which deletes it)
126 // - is no longer referenced in the map
124 // - is no longer referenced in the map
127 auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable);
125 auto variableIt = impl->m_VariableToPlotMultiMap.find(variable);
128 for (auto it = componentsIt.first; it != componentsIt.second;) {
126 if (variableIt != impl->m_VariableToPlotMultiMap.cend()) {
129 ui->widget->removePlottable(it->second);
127 auto &plottablesMap = variableIt->second;
130 it = impl->m_VariableToPlotMultiMap.erase(it);
128
129 for (auto plottableIt = plottablesMap.cbegin(), plottableEnd = plottablesMap.cend();
130 plottableIt != plottableEnd;) {
131 ui->widget->removePlottable(plottableIt->second);
132 plottableIt = plottablesMap.erase(plottableIt);
133 }
134
135 impl->m_VariableToPlotMultiMap.erase(variableIt);
131 }
136 }
132
137
133 // Updates graph
138 // Updates graph
@@ -282,29 +287,18 void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept
282
287
283 void VisualizationGraphWidget::onDataCacheVariableUpdated()
288 void VisualizationGraphWidget::onDataCacheVariableUpdated()
284 {
289 {
285 // NOTE:
286 // We don't want to call the method for each component of a variable unitarily, but for
287 // all
288 // its components at once (eg its three components in the case of a vector).
289
290 // The unordered_multimap does not do this easily, so the question is whether to:
291 // - use an ordered_multimap and the algos of std to group the values by key
292 // - use a map (unique keys) and store as values directly the list of components
293
294 auto graphRange = ui->widget->xAxis->range();
290 auto graphRange = ui->widget->xAxis->range();
295 auto dateTime = SqpRange{graphRange.lower, graphRange.upper};
291 auto dateTime = SqpRange{graphRange.lower, graphRange.upper};
296
292
297 for (auto it = impl->m_VariableToPlotMultiMap.cbegin();
293 for (auto &variableEntry : impl->m_VariableToPlotMultiMap) {
298 it != impl->m_VariableToPlotMultiMap.cend(); ++it) {
294 auto variable = variableEntry.first;
299 auto variable = it->first;
300 qCDebug(LOG_VisualizationGraphWidget())
295 qCDebug(LOG_VisualizationGraphWidget())
301 << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S" << variable->range();
296 << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S" << variable->range();
302 qCDebug(LOG_VisualizationGraphWidget())
297 qCDebug(LOG_VisualizationGraphWidget())
303 << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime;
298 << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime;
304 if (dateTime.contains(variable->range()) || dateTime.intersect(variable->range())) {
299 if (dateTime.contains(variable->range()) || dateTime.intersect(variable->range())) {
305
300 VisualizationGraphHelper::updateData(variableEntry.second, variable->dataSeries(),
306 VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second,
301 variable->range());
307 variable->dataSeries(), variable->range());
308 }
302 }
309 }
303 }
310 }
304 }
@@ -312,9 +306,8 void VisualizationGraphWidget::onDataCacheVariableUpdated()
312 void VisualizationGraphWidget::onUpdateVarDisplaying(std::shared_ptr<Variable> variable,
306 void VisualizationGraphWidget::onUpdateVarDisplaying(std::shared_ptr<Variable> variable,
313 const SqpRange &range)
307 const SqpRange &range)
314 {
308 {
315 auto componentsIt = impl->m_VariableToPlotMultiMap.equal_range(variable);
309 auto it = impl->m_VariableToPlotMultiMap.find(variable);
316 for (auto it = componentsIt.first; it != componentsIt.second;) {
310 if (it != impl->m_VariableToPlotMultiMap.end()) {
317 VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second,
311 VisualizationGraphHelper::updateData(it->second, variable->dataSeries(), range);
318 variable->dataSeries(), range);
319 }
312 }
320 }
313 }
General Comments 0
You need to be logged in to leave comments. Login now