diff --git a/src/blackgui/components/atcstationcomponent.cpp b/src/blackgui/components/atcstationcomponent.cpp index f2991a1f0..07a07fbe1 100644 --- a/src/blackgui/components/atcstationcomponent.cpp +++ b/src/blackgui/components/atcstationcomponent.cpp @@ -99,15 +99,18 @@ namespace BlackGui connect(ui->tb_Audio, &QPushButton::clicked, this, &CAtcStationComponent::requestAudioWidget); connect(ui->tb_TextMessageOverlay, &QPushButton::clicked, this, &CAtcStationComponent::showOverlayInlineTextMessage); connect(ui->tw_Atc, &QTabWidget::currentChanged, this, &CAtcStationComponent::atcStationsTabChanged); // "local" tab changed (booked, online) - connect(ui->tvp_AtcStationsOnline, &CAtcStationView::objectClicked, this, &CAtcStationComponent::onlineAtcStationSelected); - connect(ui->tvp_AtcStationsOnline, &CAtcStationView::objectSelected, this, &CAtcStationComponent::onlineAtcStationSelected); + + connect(ui->tvp_AtcStationsOnline, &CAtcStationView::objectClicked, this, &CAtcStationComponent::onOnlineAtcStationVariantSelected, Qt::QueuedConnection); + connect(ui->tvp_AtcStationsOnline, &CAtcStationView::objectSelected, this, &CAtcStationComponent::onOnlineAtcStationVariantSelected, Qt::QueuedConnection); connect(ui->tvp_AtcStationsOnline, &CAtcStationView::testRequestDummyAtcOnlineStations, this, &CAtcStationComponent::testCreateDummyOnlineAtcStations); connect(ui->tvp_AtcStationsOnline, &CAtcStationView::requestUpdate, this, &CAtcStationComponent::requestOnlineStationsUpdate); connect(ui->tvp_AtcStationsOnline, &CAtcStationView::requestNewBackendData, this, &CAtcStationComponent::requestOnlineStationsUpdate); connect(ui->tvp_AtcStationsOnline, &CAtcStationView::modelDataChangedDigest, this, &CAtcStationComponent::onCountChanged); connect(ui->tvp_AtcStationsOnline, &CAtcStationView::requestComFrequency, this, &CAtcStationComponent::setComFrequency); connect(ui->tvp_AtcStationsOnline, &CAtcStationView::requestTextMessageWidget, this, &CAtcStationComponent::requestTextMessageWidget); + connect(ui->tvp_AtcStationsOnlineTree, &CAtcStationTreeView::requestComFrequency, this, &CAtcStationComponent::setComFrequency); + connect(ui->tvp_AtcStationsOnlineTree, &CAtcStationTreeView::objectSelected, this, &CAtcStationComponent::onOnlineAtcStationSelected, Qt::QueuedConnection); connect(ui->tvp_AtcStationsOnlineTree, &CAtcStationTreeView::requestTextMessageWidget, this, &CAtcStationComponent::requestTextMessageWidget); connect(ui->comp_AtcStationsSettings, &CSettingsAtcStationsInlineComponent::changed, this, &CAtcStationComponent::forceUpdate, Qt::QueuedConnection); @@ -116,7 +119,7 @@ namespace BlackGui connect(ui->tvp_AtcStationsBooked, &CAtcStationView::requestNewBackendData, this, &CAtcStationComponent::reloadAtcStationsBooked); connect(ui->tvp_AtcStationsBooked, &CAtcStationView::modelDataChangedDigest, this, &CAtcStationComponent::onCountChanged); - connect(ui->tb_AtcStationsAtisReload, &QPushButton::clicked, this, &CAtcStationComponent::requestAtis); + connect(ui->tb_AtcStationsAtisReload, &QPushButton::clicked, this, &CAtcStationComponent::requestAtisUpdates); connect(&m_updateTimer, &QTimer::timeout, this, &CAtcStationComponent::update); // Group box @@ -153,7 +156,7 @@ namespace BlackGui CAtcStationComponent::~CAtcStationComponent() { } - void CAtcStationComponent::setTab(CAtcStationComponent::AtcTab tab) + void CAtcStationComponent::setTab(AtcTab tab) { const int t = static_cast(tab); ui->tw_Atc->setCurrentIndex(t); @@ -433,22 +436,21 @@ namespace BlackGui } } - void CAtcStationComponent::onlineAtcStationSelected(const CVariant &object) + void CAtcStationComponent::onOnlineAtcStationVariantSelected(const CVariant &object) { ui->te_AtcStationsOnlineInfo->setText(""); // reset if (!object.isValid() || !object.canConvert()) { return; } - const CAtcStation stationClicked = object.valueOrDefault(CAtcStation()); - QString infoMessage; + const CAtcStation station = object.valueOrDefault(CAtcStation()); + this->onOnlineAtcStationSelected(station); + } - if (stationClicked.hasAtis()) - { - infoMessage.append(stationClicked.getAtis().getMessage()); - } - if (stationClicked.hasMetar()) - { - if (!infoMessage.isEmpty()) { infoMessage.append("\n\n"); } - infoMessage.append(stationClicked.getMetar().getMessage()); - } + void CAtcStationComponent::onOnlineAtcStationSelected(const CAtcStation &station) + { + if (!station.hasCallsign()) { return; } + const QString infoMessage = + station.getCallsignAsString() % u": " % station.getFrequency().valueRoundedWithUnit(CFrequencyUnit::MHz(), 3) % + (station.hasAtis() ? u"\n\n" % station.getAtis().getMessage() : QStringLiteral("")) % + (station.hasMetar() ? u"\n\n" % station.getMetar().getMessage() : QStringLiteral("")); ui->te_AtcStationsOnlineInfo->setText(infoMessage); } @@ -465,10 +467,18 @@ namespace BlackGui ui->gb_Details->setVisible(!booked); } - void CAtcStationComponent::requestAtis() + void CAtcStationComponent::requestAtisUpdates() { - if (!this->canAccessContext()) return; + if (!this->canAccessContext()) { return; } sGui->getIContextNetwork()->requestAtisUpdates(); + if (ui->tw_Atc->currentIndex() == TabAtcOnline) + { + ui->tvp_AtcStationsOnline->showOverlayHTMLMessage("Requested ATIS update", 5000); + } + else + { + ui->tvp_AtcStationsOnlineTree->showOverlayHTMLMessage("Requested ATIS update", 5000); + } } bool CAtcStationComponent::canAccessContext() const diff --git a/src/blackgui/components/atcstationcomponent.h b/src/blackgui/components/atcstationcomponent.h index d91ca52db..ebc892477 100644 --- a/src/blackgui/components/atcstationcomponent.h +++ b/src/blackgui/components/atcstationcomponent.h @@ -98,10 +98,13 @@ namespace BlackGui void getMetarAsEntered(); //! Request new ATIS - void requestAtis(); + void requestAtisUpdates(); + + //! A tree view station has been selected + void onOnlineAtcStationSelected(const BlackMisc::Aviation::CAtcStation &station); //! Online ATC station selected - void onlineAtcStationSelected(const BlackMisc::CVariant &object); + void onOnlineAtcStationVariantSelected(const BlackMisc::CVariant &object); //! Tab changed void atcStationsTabChanged(); diff --git a/src/blackgui/views/atcstationtreeview.cpp b/src/blackgui/views/atcstationtreeview.cpp index 731355b7c..527a98f8f 100644 --- a/src/blackgui/views/atcstationtreeview.cpp +++ b/src/blackgui/views/atcstationtreeview.cpp @@ -34,7 +34,8 @@ namespace BlackGui this->setModel(new CAtcStationTreeModel(this)); this->setContextMenuPolicy(Qt::CustomContextMenu); connect(this, &CAtcStationTreeView::customContextMenuRequested, this, &CAtcStationTreeView::customMenu); - connect(this, &CAtcStationTreeView::expanded, this, &CAtcStationTreeView::onExpanded); + connect(this, &CAtcStationTreeView::expanded, this, &CAtcStationTreeView::onExpanded, Qt::QueuedConnection); + connect(this->selectionModel(), &QItemSelectionModel::selectionChanged, this, &CAtcStationTreeView::onSelected, Qt::QueuedConnection); } void CAtcStationTreeView::changedAtcStationConnectionStatus(const CAtcStation &station, bool added) @@ -94,6 +95,11 @@ namespace BlackGui CAtcStation CAtcStationTreeView::selectedObject() const { const QModelIndex index = this->currentIndex(); + return this->selectedObject(index); + } + + CAtcStation CAtcStationTreeView::selectedObject(const QModelIndex &index) const + { const QVariant data = this->model()->data(index.siblingAtColumn(0)); // supposed to be the callsign const QString callsign = data.toString(); const CAtcStationTreeModel *model = this->stationModel(); @@ -113,6 +119,15 @@ namespace BlackGui this->fullResizeToContents(); } + void CAtcStationTreeView::onSelected(const QItemSelection &selected, const QItemSelection &deselected) + { + Q_UNUSED(deselected); + if (selected.isEmpty()) { return; } + const CAtcStation atcStation = this->selectedObject(selected.indexes().front()); + if (!atcStation.hasCallsign()) { return; } + emit this->objectSelected(atcStation); + } + void CAtcStationTreeView::customMenu(const QPoint &point) { if (!this->stationModel()) { return; } diff --git a/src/blackgui/views/atcstationtreeview.h b/src/blackgui/views/atcstationtreeview.h index b3d7f9f84..e251751a4 100644 --- a/src/blackgui/views/atcstationtreeview.h +++ b/src/blackgui/views/atcstationtreeview.h @@ -73,6 +73,9 @@ namespace BlackGui //! Request a text message to void requestTextMessageWidget(const BlackMisc::Aviation::CCallsign &callsign); + //! This object has been selected + void objectSelected(const BlackMisc::Aviation::CAtcStation &station); + private: //! Used model const Models::CAtcStationTreeModel *stationModel() const; @@ -86,12 +89,18 @@ namespace BlackGui //! The selected object BlackMisc::Aviation::CAtcStation selectedObject() const; + //! The selected object + BlackMisc::Aviation::CAtcStation selectedObject(const QModelIndex &index) const; + //! Suffix for index QString suffixForIndex(const QModelIndex &index); //! Expanded void onExpanded(const QModelIndex &index); + //! Selected + void onSelected(const QItemSelection &selected, const QItemSelection &deselected); + //! Custom menu void customMenu(const QPoint &point); diff --git a/src/blackmisc/aviation/atcstation.h b/src/blackmisc/aviation/atcstation.h index 08d7f60b2..99be768a9 100644 --- a/src/blackmisc/aviation/atcstation.h +++ b/src/blackmisc/aviation/atcstation.h @@ -89,6 +89,9 @@ namespace BlackMisc //! Get callsign. const CCallsign &getCallsign() const { return m_callsign; } + //! Has callsign? + bool hasCallsign() const { return !m_callsign.isEmpty(); } + //! Get callsign as string. QString getCallsignAsString() const { return m_callsign.asString(); }