From 5091a6be2be49e57f0908f4226fa9133de615d33 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Mon, 29 Oct 2018 02:58:01 +0100 Subject: [PATCH] Ref T412, Ref T407, Ref T227, update aircraft UI if aircraft was moved --- src/blackgui/components/aircraftcomponent.cpp | 26 ++++++++++++++----- src/blackgui/components/aircraftcomponent.h | 7 +++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/blackgui/components/aircraftcomponent.cpp b/src/blackgui/components/aircraftcomponent.cpp index f1196afd3..886ce5955 100644 --- a/src/blackgui/components/aircraftcomponent.cpp +++ b/src/blackgui/components/aircraftcomponent.cpp @@ -17,6 +17,7 @@ #include "blackgui/views/viewbase.h" #include "blackcore/context/contextnetwork.h" #include "blackcore/context/contextsimulator.h" +#include "blackcore/context/contextownaircraft.h" #include "blackcore/network.h" #include "blackmisc/network/server.h" #include "blackmisc/network/fsdsetup.h" @@ -46,18 +47,23 @@ namespace BlackGui ui(new Ui::CAircraftComponent) { ui->setupUi(this); + + Q_ASSERT(sGui->getIContextNetwork()); + Q_ASSERT(sGui->getIContextSimulator()); + Q_ASSERT(sGui->getIContextOwnAircraft()); + this->setCurrentIndex(0); this->tabBar()->setExpanding(false); this->tabBar()->setUsesScrollButtons(true); ui->tvp_AirportsInRange->setResizeMode(CAirportView::ResizingOnce); - ui->tvp_AircraftInRange->setAircraftMode(CSimulatedAircraftListModel::NetworkMode); ui->tvp_AircraftInRange->configureMenu(true, false, true, true); connect(ui->tvp_AircraftInRange, &CSimulatedAircraftView::modelDataChangedDigest, this, &CAircraftComponent::onRowCountChanged); connect(ui->tvp_AircraftInRange, &CSimulatedAircraftView::requestTextMessageWidget, this, &CAircraftComponent::requestTextMessageWidget); connect(ui->tvp_AirportsInRange, &CSimulatedAircraftView::modelDataChangedDigest, this, &CAircraftComponent::onRowCountChanged); - connect(sGui->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CAircraftComponent::onConnectionStatusChanged); + connect(sGui->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CAircraftComponent::onConnectionStatusChanged, Qt::QueuedConnection); + connect(sGui->getIContextOwnAircraft(), &IContextOwnAircraft::movedAircraft, this, &CAircraftComponent::onOwnAircraftMoved, Qt::QueuedConnection); connect(&m_updateTimer, &QTimer::timeout, this, &CAircraftComponent::update); this->onSettingsChanged(); @@ -92,10 +98,6 @@ namespace BlackGui { if (!sGui || sGui->isShuttingDown()) { return; } - Q_ASSERT(ui->tvp_AircraftInRange); - Q_ASSERT(sGui->getIContextNetwork()); - Q_ASSERT(sGui->getIContextSimulator()); - // count < 1 checks if view already has been updated if (sGui->getIContextNetwork()->isConnected()) { @@ -124,6 +126,13 @@ namespace BlackGui this->setCurrentIndex(tabIndex); } + void CAircraftComponent::updateViews() + { + if (!sGui || sGui->isShuttingDown() || !sGui->getIContextNetwork() || !sGui->getIContextSimulator()) { return; } + ui->tvp_AircraftInRange->updateContainerMaybeAsync(sGui->getIContextNetwork()->getAircraftInRange()); + ui->tvp_AirportsInRange->updateContainerMaybeAsync(sGui->getIContextSimulator()->getAirportsInRange(true)); + } + void CAircraftComponent::onInfoAreaTabBarChanged(int index) { // ignore in those cases @@ -179,5 +188,10 @@ namespace BlackGui const int ms = settings.getAircraftUpdateTime().toMs(); m_updateTimer.setInterval(ms); } + + void CAircraftComponent::onOwnAircraftMoved() + { + this->updateViews(); + } } // namespace } // namespace diff --git a/src/blackgui/components/aircraftcomponent.h b/src/blackgui/components/aircraftcomponent.h index 77d2f31e6..f5fd28d43 100644 --- a/src/blackgui/components/aircraftcomponent.h +++ b/src/blackgui/components/aircraftcomponent.h @@ -32,6 +32,7 @@ namespace Ui { class CAircraftComponent; } namespace BlackGui { class CDockWidgetInfoArea; + namespace Components { //! Aircraft widget @@ -76,6 +77,9 @@ namespace BlackGui void requestTextMessageWidget(const BlackMisc::Aviation::CCallsign &callsign); private: + //! Update the views + void updateViews(); + //! Info area tab bar has changed void onInfoAreaTabBarChanged(int index); @@ -88,6 +92,9 @@ namespace BlackGui //! Settings have been changed void onSettingsChanged(); + //! Own aircraft has been moved + void onOwnAircraftMoved(); + QScopedPointer ui; BlackMisc::CSettingReadOnly m_settings { this, &CAircraftComponent::onSettingsChanged }; //!< settings changed QTimer m_updateTimer;