##// END OF EJS Templates
Handles desynchronisation when removing variable from a graph (1)...
Alexandre Leroux -
r676:e5aabf0f62fb
parent child
Show More
@@ -111,11 +111,15 public slots:
111 111 /// Cancel the current request for the variable
112 112 void onAbortProgressRequested(std::shared_ptr<Variable> variable);
113 113
114 /// synchronization group methods
114 // synchronization group methods
115 115 void onAddSynchronizationGroupId(QUuid synchronizationGroupId);
116 116 void onRemoveSynchronizationGroupId(QUuid synchronizationGroupId);
117 117 void onAddSynchronized(std::shared_ptr<Variable> variable, QUuid synchronizationGroupId);
118 118
119 /// Desynchronizes the variable of the group whose identifier is passed in parameter
120 /// @remarks the method does nothing if the variable is not part of the group
121 void desynchronize(std::shared_ptr<Variable> variable, QUuid synchronizationGroupId);
122
119 123 void initialize();
120 124 void finalize();
121 125
@@ -389,6 +389,36 void VariableController::onAddSynchronized(std::shared_ptr<Variable> variable,
389 389 }
390 390 }
391 391
392 void VariableController::desynchronize(std::shared_ptr<Variable> variable,
393 QUuid synchronizationGroupId)
394 {
395 // Gets variable id
396 auto variableIt = impl->m_VariableToIdentifierMap.find(variable);
397 if (variableIt == impl->m_VariableToIdentifierMap.cend()) {
398 qCCritical(LOG_VariableController())
399 << tr("Can't desynchronize variable %1: variable identifier not found")
400 .arg(variable->name());
401 return;
402 }
403
404 // Gets synchronization group
405 auto groupIt = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
406 if (groupIt == impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
407 qCCritical(LOG_VariableController())
408 << tr("Can't desynchronize variable %1: unknown synchronization group")
409 .arg(variable->name());
410 return;
411 }
412
413 auto variableId = variableIt->second;
414
415 // Removes variable from synchronization group
416 auto synchronizationGroup = groupIt->second;
417 synchronizationGroup->removeVariableId(variableId);
418
419 // Removes link between variable and synchronization group
420 impl->m_VariableIdGroupIdMap.erase(variableId);
421 }
392 422
393 423 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables,
394 424 const SqpRange &range, const SqpRange &oldRange,
@@ -56,6 +56,9 signals:
56 56 void requestDataLoading(QVector<std::shared_ptr<Variable> > variable, const SqpRange &range,
57 57 const SqpRange &oldRange, bool synchronise);
58 58
59 /// Signal emitted when the variable is about to be removed from the graph
60 void variableAboutToBeRemoved(std::shared_ptr<Variable> var);
61 /// Signal emitted when the variable has been added to the graph
59 62 void variableAdded(std::shared_ptr<Variable> var);
60 63
61 64 protected:
@@ -50,6 +50,8 private:
50 50
51 51 private slots:
52 52 void onVariableAdded(std::shared_ptr<Variable> variable);
53 /// Slot called when a variable is about to be removed from a graph contained in the zone
54 void onVariableAboutToBeRemoved(std::shared_ptr<Variable> variable);
53 55 };
54 56
55 57 #endif // SCIQLOP_VISUALIZATIONZONEWIDGET_H
@@ -138,6 +138,8 void VisualizationGraphWidget::removeVariable(std::shared_ptr<Variable> variable
138 138 // - is no longer referenced in the map
139 139 auto variableIt = impl->m_VariableToPlotMultiMap.find(variable);
140 140 if (variableIt != impl->m_VariableToPlotMultiMap.cend()) {
141 emit variableAboutToBeRemoved(variable);
142
141 143 auto &plottablesMap = variableIt->second;
142 144
143 145 for (auto plottableIt = plottablesMap.cbegin(), plottableEnd = plottablesMap.cend();
@@ -177,6 +177,8 VisualizationGraphWidget *VisualizationZoneWidget::createGraph(std::shared_ptr<V
177 177 connect(graphWidget, &VisualizationGraphWidget::synchronize, synchronizeZoneWidget);
178 178 connect(graphWidget, &VisualizationGraphWidget::variableAdded, this,
179 179 &VisualizationZoneWidget::onVariableAdded);
180 connect(graphWidget, &VisualizationGraphWidget::variableAboutToBeRemoved, this,
181 &VisualizationZoneWidget::onVariableAboutToBeRemoved);
180 182
181 183 auto range = SqpRange{};
182 184
@@ -266,3 +268,10 void VisualizationZoneWidget::onVariableAdded(std::shared_ptr<Variable> variable
266 268 Qt::QueuedConnection, Q_ARG(std::shared_ptr<Variable>, variable),
267 269 Q_ARG(QUuid, impl->m_SynchronisationGroupId));
268 270 }
271
272 void VisualizationZoneWidget::onVariableAboutToBeRemoved(std::shared_ptr<Variable> variable)
273 {
274 QMetaObject::invokeMethod(&sqpApp->variableController(), "desynchronize", Qt::QueuedConnection,
275 Q_ARG(std::shared_ptr<Variable>, variable),
276 Q_ARG(QUuid, impl->m_SynchronisationGroupId));
277 }
General Comments 0
You need to be logged in to leave comments. Login now