From 81409bbf81789b698545998a2a709fe5506dbf17 2017-06-19 09:05:38 From: Alexandre Leroux Date: 2017-06-19 09:05:38 Subject: [PATCH] Updates VariableModel::createVariable() method - Stores variable as shared_ptr (maybe the variable may exist outside this controller) - Adds default data series for the variable - Returns the shared_ptr after variable creation --- diff --git a/core/include/Variable/VariableModel.h b/core/include/Variable/VariableModel.h index 074da18..140a02a 100644 --- a/core/include/Variable/VariableModel.h +++ b/core/include/Variable/VariableModel.h @@ -8,6 +8,7 @@ Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel) +class IDataSeries; class Variable; /** @@ -20,9 +21,11 @@ public: /** * Creates a new variable in the model * @param name the name of the new variable - * @return the variable if it was created successfully, nullptr otherwise + * @param defaultDataSeries the default data of the new variable + * @return the pointer to the new variable */ - Variable *createVariable(const QString &name) noexcept; + std::shared_ptr + createVariable(const QString &name, std::unique_ptr defaultDataSeries) noexcept; // /////////////////////////// // // QAbstractTableModel methods // diff --git a/core/src/Variable/VariableModel.cpp b/core/src/Variable/VariableModel.cpp index 30b5009..25edb92 100644 --- a/core/src/Variable/VariableModel.cpp +++ b/core/src/Variable/VariableModel.cpp @@ -1,6 +1,7 @@ #include #include +#include Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel") @@ -16,7 +17,7 @@ const auto NB_COLUMNS = 3; struct VariableModel::VariableModelPrivate { /// Variables created in SciQlop - std::vector > m_Variables; + std::vector > m_Variables; }; VariableModel::VariableModel(QObject *parent) @@ -24,19 +25,23 @@ VariableModel::VariableModel(QObject *parent) { } -Variable *VariableModel::createVariable(const QString &name) noexcept +std::shared_ptr +VariableModel::createVariable(const QString &name, + std::unique_ptr defaultDataSeries) noexcept { auto insertIndex = rowCount(); beginInsertRows({}, insertIndex, insertIndex); /// @todo For the moment, the other data of the variable is initialized with default values auto variable - = std::make_unique(name, QStringLiteral("unit"), QStringLiteral("mission")); - impl->m_Variables.push_back(std::move(variable)); + = std::make_shared(name, QStringLiteral("unit"), QStringLiteral("mission")); + variable->addDataSeries(std::move(defaultDataSeries)); + + impl->m_Variables.push_back(variable); endInsertRows(); - return impl->m_Variables.at(insertIndex).get(); + return variable; } int VariableModel::columnCount(const QModelIndex &parent) const