From 06687a7f140678f26d9394b4f0b5a4a41aaab63c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Tue, 18 Oct 2016 11:55:14 +0200 Subject: QStateAction: add ability to activate or change state by variant string --- libqmenumodel/src/qstateaction.cpp | 20 ++++++++++++++++++++ libqmenumodel/src/qstateaction.h | 2 ++ libqmenumodel/src/unitymenumodel.h | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) (limited to 'libqmenumodel') diff --git a/libqmenumodel/src/qstateaction.cpp b/libqmenumodel/src/qstateaction.cpp index 983064a..fcffa44 100644 --- a/libqmenumodel/src/qstateaction.cpp +++ b/libqmenumodel/src/qstateaction.cpp @@ -19,6 +19,7 @@ #include "qstateaction.h" +#include "converter.h" #include "qdbusactiongroup.h" /*! @@ -98,6 +99,15 @@ void QStateAction::updateState(const QVariant &state) m_group->updateActionState(m_name, v); } +/*! + Request for the state of action to be changed to \a paramenter. + This call merely requests a change. The action may refuse to change its state or may change its state to something other than \a paramenter. +*/ +void QStateAction::updateStateByVariantString(const QString &state) +{ + updateState(Converter::toQVariantFromVariantString(state)); +} + /*! Activates the action passing \a parameter. \a parameter must be the correct type of parameter for the action @@ -107,6 +117,16 @@ void QStateAction::activate(const QVariant ¶meter) m_group->activateAction(m_name, parameter); } +/*! + Activates the action passing \a parameter using GLib Variant String format. + \a parameter must be the correct type of parameter for the action +*/ +void QStateAction::activateByVariantString(const QString ¶meter) +{ + activate(Converter::toQVariantFromVariantString(parameter)); +} + + /*! \internal */ QString QStateAction::name() const { diff --git a/libqmenumodel/src/qstateaction.h b/libqmenumodel/src/qstateaction.h index 0fc68c2..4d05a7a 100644 --- a/libqmenumodel/src/qstateaction.h +++ b/libqmenumodel/src/qstateaction.h @@ -36,7 +36,9 @@ public: bool isValid() const; Q_INVOKABLE void activate(const QVariant ¶meter = QVariant()); + Q_INVOKABLE void activateByVariantString(const QString ¶meter = QString()); Q_INVOKABLE void updateState(const QVariant ¶meter); + Q_INVOKABLE void updateStateByVariantString(const QString ¶meter); Q_SIGNALS: void stateChanged(QVariant state); diff --git a/libqmenumodel/src/unitymenumodel.h b/libqmenumodel/src/unitymenumodel.h index 826d5b2..ed3bcd7 100644 --- a/libqmenumodel/src/unitymenumodel.h +++ b/libqmenumodel/src/unitymenumodel.h @@ -65,7 +65,7 @@ public: Q_INVOKABLE void activate(int index, const QVariant& parameter = QVariant()); Q_INVOKABLE void activateByVariantString(int index, const QString& parameter = QString()); Q_INVOKABLE void changeState(int index, const QVariant& parameter); - Q_INVOKABLE void changeStateByVariantString(int index, const QString& parameter = QString()); + Q_INVOKABLE void changeStateByVariantString(int index, const QString& parameter); void registerAction(UnityMenuAction* action); void unregisterAction(UnityMenuAction* action); -- cgit v1.2.3