From f1ac4deda6b24b0805c3d073828bebae8056b896 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 28 May 2014 13:14:56 +0200 Subject: [PATCH] refs #253, faster updates of ATC stations by changedAtcStationConnectionStatus(const --- src/blackgui/atcstationcomponent.cpp | 8 ++++++++ src/blackgui/atcstationcomponent.h | 13 +++++++++---- src/blackgui/atcstationlistmodel.cpp | 22 ++++++++++++++++++++++ src/blackgui/atcstationlistmodel.h | 4 ++++ src/blackgui/atcstationview.cpp | 7 +++++++ src/blackgui/atcstationview.h | 5 +++++ 6 files changed, 55 insertions(+), 4 deletions(-) diff --git a/src/blackgui/atcstationcomponent.cpp b/src/blackgui/atcstationcomponent.cpp index ba434e861..20c39fa29 100644 --- a/src/blackgui/atcstationcomponent.cpp +++ b/src/blackgui/atcstationcomponent.cpp @@ -37,6 +37,7 @@ namespace BlackGui Q_ASSERT(this->getIContextNetwork()); this->connect(this->getIContextNetwork(), &IContextNetwork::changedAtcStationsOnline, this, &CAtcStationComponent::changedAtcStationsOnline); this->connect(this->getIContextNetwork(), &IContextNetwork::changedAtcStationsBooked, this, &CAtcStationComponent::changedAtcStationsBooked); + this->connect(this->getIContextNetwork(), &IContextNetwork::changedAtcStationOnlineConnectionStatus, this, &CAtcStationComponent::changedAtcStationOnlineConnectionStatus); } void CAtcStationComponent::update() @@ -79,9 +80,16 @@ namespace BlackGui void CAtcStationComponent::changedAtcStationsOnline() { + // just update timestamp, data will be pulled by time + // the timestamp will tell if there are newer data this->m_timestampOnlineStationsChanged = QDateTime::currentDateTimeUtc(); } + void CAtcStationComponent::changedAtcStationOnlineConnectionStatus(const CAtcStation &station, bool added) + { + this->ui->tvp_AtcStationsOnline->changedAtcStationConnectionStatus(station, added); + } + void CAtcStationComponent::changedAtcStationsBooked() { this->reloadAtcStationsBooked(); diff --git a/src/blackgui/atcstationcomponent.h b/src/blackgui/atcstationcomponent.h index d9d646684..59382e263 100644 --- a/src/blackgui/atcstationcomponent.h +++ b/src/blackgui/atcstationcomponent.h @@ -3,6 +3,8 @@ #include "blackgui/runtimebasedcomponent.h" #include "blackgui/timerbasedcomponent.h" +#include "blackmisc/avatcstation.h" + #include #include @@ -27,10 +29,6 @@ namespace BlackGui //! Timer for updating CTimerBasedComponent *getTimerComponent() { return this->m_timerComponent; } - protected: - //! \copydoc CRuntimeBasedComponent::runtimeHasBeenSet - void runtimeHasBeenSet() override; - public slots: //! Update users void update(); @@ -47,6 +45,13 @@ namespace BlackGui //! Get METAR for given ICAO airport code void getMetar(const QString &airportIcaoCode = ""); + //! \copydoc CAtcStationListModel::changedAtcStationConnectionStatus + void changedAtcStationOnlineConnectionStatus(const BlackMisc::Aviation::CAtcStation &station, bool added); + + protected: + //! \copydoc CRuntimeBasedComponent::runtimeHasBeenSet + void runtimeHasBeenSet() override; + private slots: //! Request new ATIS diff --git a/src/blackgui/atcstationlistmodel.cpp b/src/blackgui/atcstationlistmodel.cpp index 8f5b60fe0..67bb6370e 100644 --- a/src/blackgui/atcstationlistmodel.cpp +++ b/src/blackgui/atcstationlistmodel.cpp @@ -68,4 +68,26 @@ namespace BlackGui break; } } + + void CAtcStationListModel::changedAtcStationConnectionStatus(const CAtcStation &station, bool added) + { + if (station.getCallsign().isEmpty()) return; + if (added) + { + if (this->m_container.contains(&CAtcStation::getCallsign, station.getCallsign())) + { + this->m_container.replaceIf(&CAtcStation::getCallsign, station.getCallsign(), station); + } + else + { + this->insert(station); + } + } + else + { + beginRemoveRows(QModelIndex(), 0, 0); + this->m_container.removeIf(&CAtcStation::getCallsign, station.getCallsign()); + endRemoveRows(); + } + } } diff --git a/src/blackgui/atcstationlistmodel.h b/src/blackgui/atcstationlistmodel.h index 491a1475f..5894342d6 100644 --- a/src/blackgui/atcstationlistmodel.h +++ b/src/blackgui/atcstationlistmodel.h @@ -41,6 +41,10 @@ namespace BlackGui //! Set station mode void setStationMode(AtcStationMode stationMode); + public slots: + //! Used to quickly update single station (better response for the user) + void changedAtcStationConnectionStatus(const BlackMisc::Aviation::CAtcStation &station, bool added); + private: AtcStationMode m_stationMode; }; diff --git a/src/blackgui/atcstationview.cpp b/src/blackgui/atcstationview.cpp index 8fccb2e2b..745ccd3be 100644 --- a/src/blackgui/atcstationview.cpp +++ b/src/blackgui/atcstationview.cpp @@ -21,4 +21,11 @@ namespace BlackGui Q_ASSERT(this->m_model); this->m_model->setStationMode(stationMode); } + + void CAtcStationView::changedAtcStationConnectionStatus(const Aviation::CAtcStation &station, bool added) + { + this->m_model->changedAtcStationConnectionStatus(station, added); + this->resizeColumnsToContents(); + this->resizeRowsToContents(); + } } diff --git a/src/blackgui/atcstationview.h b/src/blackgui/atcstationview.h index 465033e31..ec0de08d0 100644 --- a/src/blackgui/atcstationview.h +++ b/src/blackgui/atcstationview.h @@ -19,6 +19,11 @@ namespace BlackGui //! Set station mode void setStationMode(CAtcStationListModel::AtcStationMode stationMode); + + public slots: + //! \copydoc CAtcStationListModel::changedAtcStationConnectionStatus + void changedAtcStationConnectionStatus(const BlackMisc::Aviation::CAtcStation &station, bool added); + }; } #endif // guard