aboutsummaryrefslogtreecommitdiff
path: root/libqmenumodel/src
diff options
context:
space:
mode:
authorRenato Araujo Oliveira Filho <renato.filho@canonical.com>2012-11-22 16:13:02 -0300
committerRenato Araujo Oliveira Filho <renato.filho@canonical.com>2012-11-22 16:13:02 -0300
commita745160b7a3460f25fa52f9902e306e071949346 (patch)
tree3f57894fdaae09304b7a759c8026947110743b33 /libqmenumodel/src
parent04391e9723278f8bb0a0985abd50aa9c3455980d (diff)
downloadqmenumodel-a745160b7a3460f25fa52f9902e306e071949346.tar.gz
qmenumodel-a745160b7a3460f25fa52f9902e306e071949346.tar.bz2
qmenumodel-a745160b7a3460f25fa52f9902e306e071949346.zip
Removed QAction dependecy from QStateAction.
Exported activate function on QStateAction.
Diffstat (limited to 'libqmenumodel/src')
-rw-r--r--libqmenumodel/src/CMakeLists.txt2
-rw-r--r--libqmenumodel/src/qdbusactiongroup.cpp4
-rw-r--r--libqmenumodel/src/qstateaction.cpp33
-rw-r--r--libqmenumodel/src/qstateaction.h14
4 files changed, 30 insertions, 23 deletions
diff --git a/libqmenumodel/src/CMakeLists.txt b/libqmenumodel/src/CMakeLists.txt
index 8edb3e1..fe7d433 100644
--- a/libqmenumodel/src/CMakeLists.txt
+++ b/libqmenumodel/src/CMakeLists.txt
@@ -31,7 +31,7 @@ target_link_libraries(${SHAREDLIBNAME}
${GIO_LDFLAGS}
)
-qt5_use_modules(${SHAREDLIBNAME} Core Widgets)
+qt5_use_modules(${SHAREDLIBNAME} Core)
install(TARGETS ${SHAREDLIBNAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR})
diff --git a/libqmenumodel/src/qdbusactiongroup.cpp b/libqmenumodel/src/qdbusactiongroup.cpp
index 756bb76..824b5f0 100644
--- a/libqmenumodel/src/qdbusactiongroup.cpp
+++ b/libqmenumodel/src/qdbusactiongroup.cpp
@@ -104,7 +104,7 @@ bool QDBusActionGroup::hasAction(const QString &name)
QStateAction *QDBusActionGroup::actionImpl(const QString &name)
{
Q_FOREACH(QStateAction *act, this->findChildren<QStateAction*>()) {
- if (act->text() == name) {
+ if (act->name() == name) {
return act;
}
}
@@ -194,7 +194,7 @@ void QDBusActionGroup::setActionGroup(GDBusActionGroup *ag)
void QDBusActionGroup::clear()
{
Q_FOREACH(QStateAction *act, this->findChildren<QStateAction*>()) {
- Q_EMIT actionVanish(act->text());
+ Q_EMIT actionVanish(act->name());
}
if (m_actionGroup != NULL) {
diff --git a/libqmenumodel/src/qstateaction.cpp b/libqmenumodel/src/qstateaction.cpp
index dd4e541..18c3c81 100644
--- a/libqmenumodel/src/qstateaction.cpp
+++ b/libqmenumodel/src/qstateaction.cpp
@@ -47,11 +47,10 @@
/*! \internal */
QStateAction::QStateAction(QDBusActionGroup *group, const QString &name)
- : QAction(name, group),
- m_group(group)
+ : QObject(group),
+ m_group(group),
+ m_name(name)
{
- QObject::connect(this, SIGNAL(triggered()), this, SLOT(onTriggered()));
-
// This keep the code clean
// But maybe we need move the action state control to QActionGroup to optimizations
QObject::connect(m_group, SIGNAL(actionAppear(QString)),
@@ -89,9 +88,19 @@ bool QStateAction::isValid() const
return m_valid;
}
-void QStateAction::updateState(const QVariant &state)
+QString QStateAction::name() const
+{
+ return m_name;
+}
+
+void QStateAction::updateState(const QVariant &parameter)
{
- m_group->updateActionState(text(), state);
+ m_group->updateActionState(m_name, parameter);
+}
+
+void QStateAction::activate(const QVariant &parameter)
+{
+ m_group->activateAction(m_name, parameter);
}
/*! \internal */
@@ -113,15 +122,9 @@ void QStateAction::setState(const QVariant &state)
}
/*! \internal */
-void QStateAction::onTriggered()
-{
- m_group->activateAction(text(), QVariant());
-}
-
-/*! \internal */
void QStateAction::onActionAppear(const QString &name)
{
- if (text() == name) {
+ if (m_name == name) {
setState(m_group->actionState(name));
setValid(true);
}
@@ -130,7 +133,7 @@ void QStateAction::onActionAppear(const QString &name)
/*! \internal */
void QStateAction::onActionVanish(const QString &name)
{
- if (text() == name) {
+ if (m_name == name) {
setState(QVariant());
setValid(false);
}
@@ -139,7 +142,7 @@ void QStateAction::onActionVanish(const QString &name)
/*! \internal */
void QStateAction::onActionStateChanged(const QString &name, const QVariant &state)
{
- if (text() == name) {
+ if (m_name == name) {
setState(state);
}
}
diff --git a/libqmenumodel/src/qstateaction.h b/libqmenumodel/src/qstateaction.h
index 85f207a..0fc68c2 100644
--- a/libqmenumodel/src/qstateaction.h
+++ b/libqmenumodel/src/qstateaction.h
@@ -20,21 +20,23 @@
#ifndef QDBUSACTION_H
#define QDBUSACTION_H
-#include <QAction>
+#include <QObject>
#include <QVariant>
class QDBusActionGroup;
-class QStateAction : public QAction
+class QStateAction : public QObject
{
Q_OBJECT
- Q_PROPERTY(QVariant state READ state WRITE setState NOTIFY stateChanged)
+ Q_PROPERTY(QString name READ name)
+ Q_PROPERTY(QVariant state READ state NOTIFY stateChanged)
Q_PROPERTY(bool valid READ isValid NOTIFY validChanged)
public:
QVariant state() const;
bool isValid() const;
- Q_INVOKABLE void updateState(const QVariant &state);
+ Q_INVOKABLE void activate(const QVariant &parameter = QVariant());
+ Q_INVOKABLE void updateState(const QVariant &parameter);
Q_SIGNALS:
void stateChanged(QVariant state);
@@ -44,16 +46,18 @@ private Q_SLOTS:
void onActionAppear(const QString &name);
void onActionVanish(const QString &name);
void onActionStateChanged(const QString &name, const QVariant &state);
- void onTriggered();
private:
QDBusActionGroup *m_group;
QVariant m_state;
bool m_valid;
+ QString m_name;
QStateAction(QDBusActionGroup *group, const QString &name);
+
void setValid(bool valid);
void setState(const QVariant &state);
+ QString name() const;
friend class QDBusActionGroup;
};