refs #116 demonstrate CVariant by using it in the settings context

This commit is contained in:
Mathew Sutcliffe
2014-05-16 19:45:55 +01:00
parent 2726a7a09a
commit 1b82536913
7 changed files with 18 additions and 43 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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