From 35f2c85a199f6f5b19ae46f807e73fa179e66314 Mon Sep 17 00:00:00 2001 From: AdenKoperczak Date: Mon, 25 Nov 2024 11:18:03 -0500 Subject: [PATCH] Some minor code changes, as well as properly using marker index --- scwx-qt/source/scwx/qt/manager/marker_manager.cpp | 2 +- scwx-qt/source/scwx/qt/model/marker_model.cpp | 11 ++++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/scwx-qt/source/scwx/qt/manager/marker_manager.cpp b/scwx-qt/source/scwx/qt/manager/marker_manager.cpp index e91f03fb..99208a10 100644 --- a/scwx-qt/source/scwx/qt/manager/marker_manager.cpp +++ b/scwx-qt/source/scwx/qt/manager/marker_manager.cpp @@ -315,7 +315,7 @@ void MarkerManager::remove_marker(types::MarkerId id) { if (pair.second > index) { - p->idToIndex_[pair.first] = pair.second - 1; + pair.second -= 1; } } } diff --git a/scwx-qt/source/scwx/qt/model/marker_model.cpp b/scwx-qt/source/scwx/qt/model/marker_model.cpp index 97cafcb1..9bd057ea 100644 --- a/scwx-qt/source/scwx/qt/model/marker_model.cpp +++ b/scwx-qt/source/scwx/qt/model/marker_model.cpp @@ -297,14 +297,19 @@ void MarkerModel::HandleMarkerAdded(types::MarkerId id) const int newIndex = static_cast(*index); beginInsertRows(QModelIndex(), newIndex, newIndex); - p->markerIds_.emplace_back(id); + auto it = std::next(p->markerIds_.begin(), newIndex); + p->markerIds_.emplace(it, id); endInsertRows(); } void MarkerModel::HandleMarkerChanged(types::MarkerId id) { - std::optional index = p->markerManager_->get_index(id); - const int changedIndex = static_cast(*index); + auto it = std::find(p->markerIds_.begin(), p->markerIds_.end(), id); + if (it == p->markerIds_.end()) + { + return; + } + const int changedIndex = std::distance(p->markerIds_.begin(), it); QModelIndex topLeft = createIndex(changedIndex, kFirstColumn); QModelIndex bottomRight = createIndex(changedIndex, kLastColumn);