mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-06 01:45:38 +08:00
* discussion: https://dev.vatsim-germany.org/boards/22/topics/2027?r=2040#message-2040 * fixed bug with ATC station component, wrong signals for booked stations * booked stations loading to frequently (for each minor change such as online), changed to timestamp based concept * update booked stations with receiving ATIS/voiceroom to online * CDigestSignal class: new class and methods for collecting signals, avoiding too many signals - one of the cures for the performance issues * fixed bug found during testing, missing start for timers when connecting to network
This commit is contained in:
@@ -26,6 +26,9 @@ namespace BlackGui
|
||||
{
|
||||
ui->setupUi(this);
|
||||
this->m_timerComponent = new CTimerBasedComponent(SLOT(update()), this);
|
||||
|
||||
// set station mode
|
||||
this->ui->tvp_AtcStationsOnline->setStationMode(CAtcStationListModel::StationsOnline);
|
||||
this->ui->tvp_AtcStationsBooked->setStationMode(CAtcStationListModel::StationsBooked);
|
||||
|
||||
// Signal / Slots
|
||||
@@ -33,10 +36,10 @@ namespace BlackGui
|
||||
Q_ASSERT(connected);
|
||||
connected = this->connect(this->ui->pb_AtcStationsLoadMetar, SIGNAL(clicked()), this, SLOT(getMetar()));
|
||||
Q_ASSERT(connected);
|
||||
this->connect(this, &QTabWidget::currentChanged, this, &CAtcStationComponent::atcStationsTabChanged);
|
||||
this->connect(this->ui->tvp_AtcStationsOnline, &QTableView::clicked, this, &CAtcStationComponent::onlineAtcStationSelected);
|
||||
this->connect(this->ui->pb_AtcStationsAtisReload, &QPushButton::clicked, this, &CAtcStationComponent::requestAtis);
|
||||
this->connect(this->ui->pb_ReloadAtcStationsBooked, &QPushButton::clicked, this, &CAtcStationComponent::reloadAtcStationsBooked);
|
||||
this->connect(this, &QTabWidget::currentChanged, this, &CAtcStationComponent::ps_atcStationsTabChanged);
|
||||
this->connect(this->ui->tvp_AtcStationsOnline, &QTableView::clicked, this, &CAtcStationComponent::ps_onlineAtcStationSelected);
|
||||
this->connect(this->ui->pb_AtcStationsAtisReload, &QPushButton::clicked, this, &CAtcStationComponent::ps_requestAtis);
|
||||
this->connect(this->ui->pb_ReloadAtcStationsBooked, &QPushButton::clicked, this, &CAtcStationComponent::ps_reloadAtcStationsBooked);
|
||||
}
|
||||
|
||||
CAtcStationComponent::~CAtcStationComponent()
|
||||
@@ -50,10 +53,10 @@ namespace BlackGui
|
||||
Q_ASSERT(this->getIContextNetwork());
|
||||
if (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::changedAtcStationsOnlineDigest, this, &CAtcStationComponent::ps_changedAtcStationsOnline);
|
||||
this->connect(this->getIContextNetwork(), &IContextNetwork::changedAtcStationsBookedDigest, this, &CAtcStationComponent::ps_changedAtcStationsBooked);
|
||||
this->connect(this->getIContextNetwork(), &IContextNetwork::changedAtcStationOnlineConnectionStatus, this, &CAtcStationComponent::changedAtcStationOnlineConnectionStatus);
|
||||
this->connect(this->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CAtcStationComponent::connectionStatusChanged);
|
||||
this->connect(this->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CAtcStationComponent::ps_connectionStatusChanged);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,14 +66,17 @@ namespace BlackGui
|
||||
Q_ASSERT(this->ui->tvp_AtcStationsOnline);
|
||||
Q_ASSERT(this->getIContextNetwork());
|
||||
|
||||
// initial read for bookings
|
||||
if (this->ui->tvp_AtcStationsBooked->isEmpty()) this->reloadAtcStationsBooked();
|
||||
// bookings
|
||||
if (this->m_timestampBookedStationsChanged > this->m_timestampLastReadBookedStations)
|
||||
{
|
||||
this->ps_reloadAtcStationsBooked();
|
||||
}
|
||||
|
||||
// online stations, only when connected
|
||||
if (this->getIContextNetwork()->isConnected())
|
||||
{
|
||||
// update
|
||||
if (this->m_timestampOnlineStationsChanged.isNull() || this->m_timestampLastReadOnlineStations.isNull() ||
|
||||
(this->m_timestampOnlineStationsChanged > this->m_timestampLastReadOnlineStations))
|
||||
if (this->m_timestampOnlineStationsChanged > this->m_timestampLastReadOnlineStations)
|
||||
{
|
||||
this->ui->tvp_AtcStationsOnline->updateContainer(this->getIContextNetwork()->getAtcStationsOnline());
|
||||
this->m_timestampLastReadOnlineStations = QDateTime::currentDateTimeUtc();
|
||||
@@ -84,7 +90,7 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
void CAtcStationComponent::reloadAtcStationsBooked()
|
||||
void CAtcStationComponent::ps_reloadAtcStationsBooked()
|
||||
{
|
||||
Q_ASSERT(this->ui->tvp_AtcStationsBooked);
|
||||
Q_ASSERT(this->getIContextNetwork());
|
||||
@@ -92,8 +98,8 @@ namespace BlackGui
|
||||
QObject *sender = QObject::sender();
|
||||
if (sender == this->ui->pb_ReloadAtcStationsBooked && this->getIContextNetwork())
|
||||
{
|
||||
this->getIContextNetwork()->readAtcBookingsFromSource(); // trigger new read
|
||||
QTimer::singleShot(7500, this, SLOT(reloadAtcStationsBooked())); // deferred loading
|
||||
// trigger new read, which takes some time. A signal will be received when this is done
|
||||
this->getIContextNetwork()->readAtcBookingsFromSource();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -102,14 +108,23 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
void CAtcStationComponent::changedAtcStationsOnline()
|
||||
void CAtcStationComponent::ps_changedAtcStationsOnline()
|
||||
{
|
||||
// just update timestamp, data will be pulled by time
|
||||
// just update timestamp, data will be pulled by timer
|
||||
// the timestamp will tell if there are any newer data
|
||||
this->m_timestampOnlineStationsChanged = QDateTime::currentDateTimeUtc();
|
||||
}
|
||||
|
||||
void CAtcStationComponent::connectionStatusChanged(uint from, uint to, const QString &message)
|
||||
void CAtcStationComponent::ps_changedAtcStationsBooked()
|
||||
{
|
||||
// a change can mean a complete change of the bookings, or
|
||||
// a single value is updated (e.g. online status)
|
||||
// just update timestamp, data will be pulled by timer
|
||||
// the timestamp will tell if there are any newer data
|
||||
this->m_timestampBookedStationsChanged = QDateTime::currentDateTimeUtc();
|
||||
}
|
||||
|
||||
void CAtcStationComponent::ps_connectionStatusChanged(uint from, uint to, const QString &message)
|
||||
{
|
||||
INetwork::ConnectionStatus fromStatus = static_cast<INetwork::ConnectionStatus>(from);
|
||||
INetwork::ConnectionStatus toStatus = static_cast<INetwork::ConnectionStatus>(to);
|
||||
@@ -127,11 +142,6 @@ namespace BlackGui
|
||||
this->ui->tvp_AtcStationsOnline->changedAtcStationConnectionStatus(station, added);
|
||||
}
|
||||
|
||||
void CAtcStationComponent::changedAtcStationsBooked()
|
||||
{
|
||||
this->reloadAtcStationsBooked();
|
||||
}
|
||||
|
||||
void CAtcStationComponent::getMetar(const QString &airportIcaoCode)
|
||||
{
|
||||
if (!this->getIContextNetwork()->isConnected())
|
||||
@@ -154,7 +164,7 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
void CAtcStationComponent::onlineAtcStationSelected(QModelIndex index)
|
||||
void CAtcStationComponent::ps_onlineAtcStationSelected(QModelIndex index)
|
||||
{
|
||||
this->ui->te_AtcStationsOnlineInfo->setText(""); // reset
|
||||
const CAtcStation stationClicked = this->ui->tvp_AtcStationsOnline->derivedModel()->at(index);
|
||||
@@ -172,16 +182,16 @@ namespace BlackGui
|
||||
this->ui->te_AtcStationsOnlineInfo->setText(infoMessage);
|
||||
}
|
||||
|
||||
void CAtcStationComponent::atcStationsTabChanged()
|
||||
void CAtcStationComponent::ps_atcStationsTabChanged()
|
||||
{
|
||||
if (this->currentWidget() == this->ui->tb_AtcStationsOnline)
|
||||
{
|
||||
if (this->m_timestampLastReadBookedStations.isNull())
|
||||
this->reloadAtcStationsBooked();
|
||||
this->ps_reloadAtcStationsBooked();
|
||||
}
|
||||
}
|
||||
|
||||
void CAtcStationComponent::requestAtis()
|
||||
void CAtcStationComponent::ps_requestAtis()
|
||||
{
|
||||
if (!this->getIContextNetwork()->isConnected()) return;
|
||||
this->getIContextNetwork()->requestAtisUpdates();
|
||||
|
||||
@@ -68,32 +68,33 @@ namespace BlackGui
|
||||
private slots:
|
||||
|
||||
//! Request new ATIS
|
||||
void requestAtis();
|
||||
void ps_requestAtis();
|
||||
|
||||
//! Online ATC station selected
|
||||
void onlineAtcStationSelected(QModelIndex index);
|
||||
void ps_onlineAtcStationSelected(QModelIndex index);
|
||||
|
||||
//! Tab changed
|
||||
void atcStationsTabChanged();
|
||||
void ps_atcStationsTabChanged();
|
||||
|
||||
//! Booked stations
|
||||
void reloadAtcStationsBooked();
|
||||
//! Booked stations reloading
|
||||
void ps_reloadAtcStationsBooked();
|
||||
|
||||
//! Booked stations changed
|
||||
void changedAtcStationsBooked();
|
||||
void ps_changedAtcStationsBooked();
|
||||
|
||||
//! Online stations changed
|
||||
void changedAtcStationsOnline();
|
||||
void ps_changedAtcStationsOnline();
|
||||
|
||||
//! Connection status has been changed
|
||||
void connectionStatusChanged(uint from, uint to, const QString &message);
|
||||
void ps_connectionStatusChanged(uint from, uint to, const QString &message);
|
||||
|
||||
private:
|
||||
Ui::CAtcStationComponent *ui;
|
||||
CTimerBasedComponent *m_timerComponent;
|
||||
QDateTime m_timestampLastReadOnlineStations;
|
||||
QDateTime m_timestampOnlineStationsChanged;
|
||||
QDateTime m_timestampLastReadBookedStations;
|
||||
QDateTime m_timestampLastReadOnlineStations = CTimerBasedComponent::epoch(); //!< stations read
|
||||
QDateTime m_timestampOnlineStationsChanged = CTimerBasedComponent::epoch(); //!< stations marked as changed
|
||||
QDateTime m_timestampLastReadBookedStations = CTimerBasedComponent::epoch(); //!< stations read
|
||||
QDateTime m_timestampBookedStationsChanged = CTimerBasedComponent::epoch(); //!< stations marked as changed
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#define BLACKGUI_TIMERBASEDCOMPONENT_H
|
||||
|
||||
#include <QTimer>
|
||||
#include <QDateTime>
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
@@ -28,6 +29,13 @@ namespace BlackGui
|
||||
//! Destructor
|
||||
~CTimerBasedComponent();
|
||||
|
||||
//! Date/time of 1/1/1970, used to init timestamp values as "outdated"
|
||||
static const QDateTime &epoch()
|
||||
{
|
||||
static const QDateTime e = QDateTime::fromMSecsSinceEpoch(0);
|
||||
return e;
|
||||
}
|
||||
|
||||
public slots:
|
||||
//! Update time, time < 100 stops updates
|
||||
void setUpdateInterval(int milliSeconds);
|
||||
|
||||
Reference in New Issue
Block a user