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

Proposed by Zsombor Egri
Status: Merged
Approved by: Zsombor Egri
Approved revision: 1619
Merged at revision: 1612
Proposed branch: lp:~zsombi/ubuntu-ui-toolkit/cppActionItem
Merge into: lp:ubuntu-ui-toolkit/staging
Diff against target: 874 lines (+420/-225)
16 files modified
components.api (+6/-10)
src/Ubuntu/Components/1.2/ActionItem.qml (+0/-96)
src/Ubuntu/Components/1.2/TextField.qml (+1/-1)
src/Ubuntu/Components/1.2/TextInputPopover.qml (+1/-0)
src/Ubuntu/Components/1.2/ToolbarButton.qml (+1/-0)
src/Ubuntu/Components/1.3/ActionItem.qml (+0/-96)
src/Ubuntu/Components/1.3/TextField.qml (+1/-1)
src/Ubuntu/Components/ComponentModule.pro (+0/-2)
src/Ubuntu/Components/plugin/plugin.cpp (+2/-0)
src/Ubuntu/Components/plugin/plugin.pri (+4/-2)
src/Ubuntu/Components/plugin/ucaction.cpp (+2/-3)
src/Ubuntu/Components/plugin/ucaction.h (+7/-6)
src/Ubuntu/Components/plugin/ucactionitem.cpp (+305/-0)
src/Ubuntu/Components/plugin/ucactionitem.h (+77/-0)
src/Ubuntu/Components/qmldir (+0/-3)
tests/unit/tst_components/tst_actionitem.qml (+13/-5)
To merge this branch: bzr merge lp:~zsombi/ubuntu-ui-toolkit/cppActionItem
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Zsombor Egri Approve
Cris Dywan Approve
Review via email: mp+268348@code.launchpad.net

Commit message

ActionItem moved to C++.

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

Looks pretty good to me and seems as closely ported as possible.

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Zsombor Egri (zsombi) wrote :

The component is flaky, the ActionSelectionPopover is not showing random actions, common text input tests fail on popover. Needs a bit more love.

review: Needs Fixing
1617. By Zsombor Egri

fixing text, iconName getters to return proper values when not having custom values

1618. By Zsombor Egri

update visible and enabled when action changes, connect text, iconSource and iconName property change signals to action to keep the value changes in sync

1619. By Zsombor Egri

random icon and text disappearance in Popups caused by a stupid mistake - unititialized member

Revision history for this message
Zsombor Egri (zsombi) wrote :

Good to go now, all the needed functionality is there.

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'components.api'
2--- components.api 2015-08-12 15:22:59 +0000
3+++ components.api 2015-08-19 06:57:12 +0000
4@@ -43,14 +43,8 @@
5 property string iconName
6 property url iconSource
7 signal triggered(var value)
8- function var trigger(var value)
9- property string text
10-Ubuntu.Components.ActionItem 1.3: StyledItem
11- property Action action
12- property string iconName
13- property url iconSource
14- signal triggered(var value)
15- function var trigger(var value)
16+ function trigger(var value)
17+ function trigger()
18 property string text
19 Ubuntu.Components.ActionList 1.0 0.1: QtObject
20 readonly property Action actions
21@@ -1232,14 +1226,16 @@
22 property string iconName
23 property url iconSource
24 signal triggered(var value)
25- function var trigger(var value)
26+ function trigger(var value)
27+ function trigger()
28 property string text
29 Ubuntu.Components.ToolbarButton 1.3: StyledItem
30 property Action action
31 property string iconName
32 property url iconSource
33 signal triggered(var value)
34- function var trigger(var value)
35+ function trigger(var value)
36+ function trigger()
37 property string text
38 Ubuntu.Components.ToolbarItems 1.0 0.1: Item
39 property Item back
40
41=== removed file 'src/Ubuntu/Components/1.2/ActionItem.qml'
42--- src/Ubuntu/Components/1.2/ActionItem.qml 2015-04-30 08:32:44 +0000
43+++ src/Ubuntu/Components/1.2/ActionItem.qml 1970-01-01 00:00:00 +0000
44@@ -1,96 +0,0 @@
45-/*
46- * Copyright 2012 Canonical Ltd.
47- *
48- * This program is free software; you can redistribute it and/or modify
49- * it under the terms of the GNU Lesser General Public License as published by
50- * the Free Software Foundation; version 3.
51- *
52- * This program is distributed in the hope that it will be useful,
53- * but WITHOUT ANY WARRANTY; without even the implied warranty of
54- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
55- * GNU Lesser General Public License for more details.
56- *
57- * You should have received a copy of the GNU Lesser General Public License
58- * along with this program. If not, see <http://www.gnu.org/licenses/>.
59- */
60-
61-import QtQuick 2.4
62-import Ubuntu.Components 1.2
63-
64-/*!
65- \qmlabstract ActionItem
66- \inqmlmodule Ubuntu.Components 1.1
67- \ingroup ubuntu
68- \brief A visual representation of an Action. The API of ActionItem is a
69- copy of the API of \l Action, with additional properties to define
70- visual aspects of the ActionItem.
71-
72- If \l action is set, the values of the other properties will by default
73- be identical to the \l Action's property values. Setting the other properties
74- will override the properties copied from the \l Action.
75-
76- See \l ToolbarItems for examples of how to use \l ToolbarButton or other ActionItems
77- in a toolbar.
78-*/
79-StyledItem {
80- id: actionItem
81-
82- /*!
83- The \l Action associated with this ActionItem. If action is set,
84- the values of the Action properties are copied to the values of
85- the ActionItem properties.
86- */
87- property Action action: null
88-
89- visible: action ? action.visible : true
90- enabled: action ? action.enabled : true
91-
92- /*!
93- The title of the actionItem.
94- Default value: action.text
95- */
96- property string text: action ? action.text : ""
97-
98- /*!
99- The image associated with the actionItem.
100- Default value: action.iconSource.
101-
102- This is the URL of any image file
103- If both iconSource and iconName are defined, iconName will be ignored.
104- */
105- property url iconSource: action ? action.iconSource : (iconName ? "image://theme/" + iconName : "")
106-
107- /*!
108- The icon associated with the actionItem in the suru icon theme.
109- Default value: action.iconName.
110-
111- \note The complete list of icons available in Ubuntu is not published yet.
112- For now please refer to the folders where the icon themes are installed:
113- \list
114- \li Ubuntu Touch: \l file:/usr/share/icons/suru
115- \li Ubuntu Desktop: \l file:/usr/share/icons/ubuntu-mono-dark
116- \endlist
117- These 2 separate icon themes will be merged soon.
118-
119- If both iconSource and iconName are defined, iconName will be ignored.
120- */
121- property string iconName: action ? action.iconName : ""
122-
123- /*!
124- Called when the actionItem is triggered.
125- */
126- signal triggered(var value)
127-
128- /*!
129- If \l action is set, this will trigger it.
130- */
131- onTriggered: if (action) action.trigger(value)
132-
133- /*!
134- Trigger this action item if it is enabled.
135- */
136- function trigger(value) {
137- var passingValue = value ? value : null
138- if (actionItem.enabled) actionItem.triggered(passingValue);
139- }
140-}
141
142=== modified file 'src/Ubuntu/Components/1.2/TextField.qml'
143--- src/Ubuntu/Components/1.2/TextField.qml 2015-05-01 19:38:57 +0000
144+++ src/Ubuntu/Components/1.2/TextField.qml 2015-08-19 06:57:12 +0000
145@@ -99,7 +99,7 @@
146 \note During text selection all interactive parent Flickables are turned off.
147 */
148
149-ActionItem {
150+Ubuntu.ActionItem {
151 id: control
152
153 implicitWidth: units.gu(25)
154
155=== modified file 'src/Ubuntu/Components/1.2/TextInputPopover.qml'
156--- src/Ubuntu/Components/1.2/TextInputPopover.qml 2015-07-02 23:33:22 +0000
157+++ src/Ubuntu/Components/1.2/TextInputPopover.qml 2015-08-19 06:57:12 +0000
158@@ -88,6 +88,7 @@
159 action.text so we can get the proper button by text, action being not
160 accessible. https://bugs.launchpad.net/autopilot/+bug/1334599
161 */
162+ // FIXME: AbstractButton has text property, which is getting the action.text, so no need to override!
163 property string text: action.text
164 width: Math.max(units.gu(5), implicitWidth) + units.gu(2)
165 height: units.gu(6)
166
167=== modified file 'src/Ubuntu/Components/1.2/ToolbarButton.qml'
168--- src/Ubuntu/Components/1.2/ToolbarButton.qml 2015-04-30 08:32:44 +0000
169+++ src/Ubuntu/Components/1.2/ToolbarButton.qml 2015-08-19 06:57:12 +0000
170@@ -15,6 +15,7 @@
171 */
172
173 import QtQuick 2.4
174+import Ubuntu.Components 1.2
175
176 /*!
177 \qmltype ToolbarButton
178
179=== removed file 'src/Ubuntu/Components/1.3/ActionItem.qml'
180--- src/Ubuntu/Components/1.3/ActionItem.qml 2015-04-25 08:54:58 +0000
181+++ src/Ubuntu/Components/1.3/ActionItem.qml 1970-01-01 00:00:00 +0000
182@@ -1,96 +0,0 @@
183-/*
184- * Copyright 2012 Canonical Ltd.
185- *
186- * This program is free software; you can redistribute it and/or modify
187- * it under the terms of the GNU Lesser General Public License as published by
188- * the Free Software Foundation; version 3.
189- *
190- * This program is distributed in the hope that it will be useful,
191- * but WITHOUT ANY WARRANTY; without even the implied warranty of
192- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
193- * GNU Lesser General Public License for more details.
194- *
195- * You should have received a copy of the GNU Lesser General Public License
196- * along with this program. If not, see <http://www.gnu.org/licenses/>.
197- */
198-
199-import QtQuick 2.4
200-import Ubuntu.Components 1.3
201-
202-/*!
203- \qmlabstract ActionItem
204- \inqmlmodule Ubuntu.Components 1.1
205- \ingroup ubuntu
206- \brief A visual representation of an Action. The API of ActionItem is a
207- copy of the API of \l Action, with additional properties to define
208- visual aspects of the ActionItem.
209-
210- If \l action is set, the values of the other properties will by default
211- be identical to the \l Action's property values. Setting the other properties
212- will override the properties copied from the \l Action.
213-
214- See \l ToolbarItems for examples of how to use \l ToolbarButton or other ActionItems
215- in a toolbar.
216-*/
217-StyledItem {
218- id: actionItem
219-
220- /*!
221- The \l Action associated with this ActionItem. If action is set,
222- the values of the Action properties are copied to the values of
223- the ActionItem properties.
224- */
225- property Action action: null
226-
227- visible: action ? action.visible : true
228- enabled: action ? action.enabled : true
229-
230- /*!
231- The title of the actionItem.
232- Default value: action.text
233- */
234- property string text: action ? action.text : ""
235-
236- /*!
237- The image associated with the actionItem.
238- Default value: action.iconSource.
239-
240- This is the URL of any image file
241- If both iconSource and iconName are defined, iconName will be ignored.
242- */
243- property url iconSource: action ? action.iconSource : (iconName ? "image://theme/" + iconName : "")
244-
245- /*!
246- The icon associated with the actionItem in the suru icon theme.
247- Default value: action.iconName.
248-
249- \note The complete list of icons available in Ubuntu is not published yet.
250- For now please refer to the folders where the icon themes are installed:
251- \list
252- \li Ubuntu Touch: \l file:/usr/share/icons/suru
253- \li Ubuntu Desktop: \l file:/usr/share/icons/ubuntu-mono-dark
254- \endlist
255- These 2 separate icon themes will be merged soon.
256-
257- If both iconSource and iconName are defined, iconName will be ignored.
258- */
259- property string iconName: action ? action.iconName : ""
260-
261- /*!
262- Called when the actionItem is triggered.
263- */
264- signal triggered(var value)
265-
266- /*!
267- If \l action is set, this will trigger it.
268- */
269- onTriggered: if (action) action.trigger(value)
270-
271- /*!
272- Trigger this action item if it is enabled.
273- */
274- function trigger(value) {
275- var passingValue = value ? value : null
276- if (actionItem.enabled) actionItem.triggered(passingValue);
277- }
278-}
279
280=== modified file 'src/Ubuntu/Components/1.3/TextField.qml'
281--- src/Ubuntu/Components/1.3/TextField.qml 2015-08-11 17:15:59 +0000
282+++ src/Ubuntu/Components/1.3/TextField.qml 2015-08-19 06:57:12 +0000
283@@ -99,7 +99,7 @@
284 \note During text selection all interactive parent Flickables are turned off.
285 */
286
287-ActionItem {
288+Ubuntu.ActionItem {
289 id: control
290
291 implicitWidth: units.gu(25)
292
293=== modified file 'src/Ubuntu/Components/ComponentModule.pro'
294--- src/Ubuntu/Components/ComponentModule.pro 2015-08-10 14:10:51 +0000
295+++ src/Ubuntu/Components/ComponentModule.pro 2015-08-19 06:57:12 +0000
296@@ -25,7 +25,6 @@
297
298 #1.2
299 QML_FILES += 1.2/AbstractButton.qml \
300- 1.2/ActionItem.qml \
301 1.2/ActionList.qml \
302 1.2/ActivityIndicator.qml \
303 1.2/AnimatedItem.qml \
304@@ -83,7 +82,6 @@
305 #1.3
306 QML_FILES += 1.3/AbstractButton.qml \
307 1.3/ActionBar.qml \
308- 1.3/ActionItem.qml \
309 1.3/ActionList.qml \
310 1.3/ActivityIndicator.qml \
311 1.3/AdaptivePageLayout.qml \
312
313=== modified file 'src/Ubuntu/Components/plugin/plugin.cpp'
314--- src/Ubuntu/Components/plugin/plugin.cpp 2015-08-12 09:54:40 +0000
315+++ src/Ubuntu/Components/plugin/plugin.cpp 2015-08-19 06:57:12 +0000
316@@ -62,6 +62,7 @@
317 #include "uclistitemstyle.h"
318 #include "ucserviceproperties.h"
319 #include "ucnamespace.h"
320+#include "ucactionitem.h"
321
322 #include <sys/types.h>
323 #include <unistd.h>
324@@ -174,6 +175,7 @@
325 qmlRegisterSingletonType<UCUriHandler>(uri, major, minor, "UriHandler", registerUriHandler);
326 qmlRegisterType<UCMouse>(uri, major, minor, "Mouse");
327 qmlRegisterType<UCInverseMouse>(uri, major, minor, "InverseMouse");
328+ qmlRegisterType<UCActionItem>(uri, major, minor, "ActionItem");
329 }
330
331 void UbuntuComponentsPlugin::registerTypes(const char *uri)
332
333=== modified file 'src/Ubuntu/Components/plugin/plugin.pri'
334--- src/Ubuntu/Components/plugin/plugin.pri 2015-08-12 09:54:40 +0000
335+++ src/Ubuntu/Components/plugin/plugin.pri 2015-08-19 06:57:12 +0000
336@@ -80,7 +80,8 @@
337 $$PWD/ucstylehints.h \
338 $$PWD/livetimer.h \
339 $$PWD/livetimer_p.h \
340- $$PWD/timeutils_p.h
341+ $$PWD/timeutils_p.h \
342+ $$PWD/ucactionitem.h
343
344 SOURCES += $$PWD/plugin.cpp \
345 $$PWD/uctheme.cpp \
346@@ -132,7 +133,8 @@
347 $$PWD/ucdefaulttheme.cpp \
348 $$PWD/ucstylehints.cpp \
349 $$PWD/livetimer.cpp \
350- $$PWD/livetimer_p.cpp
351+ $$PWD/livetimer_p.cpp \
352+ $$PWD/ucactionitem.cpp
353
354 # adapters
355 SOURCES += $$PWD/adapters/alarmsadapter_organizer.cpp
356
357=== modified file 'src/Ubuntu/Components/plugin/ucaction.cpp'
358--- src/Ubuntu/Components/plugin/ucaction.cpp 2015-07-03 19:16:56 +0000
359+++ src/Ubuntu/Components/plugin/ucaction.cpp 2015-08-19 06:57:12 +0000
360@@ -150,13 +150,12 @@
361
362 UCAction::UCAction(QObject *parent)
363 : QObject(parent)
364+ , m_itemHint(Q_NULLPTR)
365+ , m_parameterType(None)
366 , m_factoryIconSource(true)
367 , m_enabled(true)
368 , m_visible(true)
369 , m_published(false)
370- , m_itemHint(0)
371- , m_parameterType(None)
372- , m_shortcut(0)
373 {
374 generateName();
375 }
376
377=== modified file 'src/Ubuntu/Components/plugin/ucaction.h'
378--- src/Ubuntu/Components/plugin/ucaction.h 2015-07-07 13:57:50 +0000
379+++ src/Ubuntu/Components/plugin/ucaction.h 2015-08-19 06:57:12 +0000
380@@ -77,21 +77,22 @@
381 void trigger(const QVariant &value = QVariant());
382
383 private:
384- bool m_factoryIconSource:1;
385- bool m_enabled:1;
386- bool m_visible:1;
387- bool m_published:1;
388- QQmlComponent *m_itemHint;
389 QString m_name;
390 QString m_text;
391 QString m_iconName;
392 QUrl m_iconSource;
393 QString m_description;
394 QString m_keywords;
395+ QVariant m_shortcut;
396+ QQmlComponent *m_itemHint;
397 Type m_parameterType;
398- QVariant m_shortcut;
399+ bool m_factoryIconSource:1;
400+ bool m_enabled:1;
401+ bool m_visible:1;
402+ bool m_published:1;
403
404 friend class UCActionContext;
405+ friend class UCActionItem;
406 friend class UCListItemPrivate;
407 friend class UCListItemAttached;
408 friend class UCListItemActionsPrivate;
409
410=== added file 'src/Ubuntu/Components/plugin/ucactionitem.cpp'
411--- src/Ubuntu/Components/plugin/ucactionitem.cpp 1970-01-01 00:00:00 +0000
412+++ src/Ubuntu/Components/plugin/ucactionitem.cpp 2015-08-19 06:57:12 +0000
413@@ -0,0 +1,305 @@
414+/*
415+ * Copyright 2015 Canonical Ltd.
416+ *
417+ * This program is free software; you can redistribute it and/or modify
418+ * it under the terms of the GNU Lesser General Public License as published by
419+ * the Free Software Foundation; version 3.
420+ *
421+ * This program is distributed in the hope that it will be useful,
422+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
423+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
424+ * GNU Lesser General Public License for more details.
425+ *
426+ * You should have received a copy of the GNU Lesser General Public License
427+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
428+ */
429+
430+#include "ucactionitem.h"
431+#include "ucaction.h"
432+
433+/*!
434+ * \qmltype ActionItem
435+ * \instantiates UCActionItem
436+ * \inqmlmodule Ubuntu.Components 1.1
437+ * \ingroup ubuntu
438+ * \brief A visual representation of an Action. The API of ActionItem is a
439+ * copy of the API of \l Action, with additional properties to define
440+ * visual aspects of the ActionItem.
441+ *
442+ * If \l action is set, the values of the other properties will by default
443+ * be identical to the \l Action's property values. Setting the other properties
444+ * will override the properties copied from the \l Action.
445+ */
446+
447+/*!
448+ * \qmlsignal ActionItem::triggered(var value)
449+ * Called when the actionItem is triggered.
450+ */
451+UCActionItem::UCActionItem(QQuickItem *parent)
452+ : UCStyledItemBase(parent)
453+ , m_action(Q_NULLPTR)
454+ , m_flags(0)
455+{
456+ connect(this, &UCActionItem::visibleChanged, this, &UCActionItem::_q_visibleChanged);
457+ connect(this, &UCActionItem::enabledChanged, this, &UCActionItem::_q_enabledChanged);
458+}
459+
460+void UCActionItem::_q_visibleChanged()
461+{
462+ m_flags |= CustomVisible;
463+ disconnect(this, &UCActionItem::visibleChanged, this, &UCActionItem::_q_visibleChanged);
464+}
465+
466+void UCActionItem::_q_enabledChanged()
467+{
468+ m_flags |= CustomEnabled;
469+ disconnect(this, &UCActionItem::enabledChanged, this, &UCActionItem::_q_enabledChanged);
470+}
471+
472+// update visible property
473+void UCActionItem::_q_updateVisible()
474+{
475+ bool visible = m_action ? m_action->m_visible : true;
476+ setVisible(visible);
477+ // reset flag and reconnect signal handler disconnected by the
478+ m_flags &= ~CustomVisible;
479+ if (m_action) {
480+ connect(this, &UCActionItem::visibleChanged, this, &UCActionItem::_q_visibleChanged);
481+ }
482+}
483+
484+// update enabled property
485+void UCActionItem::_q_updateEnabled()
486+{
487+ bool enabled = m_action ? m_action->m_enabled : true;
488+ setEnabled(enabled);
489+ // reset flag and reconnect signal handler disconnected by the
490+ m_flags &= ~CustomEnabled;
491+ if (m_action) {
492+ connect(this, &UCActionItem::enabledChanged, this, &UCActionItem::_q_enabledChanged);
493+ }
494+}
495+
496+void UCActionItem::updateProperties()
497+{
498+ if (!(m_flags & CustomText)) {
499+ Q_EMIT textChanged();
500+ }
501+ if (!(m_flags & CustomIconSource)) {
502+ Q_EMIT iconSourceChanged();
503+ }
504+ if (!(m_flags & CustomIconName)) {
505+ Q_EMIT iconNameChanged();
506+ }
507+}
508+
509+void UCActionItem::attachAction(bool attach)
510+{
511+ if (attach) {
512+ connect(this, &UCActionItem::triggered,
513+ m_action, &UCAction::triggered, Qt::DirectConnection);
514+ connect(m_action, &UCAction::visibleChanged,
515+ this, &UCActionItem::_q_updateVisible, Qt::DirectConnection);
516+ connect(m_action, &UCAction::enabledChanged,
517+ this, &UCActionItem::_q_updateEnabled, Qt::DirectConnection);
518+ if (!(m_flags & CustomText)) {
519+ connect(m_action, &UCAction::textChanged,
520+ this, &UCActionItem::textChanged, Qt::DirectConnection);
521+ }
522+ if (!(m_flags & CustomIconSource)) {
523+ connect(m_action, &UCAction::iconSourceChanged,
524+ this, &UCActionItem::iconSourceChanged, Qt::DirectConnection);
525+ }
526+ if (!(m_flags & CustomIconName)) {
527+ connect(m_action, &UCAction::iconNameChanged,
528+ this, &UCActionItem::iconNameChanged, Qt::DirectConnection);
529+ }
530+ } else {
531+ disconnect(this, &UCActionItem::triggered,
532+ m_action, &UCAction::triggered);
533+ disconnect(m_action, &UCAction::visibleChanged,
534+ this, &UCActionItem::_q_updateVisible);
535+ disconnect(m_action, &UCAction::enabledChanged,
536+ this, &UCActionItem::_q_updateEnabled);
537+ if (!(m_flags & CustomText)) {
538+ disconnect(m_action, &UCAction::textChanged,
539+ this, &UCActionItem::textChanged);
540+ }
541+ if (!(m_flags & CustomIconSource)) {
542+ disconnect(m_action, &UCAction::iconSourceChanged,
543+ this, &UCActionItem::iconSourceChanged);
544+ }
545+ if (!(m_flags & CustomIconName)) {
546+ disconnect(m_action, &UCAction::iconNameChanged,
547+ this, &UCActionItem::iconNameChanged);
548+ }
549+ }
550+}
551+
552+/*!
553+ * \qmlproperty Action ActionItem::action
554+ * The \l Action associated with this ActionItem. If action is set, the values
555+ * of the \l Action properties are copied to the values of the ActionItem
556+ * properties, unless those were previously overridden.
557+ */
558+void UCActionItem::setAction(UCAction *action)
559+{
560+ if (m_action == action) {
561+ return;
562+ }
563+ if (m_action) {
564+ attachAction(false);
565+ }
566+ m_action = action;
567+ Q_EMIT actionChanged();
568+
569+ if (m_action) {
570+ attachAction(true);
571+ }
572+ _q_updateVisible();
573+ _q_updateEnabled();
574+ updateProperties();
575+}
576+
577+/*!
578+ * \qmlproperty string ActionItem::text
579+ * The title of the actionItem. Defaults to the \c action.text.
580+ */
581+QString UCActionItem::text()
582+{
583+ if (m_flags & CustomText) {
584+ return m_text;
585+ }
586+ return m_action ? m_action->m_text : QString();
587+}
588+void UCActionItem::setText(const QString &text)
589+{
590+ if (m_text == text) {
591+ return;
592+ }
593+ m_text = text;
594+ if (m_action && !(m_flags & CustomText)) {
595+ // disconnect change signal from Action
596+ disconnect(m_action, &UCAction::textChanged,
597+ this, &UCActionItem::textChanged);
598+ }
599+ m_flags |= CustomText;
600+ Q_EMIT textChanged();
601+}
602+void UCActionItem::resetText()
603+{
604+ m_text.clear();
605+ m_flags &= ~CustomText;
606+ if (m_action) {
607+ // re-connect change signal from Action
608+ connect(m_action, &UCAction::textChanged,
609+ this, &UCActionItem::textChanged, Qt::DirectConnection);
610+ }
611+ Q_EMIT textChanged();
612+}
613+
614+/*!
615+ * \qmlproperty url ActionItem::iconSource
616+ * The image associated with the ActionItem. Defaults to \c action.iconSource.
617+ *
618+ * This is the URL of any image file. If both iconSource and \l iconName are defined,
619+ * \l iconName will be ignored.
620+ */
621+QUrl UCActionItem::iconSource()
622+{
623+ if (m_flags & CustomIconSource) {
624+ return m_iconSource;
625+ }
626+ if (m_action) {
627+ return m_action->m_iconSource;
628+ }
629+ return !iconName().isEmpty() ? QUrl(QString("image://theme/%1").arg(iconName())) : QUrl();
630+}
631+void UCActionItem::setIconSource(const QUrl &iconSource)
632+{
633+ if (m_iconSource == iconSource) {
634+ return;
635+ }
636+ m_iconSource = iconSource;
637+ if (m_action && !(m_flags & CustomIconSource)) {
638+ // disconnect change signal from Action
639+ disconnect(m_action, &UCAction::iconSourceChanged,
640+ this, &UCActionItem::iconSourceChanged);
641+ }
642+ m_flags |= CustomIconSource;
643+ Q_EMIT iconSourceChanged();
644+}
645+void UCActionItem::resetIconSource()
646+{
647+ m_iconSource.clear();
648+ m_flags &= ~CustomIconSource;
649+ if (m_action) {
650+ // re-connect change signal from Action
651+ connect(m_action, &UCAction::iconSourceChanged,
652+ this, &UCActionItem::iconSourceChanged, Qt::DirectConnection);
653+ }
654+ Q_EMIT iconSourceChanged();
655+}
656+
657+/*!
658+ * \qmlproperty string ActionItem::iconName
659+ * The icon associated with the actionItem in the suru icon theme. Defaults to
660+ * \c action.iconName.
661+ *
662+ * \note The complete list of icons available in Ubuntu is not published yet.
663+ * For now please refer to the folders where the icon themes are installed:
664+ * \list
665+ * \li Ubuntu Touch: \l file:/usr/share/icons/suru
666+ * \li Ubuntu Desktop: \l file:/usr/share/icons/ubuntu-mono-dark
667+ * \endlist
668+ * These 2 separate icon themes will be merged soon.
669+ *
670+ * If both \l iconSource and iconName are defined, iconName will be ignored.
671+ */
672+QString UCActionItem::iconName()
673+{
674+ if (m_flags & CustomIconName) {
675+ return m_iconName;
676+ }
677+ return m_action ? m_action->m_iconName : QString();
678+}
679+void UCActionItem::setIconName(const QString &iconName)
680+{
681+ if (m_iconName == iconName) {
682+ return;
683+ }
684+ m_iconName = iconName;
685+ if (m_action && !(m_flags & CustomIconName)) {
686+ // disconnect change signal from Action
687+ disconnect(m_action, &UCAction::iconNameChanged,
688+ this, &UCActionItem::iconNameChanged);
689+ }
690+ m_flags |= CustomIconName;
691+ Q_EMIT iconNameChanged();
692+ // also sync iconSource if that is not a custom one or taken from action
693+ if (!m_action || (m_flags & CustomIconSource)) {
694+ Q_EMIT iconSourceChanged();
695+ }
696+}
697+void UCActionItem::resetIconName()
698+{
699+ m_iconName.clear();
700+ m_flags &= ~CustomIconName;
701+ if (m_action) {
702+ // re-connect change signal from Action
703+ connect(m_action, &UCAction::iconNameChanged,
704+ this, &UCActionItem::iconNameChanged, Qt::DirectConnection);
705+ }
706+ Q_EMIT iconNameChanged();
707+}
708+
709+/*!
710+ * \qmlmethod void ActionItem::trigger(var value)
711+ * Trigger this action item if it is enabled.
712+ */
713+void UCActionItem::trigger(const QVariant &value)
714+{
715+ if (isEnabled()) {
716+ Q_EMIT triggered(value);
717+ }
718+}
719
720=== added file 'src/Ubuntu/Components/plugin/ucactionitem.h'
721--- src/Ubuntu/Components/plugin/ucactionitem.h 1970-01-01 00:00:00 +0000
722+++ src/Ubuntu/Components/plugin/ucactionitem.h 2015-08-19 06:57:12 +0000
723@@ -0,0 +1,77 @@
724+/*
725+ * Copyright 2015 Canonical Ltd.
726+ *
727+ * This program is free software; you can redistribute it and/or modify
728+ * it under the terms of the GNU Lesser General Public License as published by
729+ * the Free Software Foundation; version 3.
730+ *
731+ * This program is distributed in the hope that it will be useful,
732+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
733+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
734+ * GNU Lesser General Public License for more details.
735+ *
736+ * You should have received a copy of the GNU Lesser General Public License
737+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
738+ */
739+#ifndef UCACTIONITEM_H
740+#define UCACTIONITEM_H
741+
742+#include "ucstyleditembase.h"
743+
744+class UCAction;
745+class UCActionItem : public UCStyledItemBase
746+{
747+ Q_OBJECT
748+ Q_PROPERTY(UCAction *action MEMBER m_action WRITE setAction NOTIFY actionChanged FINAL)
749+ Q_PROPERTY(QString text READ text WRITE setText RESET resetText NOTIFY textChanged)
750+ Q_PROPERTY(QUrl iconSource READ iconSource WRITE setIconSource RESET resetIconSource NOTIFY iconSourceChanged)
751+ Q_PROPERTY(QString iconName READ iconName WRITE setIconName RESET resetIconName NOTIFY iconNameChanged)
752+public:
753+ explicit UCActionItem(QQuickItem *parent = 0);
754+
755+ void setAction(UCAction *action);
756+ QString text();
757+ void setText(const QString &text);
758+ void resetText();
759+ QUrl iconSource();
760+ void setIconSource(const QUrl &iconSource);
761+ void resetIconSource();
762+ QString iconName();
763+ void setIconName(const QString &iconName);
764+ void resetIconName();
765+
766+Q_SIGNALS:
767+ void actionChanged();
768+ void textChanged();
769+ void iconSourceChanged();
770+ void iconNameChanged();
771+ void triggered(const QVariant &value);
772+
773+public Q_SLOTS:
774+ void trigger(const QVariant &value = QVariant());
775+
776+protected Q_SLOTS:
777+ void _q_visibleChanged();
778+ void _q_enabledChanged();
779+ void _q_updateVisible();
780+ void _q_updateEnabled();
781+
782+protected:
783+ enum {
784+ CustomText = 0x01,
785+ CustomIconSource = 0x02,
786+ CustomIconName = 0x04,
787+ CustomVisible = 0x40,
788+ CustomEnabled = 0x80
789+ };
790+ QString m_text;
791+ QString m_iconName;
792+ QUrl m_iconSource;
793+ UCAction *m_action;
794+ quint8 m_flags;
795+
796+ void updateProperties();
797+ void attachAction(bool attach);
798+};
799+
800+#endif // UCACTIONITEM_H
801
802=== modified file 'src/Ubuntu/Components/qmldir'
803--- src/Ubuntu/Components/qmldir 2015-08-10 14:27:35 +0000
804+++ src/Ubuntu/Components/qmldir 2015-08-19 06:57:12 +0000
805@@ -1,6 +1,5 @@
806 module Ubuntu.Components
807 plugin UbuntuComponents
808-ActionItem 0.1 1.2/ActionItem.qml
809 ActionList 0.1 1.2/ActionList.qml
810 ToolbarItems 0.1 1.2/ToolbarItems.qml
811 ToolbarButton 0.1 1.2/ToolbarButton.qml
812@@ -44,7 +43,6 @@
813 DateUtils 0.1 1.2/dateUtils.js
814
815 #version 1.0
816-ActionItem 1.0 1.2/ActionItem.qml
817 ActionList 1.0 1.2/ActionList.qml
818 ToolbarItems 1.0 1.2/ToolbarItems.qml
819 ToolbarButton 1.0 1.2/ToolbarButton.qml
820@@ -105,7 +103,6 @@
821 #################################################
822 #version 1.3
823 ActionBar 1.3 1.3/ActionBar.qml
824-ActionItem 1.3 1.3/ActionItem.qml
825 ActionList 1.3 1.3/ActionList.qml
826 AdaptivePageLayout 1.3 1.3/AdaptivePageLayout.qml
827 PageColumnsLayout 1.3 1.3/PageColumnsLayout.qml
828
829=== modified file 'tests/unit/tst_components/tst_actionitem.qml'
830--- tests/unit/tst_components/tst_actionitem.qml 2015-03-03 13:20:06 +0000
831+++ tests/unit/tst_components/tst_actionitem.qml 2015-08-19 06:57:12 +0000
832@@ -21,10 +21,22 @@
833 TestCase {
834 name: "ActionItemAPI"
835
836+ SignalSpy {
837+ id: triggerSpy
838+ target: action1
839+ signalName: "triggered"
840+ }
841+
842 function initTestCase() {
843 compare(item1.action, null, "action is null by default")
844 compare(item1.text, "", "text is empty string set by default")
845 compare(item1.iconSource, "", "iconSource is empty string by default")
846+ compare(item1.iconName, "", "iconSource is empty string by default")
847+ }
848+
849+ function cleanup() {
850+ item1.action = null;
851+ triggerSpy.clear();
852 }
853
854 function test_action() {
855@@ -33,10 +45,8 @@
856 compare(item1.action, action1, "Action can be set")
857 compare(item1.text, action1.text, "text is automatically set to action text")
858 compare(item1.iconSource, action1.iconSource, "iconSource is automatically set to action iconSource")
859- var numTriggers = action1.triggerCount
860 item1.triggered(null)
861- compare(action1.triggerCount, numTriggers+1, "ActionItem triggered() triggers action")
862- item1.action = null
863+ triggerSpy.wait(400);
864 }
865
866 // NOTE: This test must be run AFTER test_action(), otherwise setting the action will
867@@ -89,7 +99,5 @@
868 id: action1
869 text: "actionText"
870 iconSource: "imageURL"
871- property int triggerCount: 0
872- onTriggered: triggerCount++
873 }
874 }

Subscribers

People subscribed via source and target branches