@@ -1,5 +1,6 | |||
|
1 | 1 | #include "Visualization/VisualizationGraphWidget.h" |
|
2 | 2 | #include "Visualization/IVisualizationWidgetVisitor.h" |
|
3 | #include "Visualization/VisualizationDefs.h" | |
|
3 | 4 | #include "Visualization/VisualizationGraphHelper.h" |
|
4 | 5 | #include "Visualization/VisualizationGraphRenderingDelegate.h" |
|
5 | 6 | #include "ui_VisualizationGraphWidget.h" |
@@ -33,7 +34,7 struct VisualizationGraphWidget::VisualizationGraphWidgetPrivate { | |||
|
33 | 34 | } |
|
34 | 35 | |
|
35 | 36 | // 1 variable -> n qcpplot |
|
36 |
std:: |
|
|
37 | std::map<std::shared_ptr<Variable>, PlottablesMap> m_VariableToPlotMultiMap; | |
|
37 | 38 | bool m_DoAcquisition; |
|
38 | 39 | bool m_IsCalibration; |
|
39 | 40 | QCPItemTracer *m_TextTracer; |
@@ -99,11 +100,8 void VisualizationGraphWidget::enableAcquisition(bool enable) | |||
|
99 | 100 | void VisualizationGraphWidget::addVariable(std::shared_ptr<Variable> variable, SqpRange range) |
|
100 | 101 | { |
|
101 | 102 | // Uses delegate to create the qcpplot components according to the variable |
|
102 |
auto createdPlottables = VisualizationGraphHelper::create |
|
|
103 | ||
|
104 | for (auto createdPlottable : qAsConst(createdPlottables)) { | |
|
105 | impl->m_VariableToPlotMultiMap.insert({variable, createdPlottable}); | |
|
106 | } | |
|
103 | auto createdPlottables = VisualizationGraphHelper::create(variable, *ui->widget); | |
|
104 | impl->m_VariableToPlotMultiMap.insert({variable, std::move(createdPlottables)}); | |
|
107 | 105 | |
|
108 | 106 | connect(variable.get(), SIGNAL(updated()), this, SLOT(onDataCacheVariableUpdated())); |
|
109 | 107 | |
@@ -124,10 +122,17 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable | |||
|
124 | 122 | // Each component associated to the variable : |
|
125 | 123 | // - is removed from qcpplot (which deletes it) |
|
126 | 124 | // - is no longer referenced in the map |
|
127 |
auto |
|
|
128 | for (auto it = componentsIt.first; it != componentsIt.second;) { | |
|
129 |
|
|
|
130 | it = impl->m_VariableToPlotMultiMap.erase(it); | |
|
125 | auto variableIt = impl->m_VariableToPlotMultiMap.find(variable); | |
|
126 | if (variableIt != impl->m_VariableToPlotMultiMap.cend()) { | |
|
127 | auto &plottablesMap = variableIt->second; | |
|
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 | 138 | // Updates graph |
@@ -282,29 +287,18 void VisualizationGraphWidget::onMouseRelease(QMouseEvent *event) noexcept | |||
|
282 | 287 | |
|
283 | 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 | 290 | auto graphRange = ui->widget->xAxis->range(); |
|
295 | 291 | auto dateTime = SqpRange{graphRange.lower, graphRange.upper}; |
|
296 | 292 | |
|
297 |
for (auto it |
|
|
298 | it != impl->m_VariableToPlotMultiMap.cend(); ++it) { | |
|
299 | auto variable = it->first; | |
|
293 | for (auto &variableEntry : impl->m_VariableToPlotMultiMap) { | |
|
294 | auto variable = variableEntry.first; | |
|
300 | 295 | qCDebug(LOG_VisualizationGraphWidget()) |
|
301 | 296 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated S" << variable->range(); |
|
302 | 297 | qCDebug(LOG_VisualizationGraphWidget()) |
|
303 | 298 | << "TORM: VisualizationGraphWidget::onDataCacheVariableUpdated E" << dateTime; |
|
304 | 299 | if (dateTime.contains(variable->range()) || dateTime.intersect(variable->range())) { |
|
305 | ||
|
306 | VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second, | |
|
307 | variable->dataSeries(), variable->range()); | |
|
300 | VisualizationGraphHelper::updateData(variableEntry.second, variable->dataSeries().get(), | |
|
301 | variable->range()); | |
|
308 | 302 | } |
|
309 | 303 | } |
|
310 | 304 | } |
@@ -312,9 +306,8 void VisualizationGraphWidget::onDataCacheVariableUpdated() | |||
|
312 | 306 | void VisualizationGraphWidget::onUpdateVarDisplaying(std::shared_ptr<Variable> variable, |
|
313 | 307 | const SqpRange &range) |
|
314 | 308 | { |
|
315 |
auto |
|
|
316 | for (auto it = componentsIt.first; it != componentsIt.second;) { | |
|
317 | VisualizationGraphHelper::updateData(QVector<QCPAbstractPlottable *>{} << it->second, | |
|
318 | variable->dataSeries(), range); | |
|
309 | auto it = impl->m_VariableToPlotMultiMap.find(variable); | |
|
310 | if (it != impl->m_VariableToPlotMultiMap.end()) { | |
|
311 | VisualizationGraphHelper::updateData(it->second, variable->dataSeries().get(), range); | |
|
319 | 312 | } |
|
320 | 313 | } |
General Comments 0
You need to be logged in to leave comments.
Login now