##// END OF EJS Templates
Variable deletion (3)...
Alexandre Leroux -
r332:ec40cfe998fe
parent child
Show More
@@ -34,6 +34,7 public:
34 * Deletes from the controller the variable passed in parameter.
34 * Deletes from the controller the variable passed in parameter.
35 *
35 *
36 * Delete a variable includes:
36 * Delete a variable includes:
37 * - the deletion of the model variable
37 * - the deletion of the provider associated with the variable
38 * - the deletion of the provider associated with the variable
38 * - removing the cache associated with the variable
39 * - removing the cache associated with the variable
39 *
40 *
@@ -30,6 +30,12 public:
30 std::shared_ptr<Variable> createVariable(const QString &name,
30 std::shared_ptr<Variable> createVariable(const QString &name,
31 const SqpDateTime &dateTime) noexcept;
31 const SqpDateTime &dateTime) noexcept;
32
32
33 /**
34 * Deletes a variable from the model, if it exists
35 * @param variable the variable to delete
36 */
37 void deleteVariable(std::shared_ptr<Variable> variable) noexcept;
38
33 std::shared_ptr<Variable> variable(int index) const;
39 std::shared_ptr<Variable> variable(int index) const;
34
40
35 // /////////////////////////// //
41 // /////////////////////////// //
@@ -99,6 +99,9 void VariableController::deleteVariable(std::shared_ptr<Variable> variable) noex
99 // Clears cache
99 // Clears cache
100 impl->m_VariableCacheController->clear(variable);
100 impl->m_VariableCacheController->clear(variable);
101
101
102 // Deletes from model
103 impl->m_VariableModel->deleteVariable(variable);
104 }
102
105
103 void VariableController::deleteVariables(
106 void VariableController::deleteVariables(
104 const QVector<std::shared_ptr<Variable> > &variables) noexcept
107 const QVector<std::shared_ptr<Variable> > &variables) noexcept
@@ -69,6 +69,32 std::shared_ptr<Variable> VariableModel::createVariable(const QString &name,
69 return variable;
69 return variable;
70 }
70 }
71
71
72 void VariableModel::deleteVariable(std::shared_ptr<Variable> variable) noexcept
73 {
74 if (!variable) {
75 qCCritical(LOG_Variable()) << "Can't delete a null variable from the model";
76 return;
77 }
78
79 // Finds variable in the model
80 auto begin = impl->m_Variables.cbegin();
81 auto end = impl->m_Variables.cend();
82 auto it = std::find(begin, end, variable);
83 if (it != end) {
84 auto removeIndex = std::distance(begin, it);
85
86 // Deletes variable
87 beginRemoveRows({}, removeIndex, removeIndex);
88 impl->m_Variables.erase(it);
89 endRemoveRows();
90 }
91 else {
92 qCritical(LOG_VariableModel())
93 << tr("Can't delete variable %1 from the model: the variable is not in the model")
94 .arg(variable->name());
95 }
96 }
97
72 std::shared_ptr<Variable> VariableModel::variable(int index) const
98 std::shared_ptr<Variable> VariableModel::variable(int index) const
73 {
99 {
74 return (index >= 0 && index < impl->m_Variables.size()) ? impl->m_Variables[index] : nullptr;
100 return (index >= 0 && index < impl->m_Variables.size()) ? impl->m_Variables[index] : nullptr;
General Comments 0
You need to be logged in to leave comments. Login now