From fbfbdedb652d4f9d1daa72c0d24136abb9cd7d83 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 28 Jul 2018 00:19:06 +0200 Subject: [PATCH] Ref T294, display simulator internals correctly * view rows not selectable * added settings to ISimulator * ISimulator implements initSimulatorInternals() and sets default values * also display plugin name * XPlane using initSimulatorInternals() --- src/blackcore/simulator.cpp | 13 ++++++++ src/blackcore/simulator.h | 9 ++++++ src/blackgui/components/simulatorcomponent.ui | 6 ++++ .../simulation/simulatorinternals.cpp | 31 ++++++++++--------- src/blackmisc/simulation/simulatorinternals.h | 6 ++++ src/plugins/simulator/fs9/simulatorfs9.cpp | 2 +- .../simulator/fscommon/simulatorfscommon.cpp | 12 +++---- .../simulator/fscommon/simulatorfscommon.h | 2 +- .../fsxcommon/simulatorfsxcommon.cpp | 13 +++----- .../simulator/xplane/simulatorxplane.cpp | 7 +++-- 10 files changed, 67 insertions(+), 34 deletions(-) diff --git a/src/blackcore/simulator.cpp b/src/blackcore/simulator.cpp index e36bfb587..f46f8372d 100644 --- a/src/blackcore/simulator.cpp +++ b/src/blackcore/simulator.cpp @@ -32,6 +32,7 @@ using namespace BlackMisc; using namespace BlackMisc::Aviation; using namespace BlackMisc::Geo; using namespace BlackMisc::Simulation; +using namespace BlackMisc::Simulation::Settings; using namespace BlackMisc::PhysicalQuantities; using namespace BlackMisc::Network; using namespace BlackMisc::Weather; @@ -612,6 +613,10 @@ namespace BlackCore connect(sApp, &CApplication::aboutToShutdown, this, &ISimulator::unload, Qt::QueuedConnection); + // info data + m_simulatorInternals.setSimulatorName(this->getSimulatorName()); + m_simulatorInternals.setSwiftPluginName(this->getSimulatorPluginInfo().toQString()); + // info CLogMessage(this).info("Initialized simulator driver: '%1'") << this->getSimulatorInfo().toQString(); } @@ -724,6 +729,14 @@ namespace BlackCore // void, can be overridden in specialized drivers } + void ISimulator::initSimulatorInternals() + { + const CSimulatorSettings s = this->getSimulatorSettings(); + m_simulatorInternals.setSimulatorName(this->getSimulatorName()); + m_simulatorInternals.setSwiftPluginName(this->getSimulatorPluginInfo().toQString()); + m_simulatorInternals.setSimulatorInstallationDirectory(s.getSimulatorDirectory()); + } + void ISimulator::rememberElevationAndCG(const CCallsign &callsign, const QString &modelString, const Geo::CElevationPlane &elevation, const CLength &cg) { if (callsign.isEmpty()) { return; } diff --git a/src/blackcore/simulator.h b/src/blackcore/simulator.h index 15ae18fad..a040a69b1 100644 --- a/src/blackcore/simulator.h +++ b/src/blackcore/simulator.h @@ -172,6 +172,9 @@ namespace BlackCore //! Reload weather settings void reloadWeatherSettings(); + //! Settings for current simulator + BlackMisc::Simulation::Settings::CSimulatorSettings getSimulatorSettings() const { return m_settings.getSettings(this->getSimulatorInfo()); } + //! Driver will be unloaded virtual void unload(); @@ -346,6 +349,9 @@ namespace BlackCore virtual void onSwiftDbAirportsRead(); //! @} + //! Init the internals info + virtual void initSimulatorInternals(); + //! Parsed in derived classes virtual bool parseDetails(const BlackMisc::CSimpleCommandParser &parser) = 0; @@ -512,6 +518,9 @@ namespace BlackCore BlackMisc::CTokenBucket m_limitUpdateAircraftBucket { 5, 100, 5 }; //!< means 50 per second bool m_limitUpdateAircraft = false; //!< limit the update frequency by using BlackMisc::CTokenBucket + // general settings + BlackMisc::Simulation::Settings::CMultiSimulatorSettings m_settings { this }; //!< simulator settings for all simulators + // weather bool m_isWeatherActivated = false; //!< Is simulator weather activated? BlackMisc::Geo::CCoordinateGeodetic m_lastWeatherPosition; //!< Own aircraft position at which weather was fetched and injected last diff --git a/src/blackgui/components/simulatorcomponent.ui b/src/blackgui/components/simulatorcomponent.ui index 33b6a4ef3..9b0b7f79d 100644 --- a/src/blackgui/components/simulatorcomponent.ui +++ b/src/blackgui/components/simulatorcomponent.ui @@ -73,6 +73,12 @@ + + QAbstractItemView::NoSelection + + + QAbstractItemView::SelectRows + false diff --git a/src/blackmisc/simulation/simulatorinternals.cpp b/src/blackmisc/simulation/simulatorinternals.cpp index e6a674087..a865a21b4 100644 --- a/src/blackmisc/simulation/simulatorinternals.cpp +++ b/src/blackmisc/simulation/simulatorinternals.cpp @@ -19,7 +19,7 @@ namespace BlackMisc { void CSimulatorInternals::setValue(const QString &name, const QString &value) { - this->m_data.addOrReplaceValue(name, value); + m_data.addOrReplaceValue(name, value); } CVariant CSimulatorInternals::getVariantValue(const QString &name) const @@ -57,6 +57,16 @@ namespace BlackMisc this->setValue("all/simulatorName", name); } + QString CSimulatorInternals::getSimulatorSwiftPluginName() const + { + return this->getStringValue("all/pluginName"); + } + + void CSimulatorInternals::setSwiftPluginName(const QString &name) + { + this->setValue("all/pluginName", name); + } + QString CSimulatorInternals::getSimulatorVersion() const { return this->getStringValue("all/versionInfo"); @@ -82,30 +92,23 @@ namespace BlackMisc CVariant CSimulatorInternals::propertyByIndex(const BlackMisc::CPropertyIndex &index) const { if (index.isMyself()) { return CVariant::from(*this); } - ColumnIndex i = index.frontCasted(); + const ColumnIndex i = index.frontCasted(); switch (i) { - case IndexData: - return CVariant::from(m_data); - default: - return CValueObject::propertyByIndex(index); + case IndexData: return CVariant::from(m_data); + default: return CValueObject::propertyByIndex(index); } } void CSimulatorInternals::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant) { if (index.isMyself()) { (*this) = variant.to(); return; } - ColumnIndex i = index.frontCasted(); + const ColumnIndex i = index.frontCasted(); switch (i) { - case IndexData: - this->m_data = variant.to(); - break; - default: - CValueObject::setPropertyByIndex(index, variant); - break; + case IndexData: m_data = variant.to(); break; + default: CValueObject::setPropertyByIndex(index, variant); break; } } - } // ns } // ns diff --git a/src/blackmisc/simulation/simulatorinternals.h b/src/blackmisc/simulation/simulatorinternals.h index 325622d07..ed751acdb 100644 --- a/src/blackmisc/simulation/simulatorinternals.h +++ b/src/blackmisc/simulation/simulatorinternals.h @@ -68,6 +68,12 @@ namespace BlackMisc //! Set simulator name void setSimulatorName(const QString &name); + //! Plugin name + QString getSimulatorSwiftPluginName() const; + + //! Set plugin name + void setSwiftPluginName(const QString &name); + //! Simulator version info, something like "10.3.2" QString getSimulatorVersion() const; diff --git a/src/plugins/simulator/fs9/simulatorfs9.cpp b/src/plugins/simulator/fs9/simulatorfs9.cpp index a39d2b120..9474c7c1a 100644 --- a/src/plugins/simulator/fs9/simulatorfs9.cpp +++ b/src/plugins/simulator/fs9/simulatorfs9.cpp @@ -142,7 +142,7 @@ namespace BlackSimPlugin { m_fsuipc->connect(); // connect FSUIPC too } - initSimulatorInternals(); + this->initSimulatorInternals(); m_timerId = startTimer(50); return true; } diff --git a/src/plugins/simulator/fscommon/simulatorfscommon.cpp b/src/plugins/simulator/fscommon/simulatorfscommon.cpp index 67acfb57f..b7fc0d634 100644 --- a/src/plugins/simulator/fscommon/simulatorfscommon.cpp +++ b/src/plugins/simulator/fscommon/simulatorfscommon.cpp @@ -45,17 +45,15 @@ namespace BlackSimPlugin void CSimulatorFsCommon::initSimulatorInternals() { - CSimulatorInternals s; - s.setSimulatorName(this->getSimulatorName()); - s.setSimulatorVersion(this->getSimulatorVersion()); - s.setValue("fscommon/fsuipc", boolToOnOff(m_useFsuipc)); + CSimulatorPluginCommon::initSimulatorInternals(); + m_simulatorInternals.setSimulatorVersion(this->getSimulatorVersion()); + m_simulatorInternals.setValue("fscommon/fsuipc", boolToOnOff(m_useFsuipc)); if (m_fsuipc) { const QString v(m_fsuipc->getVersion()); - if (!v.isEmpty()) { s.setValue("fscommon/fsuipcversion", v); } - s.setValue("fscommon/fsuipcconnect", boolToYesNo(m_fsuipc->isConnected())); + if (!v.isEmpty()) { m_simulatorInternals.setValue("fscommon/fsuipcversion", v); } + m_simulatorInternals.setValue("fscommon/fsuipcconnect", boolToYesNo(m_fsuipc->isConnected())); } - m_simulatorInternals = s; } bool CSimulatorFsCommon::parseDetails(const CSimpleCommandParser &parser) diff --git a/src/plugins/simulator/fscommon/simulatorfscommon.h b/src/plugins/simulator/fscommon/simulatorfscommon.h index a6620161b..95bbbdca3 100644 --- a/src/plugins/simulator/fscommon/simulatorfscommon.h +++ b/src/plugins/simulator/fscommon/simulatorfscommon.h @@ -56,7 +56,7 @@ namespace BlackSimPlugin QObject *parent = nullptr); //! Init the internal objects - virtual void initSimulatorInternals(); + virtual void initSimulatorInternals() override; //! \name When swift DB data are read //! @{ diff --git a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp index af8ed45d6..984bed310 100644 --- a/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp +++ b/src/plugins/simulator/fsxcommon/simulatorfsxcommon.cpp @@ -370,10 +370,10 @@ namespace BlackSimPlugin this->initSimulatorInternals(); this->emitSimulatorCombinedStatus(); - // Internals depends on sim data which take a while to be read + // Internals depends on simulator data which take a while to be read // this is a trick and I re-init again after a while (which is not really expensive) const QPointer myself(this); - QTimer::singleShot(1000, this, [myself] + QTimer::singleShot(2500, this, [myself] { if (myself.isNull()) { return; } myself->initSimulatorInternals(); @@ -1833,13 +1833,8 @@ namespace BlackSimPlugin void CSimulatorFsxCommon::initSimulatorInternals() { CSimulatorFsCommon::initSimulatorInternals(); - CSimulatorInternals s = m_simulatorInternals; - const QString fsxPath = CFsCommonUtil::fsxDirFromRegistry(); // can be empty for remote FSX - if (!fsxPath.isEmpty()) { s.setSimulatorInstallationDirectory(fsxPath); } - - s.setValue("fsx/simConnectCfgFilename", CSimConnectUtilities::getSwiftLocalSimConnectCfgFilename()); - s.setValue("fsx/simConnectVersion", m_simConnectVersion); - m_simulatorInternals = s; + m_simulatorInternals.setValue("fsx/simConnectCfgFilename", CSimConnectUtilities::getSwiftLocalSimConnectCfgFilename()); + m_simulatorInternals.setValue("fsx/simConnectVersion", m_simConnectVersion); } void CSimulatorFsxCommon::reset() diff --git a/src/plugins/simulator/xplane/simulatorxplane.cpp b/src/plugins/simulator/xplane/simulatorxplane.cpp index 807d87b9a..0a9d160a2 100644 --- a/src/plugins/simulator/xplane/simulatorxplane.cpp +++ b/src/plugins/simulator/xplane/simulatorxplane.cpp @@ -294,6 +294,7 @@ namespace BlackSimPlugin m_trafficProxy = new CXSwiftBusTrafficProxy(m_dBusConnection, this); m_weatherProxy = new CXSwiftBusWeatherProxy(m_dBusConnection, this); + bool ok = false; if (m_serviceProxy->isValid() && m_trafficProxy->isValid() && m_weatherProxy->isValid() && m_trafficProxy->initialize()) { emitOwnAircraftModelChanged(m_serviceProxy->getAircraftModelPath(), m_serviceProxy->getAircraftModelFilename(), m_serviceProxy->getAircraftLivery(), @@ -308,13 +309,15 @@ namespace BlackSimPlugin m_trafficProxy->removeAllPlanes(); this->loadCslPackages(); this->emitSimulatorCombinedStatus(); - return true; + ok = true; } else { this->disconnectFrom(); - return false; } + + if (ok) { this->initSimulatorInternals(); } + return ok; } bool CSimulatorXPlane::disconnectFrom()