mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-15 17:55:34 +08:00
refs #335, shifted simulator update from main window into component
This commit is contained in:
committed by
Roland Winklmeier
parent
c350744a87
commit
e45087c933
@@ -10,6 +10,10 @@
|
||||
#include "simulatorcomponent.h"
|
||||
#include "ui_simulatorcomponent.h"
|
||||
#include "blackmisc/iconlist.h"
|
||||
#include "blackmisc/avaircraft.h"
|
||||
|
||||
using namespace BlackMisc::Aviation;
|
||||
using namespace BlackCore;
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
@@ -24,6 +28,7 @@ namespace BlackGui
|
||||
this->ui->tvp_LiveData->setIconMode(true);
|
||||
this->ui->tvp_LiveData->setAutoResizeFrequency(10); // only resize every n-th time
|
||||
this->addOrUpdateByName("info", "no data yet", CIcons::StandardIconWarning16);
|
||||
m_updateTimer = new CUpdateTimer(SLOT(update()), this);
|
||||
}
|
||||
|
||||
CSimulatorComponent::~CSimulatorComponent()
|
||||
@@ -37,7 +42,7 @@ namespace BlackGui
|
||||
|
||||
void CSimulatorComponent::addOrUpdateByName(const QString &name, const QString &value, CIcons::IconIndex iconIndex)
|
||||
{
|
||||
this->addOrUpdateByName(name, value, CIconList::iconForIndex(iconIndex));
|
||||
this->addOrUpdateByName(name, value, CIconList::iconByIndex(iconIndex));
|
||||
}
|
||||
|
||||
int CSimulatorComponent::rowCount() const
|
||||
@@ -49,5 +54,77 @@ namespace BlackGui
|
||||
{
|
||||
this->ui->tvp_LiveData->clear();
|
||||
}
|
||||
|
||||
void CSimulatorComponent::update()
|
||||
{
|
||||
if (!this->isVisibleWidget()) return; // no updates on invisible widgets
|
||||
if (!this->getIContextOwnAircraft()) return;
|
||||
if (!this->getIContextSimulator()->isConnected())
|
||||
{
|
||||
if (this->rowCount() == 1) return;
|
||||
this->clear();
|
||||
this->addOrUpdateByName("info", "sim not connected", CIcons::StandardIconWarning16);
|
||||
return;
|
||||
}
|
||||
|
||||
// clear old warnings / information
|
||||
if (this->rowCount() < 5)
|
||||
{
|
||||
this->clear();
|
||||
}
|
||||
|
||||
CAircraft ownAircraft = this->getIContextOwnAircraft()->getOwnAircraft();
|
||||
CAircraftSituation s = ownAircraft.getSituation();
|
||||
CComSystem c1 = ownAircraft.getCom1System();
|
||||
CComSystem c2 = ownAircraft.getCom2System();
|
||||
|
||||
this->addOrUpdateByName("latitude", s.latitude().toFormattedQString(), s.latitude().toIcon());
|
||||
this->addOrUpdateByName("longitude", s.longitude().toFormattedQString(), s.longitude().toIcon());
|
||||
this->addOrUpdateByName("altitude", s.getAltitude().toFormattedQString(), s.getAltitude().toIcon());
|
||||
this->addOrUpdateByName("pitch", s.getPitch().toFormattedQString(), CIcons::AviationAttitudeIndicator);
|
||||
this->addOrUpdateByName("bank", s.getBank().toFormattedQString(), CIcons::AviationAttitudeIndicator);
|
||||
this->addOrUpdateByName("heading", s.getHeading().toFormattedQString(), s.getHeading().toIcon());
|
||||
this->addOrUpdateByName("ground speed", s.getGroundSpeed().toFormattedQString(), s.getGroundSpeed().toIcon());
|
||||
|
||||
this->addOrUpdateByName("COM1 active", c1.getFrequencyActive().toFormattedQString(), CIcons::StandardIconRadio16);
|
||||
this->addOrUpdateByName("COM2 active", c2.getFrequencyActive().toFormattedQString(), CIcons::StandardIconRadio16);
|
||||
this->addOrUpdateByName("COM1 standby", c1.getFrequencyStandby().toFormattedQString(), CIcons::StandardIconRadio16);
|
||||
this->addOrUpdateByName("COM2 standby", c2.getFrequencyStandby().toFormattedQString(), CIcons::StandardIconRadio16);
|
||||
this->addOrUpdateByName("Transponder", ownAircraft.getTransponderCodeFormatted(), CIcons::StandardIconRadio16);
|
||||
}
|
||||
|
||||
void CSimulatorComponent::runtimeHasBeenSet()
|
||||
{
|
||||
Q_ASSERT(this->getIContextSimulator());
|
||||
if (!this->getIContextSimulator()) return;
|
||||
QObject::connect(this->getIContextSimulator(), &IContextSimulator::connectionChanged, this, &CSimulatorComponent::ps_onSimulatorConnectionChanged);
|
||||
|
||||
this->setUpdateInterval(getUpdateIntervalMs());
|
||||
if (!getIContextSimulator()->isConnected())
|
||||
{
|
||||
this->stopTimer();
|
||||
}
|
||||
}
|
||||
|
||||
void CSimulatorComponent::ps_onSimulatorConnectionChanged(bool isAvailable)
|
||||
{
|
||||
if (isAvailable)
|
||||
{
|
||||
int intervalMs = getUpdateIntervalMs();
|
||||
this->m_updateTimer->startTimer(intervalMs);
|
||||
}
|
||||
else
|
||||
{
|
||||
this->stopTimer();
|
||||
}
|
||||
}
|
||||
|
||||
int CSimulatorComponent::getUpdateIntervalMs() const
|
||||
{
|
||||
Q_ASSERT(this->getIContextSimulator());
|
||||
|
||||
// much slower updates via DBus
|
||||
return this->getIContextSimulator()->isUsingImplementingObject() ? 500 : 5000;
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include "enableforruntime.h"
|
||||
#include "blackmisc/icon.h"
|
||||
#include "blackgui/components/enablefordockwidgetinfoarea.h"
|
||||
#include "blackgui/components/updatetimer.h"
|
||||
|
||||
#include <QTabWidget>
|
||||
#include <QScopedPointer>
|
||||
@@ -53,8 +54,33 @@ namespace BlackGui
|
||||
//! Clear
|
||||
void clear();
|
||||
|
||||
public slots:
|
||||
//! Update simulator
|
||||
void update();
|
||||
|
||||
//! \copydoc CTimerBasedComponent::setUpdateIntervalSeconds
|
||||
void setUpdateIntervalSeconds(int seconds) { Q_ASSERT(this->m_updateTimer); this->m_updateTimer->setUpdateIntervalSeconds(seconds); }
|
||||
|
||||
//! \copydoc CTimerBasedComponent::setUpdateInterval
|
||||
void setUpdateInterval(int milliSeconds) { Q_ASSERT(this->m_updateTimer); this->m_updateTimer->setUpdateInterval(milliSeconds); }
|
||||
|
||||
//! \copydoc CTimerBasedComponent::stopTimer
|
||||
void stopTimer() { Q_ASSERT(this->m_updateTimer); this->m_updateTimer->stopTimer(); }
|
||||
|
||||
protected:
|
||||
//! \copydoc CEnableForRuntime::runtimeHasBeenSet
|
||||
void runtimeHasBeenSet() override;
|
||||
|
||||
private slots:
|
||||
//! \copydoc ISimulator::
|
||||
void ps_onSimulatorConnectionChanged(bool isAvailable);
|
||||
|
||||
private:
|
||||
//! Update interval
|
||||
int getUpdateIntervalMs() const;
|
||||
|
||||
QScopedPointer<Ui::CSimulatorComponent> ui;
|
||||
CUpdateTimer *m_updateTimer = nullptr;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user