From e930cf3c90e0483a425b4c097fd91fcf28faea77 Mon Sep 17 00:00:00 2001 From: Jon Beniston Date: Mon, 6 Mar 2023 17:11:34 +0000 Subject: [PATCH] Fix updateVORs so it doesn't delete selected VORs. For #1590 --- .../feature/vorlocalizer/vorlocalizergui.cpp | 4 +-- .../feature/vorlocalizer/vorlocalizergui.h | 36 ++++++++++++++----- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/plugins/feature/vorlocalizer/vorlocalizergui.cpp b/plugins/feature/vorlocalizer/vorlocalizergui.cpp index af8b6e098..d8361c857 100644 --- a/plugins/feature/vorlocalizer/vorlocalizergui.cpp +++ b/plugins/feature/vorlocalizer/vorlocalizergui.cpp @@ -496,7 +496,7 @@ void VORLocalizerGUI::selectVOR(VORGUI *vorGUI, bool selected) void VORLocalizerGUI::updateVORs() { - m_vorModel.removeAllVORs(); + m_vorModel.removeAllExceptSelected(); AzEl azEl = m_azEl; for (const auto vor : *m_vors) @@ -509,7 +509,7 @@ void VORLocalizerGUI::updateVORs() // Only display VOR if in range if (azEl.getDistance() <= 200000) { - m_vorModel.addVOR(vor); + m_vorModel.addVOR(vor); // addVOR checks for duplicates } } } diff --git a/plugins/feature/vorlocalizer/vorlocalizergui.h b/plugins/feature/vorlocalizer/vorlocalizergui.h index 3c7695fbf..b9d29cb98 100644 --- a/plugins/feature/vorlocalizer/vorlocalizergui.h +++ b/plugins/feature/vorlocalizer/vorlocalizergui.h @@ -101,12 +101,15 @@ public: } Q_INVOKABLE void addVOR(NavAid *vor) { - beginInsertRows(QModelIndex(), rowCount(), rowCount()); - m_vors.append(vor); - m_selected.append(false); - m_radials.append(-1.0f); - m_vorGUIs.append(nullptr); - endInsertRows(); + if (!m_vors.contains(vor)) + { + beginInsertRows(QModelIndex(), rowCount(), rowCount()); + m_vors.append(vor); + m_selected.append(false); + m_radials.append(-1.0f); + m_vorGUIs.append(nullptr); + endInsertRows(); + } } int rowCount(const QModelIndex &parent = QModelIndex()) const override { @@ -123,7 +126,8 @@ public: return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable; } - void allVORUpdated() { + void allVORUpdated() + { for (int i = 0; i < m_vors.count(); i++) { QModelIndex idx = index(i); @@ -131,7 +135,8 @@ public: } } - void removeVOR(NavAid *vor) { + void removeVOR(NavAid *vor) + { int row = m_vors.indexOf(vor); if (row >= 0) { @@ -144,7 +149,8 @@ public: } } - void removeAllVORs() { + void removeAllVORs() + { if (m_vors.count() > 0) { beginRemoveRows(QModelIndex(), 0, m_vors.count() - 1); @@ -156,6 +162,18 @@ public: } } + void removeAllExceptSelected() + { + for (int i = 0; i < m_vors.count(); i++) + { + if (!m_selected[i]) + { + removeVOR(m_vors[i]); + i--; + } + } + } + QHash roleNames() const { QHash roles; roles[positionRole] = "position";