##// END OF EJS Templates
Updates VariableModel::createVariable() method...
Alexandre Leroux -
r153:81409bbf8178
parent child
Show More
@@ -8,6 +8,7
8 8
9 9 Q_DECLARE_LOGGING_CATEGORY(LOG_VariableModel)
10 10
11 class IDataSeries;
11 12 class Variable;
12 13
13 14 /**
@@ -20,9 +21,11 public:
20 21 /**
21 22 * Creates a new variable in the model
22 23 * @param name the name of the new variable
23 * @return the variable if it was created successfully, nullptr otherwise
24 * @param defaultDataSeries the default data of the new variable
25 * @return the pointer to the new variable
24 26 */
25 Variable *createVariable(const QString &name) noexcept;
27 std::shared_ptr<Variable>
28 createVariable(const QString &name, std::unique_ptr<IDataSeries> defaultDataSeries) noexcept;
26 29
27 30 // /////////////////////////// //
28 31 // QAbstractTableModel methods //
@@ -1,6 +1,7
1 1 #include <Variable/Variable.h>
2 2 #include <Variable/VariableModel.h>
3 3
4 #include <Data/IDataSeries.h>
4 5
5 6 Q_LOGGING_CATEGORY(LOG_VariableModel, "VariableModel")
6 7
@@ -16,7 +17,7 const auto NB_COLUMNS = 3;
16 17
17 18 struct VariableModel::VariableModelPrivate {
18 19 /// Variables created in SciQlop
19 std::vector<std::unique_ptr<Variable> > m_Variables;
20 std::vector<std::shared_ptr<Variable> > m_Variables;
20 21 };
21 22
22 23 VariableModel::VariableModel(QObject *parent)
@@ -24,19 +25,23 VariableModel::VariableModel(QObject *parent)
24 25 {
25 26 }
26 27
27 Variable *VariableModel::createVariable(const QString &name) noexcept
28 std::shared_ptr<Variable>
29 VariableModel::createVariable(const QString &name,
30 std::unique_ptr<IDataSeries> defaultDataSeries) noexcept
28 31 {
29 32 auto insertIndex = rowCount();
30 33 beginInsertRows({}, insertIndex, insertIndex);
31 34
32 35 /// @todo For the moment, the other data of the variable is initialized with default values
33 36 auto variable
34 = std::make_unique<Variable>(name, QStringLiteral("unit"), QStringLiteral("mission"));
35 impl->m_Variables.push_back(std::move(variable));
37 = std::make_shared<Variable>(name, QStringLiteral("unit"), QStringLiteral("mission"));
38 variable->addDataSeries(std::move(defaultDataSeries));
39
40 impl->m_Variables.push_back(variable);
36 41
37 42 endInsertRows();
38 43
39 return impl->m_Variables.at(insertIndex).get();
44 return variable;
40 45 }
41 46
42 47 int VariableModel::columnCount(const QModelIndex &parent) const
General Comments 0
You need to be logged in to leave comments. Login now