Some minor code changes, as well as properly using marker index

This commit is contained in:
AdenKoperczak 2024-11-25 11:18:03 -05:00
parent 7a070b3e7f
commit 35f2c85a19
2 changed files with 9 additions and 4 deletions

View file

@ -315,7 +315,7 @@ void MarkerManager::remove_marker(types::MarkerId id)
{ {
if (pair.second > index) if (pair.second > index)
{ {
p->idToIndex_[pair.first] = pair.second - 1; pair.second -= 1;
} }
} }
} }

View file

@ -297,14 +297,19 @@ void MarkerModel::HandleMarkerAdded(types::MarkerId id)
const int newIndex = static_cast<int>(*index); const int newIndex = static_cast<int>(*index);
beginInsertRows(QModelIndex(), newIndex, newIndex); beginInsertRows(QModelIndex(), newIndex, newIndex);
p->markerIds_.emplace_back(id); auto it = std::next(p->markerIds_.begin(), newIndex);
p->markerIds_.emplace(it, id);
endInsertRows(); endInsertRows();
} }
void MarkerModel::HandleMarkerChanged(types::MarkerId id) void MarkerModel::HandleMarkerChanged(types::MarkerId id)
{ {
std::optional<size_t> index = p->markerManager_->get_index(id); auto it = std::find(p->markerIds_.begin(), p->markerIds_.end(), id);
const int changedIndex = static_cast<int>(*index); if (it == p->markerIds_.end())
{
return;
}
const int changedIndex = std::distance(p->markerIds_.begin(), it);
QModelIndex topLeft = createIndex(changedIndex, kFirstColumn); QModelIndex topLeft = createIndex(changedIndex, kFirstColumn);
QModelIndex bottomRight = createIndex(changedIndex, kLastColumn); QModelIndex bottomRight = createIndex(changedIndex, kLastColumn);