Skip to content

Commit

Permalink
Merge pull request #1619 from srcejon/fix_1590_update_vors
Browse files Browse the repository at this point in the history
VOR Localizer: Fix updateVORs so it doesn't delete selected VORs.
  • Loading branch information
f4exb authored Mar 6, 2023
2 parents e1947d3 + e930cf3 commit 1520507
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
4 changes: 2 additions & 2 deletions plugins/feature/vorlocalizer/vorlocalizergui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
}
}
}
Expand Down
36 changes: 27 additions & 9 deletions plugins/feature/vorlocalizer/vorlocalizergui.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,15 @@ class VORModel : public QAbstractListModel {
}

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 {
Expand All @@ -123,15 +126,17 @@ class VORModel : public QAbstractListModel {
return Qt::ItemIsEnabled | Qt::ItemIsSelectable | Qt::ItemIsEditable;
}

void allVORUpdated() {
void allVORUpdated()
{
for (int i = 0; i < m_vors.count(); i++)
{
QModelIndex idx = index(i);
emit dataChanged(idx, idx);
}
}

void removeVOR(NavAid *vor) {
void removeVOR(NavAid *vor)
{
int row = m_vors.indexOf(vor);
if (row >= 0)
{
Expand All @@ -144,7 +149,8 @@ class VORModel : public QAbstractListModel {
}
}

void removeAllVORs() {
void removeAllVORs()
{
if (m_vors.count() > 0)
{
beginRemoveRows(QModelIndex(), 0, m_vors.count() - 1);
Expand All @@ -156,6 +162,18 @@ class VORModel : public QAbstractListModel {
}
}

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> roles;
roles[positionRole] = "position";
Expand Down

0 comments on commit 1520507

Please sign in to comment.