refs #808, UI for CSimulatorInternals

* some functions renamed
* update function and view for internals
This commit is contained in:
Klaus Basan
2016-11-17 04:45:31 +01:00
parent 47b395f6b5
commit 3d314f8820
4 changed files with 90 additions and 36 deletions

View File

@@ -45,25 +45,26 @@ namespace BlackGui
ui->setupUi(this); ui->setupUi(this);
ui->tvp_LiveData->setIconMode(true); ui->tvp_LiveData->setIconMode(true);
ui->tvp_LiveData->setAutoResizeFrequency(10); // only resize every n-th time 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(sGui->getIContextSimulator(), &IContextSimulator::simulatorStatusChanged, this, &CSimulatorComponent::ps_onSimulatorStatusChanged);
connect(&this->m_updateTimer, &QTimer::timeout, this, &CSimulatorComponent::update); 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()); this->ps_onSimulatorStatusChanged(sGui->getIContextSimulator()->getSimulatorStatus());
} }
CSimulatorComponent::~CSimulatorComponent() 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? 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);
} }
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 int CSimulatorComponent::rowCount() const
@@ -84,17 +85,17 @@ namespace BlackGui
int simualtorStatus = sGui->getIContextSimulator()->getSimulatorStatus(); int simualtorStatus = sGui->getIContextSimulator()->getSimulatorStatus();
if (simualtorStatus == 0) if (simualtorStatus == 0)
{ {
addOrUpdateByName("info", tr("No simulator available"), CIcons::StandardIconWarning16); addOrUpdateLiveDataByName("info", tr("No simulator available"), CIcons::StandardIconWarning16);
return; return;
} }
if (!(simualtorStatus & ISimulator::Simulating)) if (!(simualtorStatus & ISimulator::Simulating))
{ {
this->addOrUpdateByName("info", this->addOrUpdateLiveDataByName("info",
tr("Simulator (%1) not yet running").arg( tr("Simulator (%1) not yet running").arg(
sGui->getIContextSimulator()->getSimulatorPluginInfo().getSimulator() sGui->getIContextSimulator()->getSimulatorPluginInfo().getSimulator()
), ),
CIcons::StandardIconWarning16); CIcons::StandardIconWarning16);
return; return;
} }
@@ -109,19 +110,19 @@ namespace BlackGui
CComSystem c1 = ownAircraft.getCom1System(); CComSystem c1 = ownAircraft.getCom1System();
CComSystem c2 = ownAircraft.getCom2System(); CComSystem c2 = ownAircraft.getCom2System();
this->addOrUpdateByName("latitude", s.latitude().toFormattedQString(), s.latitude().toIcon()); this->addOrUpdateLiveDataByName("latitude", s.latitude().toFormattedQString(), s.latitude().toIcon());
this->addOrUpdateByName("longitude", s.longitude().toFormattedQString(), s.longitude().toIcon()); this->addOrUpdateLiveDataByName("longitude", s.longitude().toFormattedQString(), s.longitude().toIcon());
this->addOrUpdateByName("altitude", s.getAltitude().toFormattedQString(), s.getAltitude().toIcon()); this->addOrUpdateLiveDataByName("altitude", s.getAltitude().toFormattedQString(), s.getAltitude().toIcon());
this->addOrUpdateByName("pitch", s.getPitch().toFormattedQString(), CIcons::AviationAttitudeIndicator); this->addOrUpdateLiveDataByName("pitch", s.getPitch().toFormattedQString(), CIcons::AviationAttitudeIndicator);
this->addOrUpdateByName("bank", s.getBank().toFormattedQString(), CIcons::AviationAttitudeIndicator); this->addOrUpdateLiveDataByName("bank", s.getBank().toFormattedQString(), CIcons::AviationAttitudeIndicator);
this->addOrUpdateByName("heading", s.getHeading().toFormattedQString(), s.getHeading().toIcon()); this->addOrUpdateLiveDataByName("heading", s.getHeading().toFormattedQString(), s.getHeading().toIcon());
this->addOrUpdateByName("ground speed", s.getGroundSpeed().toFormattedQString(), s.getGroundSpeed().toIcon()); this->addOrUpdateLiveDataByName("ground speed", s.getGroundSpeed().toFormattedQString(), s.getGroundSpeed().toIcon());
this->addOrUpdateByName("COM1 active", c1.getFrequencyActive().toFormattedQString(), CIcons::StandardIconRadio16); this->addOrUpdateLiveDataByName("COM1 active", c1.getFrequencyActive().toFormattedQString(), CIcons::StandardIconRadio16);
this->addOrUpdateByName("COM2 active", c2.getFrequencyActive().toFormattedQString(), CIcons::StandardIconRadio16); this->addOrUpdateLiveDataByName("COM2 active", c2.getFrequencyActive().toFormattedQString(), CIcons::StandardIconRadio16);
this->addOrUpdateByName("COM1 standby", c1.getFrequencyStandby().toFormattedQString(), CIcons::StandardIconRadio16); this->addOrUpdateLiveDataByName("COM1 standby", c1.getFrequencyStandby().toFormattedQString(), CIcons::StandardIconRadio16);
this->addOrUpdateByName("COM2 standby", c2.getFrequencyStandby().toFormattedQString(), CIcons::StandardIconRadio16); this->addOrUpdateLiveDataByName("COM2 standby", c2.getFrequencyStandby().toFormattedQString(), CIcons::StandardIconRadio16);
this->addOrUpdateByName("Transponder", ownAircraft.getTransponderCodeFormatted(), CIcons::StandardIconRadio16); this->addOrUpdateLiveDataByName("Transponder", ownAircraft.getTransponderCodeFormatted(), CIcons::StandardIconRadio16);
} }
void CSimulatorComponent::ps_onSimulatorStatusChanged(int status) void CSimulatorComponent::ps_onSimulatorStatusChanged(int status)
@@ -130,6 +131,7 @@ namespace BlackGui
{ {
const int intervalMs = getUpdateIntervalMs(); const int intervalMs = getUpdateIntervalMs();
this->m_updateTimer.start(intervalMs); this->m_updateTimer.start(intervalMs);
this->ps_refreshInternals();
} }
else 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 int CSimulatorComponent::getUpdateIntervalMs() const
{ {
// much slower updates via DBus // much slower updates via DBus
return sGui->getIContextSimulator()->isUsingImplementingObject() ? 500 : 5000; return sGui->getIContextSimulator()->isUsingImplementingObject() ? 1000 : 5000;
} }
} }
} // namespace } // namespace

View File

@@ -44,13 +44,7 @@ namespace BlackGui
explicit CSimulatorComponent(QWidget *parent = nullptr); explicit CSimulatorComponent(QWidget *parent = nullptr);
//! Destructor //! Destructor
~CSimulatorComponent(); virtual ~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);
//! Number of entries //! Number of entries
int rowCount() const; int rowCount() const;
@@ -66,14 +60,23 @@ namespace BlackGui
//! \copydoc ISimulator::simulatorStatusChanged //! \copydoc ISimulator::simulatorStatusChanged
void ps_onSimulatorStatusChanged(int status); void ps_onSimulatorStatusChanged(int status);
//! Refresh the internals
void ps_refreshInternals();
private: private:
//! Update interval //! Update interval
int getUpdateIntervalMs() const; 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; QScopedPointer<Ui::CSimulatorComponent> ui;
QTimer m_updateTimer; QTimer m_updateTimer;
}; };
} } // ns
} } // ns
#endif // guard #endif // guard

View File

@@ -45,10 +45,41 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<widget class="QWidget" name="tb_Information"> <widget class="QWidget" name="tb_Internals">
<attribute name="title"> <attribute name="title">
<string>Information</string> <string>Information</string>
</attribute> </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>
</widget> </widget>
<customwidgets> <customwidgets>

View File

@@ -24,7 +24,6 @@
class QWidget; class QWidget;
namespace BlackMisc { class CNameVariantPair; } namespace BlackMisc { class CNameVariantPair; }
namespace BlackGui namespace BlackGui
{ {
namespace Views namespace Views
@@ -32,7 +31,6 @@ namespace BlackGui
//! User view //! User view
class BLACKGUI_EXPORT CNameVariantPairView : public CViewBase<Models::CNameVariantPairModel, BlackMisc::CNameVariantPairList, BlackMisc::CNameVariantPair> class BLACKGUI_EXPORT CNameVariantPairView : public CViewBase<Models::CNameVariantPairModel, BlackMisc::CNameVariantPairList, BlackMisc::CNameVariantPair>
{ {
public: public:
//! Constructor //! Constructor
explicit CNameVariantPairView(QWidget *parent = nullptr); explicit CNameVariantPairView(QWidget *parent = nullptr);
@@ -48,7 +46,6 @@ namespace BlackGui
//! Contains name //! Contains name
bool containsName(const QString &name); bool containsName(const QString &name);
}; };
} }
} }