mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-05-05 01:35:45 +08:00
refs #273, added settings for simulator
* added class * adjusted settings context * adjusted "global" methods as register metadata * improved settings utility * renamed "settingsallclasses" as settings can also be in other namespaces, settingsallclasses now in core
This commit is contained in:
@@ -11,11 +11,9 @@
|
|||||||
#include "blackinput/keyboard.h"
|
#include "blackinput/keyboard.h"
|
||||||
#include "blackmisc/hwkeyboardkeylist.h"
|
#include "blackmisc/hwkeyboardkeylist.h"
|
||||||
#include "blackmisc/statusmessagelist.h"
|
#include "blackmisc/statusmessagelist.h"
|
||||||
#include "blackmisc/settingutilities.h"
|
|
||||||
#include "blackmisc/setnetwork.h"
|
|
||||||
#include "blackmisc/setaudio.h"
|
|
||||||
#include "blackmisc/dbus.h"
|
#include "blackmisc/dbus.h"
|
||||||
#include "blackmisc/variant.h"
|
#include "blackmisc/variant.h"
|
||||||
|
#include "blackcore/settingsallclasses.h"
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
|
|
||||||
@@ -38,7 +36,8 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
SettingsHotKeys,
|
SettingsHotKeys,
|
||||||
SettingsNetwork,
|
SettingsNetwork,
|
||||||
SettingsAudio
|
SettingsAudio,
|
||||||
|
SettingsSimulator
|
||||||
};
|
};
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@@ -82,6 +81,13 @@ namespace BlackCore
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Path for simulator settings
|
||||||
|
static const QString &PathSimulatorSettings()
|
||||||
|
{
|
||||||
|
static QString s("simulator");
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
//! Root path
|
//! Root path
|
||||||
static const QString &PathRoot()
|
static const QString &PathRoot()
|
||||||
{
|
{
|
||||||
@@ -123,6 +129,9 @@ namespace BlackCore
|
|||||||
//! Audio settings
|
//! Audio settings
|
||||||
virtual BlackMisc::Settings::CSettingsAudio getAudioSettings() const = 0;
|
virtual BlackMisc::Settings::CSettingsAudio getAudioSettings() const = 0;
|
||||||
|
|
||||||
|
//! Audio settings
|
||||||
|
virtual BlackSim::Settings::CSettingsSimulator getSimulatorSettings() const = 0;
|
||||||
|
|
||||||
//! Hotkeys
|
//! Hotkeys
|
||||||
virtual BlackMisc::Hardware::CKeyboardKeyList getHotkeys() const = 0;
|
virtual BlackMisc::Hardware::CKeyboardKeyList getHotkeys() const = 0;
|
||||||
|
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ using namespace BlackMisc;
|
|||||||
using namespace BlackMisc::Settings;
|
using namespace BlackMisc::Settings;
|
||||||
using namespace BlackMisc::Network;
|
using namespace BlackMisc::Network;
|
||||||
using namespace BlackMisc::Hardware;
|
using namespace BlackMisc::Hardware;
|
||||||
|
using namespace BlackSim::Settings;
|
||||||
|
|
||||||
namespace BlackCore
|
namespace BlackCore
|
||||||
{
|
{
|
||||||
@@ -62,7 +63,7 @@ namespace BlackCore
|
|||||||
if (jsonObject.contains(IContextSettings::PathAudioSettings()))
|
if (jsonObject.contains(IContextSettings::PathAudioSettings()))
|
||||||
{
|
{
|
||||||
this->m_settingsAudio.fromJson(
|
this->m_settingsAudio.fromJson(
|
||||||
jsonObject.value(IContextSettings::PathNetworkSettings()).toObject()
|
jsonObject.value(IContextSettings::PathAudioSettings()).toObject()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -70,6 +71,18 @@ namespace BlackCore
|
|||||||
this->m_settingsAudio.initDefaultValues();
|
this->m_settingsAudio.initDefaultValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// init simulator
|
||||||
|
if (jsonObject.contains(IContextSettings::PathSimulatorSettings()))
|
||||||
|
{
|
||||||
|
this->m_settingsSimulator.fromJson(
|
||||||
|
jsonObject.value(IContextSettings::PathSimulatorSettings()).toObject()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this->m_settingsSimulator.initDefaultValues();
|
||||||
|
}
|
||||||
|
|
||||||
// init own members
|
// init own members
|
||||||
if (jsonObject.contains(IContextSettings::PathHotkeys()))
|
if (jsonObject.contains(IContextSettings::PathHotkeys()))
|
||||||
{
|
{
|
||||||
@@ -129,6 +142,7 @@ namespace BlackCore
|
|||||||
this->m_hotkeys.initAsHotkeyList(true);
|
this->m_hotkeys.initAsHotkeyList(true);
|
||||||
this->m_settingsNetwork.initDefaultValues();
|
this->m_settingsNetwork.initDefaultValues();
|
||||||
this->m_settingsAudio.initDefaultValues();
|
this->m_settingsAudio.initDefaultValues();
|
||||||
|
this->m_settingsSimulator.initDefaultValues();
|
||||||
this->emitCompletelyChanged();
|
this->emitCompletelyChanged();
|
||||||
if (write)
|
if (write)
|
||||||
return this->write();
|
return this->write();
|
||||||
@@ -152,6 +166,7 @@ namespace BlackCore
|
|||||||
QJsonObject jsonObject;
|
QJsonObject jsonObject;
|
||||||
jsonObject.insert(IContextSettings::PathNetworkSettings(), this->m_settingsNetwork.toJson());
|
jsonObject.insert(IContextSettings::PathNetworkSettings(), this->m_settingsNetwork.toJson());
|
||||||
jsonObject.insert(IContextSettings::PathAudioSettings(), this->m_settingsAudio.toJson());
|
jsonObject.insert(IContextSettings::PathAudioSettings(), this->m_settingsAudio.toJson());
|
||||||
|
jsonObject.insert(IContextSettings::PathSimulatorSettings(), this->m_settingsSimulator.toJson());
|
||||||
jsonObject.insert(IContextSettings::PathHotkeys(), this->m_hotkeys.toJson());
|
jsonObject.insert(IContextSettings::PathHotkeys(), this->m_hotkeys.toJson());
|
||||||
QJsonDocument doc(jsonObject);
|
QJsonDocument doc(jsonObject);
|
||||||
return doc;
|
return doc;
|
||||||
@@ -165,6 +180,7 @@ namespace BlackCore
|
|||||||
emit this->changedSettings(IContextSettings::SettingsHotKeys);
|
emit this->changedSettings(IContextSettings::SettingsHotKeys);
|
||||||
emit this->changedSettings(IContextSettings::SettingsNetwork);
|
emit this->changedSettings(IContextSettings::SettingsNetwork);
|
||||||
emit this->changedSettings(IContextSettings::SettingsAudio);
|
emit this->changedSettings(IContextSettings::SettingsAudio);
|
||||||
|
emit this->changedSettings(IContextSettings::SettingsSimulator);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -191,6 +207,14 @@ namespace BlackCore
|
|||||||
return this->m_settingsAudio;
|
return this->m_settingsAudio;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Simulator settings
|
||||||
|
*/
|
||||||
|
CSettingsSimulator CContextSettings::getSimulatorSettings() const
|
||||||
|
{
|
||||||
|
return this->m_settingsSimulator;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Pass value
|
* Pass value
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -10,9 +10,7 @@
|
|||||||
#include "dbus_server.h"
|
#include "dbus_server.h"
|
||||||
#include "context_runtime.h"
|
#include "context_runtime.h"
|
||||||
|
|
||||||
#include "blackmisc/setnetwork.h"
|
#include "blackcore/settingsallclasses.h"
|
||||||
#include "blackmisc/setaudio.h"
|
|
||||||
|
|
||||||
#include "blackmisc/statusmessagelist.h"
|
#include "blackmisc/statusmessagelist.h"
|
||||||
#include "blackmisc/hwkeyboardkeylist.h"
|
#include "blackmisc/hwkeyboardkeylist.h"
|
||||||
|
|
||||||
@@ -20,7 +18,7 @@ namespace BlackCore
|
|||||||
{
|
{
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Settings context implementation
|
* Settings context implementation
|
||||||
*/
|
*/
|
||||||
class CContextSettings : public IContextSettings
|
class CContextSettings : public IContextSettings
|
||||||
{
|
{
|
||||||
@@ -30,10 +28,10 @@ namespace BlackCore
|
|||||||
friend class IContextSettings;
|
friend class IContextSettings;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
//! \brief Constructor
|
//! Constructor
|
||||||
CContextSettings(CRuntimeConfig::ContextMode mode, CRuntime *runtime = nullptr);
|
CContextSettings(CRuntimeConfig::ContextMode mode, CRuntime *runtime = nullptr);
|
||||||
|
|
||||||
//! \brief Register myself in DBus
|
//! Register myself in DBus
|
||||||
CContextSettings *registerWithDBus(CDBusServer *server)
|
CContextSettings *registerWithDBus(CDBusServer *server)
|
||||||
{
|
{
|
||||||
if (!server || this->m_mode != CRuntimeConfig::LocalInDbusServer) return this;
|
if (!server || this->m_mode != CRuntimeConfig::LocalInDbusServer) return this;
|
||||||
@@ -45,7 +43,7 @@ namespace BlackCore
|
|||||||
//! Destructor
|
//! Destructor
|
||||||
virtual ~CContextSettings() {}
|
virtual ~CContextSettings() {}
|
||||||
|
|
||||||
//! \brief settings file
|
//! settings file
|
||||||
const QString &getSettingsDirectory() const { return BlackMisc::Settings::CSettingUtilities::getSettingsDirectory(); }
|
const QString &getSettingsDirectory() const { return BlackMisc::Settings::CSettingUtilities::getSettingsDirectory(); }
|
||||||
|
|
||||||
//! \copydoc IContextSettings::value()
|
//! \copydoc IContextSettings::value()
|
||||||
@@ -58,10 +56,13 @@ namespace BlackCore
|
|||||||
//! \copydoc IContextSettings::getAudioSettings()
|
//! \copydoc IContextSettings::getAudioSettings()
|
||||||
virtual BlackMisc::Settings::CSettingsAudio getAudioSettings() const override;
|
virtual BlackMisc::Settings::CSettingsAudio getAudioSettings() const override;
|
||||||
|
|
||||||
|
//! \copydoc IContextSettings::getSimulatorSettings()
|
||||||
|
virtual BlackSim::Settings::CSettingsSimulator getSimulatorSettings() const override;
|
||||||
|
|
||||||
//! \copydoc IContextSettings::getHotkeys()
|
//! \copydoc IContextSettings::getHotkeys()
|
||||||
virtual BlackMisc::Hardware::CKeyboardKeyList getHotkeys() const override;
|
virtual BlackMisc::Hardware::CKeyboardKeyList getHotkeys() const override;
|
||||||
|
|
||||||
//! \brief read settings
|
//! read settings
|
||||||
virtual BlackMisc::CStatusMessage read() override;
|
virtual BlackMisc::CStatusMessage read() override;
|
||||||
|
|
||||||
//! \copydoc IContextSettings::write
|
//! \copydoc IContextSettings::write
|
||||||
@@ -79,6 +80,7 @@ namespace BlackCore
|
|||||||
private:
|
private:
|
||||||
BlackMisc::Settings::CSettingsNetwork m_settingsNetwork;
|
BlackMisc::Settings::CSettingsNetwork m_settingsNetwork;
|
||||||
BlackMisc::Settings::CSettingsAudio m_settingsAudio;
|
BlackMisc::Settings::CSettingsAudio m_settingsAudio;
|
||||||
|
BlackSim::Settings::CSettingsSimulator m_settingsSimulator;
|
||||||
BlackMisc::Hardware::CKeyboardKeyList m_hotkeys;
|
BlackMisc::Hardware::CKeyboardKeyList m_hotkeys;
|
||||||
QJsonDocument toJsonDocument() const;
|
QJsonDocument toJsonDocument() const;
|
||||||
void emitCompletelyChanged();
|
void emitCompletelyChanged();
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ using namespace BlackMisc;
|
|||||||
using namespace BlackMisc::Settings;
|
using namespace BlackMisc::Settings;
|
||||||
using namespace BlackMisc::Network;
|
using namespace BlackMisc::Network;
|
||||||
using namespace BlackMisc::Hardware;
|
using namespace BlackMisc::Hardware;
|
||||||
|
using namespace BlackSim::Settings;
|
||||||
|
|
||||||
namespace BlackCore
|
namespace BlackCore
|
||||||
{
|
{
|
||||||
@@ -57,6 +58,14 @@ namespace BlackCore
|
|||||||
return this->m_dBusInterface->callDBusRet<CSettingsAudio>(QLatin1Literal("getAudioSettings"));
|
return this->m_dBusInterface->callDBusRet<CSettingsAudio>(QLatin1Literal("getAudioSettings"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Relay to DBus
|
||||||
|
*/
|
||||||
|
CSettingsSimulator CContextSettingsProxy::getSimulatorSettings() const
|
||||||
|
{
|
||||||
|
return this->m_dBusInterface->callDBusRet<CSettingsSimulator>(QLatin1Literal("getSimulatorSettings"));
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Relay to DBus
|
* Relay to DBus
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -52,6 +52,9 @@ namespace BlackCore
|
|||||||
//! \copydoc IContextSettings::getAudioSettings()
|
//! \copydoc IContextSettings::getAudioSettings()
|
||||||
virtual BlackMisc::Settings::CSettingsAudio getAudioSettings() const override;
|
virtual BlackMisc::Settings::CSettingsAudio getAudioSettings() const override;
|
||||||
|
|
||||||
|
//! \copydoc IContextSettings::getSimulatorSettings()
|
||||||
|
virtual BlackSim::Settings::CSettingsSimulator getSimulatorSettings() const override;
|
||||||
|
|
||||||
//! \copydoc IContextSettings::getHotkeys()
|
//! \copydoc IContextSettings::getHotkeys()
|
||||||
virtual BlackMisc::Hardware::CKeyboardKeyList getHotkeys() const override;
|
virtual BlackMisc::Hardware::CKeyboardKeyList getHotkeys() const override;
|
||||||
|
|
||||||
|
|||||||
@@ -12,10 +12,10 @@
|
|||||||
#include "context.h"
|
#include "context.h"
|
||||||
#include "blackcore/dbus_server.h"
|
#include "blackcore/dbus_server.h"
|
||||||
#include "blackcore/context_runtime.h"
|
#include "blackcore/context_runtime.h"
|
||||||
#include "blackmisc/nwaircraftmodel.h"
|
|
||||||
#include "blackmisc/avaircraft.h"
|
|
||||||
#include "blacksim/simulatorinfo.h"
|
#include "blacksim/simulatorinfo.h"
|
||||||
#include "blacksim/simulatorinfolist.h"
|
#include "blacksim/simulatorinfolist.h"
|
||||||
|
#include "blackmisc/nwaircraftmodel.h"
|
||||||
|
#include "blackmisc/avaircraft.h"
|
||||||
#include "blackmisc/project.h"
|
#include "blackmisc/project.h"
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
|
|||||||
@@ -3,10 +3,10 @@
|
|||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
#ifndef BLACKMISC_SETTINGSALLCLASSES_H
|
#ifndef BLACKCORE_SETTINGSALLCLASSES_H
|
||||||
#define BLACKMISC_SETTINGSALLCLASSES_H
|
#define BLACKCORE_SETTINGSALLCLASSES_H
|
||||||
|
|
||||||
#include "blackmisc/setnetwork.h"
|
#include "blackmisc/settingsblackmiscclasses.h"
|
||||||
#include "blackmisc/setaudio.h"
|
#include "blacksim/setsimulator.h"
|
||||||
|
|
||||||
#endif // guard
|
#endif // guard
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
#include "blackmisc/pqallquantities.h"
|
#include "blackmisc/pqallquantities.h"
|
||||||
#include "blackmisc/avallclasses.h"
|
#include "blackmisc/avallclasses.h"
|
||||||
#include "blackmisc/geoallclasses.h"
|
#include "blackmisc/geoallclasses.h"
|
||||||
#include "blackmisc/settingsallclasses.h"
|
#include "blackmisc/settingsblackmiscclasses.h"
|
||||||
#include "blackmisc/indexvariantmap.h"
|
#include "blackmisc/indexvariantmap.h"
|
||||||
#include "blackmisc/networkallclasses.h"
|
#include "blackmisc/networkallclasses.h"
|
||||||
#include "blackmisc/statusmessagelist.h"
|
#include "blackmisc/statusmessagelist.h"
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#include "mathallclasses.h"
|
#include "mathallclasses.h"
|
||||||
#include "geoallclasses.h"
|
#include "geoallclasses.h"
|
||||||
#include "networkallclasses.h"
|
#include "networkallclasses.h"
|
||||||
#include "settingsallclasses.h"
|
#include "settingsblackmiscclasses.h"
|
||||||
#include "hwallclasses.h"
|
#include "hwallclasses.h"
|
||||||
#include "indexvariantmap.h"
|
#include "indexvariantmap.h"
|
||||||
#include "variant.h"
|
#include "variant.h"
|
||||||
|
|||||||
@@ -191,15 +191,8 @@ namespace BlackMisc
|
|||||||
if (command == CSettingUtilities::CmdUpdate())
|
if (command == CSettingUtilities::CmdUpdate())
|
||||||
{
|
{
|
||||||
QString v = value.toString();
|
QString v = value.toString();
|
||||||
if (this->m_bookingServiceUrl == v)
|
msgs.push_back(CSettingUtilities::valueChangedMessage(v != this->m_bookingServiceUrl, "booking URL"));
|
||||||
{
|
this->m_bookingServiceUrl = v;
|
||||||
msgs.push_back(CSettingUtilities::valueNotChangedMessage("booking URL"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
changedFlag = true;
|
|
||||||
msgs.push_back(CSettingUtilities::valueChangedMessage("booking URL"));
|
|
||||||
}
|
|
||||||
return msgs;
|
return msgs;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
7
src/blackmisc/settingsblackmiscclasses.h
Normal file
7
src/blackmisc/settingsblackmiscclasses.h
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
#ifndef BLACKMISC_SETTINGSBLACKMISCCLASSES_H
|
||||||
|
#define BLACKMISC_SETTINGSBLACKMISCCLASSES_H
|
||||||
|
|
||||||
|
#include "blackmisc/setaudio.h"
|
||||||
|
#include "blackmisc/setnetwork.h"
|
||||||
|
|
||||||
|
#endif // guard
|
||||||
@@ -37,7 +37,7 @@ namespace BlackMisc
|
|||||||
CStatusMessage CSettingUtilities::valueNotChangedMessage(const QString &valueName)
|
CStatusMessage CSettingUtilities::valueNotChangedMessage(const QString &valueName)
|
||||||
{
|
{
|
||||||
return CStatusMessage(CStatusMessage::TypeSettings, CStatusMessage::SeverityWarning,
|
return CStatusMessage(CStatusMessage::TypeSettings, CStatusMessage::SeverityWarning,
|
||||||
QString("Value %1 not changed").arg(valueName));
|
QString("Value '%1' not changed").arg(valueName));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -46,7 +46,17 @@ namespace BlackMisc
|
|||||||
CStatusMessage CSettingUtilities::valueChangedMessage(const QString &valueName)
|
CStatusMessage CSettingUtilities::valueChangedMessage(const QString &valueName)
|
||||||
{
|
{
|
||||||
return CStatusMessage(CStatusMessage::TypeSettings, CStatusMessage::SeverityInfo,
|
return CStatusMessage(CStatusMessage::TypeSettings, CStatusMessage::SeverityInfo,
|
||||||
QString("Value %1 changed").arg(valueName));
|
QString("Value '%1' changed").arg(valueName));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Value changed
|
||||||
|
*/
|
||||||
|
CStatusMessage CSettingUtilities::valueChangedMessage(bool changed, const QString &valueName)
|
||||||
|
{
|
||||||
|
return changed ?
|
||||||
|
valueChangedMessage(valueName) :
|
||||||
|
valueNotChangedMessage(valueName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -100,6 +110,5 @@ namespace BlackMisc
|
|||||||
static QString file(QString(CSettingUtilities::getSettingsDirectory()).append("/settings.json"));
|
static QString file(QString(CSettingUtilities::getSettingsDirectory()).append("/settings.json"));
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
#include "blacksimfreefunctions.h"
|
#include "blacksimfreefunctions.h"
|
||||||
|
|
||||||
|
#include "blacksim/simulatorinfo.h"
|
||||||
|
#include "blacksim/setsimulator.h"
|
||||||
|
|
||||||
#include "fsx/simconnectutilities.h"
|
#include "fsx/simconnectutilities.h"
|
||||||
#include "fscommon/aircraftcfgentrieslist.h"
|
#include "fscommon/aircraftcfgentrieslist.h"
|
||||||
#include "fscommon/aircraftmappinglist.h"
|
#include "fscommon/aircraftmappinglist.h"
|
||||||
#include "simulatorinfo.h"
|
|
||||||
|
|
||||||
namespace BlackSim
|
namespace BlackSim
|
||||||
{
|
{
|
||||||
@@ -10,6 +14,7 @@ namespace BlackSim
|
|||||||
void registerMetadata()
|
void registerMetadata()
|
||||||
{
|
{
|
||||||
BlackSim::CSimulatorInfo::registerMetadata();
|
BlackSim::CSimulatorInfo::registerMetadata();
|
||||||
|
BlackSim::Settings::CSettingsSimulator::registerMetadata();
|
||||||
BlackSim::FsCommon::CAircraftCfgEntries::registerMetadata();
|
BlackSim::FsCommon::CAircraftCfgEntries::registerMetadata();
|
||||||
BlackSim::FsCommon::CAircraftMapping::registerMetadata();
|
BlackSim::FsCommon::CAircraftMapping::registerMetadata();
|
||||||
BlackSim::FsCommon::CAircraftCfgEntriesList::registerMetadata();
|
BlackSim::FsCommon::CAircraftCfgEntriesList::registerMetadata();
|
||||||
|
|||||||
162
src/blacksim/setsimulator.cpp
Normal file
162
src/blacksim/setsimulator.cpp
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
#include "setsimulator.h"
|
||||||
|
|
||||||
|
using namespace BlackMisc;
|
||||||
|
using namespace BlackMisc::Settings;
|
||||||
|
|
||||||
|
namespace BlackSim
|
||||||
|
{
|
||||||
|
namespace Settings
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* Constructor
|
||||||
|
*/
|
||||||
|
CSettingsSimulator::CSettingsSimulator()
|
||||||
|
{
|
||||||
|
this->initDefaultValues();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Convert to string
|
||||||
|
*/
|
||||||
|
QString CSettingsSimulator::convertToQString(bool i18n) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(i18n);
|
||||||
|
QString s("Sel.driver:");
|
||||||
|
s.append(" ").append(m_selectedDriver.toQString(i18n));
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* metaTypeId
|
||||||
|
*/
|
||||||
|
int CSettingsSimulator::getMetaTypeId() const
|
||||||
|
{
|
||||||
|
return qMetaTypeId<CSettingsSimulator>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* is a
|
||||||
|
*/
|
||||||
|
bool CSettingsSimulator::isA(int metaTypeId) const
|
||||||
|
{
|
||||||
|
if (metaTypeId == qMetaTypeId<CSettingsSimulator>()) { return true; }
|
||||||
|
return this->CValueObject::isA(metaTypeId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Compare
|
||||||
|
*/
|
||||||
|
int CSettingsSimulator::compareImpl(const CValueObject &otherBase) const
|
||||||
|
{
|
||||||
|
const auto &other = static_cast<const CSettingsSimulator &>(otherBase);
|
||||||
|
return compare(TupleConverter<CSettingsSimulator>::toTuple(*this), TupleConverter<CSettingsSimulator>::toTuple(other));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Marshall
|
||||||
|
*/
|
||||||
|
void CSettingsSimulator::marshallToDbus(QDBusArgument &argument) const
|
||||||
|
{
|
||||||
|
argument << TupleConverter<CSettingsSimulator>::toTuple(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Unmarshall
|
||||||
|
*/
|
||||||
|
void CSettingsSimulator::unmarshallFromDbus(const QDBusArgument &argument)
|
||||||
|
{
|
||||||
|
argument >> TupleConverter<CSettingsSimulator>::toTuple(*this);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Equal?
|
||||||
|
*/
|
||||||
|
bool CSettingsSimulator::operator ==(const CSettingsSimulator &other) const
|
||||||
|
{
|
||||||
|
if (this == &other) return true;
|
||||||
|
return compare(*this, other) == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Unequal?
|
||||||
|
*/
|
||||||
|
bool CSettingsSimulator::operator !=(const CSettingsSimulator &other) const
|
||||||
|
{
|
||||||
|
return !((*this) == other);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Hash
|
||||||
|
*/
|
||||||
|
uint CSettingsSimulator::getValueHash() const
|
||||||
|
{
|
||||||
|
return qHash(TupleConverter<CSettingsSimulator>::toTuple(*this));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* To JSON
|
||||||
|
*/
|
||||||
|
QJsonObject CSettingsSimulator::toJson() const
|
||||||
|
{
|
||||||
|
return BlackMisc::serializeJson(CSettingsSimulator::jsonMembers(), TupleConverter<CSettingsSimulator>::toTuple(*this));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* From JSON
|
||||||
|
*/
|
||||||
|
void CSettingsSimulator::fromJson(const QJsonObject &json)
|
||||||
|
{
|
||||||
|
BlackMisc::deserializeJson(json, CSettingsSimulator::jsonMembers(), TupleConverter<CSettingsSimulator>::toTuple(*this));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Members
|
||||||
|
*/
|
||||||
|
const QStringList &CSettingsSimulator::jsonMembers()
|
||||||
|
{
|
||||||
|
return TupleConverter<CSettingsSimulator>::jsonMembers();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Default values
|
||||||
|
*/
|
||||||
|
void CSettingsSimulator::initDefaultValues()
|
||||||
|
{
|
||||||
|
this->m_selectedDriver = CSimulatorInfo::FSX();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Register metadata
|
||||||
|
*/
|
||||||
|
void CSettingsSimulator::registerMetadata()
|
||||||
|
{
|
||||||
|
qRegisterMetaType<CSettingsSimulator>();
|
||||||
|
qDBusRegisterMetaType<CSettingsSimulator>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Value
|
||||||
|
*/
|
||||||
|
BlackMisc::CStatusMessageList CSettingsSimulator::value(const QString &path, const QString &command, const CVariant &value, bool &changedFlag)
|
||||||
|
{
|
||||||
|
// TODO: This needs to be refactored to a smarter way to delegate commands
|
||||||
|
changedFlag = false;
|
||||||
|
CStatusMessageList msgs;
|
||||||
|
if (path == CSettingsSimulator::ValueSelectedDriver())
|
||||||
|
{
|
||||||
|
if (command == CSettingUtilities::CmdAdd() || command == CSettingUtilities::CmdUpdate())
|
||||||
|
{
|
||||||
|
if (command == CSettingUtilities::CmdUpdate())
|
||||||
|
{
|
||||||
|
CSimulatorInfo v = value.value<CSimulatorInfo>();
|
||||||
|
msgs.push_back(CSettingUtilities::valueChangedMessage(v != this->m_selectedDriver, "selected driver"));
|
||||||
|
this->m_selectedDriver = v;
|
||||||
|
return msgs;
|
||||||
|
}
|
||||||
|
return msgs;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return CSettingUtilities::wrongPathMessages(path);
|
||||||
|
}
|
||||||
|
} // namespace
|
||||||
|
} // namespace
|
||||||
103
src/blacksim/setsimulator.h
Normal file
103
src/blacksim/setsimulator.h
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
/* Copyright (C) 2013 VATSIM Community / authors
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
|
//! \file
|
||||||
|
|
||||||
|
#ifndef BLACKMISC_SETTINGS_SIMULATOR_H
|
||||||
|
#define BLACKMISC_SETTINGS_SIMULATOR_H
|
||||||
|
|
||||||
|
#include "blackmisc/valueobject.h"
|
||||||
|
#include "blackmisc/statusmessagelist.h"
|
||||||
|
#include "blackmisc/settingutilities.h"
|
||||||
|
#include "simulatorinfo.h"
|
||||||
|
|
||||||
|
namespace BlackSim
|
||||||
|
{
|
||||||
|
namespace Settings
|
||||||
|
{
|
||||||
|
//! Value object encapsulating information of simulator related settings.
|
||||||
|
class CSettingsSimulator : public BlackMisc::CValueObject
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
//! Default constructor.
|
||||||
|
CSettingsSimulator();
|
||||||
|
|
||||||
|
//! Destructor.
|
||||||
|
virtual ~CSettingsSimulator() {}
|
||||||
|
|
||||||
|
//! Path
|
||||||
|
static const QString &ValueSelectedDriver()
|
||||||
|
{
|
||||||
|
static const QString value("selecteddriver");
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::toQVariant()
|
||||||
|
virtual QVariant toQVariant() const override { return QVariant::fromValue(*this); }
|
||||||
|
|
||||||
|
//! Selected driver
|
||||||
|
BlackSim::CSimulatorInfo getSelectedDriver() const { return this->m_selectedDriver; }
|
||||||
|
|
||||||
|
//! Selected driver
|
||||||
|
bool setSelectedDriver(const BlackSim::CSimulatorInfo &driver) { this->m_selectedDriver = driver; }
|
||||||
|
|
||||||
|
//! Equal operator ==
|
||||||
|
bool operator ==(const CSettingsSimulator &other) const;
|
||||||
|
|
||||||
|
//! Unequal operator !=
|
||||||
|
bool operator !=(const CSettingsSimulator &other) const;
|
||||||
|
|
||||||
|
//! \copydoc BlackCore::IContextSettings
|
||||||
|
virtual BlackMisc::CStatusMessageList value(const QString &path, const QString &command, const BlackMisc::CVariant &value, bool &changedFlag);
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::getValueHash
|
||||||
|
virtual uint getValueHash() const override;
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::toJson
|
||||||
|
virtual QJsonObject toJson() const override;
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::fromJson
|
||||||
|
virtual void fromJson(const QJsonObject &json) override;
|
||||||
|
|
||||||
|
//! Init with meaningful default values
|
||||||
|
void initDefaultValues();
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::registerMetadata
|
||||||
|
static void registerMetadata();
|
||||||
|
|
||||||
|
//! \copydoc TupleConverter<>::jsonMembers()
|
||||||
|
static const QStringList &jsonMembers();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
//! \copydoc CValueObject::convertToQString
|
||||||
|
virtual QString convertToQString(bool i18n = false) const override;
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::getMetaTypeId
|
||||||
|
virtual int getMetaTypeId() const override;
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::isA
|
||||||
|
virtual bool isA(int metaTypeId) const override;
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::compareImpl
|
||||||
|
virtual int compareImpl(const CValueObject &other) const override;
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::marshallToDbus
|
||||||
|
virtual void marshallToDbus(QDBusArgument &argument) const override;
|
||||||
|
|
||||||
|
//! \copydoc CValueObject::unmarshallFromDbus
|
||||||
|
virtual void unmarshallFromDbus(const QDBusArgument &argument) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
BLACK_ENABLE_TUPLE_CONVERSION(CSettingsSimulator)
|
||||||
|
BlackSim::CSimulatorInfo m_selectedDriver;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace
|
||||||
|
} // namespace
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(BlackSim::Settings::CSettingsSimulator)
|
||||||
|
BLACK_DECLARE_TUPLE_CONVERSION(BlackSim::Settings::CSettingsSimulator, (o.m_selectedDriver))
|
||||||
|
|
||||||
|
#endif // guard
|
||||||
Reference in New Issue
Block a user