1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-30 03:38:55 -05:00

Merge pull request #1619 from srcejon/fix_1590_update_vors

VOR Localizer: Fix updateVORs so it doesn't delete selected VORs.
This commit is contained in:
Edouard Griffiths 2023-03-06 23:41:59 +01:00 committed by GitHub
commit 15205076ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 11 deletions

View File

@ -496,7 +496,7 @@ void VORLocalizerGUI::selectVOR(VORGUI *vorGUI, bool selected)
void VORLocalizerGUI::updateVORs() void VORLocalizerGUI::updateVORs()
{ {
m_vorModel.removeAllVORs(); m_vorModel.removeAllExceptSelected();
AzEl azEl = m_azEl; AzEl azEl = m_azEl;
for (const auto vor : *m_vors) for (const auto vor : *m_vors)
@ -509,7 +509,7 @@ void VORLocalizerGUI::updateVORs()
// Only display VOR if in range // Only display VOR if in range
if (azEl.getDistance() <= 200000) { if (azEl.getDistance() <= 200000) {
m_vorModel.addVOR(vor); m_vorModel.addVOR(vor); // addVOR checks for duplicates
} }
} }
} }

View File

@ -101,12 +101,15 @@ public:
} }
Q_INVOKABLE void addVOR(NavAid *vor) { Q_INVOKABLE void addVOR(NavAid *vor) {
beginInsertRows(QModelIndex(), rowCount(), rowCount()); if (!m_vors.contains(vor))
m_vors.append(vor); {
m_selected.append(false); beginInsertRows(QModelIndex(), rowCount(), rowCount());
m_radials.append(-1.0f); m_vors.append(vor);
m_vorGUIs.append(nullptr); m_selected.append(false);
endInsertRows(); m_radials.append(-1.0f);
m_vorGUIs.append(nullptr);
endInsertRows();
}
} }
int rowCount(const QModelIndex &parent = QModelIndex()) const override { int rowCount(const QModelIndex &parent = QModelIndex()) const override {
@ -123,7 +126,8 @@ public:
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable; return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
} }
void allVORUpdated() { void allVORUpdated()
{
for (int i = 0; i < m_vors.count(); i++) for (int i = 0; i < m_vors.count(); i++)
{ {
QModelIndex idx = index(i); QModelIndex idx = index(i);
@ -131,7 +135,8 @@ public:
} }
} }
void removeVOR(NavAid *vor) { void removeVOR(NavAid *vor)
{
int row = m_vors.indexOf(vor); int row = m_vors.indexOf(vor);
if (row >= 0) if (row >= 0)
{ {
@ -144,7 +149,8 @@ public:
} }
} }
void removeAllVORs() { void removeAllVORs()
{
if (m_vors.count() > 0) if (m_vors.count() > 0)
{ {
beginRemoveRows(QModelIndex(), 0, m_vors.count() - 1); 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<int, QByteArray> roleNames() const { QHash<int, QByteArray> roleNames() const {
QHash<int, QByteArray> roles; QHash<int, QByteArray> roles;
roles[positionRole] = "position"; roles[positionRole] = "position";