From 59e409b0fbd44b81594452579a6cb487e7ecff10 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 16 Sep 2014 22:18:49 +0200 Subject: [PATCH] refs #325, reduced loading in aircraft component --- src/blackgui/components/aircraftcomponent.cpp | 54 +++++++++++++++++-- src/blackgui/components/aircraftcomponent.h | 20 ++++++- 2 files changed, 69 insertions(+), 5 deletions(-) diff --git a/src/blackgui/components/aircraftcomponent.cpp b/src/blackgui/components/aircraftcomponent.cpp index 6738990ec..63e709c5c 100644 --- a/src/blackgui/components/aircraftcomponent.cpp +++ b/src/blackgui/components/aircraftcomponent.cpp @@ -8,6 +8,7 @@ */ #include "aircraftcomponent.h" +#include "dockwidgetinfoareacomponent.h" #include "ui_aircraftcomponent.h" namespace BlackGui @@ -30,6 +31,18 @@ namespace BlackGui delete ui; } + int CAircraftComponent::countAircrafts() const + { + Q_ASSERT(this->ui->tvp_AircraftsInRange); + return this->ui->tvp_AircraftsInRange->rowCount(); + } + + int CAircraftComponent::countAirportsInRange() const + { + Q_ASSERT(this->ui->tvp_AirportsInRange); + return this->ui->tvp_AirportsInRange->rowCount(); + } + void CAircraftComponent::update() { Q_ASSERT(this->ui->tvp_AircraftsInRange); @@ -38,12 +51,45 @@ namespace BlackGui if (this->getIContextNetwork()->isConnected()) { - this->ui->tvp_AircraftsInRange->updateContainer(this->getIContextNetwork()->getAircraftsInRange()); + if (this->countAircrafts() < 1 || this->isVisibleWidget()) + { + this->ui->tvp_AircraftsInRange->updateContainer(this->getIContextNetwork()->getAircraftsInRange()); + } + else + { + // KWB remove: qDebug() will be removed soo + qDebug() << this->objectName() << "Skipping update (aircrafts)"; + } } if (this->getIContextSimulator()->isConnected()) { - this->ui->tvp_AirportsInRange->updateContainer(this->getIContextSimulator()->getAirportsInRange()); + if (this->countAirportsInRange() < 1 || this->isVisibleWidget()) + { + this->ui->tvp_AirportsInRange->updateContainer(this->getIContextSimulator()->getAirportsInRange()); + } + else + { + qDebug() << this->objectName() << "Skipping update (airports)"; + } } } - } -} + + void CAircraftComponent::runtimeHasBeenSet() + { + connect(this->getParentInfoArea(), &CInfoArea::tabBarCurrentChanged, this, &CAircraftComponent::ps_infoAreaTabBarChanged); + } + + void CAircraftComponent::ps_infoAreaTabBarChanged(int index) + { + // ignore in those cases + if (!this->isVisibleWidget()) return; + if (this->isParentDockWidgetFloating()) return; + if (!this->getIContextNetwork()->isConnected()) return; + + // here I know I am the selected widget, update, but keep GUI responsive (hence + QTimer::singleShot(1000, this, SLOT(update())); + Q_UNUSED(index); + } + + } // namespace +} // namespace diff --git a/src/blackgui/components/aircraftcomponent.h b/src/blackgui/components/aircraftcomponent.h index 8dbd02753..50a4d2c50 100644 --- a/src/blackgui/components/aircraftcomponent.h +++ b/src/blackgui/components/aircraftcomponent.h @@ -14,6 +14,7 @@ #include "blackgui/components/runtimebasedcomponent.h" #include "blackgui/components/timerbasedcomponent.h" +#include "blackgui/components/dockwidgetinfoareacomponent.h" #include "blackmisc/avaircraft.h" #include @@ -24,7 +25,10 @@ namespace BlackGui namespace Components { //! Aircraft widget - class CAircraftComponent : public QTabWidget, public CRuntimeBasedComponent + class CAircraftComponent : + public QTabWidget, + public CDockWidgetInfoAreaComponent, + public CRuntimeBasedComponent { Q_OBJECT @@ -38,6 +42,12 @@ namespace BlackGui //! Timer for updating CTimerBasedComponent *getTimerComponent() { return this->m_timerComponent; } + //! Aircrafts in range + int countAircrafts() const; + + //! Airports in range + int countAirportsInRange() const; + public slots: //! Update users void update(); @@ -51,6 +61,14 @@ namespace BlackGui //! \copydoc CTimerBasedComponent::stopTimer void stopTimer() { Q_ASSERT(this->m_timerComponent); this->m_timerComponent->stopTimer(); } + protected: + //! \copydoc CRuntimeBasedComponent::runtimeHasBeenSet + void runtimeHasBeenSet() override; + + private slots: + //! Info area tab bar has changed + void ps_infoAreaTabBarChanged(int index); + private: Ui::CAircraftComponent *ui; CTimerBasedComponent *m_timerComponent;