mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-31 12:55:33 +08:00
refs #808, UI for CSimulatorInternals
* some functions renamed * update function and view for internals
This commit is contained in:
@@ -45,25 +45,26 @@ namespace BlackGui
|
||||
ui->setupUi(this);
|
||||
ui->tvp_LiveData->setIconMode(true);
|
||||
ui->tvp_LiveData->setAutoResizeFrequency(10); // only resize every n-th time
|
||||
this->addOrUpdateByName("info", "no data yet", CIcons::StandardIconWarning16);
|
||||
this->addOrUpdateLiveDataByName("info", "no data yet", CIcons::StandardIconWarning16);
|
||||
|
||||
connect(sGui->getIContextSimulator(), &IContextSimulator::simulatorStatusChanged, this, &CSimulatorComponent::ps_onSimulatorStatusChanged);
|
||||
connect(&this->m_updateTimer, &QTimer::timeout, this, &CSimulatorComponent::update);
|
||||
connect(ui->pb_RefreshInternals, &QPushButton::pressed, this, &CSimulatorComponent::ps_refreshInternals);
|
||||
this->ps_onSimulatorStatusChanged(sGui->getIContextSimulator()->getSimulatorStatus());
|
||||
}
|
||||
|
||||
CSimulatorComponent::~CSimulatorComponent()
|
||||
{ }
|
||||
|
||||
void CSimulatorComponent::addOrUpdateByName(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?
|
||||
ui->tvp_LiveData->addOrUpdateByName(name, value, icon, resize, false);
|
||||
}
|
||||
|
||||
void CSimulatorComponent::addOrUpdateByName(const QString &name, const QString &value, CIcons::IconIndex iconIndex)
|
||||
void CSimulatorComponent::addOrUpdateLiveDataByName(const QString &name, const QString &value, CIcons::IconIndex iconIndex)
|
||||
{
|
||||
this->addOrUpdateByName(name, value, CIconList::iconByIndex(iconIndex));
|
||||
this->addOrUpdateLiveDataByName(name, value, CIconList::iconByIndex(iconIndex));
|
||||
}
|
||||
|
||||
int CSimulatorComponent::rowCount() const
|
||||
@@ -84,17 +85,17 @@ namespace BlackGui
|
||||
int simualtorStatus = sGui->getIContextSimulator()->getSimulatorStatus();
|
||||
if (simualtorStatus == 0)
|
||||
{
|
||||
addOrUpdateByName("info", tr("No simulator available"), CIcons::StandardIconWarning16);
|
||||
addOrUpdateLiveDataByName("info", tr("No simulator available"), CIcons::StandardIconWarning16);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!(simualtorStatus & ISimulator::Simulating))
|
||||
{
|
||||
this->addOrUpdateByName("info",
|
||||
tr("Simulator (%1) not yet running").arg(
|
||||
sGui->getIContextSimulator()->getSimulatorPluginInfo().getSimulator()
|
||||
),
|
||||
CIcons::StandardIconWarning16);
|
||||
this->addOrUpdateLiveDataByName("info",
|
||||
tr("Simulator (%1) not yet running").arg(
|
||||
sGui->getIContextSimulator()->getSimulatorPluginInfo().getSimulator()
|
||||
),
|
||||
CIcons::StandardIconWarning16);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -109,19 +110,19 @@ namespace BlackGui
|
||||
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->addOrUpdateLiveDataByName("latitude", s.latitude().toFormattedQString(), s.latitude().toIcon());
|
||||
this->addOrUpdateLiveDataByName("longitude", s.longitude().toFormattedQString(), s.longitude().toIcon());
|
||||
this->addOrUpdateLiveDataByName("altitude", s.getAltitude().toFormattedQString(), s.getAltitude().toIcon());
|
||||
this->addOrUpdateLiveDataByName("pitch", s.getPitch().toFormattedQString(), CIcons::AviationAttitudeIndicator);
|
||||
this->addOrUpdateLiveDataByName("bank", s.getBank().toFormattedQString(), CIcons::AviationAttitudeIndicator);
|
||||
this->addOrUpdateLiveDataByName("heading", s.getHeading().toFormattedQString(), s.getHeading().toIcon());
|
||||
this->addOrUpdateLiveDataByName("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);
|
||||
this->addOrUpdateLiveDataByName("COM1 active", c1.getFrequencyActive().toFormattedQString(), CIcons::StandardIconRadio16);
|
||||
this->addOrUpdateLiveDataByName("COM2 active", c2.getFrequencyActive().toFormattedQString(), CIcons::StandardIconRadio16);
|
||||
this->addOrUpdateLiveDataByName("COM1 standby", c1.getFrequencyStandby().toFormattedQString(), CIcons::StandardIconRadio16);
|
||||
this->addOrUpdateLiveDataByName("COM2 standby", c2.getFrequencyStandby().toFormattedQString(), CIcons::StandardIconRadio16);
|
||||
this->addOrUpdateLiveDataByName("Transponder", ownAircraft.getTransponderCodeFormatted(), CIcons::StandardIconRadio16);
|
||||
}
|
||||
|
||||
void CSimulatorComponent::ps_onSimulatorStatusChanged(int status)
|
||||
@@ -130,6 +131,7 @@ namespace BlackGui
|
||||
{
|
||||
const int intervalMs = getUpdateIntervalMs();
|
||||
this->m_updateTimer.start(intervalMs);
|
||||
this->ps_refreshInternals();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -139,10 +141,31 @@ namespace BlackGui
|
||||
}
|
||||
}
|
||||
|
||||
void CSimulatorComponent::ps_refreshInternals()
|
||||
{
|
||||
if (!sGui->getIContextSimulator()) { return; }
|
||||
const CSimulatorInternals internals = sGui->getIContextSimulator()->getSimulatorInternals();
|
||||
const QStringList names(internals.getSortedNames());
|
||||
if (names.isEmpty())
|
||||
{
|
||||
ui->tvp_Internals->clear();
|
||||
return;
|
||||
}
|
||||
|
||||
static const CIcon emptyIcon;
|
||||
const bool resize = true;
|
||||
const bool skipEqualValues = true;
|
||||
for (const QString &name : names)
|
||||
{
|
||||
ui->tvp_Internals->addOrUpdateByName(name, internals.getVariantValue(name), emptyIcon, resize, skipEqualValues);
|
||||
}
|
||||
ui->tvp_Internals->fullResizeToContents();
|
||||
}
|
||||
|
||||
int CSimulatorComponent::getUpdateIntervalMs() const
|
||||
{
|
||||
// much slower updates via DBus
|
||||
return sGui->getIContextSimulator()->isUsingImplementingObject() ? 500 : 5000;
|
||||
return sGui->getIContextSimulator()->isUsingImplementingObject() ? 1000 : 5000;
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@@ -44,13 +44,7 @@ namespace BlackGui
|
||||
explicit CSimulatorComponent(QWidget *parent = nullptr);
|
||||
|
||||
//! Destructor
|
||||
~CSimulatorComponent();
|
||||
|
||||
//! Simple add or update name / value pair
|
||||
void addOrUpdateByName(const QString &name, const QString &value, const BlackMisc::CIcon &icon);
|
||||
|
||||
//! Simple add or update name / value pair
|
||||
void addOrUpdateByName(const QString &name, const QString &value, BlackMisc::CIcons::IconIndex iconIndex);
|
||||
virtual ~CSimulatorComponent();
|
||||
|
||||
//! Number of entries
|
||||
int rowCount() const;
|
||||
@@ -66,14 +60,23 @@ namespace BlackGui
|
||||
//! \copydoc ISimulator::simulatorStatusChanged
|
||||
void ps_onSimulatorStatusChanged(int status);
|
||||
|
||||
//! Refresh the internals
|
||||
void ps_refreshInternals();
|
||||
|
||||
private:
|
||||
//! Update interval
|
||||
int getUpdateIntervalMs() const;
|
||||
|
||||
//! Simple add or update name / value pair
|
||||
void addOrUpdateLiveDataByName(const QString &name, const QString &value, const BlackMisc::CIcon &icon);
|
||||
|
||||
//! Simple add or update name / value pair
|
||||
void addOrUpdateLiveDataByName(const QString &name, const QString &value, BlackMisc::CIcons::IconIndex iconIndex);
|
||||
|
||||
QScopedPointer<Ui::CSimulatorComponent> ui;
|
||||
QTimer m_updateTimer;
|
||||
};
|
||||
}
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -45,10 +45,41 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<widget class="QWidget" name="tb_Information">
|
||||
<widget class="QWidget" name="tb_Internals">
|
||||
<attribute name="title">
|
||||
<string>Information</string>
|
||||
</attribute>
|
||||
<layout class="QVBoxLayout" name="vl_Internals">
|
||||
<property name="spacing">
|
||||
<number>3</number>
|
||||
</property>
|
||||
<property name="leftMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="rightMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item>
|
||||
<widget class="BlackGui::Views::CNameVariantPairView" name="tvp_Internals">
|
||||
<attribute name="verticalHeaderVisible">
|
||||
<bool>false</bool>
|
||||
</attribute>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pb_RefreshInternals">
|
||||
<property name="text">
|
||||
<string>refresh</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
|
||||
@@ -24,7 +24,6 @@
|
||||
class QWidget;
|
||||
|
||||
namespace BlackMisc { class CNameVariantPair; }
|
||||
|
||||
namespace BlackGui
|
||||
{
|
||||
namespace Views
|
||||
@@ -32,7 +31,6 @@ namespace BlackGui
|
||||
//! User view
|
||||
class BLACKGUI_EXPORT CNameVariantPairView : public CViewBase<Models::CNameVariantPairModel, BlackMisc::CNameVariantPairList, BlackMisc::CNameVariantPair>
|
||||
{
|
||||
|
||||
public:
|
||||
//! Constructor
|
||||
explicit CNameVariantPairView(QWidget *parent = nullptr);
|
||||
@@ -48,7 +46,6 @@ namespace BlackGui
|
||||
|
||||
//! Contains name
|
||||
bool containsName(const QString &name);
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user