Merge lp:~zsombi/ubuntu-ui-toolkit/switchAndCheckboxFix into lp:~bzoltan/ubuntu-ui-toolkit/OTA9-landing-2015-12-16

Proposed by Zsombor Egri
Status: Merged
Merged at revision: 1781
Proposed branch: lp:~zsombi/ubuntu-ui-toolkit/switchAndCheckboxFix
Merge into: lp:~bzoltan/ubuntu-ui-toolkit/OTA9-landing-2015-12-16
Diff against target: 168 lines (+98/-13)
4 files modified
src/Ubuntu/Components/plugin/ucabstractbutton.cpp (+16/-12)
src/Ubuntu/Components/plugin/ucabstractbutton.h (+1/-1)
src/Ubuntu/Components/plugin/ucabstractbutton_p.h (+1/-0)
tests/unit_x11/tst_components/tst_toggles.qml (+80/-0)
To merge this branch: bzr merge lp:~zsombi/ubuntu-ui-toolkit/switchAndCheckboxFix
Reviewer Review Type Date Requested Status
Cris Dywan (community) Approve
Zoltan Balogh Pending
Review via email: mp+280844@code.launchpad.net

Commit message

Fix regression caused on CheckBox and Switch by revision 1760.

To post a comment you must log in.
Revision history for this message
Cris Dywan (kalikiana) wrote :

For the record, since I at first wasn't convinced that the test is correct: clickedSpy.wait will make way for the compare(checkedNow and that can only pass if the trigger, which changes the checked value, was already emitted.
Nice!

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/ucabstractbutton.cpp'
2--- src/Ubuntu/Components/plugin/ucabstractbutton.cpp 2015-12-14 15:49:19 +0000
3+++ src/Ubuntu/Components/plugin/ucabstractbutton.cpp 2015-12-17 13:03:03 +0000
4@@ -81,6 +81,15 @@
5 IS_SIGNAL_CONNECTED(q, UCAbstractButton, pressAndHold, ());
6 }
7
8+void UCAbstractButtonPrivate::onClicked()
9+{
10+ Q_Q(UCAbstractButton);
11+ // call the overridden QML trigger function
12+ invokeTrigger<UCAbstractButton>(q, QVariant());
13+ // then emit the clicked signal
14+ Q_EMIT q->clicked();
15+}
16+
17 void UCAbstractButton::classBegin()
18 {
19 UCActionItem::classBegin();
20@@ -137,9 +146,7 @@
21 }
22 // play haptics
23 HapticsProxy::instance().play(QVariant());
24- Q_EMIT q->clicked();
25- // call the overridden QML trigger function
26- invokeTrigger<UCAbstractButton>(q, QVariant());
27+ onClicked();
28 }
29
30 // handle pressAndHold
31@@ -154,21 +161,18 @@
32 }
33
34 // emit clicked when Enter/Return is pressed
35-void UCAbstractButton::keyPressEvent(QKeyEvent *event)
36+void UCAbstractButton::keyReleaseEvent(QKeyEvent *event)
37 {
38- UCActionItem::keyPressEvent(event);
39+ UCActionItem::keyReleaseEvent(event);
40
41 switch (event->key()) {
42 case Qt::Key_Enter:
43 case Qt::Key_Return:
44 case Qt::Key_Space:
45- {
46- // trigger clicked signal first
47- Q_EMIT clicked();
48- // then invoke the overloaded trigger
49- invokeTrigger<UCAbstractButton>(this, QVariant());
50- break;
51- }
52+ d_func()->onClicked();
53+ break;
54+ default:
55+ break;
56 }
57 }
58
59
60=== modified file 'src/Ubuntu/Components/plugin/ucabstractbutton.h'
61--- src/Ubuntu/Components/plugin/ucabstractbutton.h 2015-12-11 11:36:18 +0000
62+++ src/Ubuntu/Components/plugin/ucabstractbutton.h 2015-12-17 13:03:03 +0000
63@@ -45,7 +45,7 @@
64
65 protected:
66 void classBegin();
67- void keyPressEvent(QKeyEvent *key);
68+ void keyReleaseEvent(QKeyEvent *key);
69
70 Q_SIGNALS:
71 void pressedChanged();
72
73=== modified file 'src/Ubuntu/Components/plugin/ucabstractbutton_p.h'
74--- src/Ubuntu/Components/plugin/ucabstractbutton_p.h 2015-12-11 10:28:46 +0000
75+++ src/Ubuntu/Components/plugin/ucabstractbutton_p.h 2015-12-17 13:03:03 +0000
76@@ -35,6 +35,7 @@
77 void completeComponentInitialization() override;
78
79 bool isPressAndHoldConnected();
80+ void onClicked();
81
82 // private slots
83 void _q_mouseAreaPressed();
84
85=== added file 'tests/unit_x11/tst_components/tst_toggles.qml'
86--- tests/unit_x11/tst_components/tst_toggles.qml 1970-01-01 00:00:00 +0000
87+++ tests/unit_x11/tst_components/tst_toggles.qml 2015-12-17 13:03:03 +0000
88@@ -0,0 +1,80 @@
89+/*
90+ * Copyright 2014 Canonical Ltd.
91+ *
92+ * This program is free software; you can redistribute it and/or modify
93+ * it under the terms of the GNU Lesser General Public License as published by
94+ * the Free Software Foundation; version 3.
95+ *
96+ * This program is distributed in the hope that it will be useful,
97+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
98+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
99+ * GNU Lesser General Public License for more details.
100+ *
101+ * You should have received a copy of the GNU Lesser General Public License
102+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
103+ */
104+
105+import QtQuick 2.0
106+import QtTest 1.0
107+import Ubuntu.Test 1.0
108+import Ubuntu.Components 1.3
109+
110+MainView {
111+ id: main
112+
113+ width: units.gu(40)
114+ height: units.gu(71)
115+
116+ Column {
117+ Switch {
118+ id: testSwitch
119+ checked: true
120+ property bool checkedNow: true
121+ onClicked: checkedNow = checked
122+ }
123+
124+ CheckBox {
125+ id: testCheck
126+ checked: true
127+ property bool checkedNow: true
128+ onClicked: checkedNow = checked
129+ }
130+ }
131+
132+ UbuntuTestCase {
133+ name: "Toggles13"
134+ when: windowShown
135+
136+ SignalSpy {
137+ id: clickedSpy
138+ signalName: "clicked"
139+ }
140+
141+ function cleanup() {
142+ clickedSpy.clear();
143+ clickedSpy.target = null;
144+ }
145+
146+ function test_toggle_checked_delayed_bug1524234_data() {
147+ return [
148+ {tag: "CheckBox", testItem: testCheck, mouse: true},
149+ {tag: "Switch", testItem: testSwitch, mouse: true},
150+ {tag: "CheckBox, space key", testItem: testCheck, key: Qt.Key_Space},
151+ {tag: "Switch, space key", testItem: testSwitch, key: Qt.Key_Space},
152+ ];
153+ }
154+ function test_toggle_checked_delayed_bug1524234(data) {
155+ data.testItem.checkedNow = data.testItem.checked;
156+ data.testItem.forceActiveFocus();
157+ clickedSpy.target = data.testItem;
158+ if (data.key) {
159+ keyClick(data.key);
160+ } else {
161+ mouseClick(data.testItem, centerOf(data.testItem).x, centerOf(data.testItem).y);
162+ }
163+ clickedSpy.wait(400);
164+ compare(data.testItem.checkedNow, data.testItem.checked);
165+ }
166+ }
167+}
168+

Subscribers

People subscribed via source and target branches

to all changes: