##// END OF EJS Templates
Adds variable to model
Alexandre Leroux -
r652:9aa695e50c87
parent child
Show More
@@ -28,6 +28,14 public:
28 28 explicit VariableModel(QObject *parent = nullptr);
29 29
30 30 /**
31 * Adds an existing variable in the model.
32 * @param variable the variable to add.
33 * @remarks the variable's name is modified to avoid name duplicates
34 * @remarks this method does nothing if the variable already exists in the model
35 */
36 void addVariable(std::shared_ptr<Variable> variable) noexcept;
37
38 /**
31 39 * Creates a new variable in the model
32 40 * @param name the name of the new variable
33 41 * @param dateTime the dateTime of the new variable
@@ -194,6 +194,9 VariableController::cloneVariable(std::shared_ptr<Variable> variable) noexcept
194 194 // Clones variable
195 195 auto duplicate = variable->clone();
196 196
197 // Adds clone to model
198 impl->m_VariableModel->addVariable(duplicate);
199
197 200 return duplicate;
198 201 }
199 202
@@ -62,19 +62,23 VariableModel::VariableModel(QObject *parent)
62 62 {
63 63 }
64 64
65 std::shared_ptr<Variable> VariableModel::createVariable(const QString &name,
66 const SqpRange &dateTime,
67 const QVariantHash &metadata) noexcept
65 void VariableModel::addVariable(std::shared_ptr<Variable> variable) noexcept
68 66 {
69 67 auto insertIndex = rowCount();
70 68 beginInsertRows({}, insertIndex, insertIndex);
71 69
72 auto variable = std::make_shared<Variable>(name, dateTime, metadata);
73
74 70 impl->m_Variables.push_back(variable);
75 71 connect(variable.get(), &Variable::updated, this, &VariableModel::onVariableUpdated);
76 72
77 73 endInsertRows();
74 }
75
76 std::shared_ptr<Variable> VariableModel::createVariable(const QString &name,
77 const SqpRange &dateTime,
78 const QVariantHash &metadata) noexcept
79 {
80 auto variable = std::make_shared<Variable>(name, dateTime, metadata);
81 addVariable(variable);
78 82
79 83 return variable;
80 84 }
General Comments 0
You need to be logged in to leave comments. Login now