diff options
author | Daiwei Li <daiweili@suitabletech.com> | 2013-09-18 16:20:18 -0700 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-19 15:17:29 +0200 |
commit | 7adeff65148a3967af7b2ec44764a2c275dcd3fe (patch) | |
tree | 0345cc58792ec7cd1247696cb6c9b82afba25e7a | |
parent | 2aa8ea6850087680af18e14d93bfe40a894607a5 (diff) | |
download | qtquickcontrols-7adeff65148a3967af7b2ec44764a2c275dcd3fe.tar.gz |
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 <jpnurmi@digia.com>
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@digia.com>
-rw-r--r-- | src/controls/Private/BasicButton.qml | 6 | ||||
-rw-r--r-- | src/controls/qquickaction.cpp | 16 | ||||
-rw-r--r-- | src/controls/qquickaction_p.h | 4 | ||||
-rw-r--r-- | 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 |