Ref T111, settings value object for swift pseudo driver

This commit is contained in:
Klaus Basan
2017-07-26 14:21:51 +02:00
committed by Mathew Sutcliffe
parent b423a62626
commit 7d88a64914
6 changed files with 196 additions and 5 deletions

View File

@@ -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 \

View File

@@ -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,

View File

@@ -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();
}

View File

@@ -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<ColumnIndex>();
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<CSwiftPluginSettings>(); return; }
const ColumnIndex i = index.frontCasted<ColumnIndex>();
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

View File

@@ -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<CSwiftPluginSettings>
{
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<CSwiftPluginSettings>
{
//! 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<BlackMisc::Simulation::Settings::CSwiftPluginSettings>)
Q_DECLARE_METATYPE(BlackMisc::CSequence<BlackMisc::Simulation::Settings::CSwiftPluginSettings>)
#endif // guard

View File

@@ -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