From 7d88a6491431266e1dec0b067cbe7d38ee3b9ef1 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Wed, 26 Jul 2017 14:21:51 +0200 Subject: [PATCH] Ref T111, settings value object for swift pseudo driver --- src/blackmisc/blackmisc.pro | 2 + src/blackmisc/propertyindex.h | 11 +- .../simulation/registermetadatasimulation.cpp | 2 + .../settings/swiftpluginsettings.cpp | 79 +++++++++++++ .../simulation/settings/swiftpluginsettings.h | 106 ++++++++++++++++++ src/blackmisc/simulation/simulation.h | 1 + 6 files changed, 196 insertions(+), 5 deletions(-) create mode 100644 src/blackmisc/simulation/settings/swiftpluginsettings.cpp create mode 100644 src/blackmisc/simulation/settings/swiftpluginsettings.h diff --git a/src/blackmisc/blackmisc.pro b/src/blackmisc/blackmisc.pro index a40e4d464..03463f959 100644 --- a/src/blackmisc/blackmisc.pro +++ b/src/blackmisc/blackmisc.pro @@ -35,6 +35,7 @@ HEADERS += *.h \ $$PWD/pq/*.h \ $$PWD/simulation/*.h \ $$PWD/simulation/data/*.h \ + $$PWD/simulation/settings/*.h \ $$PWD/simulation/fscommon/*.h \ $$PWD/simulation/fsx/*.h \ $$PWD/simulation/xplane/*.h \ @@ -52,6 +53,7 @@ SOURCES += *.cpp \ $$PWD/pq/*.cpp \ $$PWD/simulation/*.cpp \ $$PWD/simulation/data/*.cpp \ + $$PWD/simulation/settings/*.cpp \ $$PWD/simulation/fscommon/*.cpp \ $$PWD/simulation/fsx/*.cpp \ $$PWD/simulation/xplane/*.cpp \ diff --git a/src/blackmisc/propertyindex.h b/src/blackmisc/propertyindex.h index 251511a4f..4ae66ca83 100644 --- a/src/blackmisc/propertyindex.h +++ b/src/blackmisc/propertyindex.h @@ -125,11 +125,12 @@ namespace BlackMisc GlobalIndexCTextMessage = 7000, GlobalIndexCSimulatorInternals = 7100, GlobalIndexCSimulatorSettings = 7200, - GlobalIndexCSimulatorMessageSettings = 7300, - GlobalIndexCModelSettings = 7400, - GlobalIndexCAircraftCfgEntries = 7500, - GlobalIndexCDistributor = 7600, - GlobalIndexCMatchingStatisticsEntry = 7700, + GlobalIndexCSwiftPluignSettings = 7300, + GlobalIndexCSimulatorMessageSettings = 7400, + GlobalIndexCModelSettings = 7500, + GlobalIndexCAircraftCfgEntries = 7600, + GlobalIndexCDistributor = 7700, + GlobalIndexCMatchingStatisticsEntry = 7800, GlobalIndexCVPilotModelRule = 8000, GlobalIndexCVoiceRoom = 9000, GlobalIndexCSettingKeyboardHotkey = 10000, diff --git a/src/blackmisc/simulation/registermetadatasimulation.cpp b/src/blackmisc/simulation/registermetadatasimulation.cpp index 33bc7b3ae..0043c3ea3 100644 --- a/src/blackmisc/simulation/registermetadatasimulation.cpp +++ b/src/blackmisc/simulation/registermetadatasimulation.cpp @@ -13,6 +13,7 @@ using namespace BlackMisc::Simulation; using namespace BlackMisc::Simulation::Fsx; using namespace BlackMisc::Simulation::FsCommon; +using namespace BlackMisc::Simulation::Settings; namespace BlackMisc { @@ -43,6 +44,7 @@ namespace BlackMisc CSimulatorPluginInfo::registerMetadata(); CSimulatorPluginInfoList::registerMetadata(); CSimulatorSettings::registerMetadata(); + CSwiftPluginSettings::registerMetadata(); CVPilotModelRule::registerMetadata(); CVPilotModelRuleSet::registerMetadata(); } diff --git a/src/blackmisc/simulation/settings/swiftpluginsettings.cpp b/src/blackmisc/simulation/settings/swiftpluginsettings.cpp new file mode 100644 index 000000000..6db7af64c --- /dev/null +++ b/src/blackmisc/simulation/settings/swiftpluginsettings.cpp @@ -0,0 +1,79 @@ +/* Copyright (C) 2017 + * swift project community / contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +#include "swiftpluginsettings.h" +#include "blackmisc/stringutils.h" + +namespace BlackMisc +{ + namespace Simulation + { + namespace Settings + { + CSwiftPluginSettings::CSwiftPluginSettings() + { } + + void CSwiftPluginSettings::setEmulatedSimulator(const CSimulatorInfo &simulator) + { + Q_ASSERT_X(simulator.isSingleSimulator(), Q_FUNC_INFO, "need single simulator"); + m_emulatedSimulator = simulator; + } + + QString CSwiftPluginSettings::convertToQString(bool i18n) const + { + Q_UNUSED(i18n); + static const QString ms("Emulated simulator: %1, default model: '%2', log.function calls: %3"); + return ms.arg(this->m_emulatedSimulator.toQString(), m_defaultModel.getModelStringAndDbKey(), boolToYesNo(m_logFunctionCalls)); + } + + CVariant CSwiftPluginSettings::propertyByIndex(const CPropertyIndex &index) const + { + if (index.isMyself()) { return CVariant::from(*this); } + const ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexEmulatedSimulator: + return this->m_emulatedSimulator.propertyByIndex(index.copyFrontRemoved()); + case IndexOwnModel: + return CVariant::from(m_ownModel); + case IndexDefaultModel: + return CVariant::from(m_defaultModel); + case IndexLoggingFunctionCalls: + return CVariant::from(m_logFunctionCalls); + default: + return CValueObject::propertyByIndex(index); + } + } + + void CSwiftPluginSettings::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant) + { + if (index.isMyself()) { (*this) = variant.to(); return; } + const ColumnIndex i = index.frontCasted(); + switch (i) + { + case IndexEmulatedSimulator: + this->m_emulatedSimulator.setPropertyByIndex(index.copyFrontRemoved(), variant); + break; + case IndexOwnModel: + this->m_ownModel.setPropertyByIndex(index.copyFrontRemoved(), variant); + break; + case IndexDefaultModel: + this->m_defaultModel.setPropertyByIndex(index.copyFrontRemoved(), variant); + break; + case IndexLoggingFunctionCalls: + this->m_logFunctionCalls = variant.toBool(); + break; + default: + CValueObject::setPropertyByIndex(index, variant); + break; + } + } + } // ns + } // ns +} // ns diff --git a/src/blackmisc/simulation/settings/swiftpluginsettings.h b/src/blackmisc/simulation/settings/swiftpluginsettings.h new file mode 100644 index 000000000..008696928 --- /dev/null +++ b/src/blackmisc/simulation/settings/swiftpluginsettings.h @@ -0,0 +1,106 @@ +/* Copyright (C) 2017 + * swift project community / contributors + * + * This file is part of swift project. It is subject to the license terms in the LICENSE file found in the top-level + * directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project, + * including this file, may be copied, modified, propagated, or distributed except according to the terms + * contained in the LICENSE file. + */ + +//! \file + +#ifndef BLACKMISC_SIMULATION_SETTINGS_SWIFTPLUGINSETTINGS_H +#define BLACKMISC_SIMULATION_SETTINGS_SWIFTPLUGINSETTINGS_H + +#include "blackmisc/settingscache.h" +#include "blackmisc/blackmiscexport.h" +#include "blackmisc/propertyindex.h" +#include "blackmisc/simulation/simulatorinfo.h" +#include "blackmisc/simulation/aircraftmodel.h" + +namespace BlackMisc +{ + namespace Simulation + { + namespace Settings + { + //! Settings for models + class BLACKMISC_EXPORT CSwiftPluginSettings : + public BlackMisc::CValueObject + { + public: + //! Properties by index + enum ColumnIndex + { + IndexEmulatedSimulator = BlackMisc::CPropertyIndex::GlobalIndexCSwiftPluignSettings, + IndexOwnModel, + IndexDefaultModel, + IndexLoggingFunctionCalls + }; + + //! Default constructor + CSwiftPluginSettings(); + + //! Emulated simualtor + BlackMisc::Simulation::CSimulatorInfo getEmulatedSimulator() const { return m_emulatedSimulator; } + + //! Emulated simualtor + void setEmulatedSimulator(const BlackMisc::Simulation::CSimulatorInfo &simulator); + + //! Get own model + const BlackMisc::Simulation::CAircraftModel &getOwnModel() const { return m_ownModel; } + + //! Set own model + void setOwnModel(const BlackMisc::Simulation::CAircraftModel &ownModel) { m_ownModel = ownModel; } + + //! Get default model + const BlackMisc::Simulation::CAircraftModel &getDefaultModel() const { return m_defaultModel; } + + //! Set default model + void setDefaultModel(const BlackMisc::Simulation::CAircraftModel &defaultModel) { m_defaultModel = defaultModel; } + + //! Log function calls? + bool isLoggingFunctionCalls() const { return m_logFunctionCalls; } + + //! Log function calls? + void setLoggingFunctionCalls(bool log) { m_logFunctionCalls = log; } + + //! \copydoc BlackMisc::Mixin::String::toQString + QString convertToQString(bool i18n = false) const; + + //! \copydoc BlackMisc::Mixin::Index::propertyByIndex + BlackMisc::CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const; + + //! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex + void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const BlackMisc::CVariant &variant); + + private: + BlackMisc::Simulation::CSimulatorInfo m_emulatedSimulator; + BlackMisc::Simulation::CAircraftModel m_ownModel; + BlackMisc::Simulation::CAircraftModel m_defaultModel; + bool m_logFunctionCalls = true; + + BLACK_METACLASS( + CSwiftPluginSettings, + BLACK_METAMEMBER(emulatedSimulator), + BLACK_METAMEMBER(ownModel), + BLACK_METAMEMBER(defaultModel), + BLACK_METAMEMBER(logFunctionCalls) + ); + }; + + //! Trait for swift plugin settings + struct TSwiftPlugin : public BlackMisc::TSettingTrait + { + //! Key in data cache + static const char *key() { return "settingsswiftplugin"; } + }; + } // ns + } // ns +} // ns + +Q_DECLARE_METATYPE(BlackMisc::Simulation::Settings::CSwiftPluginSettings) +Q_DECLARE_METATYPE(BlackMisc::CCollection) +Q_DECLARE_METATYPE(BlackMisc::CSequence) + +#endif // guard diff --git a/src/blackmisc/simulation/simulation.h b/src/blackmisc/simulation/simulation.h index af1c5350e..090a0cd25 100644 --- a/src/blackmisc/simulation/simulation.h +++ b/src/blackmisc/simulation/simulation.h @@ -33,5 +33,6 @@ #include "blackmisc/simulation/fscommon/aircraftcfgentrieslist.h" #include "blackmisc/simulation/fscommon/vpilotmodelruleset.h" #include "blackmisc/simulation/fsx/simconnectutilities.h" +#include "blackmisc/simulation/settings/swiftpluginsettings.h" #endif // guard