mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-23 07:15:35 +08:00
refs #116 demonstrate CVariant by using it in the settings context
This commit is contained in:
@@ -14,6 +14,7 @@
|
||||
#include "blackmisc/settingutilities.h"
|
||||
#include "blackmisc/setnetwork.h"
|
||||
#include "blackmisc/dbus.h"
|
||||
#include "blackmisc/variant.h"
|
||||
#include <QObject>
|
||||
#include <QVariant>
|
||||
|
||||
@@ -92,23 +93,20 @@ namespace BlackCore
|
||||
//! Destructor
|
||||
virtual ~IContextSettings() {}
|
||||
|
||||
signals:
|
||||
//! Settings have been changed
|
||||
void changedSettings(uint type);
|
||||
|
||||
public slots:
|
||||
|
||||
/*!
|
||||
* Handle value
|
||||
* \param path where value belongs to
|
||||
* \param command what to do with value
|
||||
* \param value
|
||||
* \return messages generated during handling
|
||||
* \remarks Do not make this a slot, no DBus XML signature shall be created. The QVariant
|
||||
* will be send a tailored value method using QDBusVariant
|
||||
* @see value(const QString &, const QString &, QDBusVariant, int)
|
||||
*/
|
||||
virtual BlackMisc::CStatusMessageList value(const QString &path, const QString &command, const QVariant &value) = 0;
|
||||
|
||||
signals:
|
||||
//! Settings have been changed
|
||||
void changedSettings(uint type);
|
||||
|
||||
public slots:
|
||||
virtual BlackMisc::CStatusMessageList value(const QString &path, const QString &command, const BlackMisc::CVariant &value) = 0;
|
||||
|
||||
//! Network settings
|
||||
virtual BlackMisc::Settings::CSettingsNetwork getNetworkSettings() const = 0;
|
||||
|
||||
@@ -171,7 +171,7 @@ namespace BlackCore
|
||||
/*
|
||||
* Pass value
|
||||
*/
|
||||
BlackMisc::CStatusMessageList CContextSettings::value(const QString &path, const QString &command, const QVariant &value)
|
||||
BlackMisc::CStatusMessageList CContextSettings::value(const QString &path, const QString &command, const BlackMisc::CVariant &value)
|
||||
{
|
||||
Q_ASSERT(path.length() > 3);
|
||||
Q_ASSERT(path.indexOf('/') >= 0);
|
||||
@@ -212,21 +212,4 @@ namespace BlackCore
|
||||
return msgs;
|
||||
}
|
||||
|
||||
/*
|
||||
* DBus version of value
|
||||
*/
|
||||
BlackMisc::CStatusMessageList CContextSettings::value(const QString &path, const QString &command, QDBusVariant value, int unifiedBlackMetaType)
|
||||
{
|
||||
QVariant qv = value.variant();
|
||||
if (qv.canConvert<QDBusArgument>())
|
||||
{
|
||||
// convert from QDBusArgument
|
||||
int type = BlackMisc::firstBlackMetaType() + unifiedBlackMetaType; // unify
|
||||
qv = BlackMisc::fixQVariantFromDbusArgument(qv, type);
|
||||
}
|
||||
// when called locally, this will call the virtual method
|
||||
// of the concrete implementation in context_settings
|
||||
return this->value(path, command, qv);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace BlackCore
|
||||
const QString &getSettingsDirectory() const { return BlackMisc::Settings::CSettingUtilities::getSettingsDirectory(); }
|
||||
|
||||
//! \copydoc IContextSettings::value()
|
||||
virtual BlackMisc::CStatusMessageList value(const QString &path, const QString &command, const QVariant &value) override;
|
||||
virtual BlackMisc::CStatusMessageList value(const QString &path, const QString &command, const BlackMisc::CVariant &value) override;
|
||||
|
||||
public slots:
|
||||
//! \copydoc IContextSettings::getNetworkSettings()
|
||||
@@ -55,14 +55,6 @@ namespace BlackCore
|
||||
//! \copydoc IContextSettings::getHotkeys()
|
||||
virtual BlackMisc::Hardware::CKeyboardKeyList getHotkeys() const override;
|
||||
|
||||
/*!
|
||||
* \brief DBus version of value method.
|
||||
* \remarks Basically an unwanted signature as this is different from the "local" signature and
|
||||
* contains explicit DBus types (a: QDbusArgument, b: type for conversion).
|
||||
* If this can be removed, fine. -> https://dev.vatsim-germany.org/issues/116
|
||||
*/
|
||||
virtual BlackMisc::CStatusMessageList value(const QString &path, const QString &command, QDBusVariant value, int unifiedBlackMetaType);
|
||||
|
||||
//! \brief read settings
|
||||
virtual BlackMisc::CStatusMessage read() override;
|
||||
|
||||
|
||||
@@ -60,10 +60,9 @@ namespace BlackCore
|
||||
/*
|
||||
* Relay to DBus, but make this no slot
|
||||
*/
|
||||
BlackMisc::CStatusMessageList CContextSettingsProxy::value(const QString &path, const QString &command, const QVariant &value)
|
||||
BlackMisc::CStatusMessageList CContextSettingsProxy::value(const QString &path, const QString &command, const BlackMisc::CVariant &value)
|
||||
{
|
||||
int type = value.userType() - BlackMisc::firstBlackMetaType();
|
||||
return this->m_dBusInterface->callDBusRet<BlackMisc::CStatusMessageList>(QLatin1Literal("value"), path, command, QDBusVariant(value), type);
|
||||
return this->m_dBusInterface->callDBusRet<BlackMisc::CStatusMessageList>(QLatin1Literal("value"), path, command, value);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -53,7 +53,7 @@ namespace BlackCore
|
||||
virtual BlackMisc::Hardware::CKeyboardKeyList getHotkeys() const override;
|
||||
|
||||
//! \copydoc IContextSettings::value
|
||||
virtual BlackMisc::CStatusMessageList value(const QString &path, const QString &command, const QVariant &value) override;
|
||||
virtual BlackMisc::CStatusMessageList value(const QString &path, const QString &command, const BlackMisc::CVariant &value) override;
|
||||
|
||||
//! \copydoc IContextSettings::write
|
||||
BlackMisc::CStatusMessage write() const override;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "blackmisc/blackmiscfreefunctions.h"
|
||||
#include "blackmisc/statusmessagelist.h"
|
||||
#include "blackmisc/settingutilities.h"
|
||||
#include "blackmisc/variant.h"
|
||||
|
||||
using namespace BlackMisc::Network;
|
||||
|
||||
@@ -155,7 +156,7 @@ namespace BlackMisc
|
||||
/*
|
||||
* Value
|
||||
*/
|
||||
BlackMisc::CStatusMessageList CSettingsNetwork::value(const QString &path, const QString &command, const QVariant &value, bool &changedFlag)
|
||||
BlackMisc::CStatusMessageList CSettingsNetwork::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;
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
|
||||
namespace BlackMisc
|
||||
{
|
||||
class CVariant;
|
||||
|
||||
namespace Settings
|
||||
{
|
||||
//! \brief Value object encapsulating information of network related settings.
|
||||
@@ -86,7 +88,7 @@ namespace BlackMisc
|
||||
bool operator !=(const CSettingsNetwork &other) const;
|
||||
|
||||
//! \copydoc BlackCore::IContextSettings
|
||||
virtual BlackMisc::CStatusMessageList value(const QString &path, const QString &command, const QVariant &value, bool &changedFlag);
|
||||
virtual BlackMisc::CStatusMessageList value(const QString &path, const QString &command, const CVariant &value, bool &changedFlag);
|
||||
|
||||
//! \copydoc CValueObject::getValueHash
|
||||
virtual uint getValueHash() const override;
|
||||
|
||||
Reference in New Issue
Block a user