Merge lp:~zsombi/ubuntu-ui-toolkit/reset_action_shortcut into lp:ubuntu-ui-toolkit/staging

Proposed by Zsombor Egri
Status: Merged
Approved by: Cris Dywan
Approved revision: 1741
Merged at revision: 1746
Proposed branch: lp:~zsombi/ubuntu-ui-toolkit/reset_action_shortcut
Merge into: lp:ubuntu-ui-toolkit/staging
Diff against target: 94 lines (+33/-2)
3 files modified
src/Ubuntu/Components/plugin/ucaction.cpp (+14/-0)
src/Ubuntu/Components/plugin/ucaction.h (+3/-1)
tests/unit_x11/tst_components/tst_shortcuts.qml (+16/-1)
To merge this branch: bzr merge lp:~zsombi/ubuntu-ui-toolkit/reset_action_shortcut
Reviewer Review Type Date Requested Status
Cris Dywan Approve
PS Jenkins bot continuous-integration Approve
Review via email: mp+279686@code.launchpad.net

Commit message

Add reset functionality to Action.shortcut property.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
1741. By Zsombor Egri

reset shortcut when Action is destroyed

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Cris Dywan (kalikiana) wrote :

Nice, clean and effective.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/Ubuntu/Components/plugin/ucaction.cpp'
2--- src/Ubuntu/Components/plugin/ucaction.cpp 2015-09-01 08:44:11 +0000
3+++ src/Ubuntu/Components/plugin/ucaction.cpp 2015-12-08 15:14:06 +0000
4@@ -160,6 +160,11 @@
5 generateName();
6 }
7
8+UCAction::~UCAction()
9+{
10+ resetShortcut();
11+}
12+
13 bool UCAction::isValidType(QVariant::Type valueType)
14 {
15 bool valid = (valueType == QVariant::String && m_parameterType == String) ||
16@@ -289,6 +294,15 @@
17 m_shortcut = shortcut;
18 Q_EMIT shortcutChanged();
19 }
20+void UCAction::resetShortcut()
21+{
22+ if (!m_shortcut.isValid()) {
23+ return;
24+ }
25+ QGuiApplicationPrivate::instance()->shortcutMap.removeShortcut(0, this, sequenceFromVariant(m_shortcut));
26+ m_shortcut = QVariant();
27+ Q_EMIT shortcutChanged();
28+}
29
30 bool UCAction::event(QEvent *event)
31 {
32
33=== modified file 'src/Ubuntu/Components/plugin/ucaction.h'
34--- src/Ubuntu/Components/plugin/ucaction.h 2015-11-03 07:36:09 +0000
35+++ src/Ubuntu/Components/plugin/ucaction.h 2015-12-08 15:14:06 +0000
36@@ -42,7 +42,7 @@
37 Q_PROPERTY(QQmlComponent *itemHint MEMBER m_itemHint WRITE setItemHint)
38
39 // QtQuickControls.Action
40- Q_PROPERTY(QVariant shortcut MEMBER m_shortcut WRITE setShortcut NOTIFY shortcutChanged REVISION 1)
41+ Q_PROPERTY(QVariant shortcut MEMBER m_shortcut WRITE setShortcut RESET resetShortcut NOTIFY shortcutChanged REVISION 1)
42 public:
43 enum Type {
44 None,
45@@ -54,6 +54,7 @@
46 };
47
48 explicit UCAction(QObject *parent = 0);
49+ ~UCAction();
50
51 inline bool isPublished() const
52 {
53@@ -65,6 +66,7 @@
54 void setIconSource(const QUrl &url);
55 void setItemHint(QQmlComponent *);
56 void setShortcut(const QVariant&);
57+ void resetShortcut();
58
59 Q_SIGNALS:
60 void nameChanged();
61
62=== modified file 'tests/unit_x11/tst_components/tst_shortcuts.qml'
63--- tests/unit_x11/tst_components/tst_shortcuts.qml 2015-07-03 19:16:56 +0000
64+++ tests/unit_x11/tst_components/tst_shortcuts.qml 2015-12-08 15:14:06 +0000
65@@ -75,7 +75,8 @@
66 function test_shortcut_invalid_data() {
67 return [
68 { tag: 'Typo', shortcut: 'Ctr+F' },
69- { tag: 'Number', shortcut: 1234567890 }
70+ { tag: 'Number', shortcut: 1234567890 },
71+ { tag: "Empty string", shortcut: "" }
72 ];
73 }
74 function test_shortcut_invalid(data) {
75@@ -88,5 +89,19 @@
76 action.shortcut = other.shortcut;
77 keyClick(Qt.Key_G, Qt.ControlModifier);
78 }
79+
80+ SignalSpy {
81+ id: shortcutSpy
82+ signalName: "shortcutChanged"
83+ }
84+
85+ function test_shortcut_reset_bug1518420() {
86+ shortcutSpy.target = action;
87+ action.shortcut = "Ctrl+A";
88+ shortcutSpy.wait(200);
89+ shortcutSpy.clear();
90+ action.shortcut = undefined;
91+ shortcutSpy.wait(200);
92+ }
93 }
94 }

Subscribers

People subscribed via source and target branches