Simulator "live data", clean up when simulator status changes (remove no longer valid values)

This commit is contained in:
Klaus Basan
2018-08-07 19:46:30 +02:00
parent 68607a3cb8
commit bd8d11d9d6
2 changed files with 21 additions and 19 deletions

View File

@@ -79,7 +79,7 @@ namespace BlackGui
void CSimulatorComponent::addOrUpdateLiveDataByName(const QString &name, const QString &value, const CIcon &icon) 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); ui->tvp_LiveData->addOrUpdateByName(name, value, icon, resize, false);
} }
@@ -88,6 +88,11 @@ namespace BlackGui
this->addOrUpdateLiveDataByName(name, value, CIcon::iconByIndex(iconIndex)); this->addOrUpdateLiveDataByName(name, value, CIcon::iconByIndex(iconIndex));
} }
void CSimulatorComponent::removeLiveDataByName(const QString &name)
{
ui->tvp_LiveData->removeByName(name);
}
int CSimulatorComponent::rowCount() const int CSimulatorComponent::rowCount() const
{ {
return ui->tvp_LiveData->rowCount(); return ui->tvp_LiveData->rowCount();
@@ -101,30 +106,25 @@ namespace BlackGui
void CSimulatorComponent::update() void CSimulatorComponent::update()
{ {
if (!this->isVisibleWidget()) return; // no updates on invisible widgets 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(); ISimulator::SimulatorStatus simulatorStatus = static_cast<ISimulator::SimulatorStatus>(sGui->getIContextSimulator()->getSimulatorStatus());
if (simualtorStatus == 0) 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; return;
} }
if (!(simualtorStatus & ISimulator::Simulating)) if (!(simulatorStatus & ISimulator::Simulating))
{ {
this->addOrUpdateLiveDataByName("info", static const QString s("Simulator (%1) not yet running");
tr("Simulator (%1) not yet running").arg( this->addOrUpdateLiveDataByName("info", s.arg(sGui->getIContextSimulator()->getSimulatorPluginInfo().getSimulator()), CIcons::StandardIconWarning16);
sGui->getIContextSimulator()->getSimulatorPluginInfo().getSimulator()
),
CIcons::StandardIconWarning16);
return; return;
} }
// clear old warnings / information // clear old warnings / information
if (this->rowCount() < 5) if (this->rowCount() < 5) { this->clear(); }
{
this->clear();
}
const CSimulatedAircraft ownAircraft = sGui->getIContextOwnAircraft()->getOwnAircraft(); const CSimulatedAircraft ownAircraft = sGui->getIContextOwnAircraft()->getOwnAircraft();
const CAircraftSituation s = ownAircraft.getSituation(); const CAircraftSituation s = ownAircraft.getSituation();
@@ -156,7 +156,9 @@ namespace BlackGui
void CSimulatorComponent::onSimulatorStatusChanged(int status) void CSimulatorComponent::onSimulatorStatusChanged(int status)
{ {
if (status & ISimulator::Connected) ISimulator::SimulatorStatus simStatus = static_cast<ISimulator::SimulatorStatus>(status);
this->clear(); // clean up, will be refreshed
if (simStatus.testFlag(ISimulator::Connected))
{ {
const int intervalMs = getUpdateIntervalMs(); const int intervalMs = getUpdateIntervalMs();
m_updateTimer.start(intervalMs); m_updateTimer.start(intervalMs);
@@ -165,7 +167,6 @@ namespace BlackGui
else else
{ {
m_updateTimer.stop(); m_updateTimer.stop();
this->clear();
this->update(); this->update();
} }
} }

View File

@@ -24,8 +24,6 @@
#include <QTabWidget> #include <QTabWidget>
#include <QtGlobal> #include <QtGlobal>
class QWidget;
namespace BlackMisc namespace BlackMisc
{ {
class CIcon; class CIcon;
@@ -89,6 +87,9 @@ namespace BlackGui
//! Simple add or update name / value pair //! Simple add or update name / value pair
void addOrUpdateLiveDataByName(const QString &name, const QString &value, BlackMisc::CIcons::IconIndex iconIndex); void addOrUpdateLiveDataByName(const QString &name, const QString &value, BlackMisc::CIcons::IconIndex iconIndex);
//! Remove name
void removeLiveDataByName(const QString &name);
QScopedPointer<Ui::CSimulatorComponent> ui; QScopedPointer<Ui::CSimulatorComponent> ui;
QTimer m_updateTimer; QTimer m_updateTimer;
}; };