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/settingutilities.h"
#include "blackmisc/setnetwork.h" #include "blackmisc/setnetwork.h"
#include "blackmisc/dbus.h" #include "blackmisc/dbus.h"
#include "blackmisc/variant.h"
#include <QObject> #include <QObject>
#include <QVariant> #include <QVariant>
@@ -92,23 +93,20 @@ namespace BlackCore
//! Destructor //! Destructor
virtual ~IContextSettings() {} virtual ~IContextSettings() {}
signals:
//! Settings have been changed
void changedSettings(uint type);
public slots:
/*! /*!
* Handle value * Handle value
* \param path where value belongs to * \param path where value belongs to
* \param command what to do with value * \param command what to do with value
* \param value * \param value
* \return messages generated during handling * \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; virtual BlackMisc::CStatusMessageList value(const QString &path, const QString &command, const BlackMisc::CVariant &value) = 0;
signals:
//! Settings have been changed
void changedSettings(uint type);
public slots:
//! Network settings //! Network settings
virtual BlackMisc::Settings::CSettingsNetwork getNetworkSettings() const = 0; virtual BlackMisc::Settings::CSettingsNetwork getNetworkSettings() const = 0;

View File

@@ -171,7 +171,7 @@ namespace BlackCore
/* /*
* Pass value * 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.length() > 3);
Q_ASSERT(path.indexOf('/') >= 0); Q_ASSERT(path.indexOf('/') >= 0);
@@ -212,21 +212,4 @@ namespace BlackCore
return msgs; 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 } // namespace

View File

@@ -46,7 +46,7 @@ namespace BlackCore
const QString &getSettingsDirectory() const { return BlackMisc::Settings::CSettingUtilities::getSettingsDirectory(); } const QString &getSettingsDirectory() const { return BlackMisc::Settings::CSettingUtilities::getSettingsDirectory(); }
//! \copydoc IContextSettings::value() //! \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: public slots:
//! \copydoc IContextSettings::getNetworkSettings() //! \copydoc IContextSettings::getNetworkSettings()
@@ -55,14 +55,6 @@ namespace BlackCore
//! \copydoc IContextSettings::getHotkeys() //! \copydoc IContextSettings::getHotkeys()
virtual BlackMisc::Hardware::CKeyboardKeyList getHotkeys() const override; 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 //! \brief read settings
virtual BlackMisc::CStatusMessage read() override; virtual BlackMisc::CStatusMessage read() override;

View File

@@ -60,10 +60,9 @@ namespace BlackCore
/* /*
* Relay to DBus, but make this no slot * 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, value);
return this->m_dBusInterface->callDBusRet<BlackMisc::CStatusMessageList>(QLatin1Literal("value"), path, command, QDBusVariant(value), type);
} }
/* /*

View File

@@ -53,7 +53,7 @@ namespace BlackCore
virtual BlackMisc::Hardware::CKeyboardKeyList getHotkeys() const override; virtual BlackMisc::Hardware::CKeyboardKeyList getHotkeys() const override;
//! \copydoc IContextSettings::value //! \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 //! \copydoc IContextSettings::write
BlackMisc::CStatusMessage write() const override; BlackMisc::CStatusMessage write() const override;

View File

@@ -3,6 +3,7 @@
#include "blackmisc/blackmiscfreefunctions.h" #include "blackmisc/blackmiscfreefunctions.h"
#include "blackmisc/statusmessagelist.h" #include "blackmisc/statusmessagelist.h"
#include "blackmisc/settingutilities.h" #include "blackmisc/settingutilities.h"
#include "blackmisc/variant.h"
using namespace BlackMisc::Network; using namespace BlackMisc::Network;
@@ -155,7 +156,7 @@ namespace BlackMisc
/* /*
* Value * 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 // TODO: This needs to be refactored to a smarter way to delegate commands
changedFlag = false; changedFlag = false;

View File

@@ -14,6 +14,8 @@
namespace BlackMisc namespace BlackMisc
{ {
class CVariant;
namespace Settings namespace Settings
{ {
//! \brief Value object encapsulating information of network related settings. //! \brief Value object encapsulating information of network related settings.
@@ -86,7 +88,7 @@ namespace BlackMisc
bool operator !=(const CSettingsNetwork &other) const; bool operator !=(const CSettingsNetwork &other) const;
//! \copydoc BlackCore::IContextSettings //! \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 //! \copydoc CValueObject::getValueHash
virtual uint getValueHash() const override; virtual uint getValueHash() const override;