Ref T171, added statistics in emulated driver

* UI part
* fixed minor typo
* fixed setting of rendered flag
* UI connections Qt::QueuedConnection
This commit is contained in:
Klaus Basan
2017-10-10 22:21:14 +02:00
parent 8fcfcdaac6
commit 4cfa6189da
5 changed files with 197 additions and 21 deletions

View File

@@ -107,7 +107,10 @@ namespace BlackSimPlugin
bool CSimulatorEmulated::changeRemoteAircraftEnabled(const CSimulatedAircraft &aircraft)
{
if (canLog()) m_monitorWidget->appendReceivingCall(Q_FUNC_INFO, aircraft.toQString());
const int c = m_renderedAircraft.setEnabled(aircraft.getCallsign(), aircraft.isEnabled(), true);
const int c = m_renderedAircraft.setEnabled(aircraft.getCallsign(), aircraft.isEnabled(), true); // my own simulator list
const CCallsign cs = aircraft.getCallsign();
const bool rendered = aircraft.isEnabled();
this->updateAircraftRendered(cs, rendered); // in provider
emit this->aircraftRenderingChanged(m_renderedAircraft.findFirstByCallsign(aircraft.getCallsign(), aircraft));
return c > 0;
}
@@ -231,6 +234,14 @@ namespace BlackSimPlugin
return this->updateOwnParts(parts);
}
void CSimulatorEmulated::resetStatistics()
{
m_physicallyAdded = 0;
m_physicallyRemoved = 0;
m_partsAdded = 0;
m_situationAdded = 0;
}
bool CSimulatorEmulated::isConnected() const
{
if (canLog()) m_monitorWidget->appendReceivingCall(Q_FUNC_INFO);
@@ -254,7 +265,10 @@ namespace BlackSimPlugin
if (canLog()) m_monitorWidget->appendReceivingCall(Q_FUNC_INFO, remoteAircraft.toQString());
CSimulatedAircraft aircraft(remoteAircraft);
aircraft.setRendered(true);
m_renderedAircraft.push_back(aircraft);
m_renderedAircraft.push_back(aircraft); // my simulator list
const CCallsign cs = aircraft.getCallsign();
this->updateAircraftRendered(cs, true); // in provider
m_physicallyAdded++;
emit this->aircraftRenderingChanged(aircraft);
return true;
}
@@ -262,10 +276,24 @@ namespace BlackSimPlugin
bool CSimulatorEmulated::physicallyRemoveRemoteAircraft(const CCallsign &callsign)
{
if (canLog()) m_monitorWidget->appendReceivingCall(Q_FUNC_INFO, callsign.toQString());
m_physicallyRemoved++;
const int c = m_renderedAircraft.removeByCallsign(callsign);
return c > 0;
}
void CSimulatorEmulated::onRemoteProviderAddedAircraftSituation(const CAircraftSituation &situation)
{
Q_UNUSED(situation);
m_situationAdded++;
}
void CSimulatorEmulated::onRemoteProviderAddedAircraftParts(const CCallsign &callsign, const CAircraftParts &parts)
{
Q_UNUSED(callsign);
Q_UNUSED(parts);
m_partsAdded++;
}
bool CSimulatorEmulated::setInterpolatorMode(CInterpolatorMulti::Mode mode, const CCallsign &callsign)
{
if (canLog()) m_monitorWidget->appendReceivingCall(Q_FUNC_INFO, CInterpolatorMulti::modeToString(mode), callsign.toQString());
@@ -329,38 +357,38 @@ namespace BlackSimPlugin
{
if (!m_monitorWidget) return;
m_monitorWidget->appendSendingCall("simulatorStatusChanged", CSimulatorEmulated::statusToString(status));
}));
}, Qt::QueuedConnection));
m_connectionGuard.append(connect(this, &ISimulator::ownAircraftModelChanged, this, [ = ](CAircraftModel model)
{
if (!m_monitorWidget) return;
m_monitorWidget->appendSendingCall("ownAircraftModelChanged", model.toQString());
}));
}, Qt::QueuedConnection));
m_connectionGuard.append(connect(this, &ISimulator::renderRestrictionsChanged, this, [ = ](bool restricted, bool enabled, int maxAircraft, const BlackMisc::PhysicalQuantities::CLength & maxRenderedDistance)
{
if (!m_monitorWidget) return;
static const QString params("restricted: %1 enabled: %2 max aircraft: %3");
m_monitorWidget->appendSendingCall("renderRestrictionsChanged", params.arg(boolToYesNo(restricted), boolToYesNo(enabled)).arg(maxAircraft), maxRenderedDistance.valueRoundedWithUnit(CLengthUnit::m(), 1));
}));
}, Qt::QueuedConnection));
m_connectionGuard.append(connect(this, &ISimulator::aircraftRenderingChanged, this, [ = ](const CSimulatedAircraft & aircraft)
{
if (!m_monitorWidget) return;
m_monitorWidget->appendSendingCall("aircraftRenderingChanged", aircraft.toQString());
}));
}, Qt::QueuedConnection));
m_connectionGuard.append(connect(this, &ISimulator::physicallyAddingRemoteModelFailed, this, [ = ](const CSimulatedAircraft & aircraft)
{
if (!m_monitorWidget) return;
m_monitorWidget->appendSendingCall("physicallyAddingRemoteModelFailed", aircraft.toQString());
}));
}, Qt::QueuedConnection));
m_connectionGuard.append(connect(this, &ISimulator::airspaceSnapshotHandled, this, [ = ]
{
if (!m_monitorWidget) return;
m_monitorWidget->appendSendingCall("airspaceSnapshotHandled");
}));
}, Qt::QueuedConnection));
}
CSimulatorEmulatedListener::CSimulatorEmulatedListener(const CSimulatorPluginInfo &info)

View File

@@ -76,9 +76,6 @@ namespace BlackSimPlugin
//! \copydoc BlackCore::ISimulator::parseCommandLine
virtual bool parseCommandLine(const QString &commandLine, const BlackMisc::CIdentifier &originator) override;
//! Register help
static void registerHelp();
//! UI setter
void setCombinedStatus(bool connected, bool simulating, bool paused);
@@ -102,6 +99,12 @@ namespace BlackSimPlugin
//! \remark normally used by corresponding BlackSimPlugin::Emulated::CSimulatorEmulatedMonitorDialog
bool changeInternalParts(const BlackMisc::Aviation::CAircraftParts &parts);
//! Reset statistics
void resetStatistics();
//! Register help
static void registerHelp();
signals:
//! Internal aircraft changed
void internalAircraftChanged();
@@ -112,6 +115,8 @@ namespace BlackSimPlugin
virtual bool isSimulating() const override;
virtual bool physicallyAddRemoteAircraft(const BlackMisc::Simulation::CSimulatedAircraft &remoteAircraft) override;
virtual bool physicallyRemoveRemoteAircraft(const BlackMisc::Aviation::CCallsign &callsign) override;
virtual void onRemoteProviderAddedAircraftSituation(const BlackMisc::Aviation::CAircraftSituation &situation) override;
virtual void onRemoteProviderAddedAircraftParts(const BlackMisc::Aviation::CCallsign &callsign, const BlackMisc::Aviation::CAircraftParts &parts) override;
// just logged
virtual int physicallyRemoveAllRemoteAircraft() override;
@@ -140,9 +145,13 @@ namespace BlackSimPlugin
bool m_connected = true;
bool m_simulating = true;
bool m_timeSyncronized = false;
int m_physicallyAdded = 0; //!< statistics, how often called
int m_physicallyRemoved = 0; //!< statistics, how often called
int m_partsAdded = 0;
int m_situationAdded = 0;
BlackMisc::PhysicalQuantities::CTime m_offsetTime;
BlackMisc::Simulation::CSimulatedAircraft m_myAircraft; //!< represents own aircraft of simulator
BlackMisc::Simulation::CSimulatedAircraftList m_renderedAircraft; //!< represents other aircraft of simulator
BlackMisc::Simulation::CSimulatedAircraftList m_renderedAircraft; //!< represents remote aircraft in simulator
QScopedPointer<CSimulatorEmulatedMonitorDialog> m_monitorWidget; //!< parent will be main window, so we need to destroy widget when destroyed
BlackMisc::CSettingReadOnly<BlackMisc::Simulation::Settings::TSwiftPlugin> m_settings { this, &CSimulatorEmulated::onSettingsChanged };

View File

@@ -33,14 +33,18 @@ namespace BlackSimPlugin
{
Q_ASSERT_X(simulator, Q_FUNC_INFO, "Need simulator");
m_simulator = simulator;
connect(m_simulator, &CSimulatorEmulated::internalAircraftChanged, this, &CSimulatorEmulatedMonitorDialog::setInteralAircraftUiValues, Qt::QueuedConnection);
ui->setupUi(this);
ui->tw_SwiftMonitorDialog->setCurrentIndex(0);
ui->comp_LogComponent->setMaxLogMessages(500);
this->setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
m_simulator = simulator;
m_uiUpdateTimer.setObjectName(this->objectName() + ":uiUpdateTimer");
m_uiUpdateTimer.start(2.5 * 1000);
connect(m_simulator, &CSimulatorEmulated::internalAircraftChanged, this, &CSimulatorEmulatedMonitorDialog::setInternalAircraftUiValues, Qt::QueuedConnection);
connect(&m_uiUpdateTimer, &QTimer::timeout, this, &CSimulatorEmulatedMonitorDialog::timerBasedUiUpdates);
connect(ui->pb_ResetStatistics, &QPushButton::clicked, this, &CSimulatorEmulatedMonitorDialog::resetStatistics);
connect(ui->cb_Connected, &QCheckBox::released, this, &CSimulatorEmulatedMonitorDialog::onSimulatorValuesChanged);
connect(ui->cb_Paused, &QCheckBox::released, this, &CSimulatorEmulatedMonitorDialog::onSimulatorValuesChanged);
connect(ui->cb_Simulating, &QCheckBox::released, this, &CSimulatorEmulatedMonitorDialog::onSimulatorValuesChanged);
@@ -56,7 +60,7 @@ namespace BlackSimPlugin
ui->wi_LedSending->setShape(CLedWidget::Rounded);
this->setSimulatorUiValues();
this->setInteralAircraftUiValues();
this->setInternalAircraftUiValues();
}
CSimulatorEmulatedMonitorDialog::~CSimulatorEmulatedMonitorDialog()
@@ -165,12 +169,32 @@ namespace BlackSimPlugin
ui->le_SimulatorPlugin->setText(m_simulator->getSimulatorPluginInfo().toQString(true));
}
void CSimulatorEmulatedMonitorDialog::setInteralAircraftUiValues()
void CSimulatorEmulatedMonitorDialog::setInternalAircraftUiValues()
{
const CSimulatedAircraft internal(m_simulator->getInternalOwnAircraft());
ui->editor_Situation->setSituation(internal.getSituation());
ui->editor_AircraftParts->setAircraftParts(internal.getParts());
ui->editor_Com->setValue(internal);
}
void CSimulatorEmulatedMonitorDialog::timerBasedUiUpdates()
{
if (!m_simulator) { return; }
ui->le_PhysicallyAddedAircraft->setText(QString::number(m_simulator->m_physicallyAdded));
ui->le_PhysicallyRemovedAircraft->setText(QString::number(m_simulator->m_physicallyRemoved));
ui->le_SituationAdded->setText(QString::number(m_simulator->m_situationAdded));
ui->le_PartsAdded->setText(QString::number(m_simulator->m_partsAdded));
ui->le_AircraftRendered->setText(QString::number(m_simulator->m_renderedAircraft.size()));
ui->le_PartsEnabledAircraft->setText(QString::number(m_simulator->getRemoteAircraftSupportingPartsCount()));
}
void CSimulatorEmulatedMonitorDialog::resetStatistics()
{
if (!m_simulator) { m_simulator->resetStatistics(); }
ui->le_PhysicallyAddedAircraft->clear();
ui->le_PhysicallyRemovedAircraft->clear();
ui->le_SituationAdded->clear();
ui->le_PartsAdded->clear();
}
} // ns
} // ns

View File

@@ -12,12 +12,14 @@
#ifndef BLACKSIMPLUGIN_EMULATED_SIMULATOREMULATEDMONITORDIALOG_H
#define BLACKSIMPLUGIN_EMULATED_SIMULATOREMULATEDMONITORDIALOG_H
#include <QDialog>
#include <QScopedPointer>
#include "blackmisc/simulation/simulatedaircraft.h"
#include "blackmisc/statusmessagelist.h"
#include "blackmisc/logcategorylist.h"
#include <QDialog>
#include <QScopedPointer>
#include <QTimer>
namespace Ui { class CSimulatorEmulatedMonitorDialog; }
namespace BlackSimPlugin
{
@@ -85,10 +87,17 @@ namespace BlackSimPlugin
void setSimulatorUiValues();
//! Set values from internal aircraft
void setInteralAircraftUiValues();
void setInternalAircraftUiValues();
//! Timer based UI updates (pulling)
void timerBasedUiUpdates();
//! Reset statistics
void resetStatistics();
QScopedPointer<Ui::CSimulatorEmulatedMonitorDialog> ui;
CSimulatorEmulated *m_simulator = nullptr;
QTimer m_uiUpdateTimer { this };
};
} // ns
} // ns

View File

@@ -62,7 +62,7 @@
<item>
<widget class="QTabWidget" name="tw_SwiftMonitorDialog">
<property name="currentIndex">
<number>0</number>
<number>3</number>
</property>
<widget class="QWidget" name="tb_AircraftSituation">
<attribute name="title">
@@ -285,8 +285,114 @@
<string>Log information</string>
</attribute>
<layout class="QVBoxLayout" name="vl_LogInformation">
<item>
<widget class="QGroupBox" name="gb_Statistics">
<property name="title">
<string>Statistics</string>
</property>
<layout class="QGridLayout" name="gl_Statistics">
<item row="1" column="0">
<widget class="QLabel" name="lbl_SituationAdded">
<property name="text">
<string>Situation added:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="le_SituationAdded">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLineEdit" name="le_PartsAdded">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QLabel" name="lbl_PartsAdded">
<property name="text">
<string>Parts added:</string>
</property>
</widget>
</item>
<item row="0" column="4">
<widget class="QLabel" name="lbl_AircraftRendered">
<property name="text">
<string>Aircraft rendered:</string>
</property>
</widget>
</item>
<item row="0" column="8">
<widget class="QLineEdit" name="le_AircraftRendered">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="lbl_PhysicallyAddedAircraft">
<property name="text">
<string>Phy.added aircraft:</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="le_PhysicallyAddedAircraft">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="3">
<widget class="QLineEdit" name="le_PhysicallyRemovedAircraft">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="9">
<widget class="QPushButton" name="pb_ResetStatistics">
<property name="text">
<string>reset</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QLabel" name="lbl_PhysicallyRemovedAircraft">
<property name="text">
<string>Phy.removed aircraft:</string>
</property>
</widget>
</item>
<item row="1" column="8">
<widget class="QLineEdit" name="le_PartsEnabledAircraft">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QLabel" name="lbl_PartsEnabledAircraft">
<property name="text">
<string>Parts enabled:</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QGroupBox" name="gb_LogMessages">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Simulator API calls</string>
</property>