##// END OF EJS Templates
Creates duplicate only if the variable is in the model
Alexandre Leroux -
r710:1edff56171b6
parent child
Show More
@@ -36,6 +36,13 public:
36 void addVariable(std::shared_ptr<Variable> variable) noexcept;
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 * Creates a new variable in the model
46 * Creates a new variable in the model
40 * @param name the name of the new variable
47 * @param name the name of the new variable
41 * @param dateTime the dateTime of the new variable
48 * @param dateTime the dateTime of the new variable
@@ -191,6 +191,7 void VariableController::setTimeController(TimeController *timeController) noexc
191 std::shared_ptr<Variable>
191 std::shared_ptr<Variable>
192 VariableController::cloneVariable(std::shared_ptr<Variable> variable) noexcept
192 VariableController::cloneVariable(std::shared_ptr<Variable> variable) noexcept
193 {
193 {
194 if (impl->m_VariableModel->containsVariable(variable)) {
194 // Clones variable
195 // Clones variable
195 auto duplicate = variable->clone();
196 auto duplicate = variable->clone();
196
197
@@ -199,6 +200,13 VariableController::cloneVariable(std::shared_ptr<Variable> variable) noexcept
199
200
200 return duplicate;
201 return duplicate;
201 }
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 }
209 }
202
210
203 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept
211 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noexcept
204 {
212 {
@@ -88,6 +88,12 void VariableModel::addVariable(std::shared_ptr<Variable> variable) noexcept
88 endInsertRows();
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 std::shared_ptr<Variable> VariableModel::createVariable(const QString &name,
97 std::shared_ptr<Variable> VariableModel::createVariable(const QString &name,
92 const SqpRange &dateTime,
98 const SqpRange &dateTime,
93 const QVariantHash &metadata) noexcept
99 const QVariantHash &metadata) noexcept
General Comments 0
You need to be logged in to leave comments. Login now