171 |
171 |
172 Model::~Model() |
172 Model::~Model() |
173 { |
173 { |
174 } |
174 } |
175 |
175 |
176 ModelId Model::append(const ModelElement &value) |
176 ElementId Model::append(const ModelElement &value) |
177 { |
177 { |
178 const std::size_t position = this->size(); |
178 const std::size_t position = this->size(); |
179 const ModelId id = this->runningId; |
179 const ElementId id = this->runningId; |
180 this->runningId.value += 1; |
180 this->runningId.value += 1; |
181 const int row = narrow<int>(signed_cast(this->size())); |
181 const int row = narrow<int>(signed_cast(this->size())); |
182 Q_EMIT this->beginInsertRows({}, row, row); |
182 Q_EMIT this->beginInsertRows({}, row, row); |
183 this->body.push_back({value, id}); |
183 this->body.push_back({value, id}); |
184 this->positions[id] = position; |
184 this->positions[id] = position; |
189 const ModelElement &Model::at(std::size_t position) const |
189 const ModelElement &Model::at(std::size_t position) const |
190 { |
190 { |
191 return this->body[position].data; |
191 return this->body[position].data; |
192 } |
192 } |
193 |
193 |
194 ModelId Model::idAt(std::size_t position) const |
194 ElementId Model::idAt(std::size_t position) const |
195 { |
195 { |
196 return this->body[position].id; |
196 return this->body[position].id; |
197 } |
197 } |
198 |
198 |
199 void Model::assignAt(std::size_t position, const ModelElement &element) |
199 void Model::assignAt(std::size_t position, const ModelElement &element) |
201 this->body[position].data = element; |
201 this->body[position].data = element; |
202 const QModelIndex index = this->index(narrow<int>(signed_cast(position))); |
202 const QModelIndex index = this->index(narrow<int>(signed_cast(position))); |
203 Q_EMIT this->dataChanged(index, index); |
203 Q_EMIT this->dataChanged(index, index); |
204 } |
204 } |
205 |
205 |
206 std::optional<std::size_t> Model::find(ModelId id) const |
206 std::optional<std::size_t> Model::find(ElementId id) const |
207 { |
207 { |
208 return pointerToOptional(findInMap(this->positions, id)); |
208 return pointerToOptional(findInMap(this->positions, id)); |
209 } |
209 } |
210 |
210 |
211 template<typename K, typename V> |
211 template<typename K, typename V> |