##// END OF EJS Templates
Corrects regression on variable destruction
Alexandre Leroux -
r420:4458a8f811e4
parent child
Show More
@@ -38,7 +38,7 struct VariableController::VariableControllerPrivate {
38
38
39 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
39 std::unordered_map<std::shared_ptr<Variable>, std::shared_ptr<IDataProvider> >
40 m_VariableToProviderMap;
40 m_VariableToProviderMap;
41 std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifier;
41 std::unordered_map<std::shared_ptr<Variable>, QUuid> m_VariableToIdentifierMap;
42 };
42 };
43
43
44 VariableController::VariableController(QObject *parent)
44 VariableController::VariableController(QObject *parent)
@@ -81,6 +81,9 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noex
81 // make some treatments before the deletion
81 // make some treatments before the deletion
82 emit variableAboutToBeDeleted(variable);
82 emit variableAboutToBeDeleted(variable);
83
83
84 // Deletes identifier
85 impl->m_VariableToIdentifierMap.erase(variable);
86
84 // Deletes provider
87 // Deletes provider
85 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
88 auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable);
86 qCDebug(LOG_VariableController())
89 qCDebug(LOG_VariableController())
@@ -119,13 +122,13 void VariableController::createVariable(const QString &name, const QVariantHash
119
122
120 // store the provider
123 // store the provider
121 impl->m_VariableToProviderMap[newVariable] = provider;
124 impl->m_VariableToProviderMap[newVariable] = provider;
122 impl->m_VariableToIdentifier[newVariable] = identifier;
125 impl->m_VariableToIdentifierMap[newVariable] = identifier;
123
126
124 auto addDateTimeAcquired = [ this, varW = std::weak_ptr<Variable>{newVariable} ](
127 auto addDateTimeAcquired = [ this, varW = std::weak_ptr<Variable>{newVariable} ](
125 QUuid identifier, auto dataSeriesAcquired, auto dateTimeToPutInCache)
128 QUuid identifier, auto dataSeriesAcquired, auto dateTimeToPutInCache)
126 {
129 {
127 if (auto variable = varW.lock()) {
130 if (auto variable = varW.lock()) {
128 auto varIdentifier = impl->m_VariableToIdentifier.at(variable);
131 auto varIdentifier = impl->m_VariableToIdentifierMap.at(variable);
129 if (varIdentifier == identifier) {
132 if (varIdentifier == identifier) {
130 impl->m_VariableCacheController->addDateTime(variable, dateTimeToPutInCache);
133 impl->m_VariableCacheController->addDateTime(variable, dateTimeToPutInCache);
131 variable->setDataSeries(dataSeriesAcquired);
134 variable->setDataSeries(dataSeriesAcquired);
@@ -156,8 +159,8 void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, doub
156 {
159 {
157 auto findReply = [identifier](const auto &entry) { return identifier == entry.second; };
160 auto findReply = [identifier](const auto &entry) { return identifier == entry.second; };
158
161
159 auto end = impl->m_VariableToIdentifier.cend();
162 auto end = impl->m_VariableToIdentifierMap.cend();
160 auto it = std::find_if(impl->m_VariableToIdentifier.cbegin(), end, findReply);
163 auto it = std::find_if(impl->m_VariableToIdentifierMap.cbegin(), end, findReply);
161 if (it != end) {
164 if (it != end) {
162 impl->m_VariableModel->setDataProgress(it->first, progress);
165 impl->m_VariableModel->setDataProgress(it->first, progress);
163 }
166 }
@@ -179,7 +182,7 void VariableController::onRequestDataLoading(std::shared_ptr<Variable> variable
179
182
180 if (!dateTimeListNotInCache.empty()) {
183 if (!dateTimeListNotInCache.empty()) {
181 // Ask the provider for each data on the dateTimeListNotInCache
184 // Ask the provider for each data on the dateTimeListNotInCache
182 auto identifier = impl->m_VariableToIdentifier.at(variable);
185 auto identifier = impl->m_VariableToIdentifierMap.at(variable);
183 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(
186 impl->m_VariableToProviderMap.at(variable)->requestDataLoading(
184 identifier,
187 identifier,
185 DataProviderParameters{std::move(dateTimeListNotInCache), variable->metadata()});
188 DataProviderParameters{std::move(dateTimeListNotInCache), variable->metadata()});
@@ -47,8 +47,7 const auto DATETIME_FORMAT = QStringLiteral("dd/MM/yyyy \nhh:mm:ss:zzz");
47 struct VariableModel::VariableModelPrivate {
47 struct VariableModel::VariableModelPrivate {
48 /// Variables created in SciQlop
48 /// Variables created in SciQlop
49 std::vector<std::shared_ptr<Variable> > m_Variables;
49 std::vector<std::shared_ptr<Variable> > m_Variables;
50 std::unordered_map<std::shared_ptr<Variable>, double> m_VariableToProgress;
50 std::unordered_map<Variable *, double> m_VariableToProgress;
51
52
51
53 /// Return the row index of the variable. -1 if it's not found
52 /// Return the row index of the variable. -1 if it's not found
54 int indexOfVariable(Variable *variable) const noexcept;
53 int indexOfVariable(Variable *variable) const noexcept;
@@ -110,8 +109,7 std::shared_ptr<Variable> VariableModel::variable(int index) const
110
109
111 void VariableModel::setDataProgress(std::shared_ptr<Variable> variable, double progress)
110 void VariableModel::setDataProgress(std::shared_ptr<Variable> variable, double progress)
112 {
111 {
113
112 impl->m_VariableToProgress[variable.get()] = progress;
114 impl->m_VariableToProgress[variable] = progress;
115 auto modelIndex = createIndex(impl->indexOfVariable(variable.get()), NAME_COLUMN);
113 auto modelIndex = createIndex(impl->indexOfVariable(variable.get()), NAME_COLUMN);
116
114
117 emit dataChanged(modelIndex, modelIndex);
115 emit dataChanged(modelIndex, modelIndex);
@@ -171,7 +169,7 QVariant VariableModel::data(const QModelIndex &index, int role) const
171 else if (role == VariableRoles::ProgressRole) {
169 else if (role == VariableRoles::ProgressRole) {
172 if (auto variable = impl->m_Variables.at(index.row())) {
170 if (auto variable = impl->m_Variables.at(index.row())) {
173
171
174 auto it = impl->m_VariableToProgress.find(variable);
172 auto it = impl->m_VariableToProgress.find(variable.get());
175 if (it != impl->m_VariableToProgress.cend()) {
173 if (it != impl->m_VariableToProgress.cend()) {
176 return it->second;
174 return it->second;
177 }
175 }
General Comments 0
You need to be logged in to leave comments. Login now