diff --git a/src/blackgui/components/atcstationcomponent.cpp b/src/blackgui/components/atcstationcomponent.cpp index e6b425b76..3f022cc97 100644 --- a/src/blackgui/components/atcstationcomponent.cpp +++ b/src/blackgui/components/atcstationcomponent.cpp @@ -241,10 +241,21 @@ namespace BlackGui ui->tvp_AtcStationsOnline->showOverlayHTMLMessage(msg, 5000); ui->tvp_AtcStationsOnlineTree->showOverlayHTMLMessage(msg, 5000); } + + if (stationsCount < 1) + { + m_selectedCallsign.clear(); + } + else if (!m_selectedCallsign.isEmpty() && onlineStations.containsCallsign(m_selectedCallsign)) + { + const CAtcStation lastSelected = onlineStations.findFirstByCallsign(m_selectedCallsign); + this->triggerOnlineAtcStationSelected(lastSelected); + } } } else { + m_selectedCallsign.clear(); ui->tvp_AtcStationsOnline->clear(); this->updateTreeView(); } @@ -444,6 +455,16 @@ namespace BlackGui this->onOnlineAtcStationSelected(station); } + void CAtcStationComponent::triggerOnlineAtcStationSelected(const CAtcStation &station) + { + // pass copy, not reference -> can crash + QPointer myself(this); + QTimer::singleShot(500, this, [ = ] + { + if (myself) { myself->onOnlineAtcStationSelected(station); } + }); + } + void CAtcStationComponent::onOnlineAtcStationSelected(const CAtcStation &station) { if (!station.hasCallsign()) { return; } @@ -452,6 +473,7 @@ namespace BlackGui (station.hasAtis() ? u"\n\n" % station.getAtis().getMessage() : QStringLiteral("")) % (station.hasMetar() ? u"\n\n" % station.getMetar().getMessage() : QStringLiteral("")); ui->te_AtcStationsOnlineInfo->setText(infoMessage); + m_selectedCallsign = station.getCallsign(); } void CAtcStationComponent::atcStationsTabChanged() @@ -491,6 +513,7 @@ namespace BlackGui { ui->tvp_AtcStationsOnline->clear(); ui->tvp_AtcStationsOnlineTree->clear(); + m_selectedCallsign.clear(); } void CAtcStationComponent::showOverlayInlineTextMessage() diff --git a/src/blackgui/components/atcstationcomponent.h b/src/blackgui/components/atcstationcomponent.h index e18685466..d002d8523 100644 --- a/src/blackgui/components/atcstationcomponent.h +++ b/src/blackgui/components/atcstationcomponent.h @@ -99,12 +99,15 @@ namespace BlackGui //! Request new ATIS void requestAtisUpdates(); - //! A tree view station has been selected + //! A station has been selected void onOnlineAtcStationSelected(const BlackMisc::Aviation::CAtcStation &station); //! Online ATC station selected void onOnlineAtcStationVariantSelected(const BlackMisc::CVariant &object); + //! Trigger a selection of an onlie station (async) + void triggerOnlineAtcStationSelected(const BlackMisc::Aviation::CAtcStation &station); + //! Tab changed void atcStationsTabChanged(); @@ -168,6 +171,7 @@ namespace BlackGui QScopedPointer ui; QTimer m_updateTimer; QList m_stretch; + BlackMisc::Aviation::CCallsign m_selectedCallsign; QDateTime m_timestampLastReadOnlineStations; //!< stations read QDateTime m_timestampOnlineStationsChanged; //!< stations marked as changed QDateTime m_timestampLastReadBookedStations; //!< stations read diff --git a/src/blackmisc/aviation/atcstationlist.cpp b/src/blackmisc/aviation/atcstationlist.cpp index 9f5d6eb39..04119f3ae 100644 --- a/src/blackmisc/aviation/atcstationlist.cpp +++ b/src/blackmisc/aviation/atcstationlist.cpp @@ -58,7 +58,7 @@ namespace BlackMisc bool CAtcStationList::updateIfMessageChanged(const CInformationMessage &im, const CCallsign &callsign, bool overrideWithNewer) { - const CInformationMessage::InformationType t = im.getType(); + const CInformationMessage::InformationType type = im.getType(); // for loop just to get reference bool unequal = false; @@ -66,7 +66,7 @@ namespace BlackMisc { if (station.getCallsign() != callsign) { continue; } - const CInformationMessage m = station.getInformationMessage(t); + const CInformationMessage m = station.getInformationMessage(type); if (m.getType() == CInformationMessage::Unspecified) { break; } if (m.getMessage() == im.getMessage())