From 7adeff65148a3967af7b2ec44764a2c275dcd3fe Mon Sep 17 00:00:00 2001 From: Daiwei Li Date: Wed, 18 Sep 2013 16:20:18 -0700 Subject: Add source QObject to QQuickAction's triggered signal Based on a suggestion from Gabriel de Dietrich. Knowing the source object that triggered an action is useful for analytics purposes. Change-Id: I11f62214fa669a91769a0ce25b0c11c0fc0635d0 Reviewed-by: J-P Nurmi Reviewed-by: Gabriel de Dietrich --- src/controls/Private/BasicButton.qml | 6 +++--- src/controls/qquickaction.cpp | 16 +++++++++------- src/controls/qquickaction_p.h | 4 ++-- src/controls/qquickmenuitem.cpp | 2 +- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/controls/Private/BasicButton.qml b/src/controls/Private/BasicButton.qml index e069e7c0..e2879cf5 100644 --- a/src/controls/Private/BasicButton.qml +++ b/src/controls/Private/BasicButton.qml @@ -145,7 +145,7 @@ Control { /*! \internal */ function accessiblePressAction() { - __action.trigger() + __action.trigger(button) } Action { @@ -169,7 +169,7 @@ Control { Keys.onReleased: { if (event.key === Qt.Key_Space && !event.isAutoRepeat && behavior.keyPressed) { behavior.keyPressed = false; - __action.trigger() + __action.trigger(button) } } @@ -182,7 +182,7 @@ Control { hoverEnabled: true enabled: !keyPressed - onReleased: if (containsMouse) __action.trigger() + onReleased: if (containsMouse) __action.trigger(button) onExited: Tooltip.hideText() onCanceled: Tooltip.hideText() onPressed: { diff --git a/src/controls/qquickaction.cpp b/src/controls/qquickaction.cpp index 0d77eb32..80f4a47e 100644 --- a/src/controls/qquickaction.cpp +++ b/src/controls/qquickaction.cpp @@ -173,16 +173,18 @@ QT_BEGIN_NAMESPACE \endqml */ -/*! \qmlsignal Action::triggered() +/*! \qmlsignal Action::triggered(QObject *source) - Emitted when either the menu item or its bound action have been activated. + Emitted when either the menu item or its bound action have been activated. Includes + the object that triggered the event if relevant (e.g. a Button or MenuItem). You shouldn't need to emit this signal, use \l trigger() instead. */ -/*! \qmlmethod Action::trigger() +/*! \qmlmethod Action::trigger(QObject *source) - Will emit the \l triggered signal if the action is enabled. Will also emit the - \l toggled signal if it is checkable. + Will emit the \l triggered signal if the action is enabled. You may provide a source + object if the Action would benefit from knowing the origin of the triggering (e.g. + for analytics). Will also emit the \l toggled signal if it is checkable. */ /*! \qmlsignal Action::toggled(checked) @@ -430,7 +432,7 @@ bool QQuickAction::event(QEvent *e) return true; } -void QQuickAction::trigger() +void QQuickAction::trigger(QObject *source) { if (!m_enabled) return; @@ -438,7 +440,7 @@ void QQuickAction::trigger() if (m_checkable && !(m_checked && m_exclusiveGroup)) setChecked(!m_checked); - emit triggered(); + emit triggered(source); } QT_END_NAMESPACE diff --git a/src/controls/qquickaction_p.h b/src/controls/qquickaction_p.h index 373627d1..8c81e71b 100644 --- a/src/controls/qquickaction_p.h +++ b/src/controls/qquickaction_p.h @@ -114,10 +114,10 @@ public: bool event(QEvent *e); public Q_SLOTS: - void trigger(); + void trigger(QObject *source = 0); Q_SIGNALS: - void triggered(); + void triggered(QObject *source = 0); void toggled(bool checked); void textChanged(); diff --git a/src/controls/qquickmenuitem.cpp b/src/controls/qquickmenuitem.cpp index b9475e97..60d882c4 100644 --- a/src/controls/qquickmenuitem.cpp +++ b/src/controls/qquickmenuitem.cpp @@ -630,7 +630,7 @@ void QQuickMenuItem::setEnabled(bool enabled) void QQuickMenuItem::trigger() { - action()->trigger(); + action()->trigger(this); } QT_END_NAMESPACE -- cgit v1.2.1