mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-05 01:05:34 +08:00
Ref T709, based on the Qt free base class, added swift compliant settings class
This commit is contained in:
committed by
Mat Sutcliffe
parent
a809679b34
commit
81c832457e
@@ -49,6 +49,7 @@ namespace BlackMisc
|
||||
CVPilotModelRule::registerMetadata();
|
||||
CVPilotModelRuleSet::registerMetadata();
|
||||
CAircraftMatcherSetup::registerMetadata();
|
||||
CXSwiftBusSettings::registerMetadata();
|
||||
|
||||
qRegisterMetaType<CSimulatorSettings::CGSource>();
|
||||
qRegisterMetaType<CAircraftMatcherSetup::MatchingAlgorithm>();
|
||||
|
||||
79
src/blackmisc/simulation/settings/xswiftbussettings.cpp
Normal file
79
src/blackmisc/simulation/settings/xswiftbussettings.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
/* Copyright (C) 2019
|
||||
* 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 "xswiftbussettings.h"
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
namespace Simulation
|
||||
{
|
||||
namespace Settings
|
||||
{
|
||||
CXSwiftBusSettings::CXSwiftBusSettings() { }
|
||||
|
||||
CXSwiftBusSettings::CXSwiftBusSettings(const QString &json)
|
||||
{
|
||||
this->parseXSwiftBusStringQt(json);
|
||||
}
|
||||
|
||||
CVariant CXSwiftBusSettings::propertyByIndex(const CPropertyIndex &index) const
|
||||
{
|
||||
if (index.isMyself()) { return CVariant::from(*this); }
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexMaxPlanes: return CVariant::fromValue(m_maxPlanes);
|
||||
case IndexDBusServerAddress: return CVariant::fromValue(QString::fromStdString(m_dBusServerAddress));
|
||||
case IndexDrawingLabels: return CVariant::fromValue(m_drawingLabels);
|
||||
case IndexMaxDrawingDistance: return CVariant::fromValue(m_maxDrawDistanceNM);
|
||||
default: break;
|
||||
}
|
||||
return CValueObject::propertyByIndex(index);
|
||||
}
|
||||
|
||||
void CXSwiftBusSettings::setPropertyByIndex(const CPropertyIndex &index, const CVariant &variant)
|
||||
{
|
||||
if (index.isMyself()) { (*this) = variant.to<CXSwiftBusSettings>(); return; }
|
||||
const ColumnIndex i = index.frontCasted<ColumnIndex>();
|
||||
switch (i)
|
||||
{
|
||||
case IndexMaxPlanes: m_maxPlanes = variant.toInt(); break;
|
||||
case IndexDBusServerAddress: m_dBusServerAddress = variant.toStdString(); break;
|
||||
case IndexDrawingLabels: m_drawingLabels = variant.toBool(); break;
|
||||
case IndexMaxDrawingDistance: m_maxDrawDistanceNM = variant.toDouble(); break;
|
||||
default:
|
||||
CValueObject::setPropertyByIndex(index, variant);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
QString CXSwiftBusSettings::convertToQString(bool i18n) const
|
||||
{
|
||||
Q_UNUSED(i18n);
|
||||
return "";
|
||||
}
|
||||
|
||||
CStatusMessageList CXSwiftBusSettings::validate() const
|
||||
{
|
||||
CStatusMessageList msgs;
|
||||
const QString dbus = QString::fromStdString(m_dBusServerAddress);
|
||||
if (!CDBusServer::isSessionOrSystemAddress(dbus) && !CDBusServer::isQtDBusAddress(dbus))
|
||||
{
|
||||
msgs.addValidationMessage(QStringLiteral("Invalid DBus address '%1'").arg(dbus), CStatusMessage::SeverityError);
|
||||
}
|
||||
return msgs;
|
||||
}
|
||||
|
||||
const CXSwiftBusSettings &CXSwiftBusSettings::defaultValue()
|
||||
{
|
||||
static const CXSwiftBusSettings s;
|
||||
return s;
|
||||
}
|
||||
} // ns
|
||||
} // ns
|
||||
} // ns
|
||||
@@ -11,9 +11,14 @@
|
||||
#ifndef BLACKMISC_SIMULATION_SETTINGS_XSWIFTBUSSETTINGS_H
|
||||
#define BLACKMISC_SIMULATION_SETTINGS_XSWIFTBUSSETTINGS_H
|
||||
|
||||
#include <QString>
|
||||
#include "xswiftbussettingsqtfree.h"
|
||||
#include "blackmisc/statusmessagelist.h"
|
||||
#include "blackmisc/settingscache.h"
|
||||
#include "blackmisc/dbusserver.h"
|
||||
#include "blackmisc/valueobject.h"
|
||||
#include "blackmisc/blackmiscexport.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
@@ -21,10 +26,71 @@ namespace BlackMisc
|
||||
{
|
||||
namespace Settings
|
||||
{
|
||||
//! XSwiftBus settings
|
||||
class BLACKMISC_EXPORT CXSwiftBusSettings :
|
||||
public CValueObject<CXSwiftBusSettings>,
|
||||
public CXSwiftBusSettingsQtFree,
|
||||
public ITimestampBased
|
||||
{
|
||||
public:
|
||||
//! Properties by index
|
||||
enum ColumnIndex
|
||||
{
|
||||
IndexDBusServerAddress = CPropertyIndex::GlobalIndexCXSwiftBusSettings,
|
||||
IndexMaxPlanes,
|
||||
IndexDrawingLabels,
|
||||
IndexMaxDrawingDistance
|
||||
};
|
||||
|
||||
//! Default constructor
|
||||
CXSwiftBusSettings();
|
||||
|
||||
//! From JSON constructor
|
||||
CXSwiftBusSettings(const QString &json);
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::propertyByIndex
|
||||
CVariant propertyByIndex(const BlackMisc::CPropertyIndex &index) const;
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::Index::setPropertyByIndex
|
||||
void setPropertyByIndex(const BlackMisc::CPropertyIndex &index, const CVariant &variant);
|
||||
|
||||
//! \copydoc BlackMisc::Mixin::String::toQString
|
||||
QString convertToQString(bool i18n = false) const;
|
||||
|
||||
//! \copydoc CXSwiftBusSettingsQtFree::getDBusServerAddress
|
||||
QString getDBusServerAddressQt() const { return QString::fromStdString(this->getDBusServerAddress()); }
|
||||
|
||||
//! \copydoc CXSwiftBusSettingsQtFree::setDBusServerAddress
|
||||
void setDBusServerAddressQt(const QString &dBusAddress) { this->setDBusServerAddress(dBusAddress.toStdString()); }
|
||||
|
||||
//! \copydoc CXSwiftBusSettingsQtFree::toXSwiftBusJsonString
|
||||
QString toXSwiftBusJsonStringQt() const { return QString::fromStdString(this->toXSwiftBusJsonString()); }
|
||||
|
||||
//! \copydoc CXSwiftBusSettingsQtFree::parseXSwiftBusString
|
||||
void parseXSwiftBusStringQt(const QString &json) { this->parseXSwiftBusString(json.toStdString()); }
|
||||
|
||||
//! Valid settings?
|
||||
CStatusMessageList validate() const;
|
||||
|
||||
//! Default value for settings
|
||||
static const CXSwiftBusSettings &defaultValue();
|
||||
|
||||
private:
|
||||
BLACK_METACLASS(
|
||||
CXSwiftBusSettings,
|
||||
BLACK_METAMEMBER(dBusServerAddress),
|
||||
BLACK_METAMEMBER(maxPlanes),
|
||||
BLACK_METAMEMBER(drawingLabels),
|
||||
BLACK_METAMEMBER(maxDrawDistanceNM),
|
||||
BLACK_METAMEMBER(timestampMSecsSinceEpoch, 0, DisabledForComparison | DisabledForHashing)
|
||||
);
|
||||
};
|
||||
|
||||
/*!
|
||||
* Setting for XSwiftBus.
|
||||
* @deprecated will be changed to JSON Settings
|
||||
*/
|
||||
struct TXSwiftBusServer : public BlackMisc::TSettingTrait<QString>
|
||||
struct TXSwiftBusServer : public TSettingTrait<QString>
|
||||
{
|
||||
//! \copydoc BlackMisc::TSettingTrait::key
|
||||
static const char *key() { return "xswiftbus/server"; }
|
||||
@@ -38,8 +104,33 @@ namespace BlackMisc
|
||||
//! \copydoc BlackMisc::TSettingTrait::isValid
|
||||
static bool isValid(const QString &dBusAddress, QString &) { return BlackMisc::CDBusServer::isSessionOrSystemAddress(dBusAddress) || BlackMisc::CDBusServer::isQtDBusAddress(dBusAddress); }
|
||||
};
|
||||
|
||||
/*!
|
||||
* Setting for XSwiftBus.
|
||||
*/
|
||||
struct TXSwiftBusSettings : public TSettingTrait<CXSwiftBusSettings>
|
||||
{
|
||||
//! \copydoc BlackMisc::TSettingTrait::key
|
||||
static const char *key() { return "xswiftbus/settings"; }
|
||||
|
||||
//! \copydoc BlackMisc::TSettingTrait::humanReadable
|
||||
static const QString &humanReadable() { static const QString name("XSwiftBus"); return name; }
|
||||
|
||||
//! \copydoc BlackMisc::TSettingTrait::defaultValue
|
||||
static CXSwiftBusSettings defaultValue() { return CXSwiftBusSettings::defaultValue(); }
|
||||
|
||||
//! \copydoc BlackMisc::TSettingTrait::isValid
|
||||
static bool isValid(const CXSwiftBusSettings &settings, QString &reason)
|
||||
{
|
||||
const CStatusMessageList msgs = settings.validate();
|
||||
reason = msgs.toQString(true);
|
||||
return msgs.isSuccess();
|
||||
}
|
||||
};
|
||||
} // ns
|
||||
} // ns
|
||||
} // ns
|
||||
|
||||
Q_DECLARE_METATYPE(BlackMisc::Simulation::Settings::CXSwiftBusSettings)
|
||||
|
||||
#endif // guard
|
||||
|
||||
@@ -36,5 +36,6 @@
|
||||
#include "blackmisc/simulation/settings/modelsettings.h"
|
||||
#include "blackmisc/simulation/settings/simulatorsettings.h"
|
||||
#include "blackmisc/simulation/settings/swiftpluginsettings.h"
|
||||
#include "blackmisc/simulation/settings/xswiftbussettings.h"
|
||||
|
||||
#endif // guard
|
||||
|
||||
Reference in New Issue
Block a user