@@ -36,6 +36,13 public: | |||
|
36 | 36 | void addVariable(std::shared_ptr<Variable> variable) noexcept; |
|
37 | 37 | |
|
38 | 38 | /** |
|
39 | * Checks that a variable is contained in the model | |
|
40 | * @param variable the variable to check | |
|
41 | * @return true if the variable is in the model, false otherwise | |
|
42 | */ | |
|
43 | bool containsVariable(std::shared_ptr<Variable> variable) const noexcept; | |
|
44 | ||
|
45 | /** | |
|
39 | 46 | * Creates a new variable in the model |
|
40 | 47 | * @param name the name of the new variable |
|
41 | 48 | * @param dateTime the dateTime of the new variable |
@@ -191,13 +191,21 void VariableController::setTimeController(TimeController *timeController) noexc | |||
|
191 | 191 | std::shared_ptr<Variable> |
|
192 | 192 | VariableController::cloneVariable(std::shared_ptr<Variable> variable) noexcept |
|
193 | 193 | { |
|
194 | // Clones variable | |
|
195 | auto duplicate = variable->clone(); | |
|
194 | if (impl->m_VariableModel->containsVariable(variable)) { | |
|
195 | // Clones variable | |
|
196 | auto duplicate = variable->clone(); | |
|
196 | 197 | |
|
197 | // Adds clone to model | |
|
198 | impl->m_VariableModel->addVariable(duplicate); | |
|
198 | // Adds clone to model | |
|
199 | impl->m_VariableModel->addVariable(duplicate); | |
|
199 | 200 | |
|
200 | return duplicate; | |
|
201 | return duplicate; | |
|
202 | } | |
|
203 | else { | |
|
204 | qCCritical(LOG_VariableController()) | |
|
205 | << tr("Can't create duplicate of variable %1: variable not registered in the model") | |
|
206 | .arg(variable->name()); | |
|
207 | return nullptr; | |
|
208 | } | |
|
201 | 209 | } |
|
202 | 210 | |
|
203 | 211 | void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept |
@@ -88,6 +88,12 void VariableModel::addVariable(std::shared_ptr<Variable> variable) noexcept | |||
|
88 | 88 | endInsertRows(); |
|
89 | 89 | } |
|
90 | 90 | |
|
91 | bool VariableModel::containsVariable(std::shared_ptr<Variable> variable) const noexcept | |
|
92 | { | |
|
93 | auto end = impl->m_Variables.cend(); | |
|
94 | return std::find(impl->m_Variables.cbegin(), end, variable) != end; | |
|
95 | } | |
|
96 | ||
|
91 | 97 | std::shared_ptr<Variable> VariableModel::createVariable(const QString &name, |
|
92 | 98 | const SqpRange &dateTime, |
|
93 | 99 | const QVariantHash &metadata) noexcept |
General Comments 0
You need to be logged in to leave comments.
Login now