Merge lp:~nick-dedekind/ubuntu-ui-toolkit/exclusiveGroup into lp:ubuntu-ui-toolkit/staging

Proposed by Nick Dedekind
Status: Merged
Approved by: Zoltan Balogh
Approved revision: 1353
Merged at revision: 2077
Proposed branch: lp:~nick-dedekind/ubuntu-ui-toolkit/exclusiveGroup
Merge into: lp:ubuntu-ui-toolkit/staging
Diff against target: 1025 lines (+720/-56)
13 files modified
components.api (+14/-3)
src/Ubuntu/Components/1.3/ActionList.qml (+0/-47)
src/Ubuntu/Components/ComponentModule.pro (+0/-1)
src/Ubuntu/Components/qmldir (+0/-1)
src/Ubuntu/UbuntuToolkit/UbuntuToolkit.pro (+6/-2)
src/Ubuntu/UbuntuToolkit/actionlist.cpp (+158/-0)
src/Ubuntu/UbuntuToolkit/actionlist_p.h (+58/-0)
src/Ubuntu/UbuntuToolkit/exclusivegroup.cpp (+168/-0)
src/Ubuntu/UbuntuToolkit/exclusivegroup_p.h (+62/-0)
src/Ubuntu/UbuntuToolkit/ubuntutoolkitmodule.cpp (+4/-0)
src/Ubuntu/UbuntuToolkit/ucaction.cpp (+124/-0)
src/Ubuntu/UbuntuToolkit/ucaction_p.h (+19/-1)
tests/unit/components/tst_action.qml (+107/-1)
To merge this branch: bzr merge lp:~nick-dedekind/ubuntu-ui-toolkit/exclusiveGroup
Reviewer Review Type Date Requested Status
ubuntu-sdk-build-bot continuous-integration Approve
Zoltan Balogh Approve
Zsombor Egri Approve
PS Jenkins bot continuous-integration Pending
Review via email: mp+297921@code.launchpad.net

This proposal supersedes a proposal from 2016-06-07.

Commit message

Introduced Action states & ExclusiveGroup action list

Description of the change

Added Action::state.
Introduced ExclusiveGroup action list.
Moved ActionList to cpp.

To post a comment you must log in.
Revision history for this message
Zsombor Egri (zsombi) wrote : Posted in a previous version of this proposal

Please submit the MR against staging. And add unit tests pls.

review: Needs Fixing
Revision history for this message
Zoltan Balogh (bzoltan) wrote : Posted in a previous version of this proposal

Please retarget to the staging branch, thank you

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

There are few things to get sorted out still, the code looks good in general.

We are also planning to move all our code to UbuntuToolkit library and UbuntuTookit NS (see https://code.launchpad.net/~zsombi/ubuntu-ui-toolkit/moveStyledItem/+merge/296802), hopefully lands soon so you can move your stuff under the lib.

review: Needs Fixing
Revision history for this message
Nick Dedekind (nick-dedekind) wrote :

> There are few things to get sorted out still, the code looks good in general.
>
> We are also planning to move all our code to UbuntuToolkit library and
> UbuntuTookit NS (see https://code.launchpad.net/~zsombi/ubuntu-ui-
> toolkit/moveStyledItem/+merge/296802), hopefully lands soon so you can move
> your stuff under the lib.

I think I've addressed all the above and comments.
I've left the action::checked as a boolean rather than a tristate. On reflection, I believe that tristate should be handled in the implementer (ie Checkbox). Can't really get my head around tristate with Exclusive groups etc, as I don't think it makes much sense.
The mixed state doesn't really involve a "trigger", since it's not selectable.

Feel free to disagree :)

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

Sorry Nick, forgot to mention that UC prefix is no longer mandated. Let's get rid of it here too.

And with that change, we're all done! Thanks a lot!

review: Needs Fixing
Revision history for this message
Nick Dedekind (nick-dedekind) wrote :

> Sorry Nick, forgot to mention that UC prefix is no longer mandated. Let's get
> rid of it here too.
>
> And with that change, we're all done! Thanks a lot!

I've removed the UC prefix.

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

All cool now!!! Thanks Nick!

review: Approve
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Timo Jyrinki (timo-jyrinki) wrote :

This MP seems to have a real failure, not failing only on the armhf where there was faulty phone device doing the CI.

Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Zsombor Egri (zsombi) wrote :

One more try...

review: Approve
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Zoltan Balogh (bzoltan) :
review: Approve
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)
Revision history for this message
ubuntu-sdk-build-bot (ubuntu-sdk-build-bot) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'components.api'
--- components.api 2016-08-09 03:48:53 +0000
+++ components.api 2016-08-22 08:24:13 +0000
@@ -10,13 +10,17 @@
10 readonly property bool pressed10 readonly property bool pressed
11 readonly property UCMargins sensingMargins11 readonly property UCMargins sensingMargins
12Ubuntu.Components.Action 1.3 1.0 0.1 UCAction: QtObject12Ubuntu.Components.Action 1.3 1.0 0.1 UCAction: QtObject
13 property bool checkable 1.3
14 property bool checked 1.3
13 property string description15 property string description
14 property bool enabled16 property bool enabled
17 property ExclusiveGroup exclusiveGroup 1.3
15 property string iconName18 property string iconName
16 property url iconSource19 property url iconSource
17 property Component itemHint20 property Component itemHint
18 property string keywords21 property string keywords
19 signal triggered(var value)22 signal triggered(var value)
23 signal toggled(bool value) 1.3
20 function trigger(var value)24 function trigger(var value)
21 function trigger()25 function trigger()
22 property string name26 property string name
@@ -59,9 +63,12 @@
59Ubuntu.Components.ActionList 1.0 0.1: QtObject63Ubuntu.Components.ActionList 1.0 0.1: QtObject
60 property list<Action> actions64 property list<Action> actions
61 default property list<Action> children65 default property list<Action> children
62Ubuntu.Components.ActionList 1.3: QtObject66Ubuntu.Components.ActionList 1.3 ActionList: QtObject
63 property list<Action> actions67 default property list<Action> actions
64 default property list<Action> children68 signal added(Action action)
69 signal removed(Action action)
70 function addAction(Action action)
71 function removeAction(Action action)
65Ubuntu.Components.ActionManager 1.0 0.1 UCActionManager: QtObject72Ubuntu.Components.ActionManager 1.0 0.1 UCActionManager: QtObject
66 default property list<Action> actions73 default property list<Action> actions
67 readonly property ActionContext globalContext74 readonly property ActionContext globalContext
@@ -458,6 +465,10 @@
458 OperationPending465 OperationPending
459Ubuntu.Metrics.Event: Enum466Ubuntu.Metrics.Event: Enum
460 UserInterfaceReady467 UserInterfaceReady
468Ubuntu.Components.ExclusiveGroup 1.3 ExclusiveGroup: ActionList
469 readonly property QtObject current
470 function bindCheckable(QtObject object)
471 function unbindCheckable(QtObject object)
461Ubuntu.Components.ListItems.Expandable 1.0 0.1: Empty472Ubuntu.Components.ListItems.Expandable 1.0 0.1: Empty
462 property bool collapseOnClick473 property bool collapseOnClick
463 property double collapsedHeight474 property double collapsedHeight
464475
=== removed file 'src/Ubuntu/Components/1.3/ActionList.qml'
--- src/Ubuntu/Components/1.3/ActionList.qml 2016-05-25 12:48:10 +0000
+++ src/Ubuntu/Components/1.3/ActionList.qml 1970-01-01 00:00:00 +0000
@@ -1,47 +0,0 @@
1/*
2 * Copyright 2012 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17import QtQuick 2.4
18import Ubuntu.Components 1.3
19
20/*!
21 \qmltype ActionList
22 \inqmlmodule Ubuntu.Components
23 \ingroup ubuntu
24 \brief List of \l Action items
25*/
26
27QtObject {
28 id: list
29 // internal objects using nested elements,
30 // which isn't allowed by QtObject; this fix makes this possible
31 /*!
32 Default property to allow adding of children.
33 \qmlproperty list<Action> children
34 \default
35 */
36 default property alias children: list.actions
37
38 /*!
39 List of already defined actions when not defining them as children of the ActionList.
40 Note that when you set this property, the children of the ActionList will be ignored,
41 so do not set the list and define children.
42
43 The advantage of setting actions over using the children is that the same
44 \l Action items can be used in several sets of actions.
45 */
46 property list<Action> actions
47}
480
=== modified file 'src/Ubuntu/Components/ComponentModule.pro'
--- src/Ubuntu/Components/ComponentModule.pro 2016-07-29 13:21:05 +0000
+++ src/Ubuntu/Components/ComponentModule.pro 2016-08-22 08:24:13 +0000
@@ -78,7 +78,6 @@
7878
79#1.379#1.3
80QML_FILES += 1.3/ActionBar.qml \80QML_FILES += 1.3/ActionBar.qml \
81 1.3/ActionList.qml \
82 1.3/ActivityIndicator.qml \81 1.3/ActivityIndicator.qml \
83 1.3/AdaptivePageLayout.qml \82 1.3/AdaptivePageLayout.qml \
84 1.3/AnimatedItem.qml \83 1.3/AnimatedItem.qml \
8584
=== modified file 'src/Ubuntu/Components/qmldir'
--- src/Ubuntu/Components/qmldir 2016-07-29 13:21:05 +0000
+++ src/Ubuntu/Components/qmldir 2016-08-22 08:24:13 +0000
@@ -96,7 +96,6 @@
96#################################################96#################################################
97#version 1.397#version 1.3
98ActionBar 1.3 1.3/ActionBar.qml98ActionBar 1.3 1.3/ActionBar.qml
99ActionList 1.3 1.3/ActionList.qml
100AdaptivePageLayout 1.3 1.3/AdaptivePageLayout.qml99AdaptivePageLayout 1.3 1.3/AdaptivePageLayout.qml
101PageColumnsLayout 1.3 1.3/PageColumnsLayout.qml100PageColumnsLayout 1.3 1.3/PageColumnsLayout.qml
102PageColumn 1.3 1.3/PageColumn.qml101PageColumn 1.3 1.3/PageColumn.qml
103102
=== modified file 'src/Ubuntu/UbuntuToolkit/UbuntuToolkit.pro'
--- src/Ubuntu/UbuntuToolkit/UbuntuToolkit.pro 2016-08-04 17:25:09 +0000
+++ src/Ubuntu/UbuntuToolkit/UbuntuToolkit.pro 2016-08-22 08:24:13 +0000
@@ -149,7 +149,9 @@
149 privates/appheaderbase_p.h \149 privates/appheaderbase_p.h \
150 label_p.h \150 label_p.h \
151 ucbottomedgeregion_p_p.h \151 ucbottomedgeregion_p_p.h \
152 privates/ucscrollbarutils_p.h152 privates/ucscrollbarutils_p.h \
153 actionlist_p.h \
154 exclusivegroup_p.h
153155
154SOURCES += \156SOURCES += \
155 uctheme.cpp \157 uctheme.cpp \
@@ -226,7 +228,9 @@
226 privates/ucpagewrapper.cpp \228 privates/ucpagewrapper.cpp \
227 privates/ucpagewrapperincubator.cpp \229 privates/ucpagewrapperincubator.cpp \
228 privates/appheaderbase.cpp \230 privates/appheaderbase.cpp \
229 privates/ucscrollbarutils.cpp231 privates/ucscrollbarutils.cpp \
232 actionlist.cpp \
233 exclusivegroup.cpp
230234
231# adapters235# adapters
232SOURCES += $$PWD/adapters/alarmsadapter_organizer.cpp236SOURCES += $$PWD/adapters/alarmsadapter_organizer.cpp
233237
=== added file 'src/Ubuntu/UbuntuToolkit/actionlist.cpp'
--- src/Ubuntu/UbuntuToolkit/actionlist.cpp 1970-01-01 00:00:00 +0000
+++ src/Ubuntu/UbuntuToolkit/actionlist.cpp 2016-08-22 08:24:13 +0000
@@ -0,0 +1,158 @@
1/*
2 * Copyright 2016 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include "actionlist_p.h"
18#include "ucaction_p.h"
19
20UT_NAMESPACE_BEGIN
21
22/*!
23 * \qmltype ActionList
24 * \inqmlmodule Ubuntu.Components
25 * \ingroup ubuntu
26 * \brief List of \l Action items
27 * An ActionList provies a way of grouping actions together.
28 * \qml
29 * ActionList {
30 * Action {
31 * id: action1
32 * }
33 * Action {
34 * id: action2
35 * }
36 * }
37 * \endqml
38 */
39/*!
40 * \qmlsignal ActionList::added(Action action)
41 * \since Ubuntu.Components 1.3
42 * Signal called when an action is added to the list
43 */
44/*!
45 * \qmlsignal ActionList::removed(Action action)
46 * \since Ubuntu.Components 1.3
47 * Signal called when an action is removed from the list
48 */
49ActionList::ActionList(QObject *parent)
50 : QObject(parent)
51{
52}
53
54/*!
55 * \qmlmethod ActionList::addAction(Action action)
56 * \since Ubuntu.Components 1.3
57 * Adds an Action to the list programatically.
58 * \qml
59 * Item {
60 * Instantiator {
61 * model: 4
62 * onObjectAdded: actionList.addAction(object)
63 * onObjectRemoved: actionList.removeAction(object)
64 *
65 * Action {}
66 * }
67 *
68 * ActionList {
69 * id: actionList
70 * }
71 * }
72 * \endqml
73 * \sa ActionList::removeAction
74 */
75void ActionList::addAction(UCAction *action)
76{
77 if (m_actions.contains(action)) {
78 return;
79 }
80 m_actions.append(action);
81 Q_EMIT added(action);
82}
83
84/*!
85 * \qmlmethod ActionList::removeAction(Action action)
86 * \since Ubuntu.Components 1.3
87 * Removes an action from the list programatically.
88 * \sa ActionList::addAction
89 */
90void ActionList::removeAction(UCAction *action)
91{
92 if (!action) {
93 return;
94 }
95 if (m_actions.removeOne(action)) {
96 Q_EMIT removed(action);
97 }
98}
99
100/*!
101 * \qmlproperty list<Action> ActionList::actions
102 * \default
103 * List of Actions in this ActionList
104 * Note that when you set this property, the children of the ActionList will be ignored,
105 * so do not set the list and define children.
106 *
107 * The advantage of setting actions over using the children is that the same
108 * \l Action items can be used in several sets of actions.
109 */
110QQmlListProperty<UCAction> ActionList::actions()
111{
112 return QQmlListProperty<UCAction>(this, 0,
113 ActionList::append,
114 ActionList::count,
115 ActionList::at,
116 ActionList::clear);
117}
118
119const QList<UCAction*> &ActionList::list() const
120{
121 return m_actions;
122}
123
124void ActionList::append(QQmlListProperty<UCAction> *list, UCAction *action)
125{
126 ActionList *actionList = qobject_cast<ActionList*>(list->object);
127 if (actionList) {
128 actionList->addAction(action);
129 }
130}
131
132void ActionList::clear(QQmlListProperty<UCAction> *list)
133{
134 ActionList *actionList = qobject_cast<ActionList*>(list->object);
135 if (actionList) {
136 actionList->m_actions.clear();
137 }
138}
139
140UCAction* ActionList::at(QQmlListProperty<UCAction> *list, int index)
141{
142 ActionList *actionList = qobject_cast<ActionList*>(list->object);
143 if (actionList) {
144 return actionList->m_actions.value(index, nullptr);
145 }
146 return Q_NULLPTR;
147}
148
149int ActionList::count(QQmlListProperty<UCAction> *list)
150{
151 ActionList *actionList = qobject_cast<ActionList*>(list->object);
152 if (actionList) {
153 return actionList->m_actions.count();
154 }
155 return 0;
156}
157
158UT_NAMESPACE_END
0159
=== added file 'src/Ubuntu/UbuntuToolkit/actionlist_p.h'
--- src/Ubuntu/UbuntuToolkit/actionlist_p.h 1970-01-01 00:00:00 +0000
+++ src/Ubuntu/UbuntuToolkit/actionlist_p.h 2016-08-22 08:24:13 +0000
@@ -0,0 +1,58 @@
1/*
2 * Copyright 2016 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#ifndef ACTIONLIST_H
18#define ACTIONLIST_H
19
20#include <QObject>
21#include <QtQml/QQmlListProperty>
22#include "ubuntutoolkitglobal.h"
23
24UT_NAMESPACE_BEGIN
25
26class UCAction;
27class UBUNTUTOOLKIT_EXPORT ActionList : public QObject
28{
29 Q_OBJECT
30 Q_PROPERTY(QQmlListProperty<UT_PREPEND_NAMESPACE(UCAction)> actions READ actions)
31 Q_CLASSINFO("DefaultProperty", "actions")
32public:
33 explicit ActionList(QObject *parent = 0);
34
35 QQmlListProperty<UCAction> actions();
36
37 const QList<UCAction*> &list() const;
38
39public Q_SLOTS:
40 void addAction(UT_PREPEND_NAMESPACE(UCAction) *action);
41 void removeAction(UT_PREPEND_NAMESPACE(UCAction) *action);
42
43Q_SIGNALS:
44 void added(UCAction *action);
45 void removed(UCAction *action);
46
47protected:
48 QList<UCAction*> m_actions;
49
50 static void append(QQmlListProperty<UCAction> *list, UCAction *action);
51 static void clear(QQmlListProperty<UCAction> *list);
52 static UCAction* at(QQmlListProperty<UCAction> *list, int index);
53 static int count(QQmlListProperty<UCAction> *list);
54};
55
56UT_NAMESPACE_END
57
58#endif // ACTIONLIST_H
059
=== added file 'src/Ubuntu/UbuntuToolkit/exclusivegroup.cpp'
--- src/Ubuntu/UbuntuToolkit/exclusivegroup.cpp 1970-01-01 00:00:00 +0000
+++ src/Ubuntu/UbuntuToolkit/exclusivegroup.cpp 2016-08-22 08:24:13 +0000
@@ -0,0 +1,168 @@
1/*
2 * Copyright 2016 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18#include "exclusivegroup_p.h"
19#include "ucaction_p.h"
20
21#include <QSignalMapper>
22
23#define CHECKED_PROPERTY "checked"
24
25UT_NAMESPACE_BEGIN
26
27static const char *checkableSignals[] = {
28 "toggled(bool)",
29 0
30};
31
32static bool isChecked(const QObject *o)
33{
34 if (!o) return false;
35 QVariant checkedVariant = o->property(CHECKED_PROPERTY);
36 return checkedVariant.isValid() && checkedVariant.toBool();
37}
38
39/*!
40 * \qmltype ExclusiveGroup
41 * \inqmlmodule Ubuntu.Components
42 * \since Ubuntu.Components 1.3
43 * \ingroup ubuntu
44 * \inherits ActionList
45 * \brief ExclusiveGroup provides a way to declare several checkable controls as mutually exclusive.
46 *
47 * The ExclusiveGroup will only allow a single object to have it's checkable property set to "true"
48 * at any one time. The exclusive group accepts child Actions, but objects other than Actions can be
49 * used by using the \l bindCheckable function as long as they support one of the required signals,
50 * and a "checked" property.
51 * \qml
52 * ExclusiveGroup {
53 * Action {
54 * parameterType: Action.Bool
55 * state: true
56 * }
57 * Action {
58 * parameterType: Action.Bool
59 * state: false
60 * }
61 * }
62 * \endqml
63 */
64ExclusiveGroup::ExclusiveGroup(QObject *parent)
65 : ActionList(parent)
66 , m_signalMapper(new QSignalMapper(this))
67 , m_entranceGuard(false)
68{
69 connect(this, &ActionList::added, this, &ExclusiveGroup::onActionAdded);
70 connect(this, &ActionList::removed, this, &ExclusiveGroup::onActionRemoved);
71
72 int index = m_signalMapper->metaObject()->indexOfMethod("map()");
73 m_updateCurrentMethod = m_signalMapper->metaObject()->method(index);
74 connect(m_signalMapper, static_cast<void(QSignalMapper::*)(QObject *)>(&QSignalMapper::mapped), this, [this](QObject *object) {
75 if (isChecked(object)) {
76 setCurrent(object);
77 }
78 });
79}
80
81void ExclusiveGroup::onActionAdded(UCAction *action)
82{
83 action->setExclusiveGroup(this);
84}
85
86void ExclusiveGroup::onActionRemoved(UCAction *action)
87{
88 action->setExclusiveGroup(nullptr);
89}
90
91/*!
92 * \qmlproperty Action ExclusiveGroup::current
93 * Returns the currently checked action
94 */
95void ExclusiveGroup::setCurrent(QObject *object)
96{
97 if (m_current == object)
98 return;
99
100 if (m_current)
101 m_current->setProperty(CHECKED_PROPERTY, QVariant(false));
102 m_current = object;
103 if (m_current)
104 m_current->setProperty(CHECKED_PROPERTY, QVariant(true));
105 Q_EMIT currentChanged();
106}
107
108QObject *ExclusiveGroup::current() const
109{
110 return m_current.data();
111}
112
113/*!
114 * \qmlmethod void ExclusiveGroup::bindCheckable(object object)
115 * Explicitly bind an objects checkability to this exclusive group.
116 * \note This only works with objects which support the following signals signals:
117 * \list
118 * \li \b toggled(bool)
119 * \endlist
120 * \qml
121 * Item {
122 * ExclusiveGroup {
123 * id: exclusiveGroup
124 * }
125 * Instantiator {
126 * model: 4
127 * onObjectAdded: exclusiveGroup.bindCheckable(object)
128 * onObjectRemoved: exclusiveGroup.unbindCheckable(object)
129 *
130 * Action {
131 * checkable: true
132 * }
133 * }
134 * }
135 * \endqml
136 * \sa ExclusiveGroup::unbindCheckable
137 */
138void ExclusiveGroup::bindCheckable(QObject *object)
139{
140 for (const char **signalName = checkableSignals; *signalName; signalName++) {
141 int signalIndex = object->metaObject()->indexOfSignal(*signalName);
142 if (signalIndex != -1) {
143 QMetaMethod signalMethod = object->metaObject()->method(signalIndex);
144 connect(object, signalMethod, m_signalMapper, m_updateCurrentMethod, Qt::UniqueConnection);
145 m_signalMapper->setMapping(object, object);
146 connect(object, SIGNAL(destroyed(QObject*)), this, SLOT(unbindCheckable(QObject*)), Qt::UniqueConnection);
147 if (!m_current && isChecked(object))
148 setCurrent(object);
149 break;
150 }
151 }
152}
153
154/*!
155 * \qmlmethod void ExclusiveGroup::unbindCheckable(object object)
156 * Explicitly unbind an objects checkability from this exclusive group.
157 * \sa ExclusiveGroup::bindCheckable
158 */
159void ExclusiveGroup::unbindCheckable(QObject *object)
160{
161 if (m_current == object)
162 setCurrent(0);
163
164 disconnect(object, 0, m_signalMapper, 0);
165 disconnect(object, SIGNAL(destroyed(QObject*)), this, SLOT(unbindCheckable(QObject*)));
166}
167
168UT_NAMESPACE_END
0169
=== added file 'src/Ubuntu/UbuntuToolkit/exclusivegroup_p.h'
--- src/Ubuntu/UbuntuToolkit/exclusivegroup_p.h 1970-01-01 00:00:00 +0000
+++ src/Ubuntu/UbuntuToolkit/exclusivegroup_p.h 2016-08-22 08:24:13 +0000
@@ -0,0 +1,62 @@
1/*
2 * Copyright 2016 Canonical Ltd.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18#ifndef EXCLUSIVEGROUP_H
19#define EXCLUSIVEGROUP_H
20
21#include "actionlist_p.h"
22#include "ubuntutoolkitglobal.h"
23
24#include <QMetaMethod>
25#include <QPointer>
26
27class QSignalMapper;
28
29UT_NAMESPACE_BEGIN
30
31class UBUNTUTOOLKIT_EXPORT ExclusiveGroup : public ActionList
32{
33 Q_OBJECT
34 Q_PROPERTY(QObject* current READ current NOTIFY currentChanged)
35
36public:
37 explicit ExclusiveGroup(QObject *parent = 0);
38
39 QObject* current() const;
40
41 Q_INVOKABLE void bindCheckable(QObject* object);
42 Q_INVOKABLE void unbindCheckable(QObject* object);
43
44Q_SIGNALS:
45 void currentChanged();
46
47protected Q_SLOTS:
48 void onActionAdded(UCAction* action);
49 void onActionRemoved(UCAction* action);
50
51private:
52 void setCurrent(QObject* action);
53
54 QSignalMapper* m_signalMapper;
55 QPointer<QObject> m_current;
56 QMetaMethod m_updateCurrentMethod;
57 bool m_entranceGuard;
58};
59
60UT_NAMESPACE_END
61
62#endif // EXCLUSIVEGROUP_H
063
=== modified file 'src/Ubuntu/UbuntuToolkit/ubuntutoolkitmodule.cpp'
--- src/Ubuntu/UbuntuToolkit/ubuntutoolkitmodule.cpp 2016-08-06 00:55:32 +0000
+++ src/Ubuntu/UbuntuToolkit/ubuntutoolkitmodule.cpp 2016-08-22 08:24:13 +0000
@@ -89,6 +89,8 @@
89#include <privates/ucpagewrapper_p.h>89#include <privates/ucpagewrapper_p.h>
90#include <privates/appheaderbase_p.h>90#include <privates/appheaderbase_p.h>
91#include <privates/ucscrollbarutils_p.h>91#include <privates/ucscrollbarutils_p.h>
92#include <actionlist_p.h>
93#include <exclusivegroup_p.h>
9294
93// styles95// styles
94#include <ucbottomedgestyle_p.h>96#include <ucbottomedgestyle_p.h>
@@ -374,6 +376,8 @@
374 qmlRegisterType<UCPageTreeNode>(uri, 1, 3, "PageTreeNode");376 qmlRegisterType<UCPageTreeNode>(uri, 1, 3, "PageTreeNode");
375 qmlRegisterType<UCPopupContext>(uri, 1, 3, "PopupContext");377 qmlRegisterType<UCPopupContext>(uri, 1, 3, "PopupContext");
376 qmlRegisterType<UCMainViewBase>(uri, 1, 3, "MainViewBase");378 qmlRegisterType<UCMainViewBase>(uri, 1, 3, "MainViewBase");
379 qmlRegisterType<ActionList>(uri, 1, 3, "ActionList");
380 qmlRegisterType<ExclusiveGroup>(uri, 1, 3, "ExclusiveGroup");
377}381}
378382
379void UbuntuToolkitModule::undefineModule()383void UbuntuToolkitModule::undefineModule()
380384
=== modified file 'src/Ubuntu/UbuntuToolkit/ucaction.cpp'
--- src/Ubuntu/UbuntuToolkit/ucaction.cpp 2016-07-07 07:21:48 +0000
+++ src/Ubuntu/UbuntuToolkit/ucaction.cpp 2016-08-22 08:24:13 +0000
@@ -17,6 +17,7 @@
17#include "ucaction_p.h"17#include "ucaction_p.h"
18#include "quickutils_p.h"18#include "quickutils_p.h"
19#include "ucactioncontext_p.h"19#include "ucactioncontext_p.h"
20#include "exclusivegroup_p.h"
2021
21#include <QtDebug>22#include <QtDebug>
22#include <QtQml/QQmlInfo>23#include <QtQml/QQmlInfo>
@@ -149,6 +150,18 @@
149 * text: "&Call"150 * text: "&Call"
150 * }151 * }
151 * \endqml152 * \endqml
153 *
154 * \section2 Checkable property
155 * Since Ubuntu.Components 1.3 Action supports the checkable/checked properties.
156 * \qml
157 * Button {
158 * action: Action {
159 * checkable: true
160 * checked: false
161 * }
162 * color: action.checked ? UbuntuColor.green : UbuntuColor.red
163 * }
164 * \endqml
152 */165 */
153166
154/*!167/*!
@@ -160,6 +173,14 @@
160 */173 */
161174
162/*!175/*!
176 * \qmlsignal Action::toggled(bool value)
177 * Signal called when the action's checked property changes.
178 * \note The toggled signal should be used for checkable actions rather than the
179 * triggered signal.
180 * \sa Action::checkable, Action::checked, ExclusiveGroup
181 */
182
183/*!
163 * \qmlproperty string Action::description184 * \qmlproperty string Action::description
164 * User visible secondary description for the action. Description is more verbose185 * User visible secondary description for the action. Description is more verbose
165 * than the \l text and should describe the Action with couple of words.186 * than the \l text and should describe the Action with couple of words.
@@ -289,12 +310,15 @@
289310
290UCAction::UCAction(QObject *parent)311UCAction::UCAction(QObject *parent)
291 : QObject(parent)312 : QObject(parent)
313 , m_exclusiveGroup(Q_NULLPTR)
292 , m_itemHint(Q_NULLPTR)314 , m_itemHint(Q_NULLPTR)
293 , m_parameterType(None)315 , m_parameterType(None)
294 , m_factoryIconSource(true)316 , m_factoryIconSource(true)
295 , m_enabled(true)317 , m_enabled(true)
296 , m_visible(true)318 , m_visible(true)
297 , m_published(false)319 , m_published(false)
320 , m_checkable(false)
321 , m_checked(false)
298{322{
299 generateName();323 generateName();
300 // FIXME: we need QInputDeviceInfo to detect the keyboard attechment324 // FIXME: we need QInputDeviceInfo to detect the keyboard attechment
@@ -436,6 +460,101 @@
436 Q_EMIT shortcutChanged();460 Q_EMIT shortcutChanged();
437}461}
438462
463/*!
464 * \qmlproperty bool Action::checkable
465 * \since Ubuntu.Components 1.3
466 * Whether the action can be checked. Defaults to false.
467 * \sa Action::checked, Action::toggled, ExclusiveGroup
468 */
469void UCAction::setCheckable(bool checkable)
470{
471 if (m_checkable == checkable) {
472 return;
473 }
474 m_checkable = checkable;
475 Q_EMIT checkableChanged();
476
477 // If the Action is already checked, assert the check state.
478 if (m_checked)
479 Q_EMIT toggled(m_checkable);
480}
481
482/*!
483 * \qmlproperty bool Action::checked
484 * \since Ubuntu.Components 1.3
485 * If the action is checkable, this property reflects its checked state. Defaults to false.
486 * Its value is also false while checkable is false.
487 * \sa Action::checkable, Action::toggled, ExclusiveGroup
488 */
489void UCAction::setChecked(bool checked)
490{
491 if (m_checked == checked) {
492 return;
493 }
494 m_checked = checked;
495
496 if (m_checkable) {
497 Q_EMIT toggled(checked);
498 }
499}
500
501/*!
502 * \qmlproperty ExclusiveGroup Action::exclusiveGroup
503 * \since Ubuntu.Components 1.3
504 * The \l ExclusiveGroup associated with this action.
505 * An exclusive group allows the \l checked property to belinked to other actions,
506 * as in radio controls.
507 * \qml
508 * Column {
509 * ExclusiveGroup {
510 * Action {
511 * id: action1
512 * checkable: true
513 * checked: true
514 * }
515 * Action {
516 * id: action2
517 * checkable: true
518 * }
519 * Action {
520 * id: action3
521 * checkable: true
522 * }
523 * }
524 *
525 * Button {
526 * action: action1
527 * color: action.checked ? UbuntuColor.green : UbuntuColor.red
528 * }
529 * Button {
530 * action: action2
531 * color: action.checked ? UbuntuColor.green : UbuntuColor.red
532 * }
533 * Button {
534 * action: action3
535 * color: action.checked ? UbuntuColor.green : UbuntuColor.grey
536 * }
537 * }
538 * \endqml
539 */
540void UCAction::setExclusiveGroup(ExclusiveGroup *exclusiveGroup)
541{
542 if (m_exclusiveGroup == exclusiveGroup) {
543 return;
544 }
545
546 if (m_exclusiveGroup) {
547 m_exclusiveGroup->unbindCheckable(this);
548 }
549
550 m_exclusiveGroup = exclusiveGroup;
551
552 if (m_exclusiveGroup) {
553 m_exclusiveGroup->bindCheckable(this);
554 }
555 Q_EMIT exclusiveGroupChanged();
556}
557
439bool UCAction::event(QEvent *event)558bool UCAction::event(QEvent *event)
440{559{
441 if (event->type() != QEvent::Shortcut)560 if (event->type() != QEvent::Shortcut)
@@ -475,6 +594,11 @@
475 if (!m_enabled) {594 if (!m_enabled) {
476 return;595 return;
477 }596 }
597
598 if (m_checkable && !(m_checked && m_exclusiveGroup)) {
599 setChecked(!m_checked);
600 }
601
478 if (!isValidType(value.type())) {602 if (!isValidType(value.type())) {
479 Q_EMIT triggered(QVariant());603 Q_EMIT triggered(QVariant());
480 } else {604 } else {
481605
=== modified file 'src/Ubuntu/UbuntuToolkit/ucaction_p.h'
--- src/Ubuntu/UbuntuToolkit/ucaction_p.h 2016-07-07 07:21:48 +0000
+++ src/Ubuntu/UbuntuToolkit/ucaction_p.h 2016-08-22 08:24:13 +0000
@@ -53,7 +53,7 @@
53 }53 }
54}54}
5555
56class UCActionAttached;56class ExclusiveGroup;
57class UBUNTUTOOLKIT_EXPORT UCAction : public QObject57class UBUNTUTOOLKIT_EXPORT UCAction : public QObject
58{58{
59 Q_OBJECT59 Q_OBJECT
@@ -68,6 +68,10 @@
68 Q_PROPERTY(bool enabled MEMBER m_enabled NOTIFY enabledChanged)68 Q_PROPERTY(bool enabled MEMBER m_enabled NOTIFY enabledChanged)
69 Q_PROPERTY(Type parameterType MEMBER m_parameterType NOTIFY parameterTypeChanged)69 Q_PROPERTY(Type parameterType MEMBER m_parameterType NOTIFY parameterTypeChanged)
7070
71 Q_PROPERTY(bool checkable READ isCheckable WRITE setCheckable NOTIFY checkableChanged REVISION 1)
72 Q_PROPERTY(bool checked READ isChecked WRITE setChecked NOTIFY toggled REVISION 1)
73 Q_PROPERTY(ExclusiveGroup* exclusiveGroup READ exclusiveGroup WRITE setExclusiveGroup NOTIFY exclusiveGroupChanged REVISION 1)
74
71 // Toolkit Actions API75 // Toolkit Actions API
72 Q_PROPERTY(QUrl iconSource MEMBER m_iconSource WRITE setIconSource NOTIFY iconSourceChanged)76 Q_PROPERTY(QUrl iconSource MEMBER m_iconSource WRITE setIconSource NOTIFY iconSourceChanged)
73 Q_PROPERTY(bool visible MEMBER m_visible NOTIFY visibleChanged)77 Q_PROPERTY(bool visible MEMBER m_visible NOTIFY visibleChanged)
@@ -113,6 +117,13 @@
113 void setItemHint(QQmlComponent *);117 void setItemHint(QQmlComponent *);
114 void setShortcut(const QVariant&);118 void setShortcut(const QVariant&);
115 void resetShortcut();119 void resetShortcut();
120 void setCheckable(bool checkable);
121 bool isCheckable() const { return m_checkable; }
122 void setChecked(bool checked);
123 bool isChecked() const { return m_checkable && m_checked; }
124
125 ExclusiveGroup *exclusiveGroup() const { return m_exclusiveGroup; }
126 void setExclusiveGroup(ExclusiveGroup *exclusiveGroup);
116127
117Q_SIGNALS:128Q_SIGNALS:
118 void nameChanged();129 void nameChanged();
@@ -125,13 +136,18 @@
125 void iconSourceChanged();136 void iconSourceChanged();
126 void visibleChanged();137 void visibleChanged();
127 void shortcutChanged();138 void shortcutChanged();
139 Q_REVISION(1) void checkableChanged();
140 Q_REVISION(1) void exclusiveGroupChanged();
141
128 void triggered(const QVariant &value);142 void triggered(const QVariant &value);
143 Q_REVISION(1) void toggled(bool value);
129144
130public Q_SLOTS:145public Q_SLOTS:
131 void trigger(const QVariant &value = QVariant());146 void trigger(const QVariant &value = QVariant());
132147
133private:148private:
134 QPODVector<QQuickItem*, 4> m_owningItems;149 QPODVector<QQuickItem*, 4> m_owningItems;
150 ExclusiveGroup *m_exclusiveGroup;
135 QString m_name;151 QString m_name;
136 QString m_text;152 QString m_text;
137 QString m_iconName;153 QString m_iconName;
@@ -146,6 +162,8 @@
146 bool m_enabled:1;162 bool m_enabled:1;
147 bool m_visible:1;163 bool m_visible:1;
148 bool m_published:1;164 bool m_published:1;
165 bool m_checkable:1;
166 bool m_checked:1;
149167
150 friend class UCActionContext;168 friend class UCActionContext;
151 friend class UCActionItem;169 friend class UCActionItem;
152170
=== modified file 'tests/unit/components/tst_action.qml'
--- tests/unit/components/tst_action.qml 2015-12-22 14:42:59 +0000
+++ tests/unit/components/tst_action.qml 2016-08-22 08:24:13 +0000
@@ -16,7 +16,7 @@
1616
17import QtQuick 2.017import QtQuick 2.0
18import QtTest 1.018import QtTest 1.0
19import Ubuntu.Components 1.119import Ubuntu.Components 1.3
2020
21TestCase {21TestCase {
22 name: "ActionAPI"22 name: "ActionAPI"
@@ -39,6 +39,12 @@
39 triggeredSignalSpy.clear();39 triggeredSignalSpy.clear();
40 context1.active = false;40 context1.active = false;
41 context2.active = false;41 context2.active = false;
42
43 checkableAction.checkable = true;
44 checkableAction.checked = false;
45 action1.checked = true;
46 currentActionSpy.clear();
47 checkableSpy.clear();
42 }48 }
4349
44 function initTestCase() {50 function initTestCase() {
@@ -166,6 +172,60 @@
166 compare(data.action.invoked, data.invoked);172 compare(data.action.invoked, data.invoked);
167 }173 }
168174
175 function test_checkable() {
176 checkableAction.checkable = true;
177 checkableAction.checked = true;
178 checkableSpy.wait();
179 compare(checkableAction.checked, true, "Checkable action should be checked");
180 }
181
182 function test_not_checkable() {
183 checkableAction.checkable = false;
184 checkableAction.checked = true;
185 compare(checkableAction.checked, false, "Non-checkable action should never be checked");
186 }
187
188 function test_actionlist() {
189 verify(actionList.actions.length, 2, "Default actions not added to actionList");
190 }
191
192 function test_actionlist_dynamic_actions() {
193 actionList.addAction(dynamicListAction);
194 verify(actionList.actions.length, 3, "Dynamic action not added to actionList");
195 actionList.removeAction(dynamicListAction);
196 verify(actionList.actions.length, 2, "Dynamic action not remove from actionList");
197 }
198
199 function test_exclusive_group() {
200 compare(exclusiveGroup.actions.length, 3, "Incorrect number of actions");
201 }
202
203 function test_exclusive_group_activation_data() {
204 return [
205 {tag: "Activate action2", active: [action2], inactive: [action1, action3], current: action2},
206 {tag: "Activate action3", active: [action3], inactive: [action1, action2], current: action3},
207 {tag: "Activate action2, action3", active: [action2, action3], inactive: [action1, action2], current: action3},
208 ];
209 }
210 function test_exclusive_group_activation(data) {
211 for (var i = 0; i < data.active.length; i++) {
212 data.active[i].trigger();
213 compare(data.active[i].checked, true, "Active action checked property should be 'true'");
214 }
215 for (var i = 0; i < data.inactive.length; i++) {
216 compare(data.inactive[i].checked, false, "Inactive action checked property should be 'false'");
217 }
218 currentActionSpy.wait();
219 compare(exclusiveGroup.current, data.current, "Current action in exclusiveGroup does not match");
220 }
221
222 function test_always_one_action_selected() {
223 action1.trigger();
224 compare(action1.checked, true, "Triggering an exclusive group action should check the action");
225 action1.trigger();
226 compare(action1.checked, true, "Triggering an exclusive group action again will not uncheck the action.");
227 }
228
169 Action {229 Action {
170 id: action230 id: action
171 }231 }
@@ -197,6 +257,16 @@
197 target: action257 target: action
198 signalName: "textChanged"258 signalName: "textChanged"
199 }259 }
260 SignalSpy {
261 id: checkableSpy
262 target: checkableAction
263 signalName: "toggled"
264 }
265 SignalSpy {
266 id: currentActionSpy
267 target: exclusiveGroup
268 signalName: "currentChanged"
269 }
200270
201 ActionManager {271 ActionManager {
202 id: manager272 id: manager
@@ -236,4 +306,40 @@
236 id: testItem306 id: testItem
237 }307 }
238308
309 Action {
310 id: checkableAction
311 checkable: true
312 }
313
314 ActionList {
315 id: actionList
316 Action {
317 }
318 Action {
319 }
320 }
321
322 Action {
323 id: dynamicListAction
324 }
325
326 ExclusiveGroup {
327 id: exclusiveGroup
328 Action {
329 id: action1
330 checkable: true
331 checked: true
332 }
333 Action {
334 id: action2
335 checkable: true
336 checked: false
337 }
338 Action {
339 id: action3
340 checkable: true
341 checked: false
342 }
343 }
344
239}345}

Subscribers

People subscribed via source and target branches