##// END OF EJS Templates
Handles QCustomPlot plottables for vectors (2)...
Alexandre Leroux -
r546:dd4269fbedea
parent child
Show More
@@ -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().get(),
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().get(), range);
318 variable->dataSeries(), range);
319 }
312 }
320 }
313 }
General Comments 0
You need to be logged in to leave comments. Login now