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