##// END OF EJS Templates
Fixes problems at variable deletion...
Alexandre Leroux -
r1327:d0b687dbfe3e
parent child
Show More
@@ -136,6 +136,9 struct VariableController::VariableControllerPrivate {
136 void cancelVariableRequest(QUuid varRequestId);
136 void cancelVariableRequest(QUuid varRequestId);
137 void executeVarRequest(std::shared_ptr<Variable> var, VariableRequest &varRequest);
137 void executeVarRequest(std::shared_ptr<Variable> var, VariableRequest &varRequest);
138
138
139 template <typename VariableIterator>
140 void desynchronize(VariableIterator variableIt, const QUuid &syncGroupId);
141
139 QMutex m_WorkingMutex;
142 QMutex m_WorkingMutex;
140 /// Variable model. The VariableController has the ownership
143 /// Variable model. The VariableController has the ownership
141 VariableModel *m_VariableModel;
144 VariableModel *m_VariableModel;
@@ -258,8 +261,22 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noex
258 // make some treatments before the deletion
261 // make some treatments before the deletion
259 emit variableAboutToBeDeleted(variable);
262 emit variableAboutToBeDeleted(variable);
260
263
264 auto variableIt = impl->m_VariableToIdentifierMap.find(variable);
265 Q_ASSERT(variableIt != impl->m_VariableToIdentifierMap.cend());
266
267 auto variableId = variableIt->second;
268
269 // Removes variable's handler
270 impl->m_VarIdToVarRequestHandler.erase(variableId);
271
272 // Desynchronizes variable (if the variable is in a sync group)
273 auto syncGroupIt = impl->m_VariableIdGroupIdMap.find(variableId);
274 if (syncGroupIt != impl->m_VariableIdGroupIdMap.cend()) {
275 impl->desynchronize(variableIt, syncGroupIt->second);
276 }
277
261 // Deletes identifier
278 // Deletes identifier
262 impl->m_VariableToIdentifierMap.erase(variable);
279 impl->m_VariableToIdentifierMap.erase(variableIt);
263
280
264 // Deletes provider
281 // Deletes provider
265 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
282 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
@@ -545,23 +562,7 void VariableController::desynchronize(std::shared_ptr<Variable> variable,
545 return;
562 return;
546 }
563 }
547
564
548 // Gets synchronization group
565 impl->desynchronize(variableIt, synchronizationGroupId);
549 auto groupIt = impl->m_GroupIdToVariableSynchronizationGroupMap.find(synchronizationGroupId);
550 if (groupIt == impl->m_GroupIdToVariableSynchronizationGroupMap.cend()) {
551 qCCritical(LOG_VariableController())
552 << tr("Can't desynchronize variable %1: unknown synchronization group")
553 .arg(variable->name());
554 return;
555 }
556
557 auto variableId = variableIt->second;
558
559 // Removes variable from synchronization group
560 auto synchronizationGroup = groupIt->second;
561 synchronizationGroup->removeVariableId(variableId);
562
563 // Removes link between variable and synchronization group
564 impl->m_VariableIdGroupIdMap.erase(variableId);
565 }
566 }
566
567
567 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables,
568 void VariableController::onRequestDataLoading(QVector<std::shared_ptr<Variable> > variables,
@@ -1033,7 +1034,14 void VariableController::VariableControllerPrivate::executeVarRequest(std::share
1033 {
1034 {
1034 qCDebug(LOG_VariableController()) << tr("TORM: executeVarRequest");
1035 qCDebug(LOG_VariableController()) << tr("TORM: executeVarRequest");
1035
1036
1036 auto varId = m_VariableToIdentifierMap.at(var);
1037 auto varIdIt = m_VariableToIdentifierMap.find(var);
1038 if (varIdIt == m_VariableToIdentifierMap.cend()) {
1039 qCWarning(LOG_VariableController()) << tr(
1040 "Can't execute request of a variable that is not registered (may has been deleted)");
1041 return;
1042 }
1043
1044 auto varId = varIdIt->second;
1037
1045
1038 auto varCacheRange = var->cacheRange();
1046 auto varCacheRange = var->cacheRange();
1039 auto varCacheRangeRequested = varRequest.m_CacheRangeRequested;
1047 auto varCacheRangeRequested = varRequest.m_CacheRangeRequested;
@@ -1068,3 +1076,27 void VariableController::VariableControllerPrivate::executeVarRequest(std::share
1068 var->dataSeries()->subDataSeries(varRequest.m_CacheRangeRequested));
1076 var->dataSeries()->subDataSeries(varRequest.m_CacheRangeRequested));
1069 }
1077 }
1070 }
1078 }
1079
1080 template <typename VariableIterator>
1081 void VariableController::VariableControllerPrivate::desynchronize(VariableIterator variableIt,
1082 const QUuid &syncGroupId)
1083 {
1084 const auto &variable = variableIt->first;
1085 const auto &variableId = variableIt->second;
1086
1087 // Gets synchronization group
1088 auto groupIt = m_GroupIdToVariableSynchronizationGroupMap.find(syncGroupId);
1089 if (groupIt == m_GroupIdToVariableSynchronizationGroupMap.cend()) {
1090 qCCritical(LOG_VariableController())
1091 << tr("Can't desynchronize variable %1: unknown synchronization group")
1092 .arg(variable->name());
1093 return;
1094 }
1095
1096 // Removes variable from synchronization group
1097 auto synchronizationGroup = groupIt->second;
1098 synchronizationGroup->removeVariableId(variableId);
1099
1100 // Removes link between variable and synchronization group
1101 m_VariableIdGroupIdMap.erase(variableId);
1102 }
General Comments 0
You need to be logged in to leave comments. Login now