diff -r 1909a0123c72 -r 52e10e8d88cc src/model.cpp --- a/src/model.cpp Tue Jun 07 21:35:29 2022 +0300 +++ b/src/model.cpp Wed Jun 08 19:33:00 2022 +0300 @@ -111,11 +111,24 @@ return pointerToOptional(findInMap(this->positions, id)); } +template +void removeFromMap(std::map& map, const K& key) +{ + const auto it = map.find(key); + if (it != map.end()) { + map.erase(it); + } +} + void Model::remove(int index) { if (index >= 0 and index < this->size()) { Q_EMIT this->beginRemoveRows({}, index, index); + removeFromMap(this->positions, this->body[index].id); this->body.erase(this->body.begin() + index); + for (int i = index; i < this->size(); ++i) { + this->positions[this->body[i].id] = i; + } Q_EMIT this->endRemoveRows(); } }