From 4458a8f811e41e6d164b5ef3d9fbd46b38f33e6f 2017-07-13 10:38:30 From: Alexandre Leroux Date: 2017-07-13 10:38:30 Subject: [PATCH] Corrects regression on variable destruction --- diff --git a/core/src/Variable/VariableController.cpp b/core/src/Variable/VariableController.cpp index cd5aa59..afeaab9 100644 --- a/core/src/Variable/VariableController.cpp +++ b/core/src/Variable/VariableController.cpp @@ -38,7 +38,7 @@ struct VariableController::VariableControllerPrivate { std::unordered_map, std::shared_ptr > m_VariableToProviderMap; - std::unordered_map, QUuid> m_VariableToIdentifier; + std::unordered_map, QUuid> m_VariableToIdentifierMap; }; VariableController::VariableController(QObject *parent) @@ -81,6 +81,9 @@ void VariableController::deleteVariable(std::shared_ptr variable) noex // make some treatments before the deletion emit variableAboutToBeDeleted(variable); + // Deletes identifier + impl->m_VariableToIdentifierMap.erase(variable); + // Deletes provider auto nbProvidersDeleted = impl->m_VariableToProviderMap.erase(variable); qCDebug(LOG_VariableController()) @@ -119,13 +122,13 @@ void VariableController::createVariable(const QString &name, const QVariantHash // store the provider impl->m_VariableToProviderMap[newVariable] = provider; - impl->m_VariableToIdentifier[newVariable] = identifier; + impl->m_VariableToIdentifierMap[newVariable] = identifier; auto addDateTimeAcquired = [ this, varW = std::weak_ptr{newVariable} ]( QUuid identifier, auto dataSeriesAcquired, auto dateTimeToPutInCache) { if (auto variable = varW.lock()) { - auto varIdentifier = impl->m_VariableToIdentifier.at(variable); + auto varIdentifier = impl->m_VariableToIdentifierMap.at(variable); if (varIdentifier == identifier) { impl->m_VariableCacheController->addDateTime(variable, dateTimeToPutInCache); variable->setDataSeries(dataSeriesAcquired); @@ -156,8 +159,8 @@ void VariableController::onVariableRetrieveDataInProgress(QUuid identifier, doub { auto findReply = [identifier](const auto &entry) { return identifier == entry.second; }; - auto end = impl->m_VariableToIdentifier.cend(); - auto it = std::find_if(impl->m_VariableToIdentifier.cbegin(), end, findReply); + auto end = impl->m_VariableToIdentifierMap.cend(); + auto it = std::find_if(impl->m_VariableToIdentifierMap.cbegin(), end, findReply); if (it != end) { impl->m_VariableModel->setDataProgress(it->first, progress); } @@ -179,7 +182,7 @@ void VariableController::onRequestDataLoading(std::shared_ptr variable if (!dateTimeListNotInCache.empty()) { // Ask the provider for each data on the dateTimeListNotInCache - auto identifier = impl->m_VariableToIdentifier.at(variable); + auto identifier = impl->m_VariableToIdentifierMap.at(variable); impl->m_VariableToProviderMap.at(variable)->requestDataLoading( identifier, DataProviderParameters{std::move(dateTimeListNotInCache), variable->metadata()}); diff --git a/core/src/Variable/VariableModel.cpp b/core/src/Variable/VariableModel.cpp index 637c4cb..b3d7481 100644 --- a/core/src/Variable/VariableModel.cpp +++ b/core/src/Variable/VariableModel.cpp @@ -47,8 +47,7 @@ const auto DATETIME_FORMAT = QStringLiteral("dd/MM/yyyy \nhh:mm:ss:zzz"); struct VariableModel::VariableModelPrivate { /// Variables created in SciQlop std::vector > m_Variables; - std::unordered_map, double> m_VariableToProgress; - + std::unordered_map m_VariableToProgress; /// Return the row index of the variable. -1 if it's not found int indexOfVariable(Variable *variable) const noexcept; @@ -110,8 +109,7 @@ std::shared_ptr VariableModel::variable(int index) const void VariableModel::setDataProgress(std::shared_ptr variable, double progress) { - - impl->m_VariableToProgress[variable] = progress; + impl->m_VariableToProgress[variable.get()] = progress; auto modelIndex = createIndex(impl->indexOfVariable(variable.get()), NAME_COLUMN); emit dataChanged(modelIndex, modelIndex); @@ -171,7 +169,7 @@ QVariant VariableModel::data(const QModelIndex &index, int role) const else if (role == VariableRoles::ProgressRole) { if (auto variable = impl->m_Variables.at(index.row())) { - auto it = impl->m_VariableToProgress.find(variable); + auto it = impl->m_VariableToProgress.find(variable.get()); if (it != impl->m_VariableToProgress.cend()) { return it->second; }