mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-02 15:15:50 +08:00
Move FGSwiftBus settings to own class
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include "blackmisc/simulation/fscommon/aircraftcfgentrieslist.h"
|
||||
#include "blackmisc/simulation/fscommon/vpilotmodelruleset.h"
|
||||
#include "blackmisc/simulation/fsx/simconnectutilities.h"
|
||||
#include "blackmisc/simulation/settings/fgswiftbussettings.h"
|
||||
#include "blackmisc/simulation/settings/modelsettings.h"
|
||||
#include "blackmisc/simulation/settings/simulatorsettings.h"
|
||||
#include "blackmisc/simulation/settings/swiftpluginsettings.h"
|
||||
@@ -74,6 +75,7 @@ namespace BlackMisc::Simulation
|
||||
CVPilotModelRuleSet::registerMetadata();
|
||||
CAircraftMatcherSetup::registerMetadata();
|
||||
CXSwiftBusSettings::registerMetadata();
|
||||
CFGSwiftBusSettings::registerMetadata();
|
||||
|
||||
qRegisterMetaType<CSimulatorSettings::CGSource>();
|
||||
qRegisterMetaType<CAircraftMatcherSetup::MatchingAlgorithm>();
|
||||
|
||||
49
src/blackmisc/simulation/settings/fgswiftbussettings.cpp
Normal file
49
src/blackmisc/simulation/settings/fgswiftbussettings.cpp
Normal file
@@ -0,0 +1,49 @@
|
||||
/* Copyright (C) 2023
|
||||
* 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. 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 "blackmisc/simulation/settings/fgswiftbussettings.h"
|
||||
|
||||
BLACK_DEFINE_VALUEOBJECT_MIXINS(BlackMisc::Simulation::Settings, CFGSwiftBusSettings)
|
||||
|
||||
namespace BlackMisc::Simulation::Settings
|
||||
{
|
||||
QVariant CFGSwiftBusSettings::propertyByIndex(BlackMisc::CPropertyIndexRef index) const
|
||||
{
|
||||
if (index.isMyself()) { return QVariant::fromValue(*this); }
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexDBusServerAddress:
|
||||
return QVariant::fromValue(m_dBusServerAddress);
|
||||
default: break;
|
||||
}
|
||||
return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
|
||||
void CFGSwiftBusSettings::setPropertyByIndex(CPropertyIndexRef index, const QVariant &variant)
|
||||
{
|
||||
if (index.isMyself()) { (*this) = variant.value<CFGSwiftBusSettings>(); return; }
|
||||
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexDBusServerAddress:
|
||||
m_dBusServerAddress = variant.toString(); break;
|
||||
default:
|
||||
CValueObject::setPropertyByIndex(index, variant);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QString CFGSwiftBusSettings::convertToQString(bool i18n) const
|
||||
{
|
||||
Q_UNUSED(i18n);
|
||||
return "DBusServer: " + m_dBusServerAddress;
|
||||
}
|
||||
|
||||
} // ns
|
||||
@@ -13,28 +13,71 @@
|
||||
#define BLACKMISC_SIMULATION_SETTINGS_FGSWIFTBUSSETTINGS_H
|
||||
|
||||
#include <QString>
|
||||
#include "blackmisc/settingscache.h"
|
||||
#include "blackmisc/dbusserver.h"
|
||||
#include "blackmisc/settingscache.h"
|
||||
#include "blackmisc/valueobject.h"
|
||||
|
||||
BLACK_DECLARE_VALUEOBJECT_MIXINS(BlackMisc::Simulation::Settings, CFGSwiftBusSettings)
|
||||
|
||||
namespace BlackMisc::Simulation::Settings
|
||||
{
|
||||
//! FGSwiftBus settings
|
||||
class BLACKMISC_EXPORT CFGSwiftBusSettings final :
|
||||
public CValueObject<CFGSwiftBusSettings>
|
||||
{
|
||||
public:
|
||||
//! Properties by index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexDBusServerAddress = CPropertyIndexRef::GlobalIndexCFGSwiftBusSettings,
|
||||
};
|
||||
|
||||
//! Default constructor
|
||||
CFGSwiftBusSettings() = default;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
|
||||
QVariant propertyByIndex(BlackMisc::CPropertyIndexRef index) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
|
||||
void setPropertyByIndex(BlackMisc::CPropertyIndexRef index, const QVariant &variant);
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
//! DBus server
|
||||
QString getDBusServerAddress() const { return m_dBusServerAddress; }
|
||||
|
||||
//! Set DBus server
|
||||
void setDBusServerAddress(const QString &dBusServer) { m_dBusServerAddress = dBusServer; }
|
||||
|
||||
private:
|
||||
QString m_dBusServerAddress { "tcp:host=127.0.0.1,port=45003" }; //!< DBus server
|
||||
|
||||
BLACK_METACLASS(
|
||||
CFGSwiftBusSettings,
|
||||
BLACK_METAMEMBER(dBusServerAddress)
|
||||
);
|
||||
};
|
||||
|
||||
/*!
|
||||
* Setting for FGSwiftBus.
|
||||
*/
|
||||
struct TFGSwiftBusServer : public BlackMisc::TSettingTrait<QString>
|
||||
struct TFGSwiftBusServer : public BlackMisc::TSettingTrait<CFGSwiftBusSettings>
|
||||
{
|
||||
//! \copydoc BlackMisc::TSettingTrait::key
|
||||
static const char *key() { return "fgswiftbus/server"; }
|
||||
static const char *key() { return "fgswiftbus/settings"; }
|
||||
|
||||
//! \copydoc BlackCore::TSettingTrait::humanReadable
|
||||
static const QString &humanReadable() { static const QString name("FGSwiftBus"); return name; }
|
||||
|
||||
//! \copydoc BlackMisc::TSettingTrait::defaultValue
|
||||
static QString defaultValue() { return "tcp:host=127.0.0.1,port=45003"; }
|
||||
static CFGSwiftBusSettings defaultValue() { return CFGSwiftBusSettings(); }
|
||||
|
||||
//! \copydoc BlackMisc::TSettingTrait::isValid
|
||||
static bool isValid(const QString &dBusAddress, QString &) { return BlackMisc::CDBusServer::isSessionOrSystemAddress(dBusAddress) || BlackMisc::CDBusServer::isQtDBusAddress(dBusAddress); }
|
||||
static bool isValid(const CFGSwiftBusSettings &settings, QString &) { return BlackMisc::CDBusServer::isSessionOrSystemAddress(settings.getDBusServerAddress()) || BlackMisc::CDBusServer::isQtDBusAddress(settings.getDBusServerAddress()); }
|
||||
};
|
||||
} // ns
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::Simulation::Settings::CFGSwiftBusSettings)
|
||||
|
||||
#endif // guard
|
||||
|
||||
Reference in New Issue
Block a user