Merge lp:~osomon/unity-2d/rolesMatchingInPlace into lp:unity-2d/3.0

Proposed by Olivier Tilloy
Status: Merged
Approved by: Florian Boucault
Approved revision: 591
Merged at revision: 619
Proposed branch: lp:~osomon/unity-2d/rolesMatchingInPlace
Merge into: lp:unity-2d/3.0
Diff against target: 151 lines (+25/-34)
5 files modified
launcher/Launcher.qml (+1/-1)
libunity-2d-private/Unity2d/launcherplaceslist.cpp (+2/-21)
libunity-2d-private/Unity2d/launcherplaceslist.h (+0/-8)
libunity-2d-private/Unity2d/place.cpp (+15/-4)
libunity-2d-private/Unity2d/place.h (+7/-0)
To merge this branch: bzr merge lp:~osomon/unity-2d/rolesMatchingInPlace
Reviewer Review Type Date Requested Status
Florian Boucault (community) Approve
Ugo Riboni Pending
Review via email: mp+64130@code.launchpad.net

Commit message

[libunity-2d] Move the roles matching logic from the aggregator to the Place object, where it really belongs.
This allows to use a filter proxy model on a Place model directly in QML.

Description of the change

Move the roles matching logic from the aggregator to the Place object, where it really belongs.
This allows to use a filter proxy model on a Place model directly in QML.

This is not directly useful to unity-2d, but I need this change for an OEM project that uses it. And this logic should have been put there in the first place.

To post a comment you must log in.
Revision history for this message
Florian Boucault (fboucault) wrote :

Good to go!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'launcher/Launcher.qml'
2--- launcher/Launcher.qml 2011-06-07 16:34:46 +0000
3+++ launcher/Launcher.qml 2011-06-10 09:21:13 +0000
4@@ -95,7 +95,7 @@
5 model: places
6 dynamicSortFilter: true
7
8- filterRole: LauncherPlacesList.RoleShowEntry
9+ filterRole: Place.RoleShowEntry
10 filterRegExp: RegExp("^true$")
11 }
12
13
14=== modified file 'libunity-2d-private/Unity2d/launcherplaceslist.cpp'
15--- libunity-2d-private/Unity2d/launcherplaceslist.cpp 2011-06-07 16:34:46 +0000
16+++ libunity-2d-private/Unity2d/launcherplaceslist.cpp 2011-06-10 09:21:13 +0000
17@@ -29,8 +29,8 @@
18 ListAggregatorModel(parent)
19 {
20 QHash<int, QByteArray> roles;
21- roles[RoleItem] = "item";
22- roles[RoleShowEntry] = "showEntry";
23+ roles[Place::RoleItem] = "item";
24+ roles[Place::RoleShowEntry] = "showEntry";
25 setRoleNames(roles);
26
27 QDir dir(PLACES_DIR);
28@@ -136,22 +136,3 @@
29 }
30 }
31
32-QVariant
33-LauncherPlacesList::data(const QModelIndex& index, int role) const
34-{
35- QVariant item = ListAggregatorModel::data(index, Qt::DisplayRole);
36- if (role == RoleItem) {
37- return item;
38- } else if (role == RoleShowEntry) {
39- /* We attempt this cast because we are sure that this aggregator is only
40- aggregating Places, and Places have as items PlaceEntries */
41- PlaceEntry* entry = item.value<PlaceEntry*>();
42- if (entry == NULL) {
43- return QVariant();
44- } else {
45- return QVariant::fromValue(QString(entry->showEntry() ? "true" : "false"));
46- }
47- } else {
48- return QVariant();
49- }
50-}
51
52=== modified file 'libunity-2d-private/Unity2d/launcherplaceslist.h'
53--- libunity-2d-private/Unity2d/launcherplaceslist.h 2011-06-07 16:34:46 +0000
54+++ libunity-2d-private/Unity2d/launcherplaceslist.h 2011-06-10 09:21:13 +0000
55@@ -31,22 +31,14 @@
56 class LauncherPlacesList : public ListAggregatorModel
57 {
58 Q_OBJECT
59- Q_ENUMS(Roles)
60
61 public:
62 LauncherPlacesList(QObject* parent = 0);
63 ~LauncherPlacesList();
64
65- enum Roles {
66- RoleItem,
67- RoleShowEntry
68- };
69-
70 Q_INVOKABLE PlaceEntry* findPlaceEntry(const QString& fileName, const QString& groupName);
71 Q_INVOKABLE void startAllPlaceServices();
72
73- QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const;
74-
75 private:
76 QStringList m_placeFiles;
77 QFileSystemWatcher* m_watch;
78
79=== modified file 'libunity-2d-private/Unity2d/place.cpp'
80--- libunity-2d-private/Unity2d/place.cpp 2011-06-07 16:34:46 +0000
81+++ libunity-2d-private/Unity2d/place.cpp 2011-06-10 09:21:13 +0000
82@@ -24,8 +24,9 @@
83 #include <unity2dtr.h>
84 #include <debug_p.h>
85
86+#include <QHash>
87+#include <QByteArray>
88 #include <QStringList>
89-#include <QDebug>
90 #include <QDBusPendingReply>
91 #include <QDBusServiceWatcher>
92 #include <QDBusConnectionInterface>
93@@ -44,6 +45,11 @@
94 m_dbusIface(NULL),
95 m_querying(false)
96 {
97+ QHash<int, QByteArray> roles;
98+ roles[RoleItem] = "item";
99+ roles[RoleShowEntry] = "showEntry";
100+ setRoleNames(roles);
101+
102 m_serviceWatcher = new QDBusServiceWatcher(this);
103 m_serviceWatcher->setConnection(QDBusConnection::sessionBus());
104 connect(m_serviceWatcher, SIGNAL(serviceRegistered(QString)),
105@@ -177,13 +183,18 @@
106 QVariant
107 Place::data(const QModelIndex& index, int role) const
108 {
109- Q_UNUSED(role)
110-
111 if (!index.isValid()) {
112 return QVariant();
113 }
114
115- return QVariant::fromValue(m_entries.at(index.row()));
116+ PlaceEntry* entry = m_entries.at(index.row());
117+ if (role == Place::RoleItem) {
118+ return QVariant::fromValue(entry);
119+ } else if (role == Place::RoleShowEntry) {
120+ return QVariant::fromValue(QString(entry->showEntry() ? "true" : "false"));
121+ } else {
122+ return QVariant();
123+ }
124 }
125
126 int
127
128=== modified file 'libunity-2d-private/Unity2d/place.h'
129--- libunity-2d-private/Unity2d/place.h 2011-06-07 16:34:46 +0000
130+++ libunity-2d-private/Unity2d/place.h 2011-06-10 09:21:13 +0000
131@@ -36,6 +36,8 @@
132 {
133 Q_OBJECT
134
135+ Q_ENUMS(Roles)
136+
137 Q_PROPERTY(QString fileName READ fileName WRITE setFileName)
138 Q_PROPERTY(QString dbusName READ dbusName)
139 Q_PROPERTY(QString dbusObjectPath READ dbusObjectPath)
140@@ -46,6 +48,11 @@
141 Place(const Place& other);
142 ~Place();
143
144+ enum Roles {
145+ RoleItem,
146+ RoleShowEntry
147+ };
148+
149 /* getters */
150 QString fileName() const;
151 QString dbusName() const;

Subscribers

People subscribed via source and target branches