Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VOR Localizer: Fix updateVORs so it doesn't delete selected VORs. #1619

Merged
merged 1 commit into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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