From bd8d11d9d601d71ce8475455ac11e047a834b5b8 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Tue, 7 Aug 2018 19:46:30 +0200 Subject: [PATCH] Simulator "live data", clean up when simulator status changes (remove no longer valid values) --- .../components/simulatorcomponent.cpp | 35 ++++++++++--------- src/blackgui/components/simulatorcomponent.h | 5 +-- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/blackgui/components/simulatorcomponent.cpp b/src/blackgui/components/simulatorcomponent.cpp index b5d1d00fc..4046465a6 100644 --- a/src/blackgui/components/simulatorcomponent.cpp +++ b/src/blackgui/components/simulatorcomponent.cpp @@ -79,7 +79,7 @@ namespace BlackGui void CSimulatorComponent::addOrUpdateLiveDataByName(const QString &name, const QString &value, const CIcon &icon) { - bool resize = this->currentWidget() == ui->tb_LiveData; // simulator live data selected? + const bool resize = this->currentWidget() == ui->tb_LiveData; // simulator live data selected? ui->tvp_LiveData->addOrUpdateByName(name, value, icon, resize, false); } @@ -88,6 +88,11 @@ namespace BlackGui this->addOrUpdateLiveDataByName(name, value, CIcon::iconByIndex(iconIndex)); } + void CSimulatorComponent::removeLiveDataByName(const QString &name) + { + ui->tvp_LiveData->removeByName(name); + } + int CSimulatorComponent::rowCount() const { return ui->tvp_LiveData->rowCount(); @@ -101,30 +106,25 @@ namespace BlackGui void CSimulatorComponent::update() { if (!this->isVisibleWidget()) return; // no updates on invisible widgets - if (!sGui->getIContextOwnAircraft()) return; + if (!sGui || sGui->isShuttingDown() || !sGui->getIContextOwnAircraft()) return; - int simualtorStatus = sGui->getIContextSimulator()->getSimulatorStatus(); - if (simualtorStatus == 0) + ISimulator::SimulatorStatus simulatorStatus = static_cast(sGui->getIContextSimulator()->getSimulatorStatus()); + if (simulatorStatus == ISimulator::Unspecified || simulatorStatus == ISimulator::Disconnected) { - addOrUpdateLiveDataByName("info", tr("No simulator available"), CIcons::StandardIconWarning16); + static const QString s("No simulator available"); + addOrUpdateLiveDataByName("info", s, CIcons::StandardIconWarning16); return; } - if (!(simualtorStatus & ISimulator::Simulating)) + if (!(simulatorStatus & ISimulator::Simulating)) { - this->addOrUpdateLiveDataByName("info", - tr("Simulator (%1) not yet running").arg( - sGui->getIContextSimulator()->getSimulatorPluginInfo().getSimulator() - ), - CIcons::StandardIconWarning16); + static const QString s("Simulator (%1) not yet running"); + this->addOrUpdateLiveDataByName("info", s.arg(sGui->getIContextSimulator()->getSimulatorPluginInfo().getSimulator()), CIcons::StandardIconWarning16); return; } // clear old warnings / information - if (this->rowCount() < 5) - { - this->clear(); - } + if (this->rowCount() < 5) { this->clear(); } const CSimulatedAircraft ownAircraft = sGui->getIContextOwnAircraft()->getOwnAircraft(); const CAircraftSituation s = ownAircraft.getSituation(); @@ -156,7 +156,9 @@ namespace BlackGui void CSimulatorComponent::onSimulatorStatusChanged(int status) { - if (status & ISimulator::Connected) + ISimulator::SimulatorStatus simStatus = static_cast(status); + this->clear(); // clean up, will be refreshed + if (simStatus.testFlag(ISimulator::Connected)) { const int intervalMs = getUpdateIntervalMs(); m_updateTimer.start(intervalMs); @@ -165,7 +167,6 @@ namespace BlackGui else { m_updateTimer.stop(); - this->clear(); this->update(); } } diff --git a/src/blackgui/components/simulatorcomponent.h b/src/blackgui/components/simulatorcomponent.h index 50dbfddf4..9ccd651cf 100644 --- a/src/blackgui/components/simulatorcomponent.h +++ b/src/blackgui/components/simulatorcomponent.h @@ -24,8 +24,6 @@ #include #include -class QWidget; - namespace BlackMisc { class CIcon; @@ -89,6 +87,9 @@ namespace BlackGui //! Simple add or update name / value pair void addOrUpdateLiveDataByName(const QString &name, const QString &value, BlackMisc::CIcons::IconIndex iconIndex); + //! Remove name + void removeLiveDataByName(const QString &name); + QScopedPointer ui; QTimer m_updateTimer; };