Merge lp:~stolowski/unity8/category-reordering into lp:unity8

Proposed by Paweł Stołowski
Status: Merged
Approved by: Albert Astals Cid
Approved revision: 253
Merged at revision: 416
Proposed branch: lp:~stolowski/unity8/category-reordering
Merge into: lp:unity8
Diff against target: 194 lines (+80/-18)
2 files modified
plugins/Unity/categories.cpp (+70/-17)
plugins/Unity/categories.h (+10/-1)
To merge this branch: bzr merge lp:~stolowski/unity8/category-reordering
Reviewer Review Type Date Requested Status
Albert Astals Cid (community) Approve
PS Jenkins bot (community) continuous-integration Needs Fixing
Review via email: mp+189263@code.launchpad.net

Commit message

Handle category_order_changes signal from scopes (used in Home only) and reorder categories accordingly.

Description of the change

Handle category_order_changes signal from scopes (used in Home only) and reorder categories accordingly.

WARNING! It needs a hotfix for Qt proposed here: https://bugs.launchpad.net/ubuntu/+source/qtbase-opensource-src/+bug/1234603 ; please don't top-approve until we know it's going to land at the same time, otherwise this branch will break Dash.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

PASSED: Continuous integration, rev:247
http://jenkins.qa.ubuntu.com/job/unity8-ci/1258/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-saucy/4528
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-touch/2311
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity-phablet-qmluitests-saucy/2090
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-saucy-amd64-ci/281
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-saucy-armhf-ci/1258
        deb: http://jenkins.qa.ubuntu.com/job/unity8-saucy-armhf-ci/1258/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-saucy-i386-ci/1257
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-saucy/812
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-saucy-amd64/403
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-saucy-amd64/403/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-saucy-armhf/2313
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-saucy-armhf/2313/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-maguro/1986
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-mako/2001

Click here to trigger a rebuild:
http://s-jenkins:8080/job/unity8-ci/1258/rebuild

review: Approve (continuous-integration)
248. By Paweł Stołowski

Removed unneeded include.

249. By Paweł Stołowski

Merged trunk.

Revision history for this message
Albert Astals Cid (aacid) wrote :

We don't use
  const int mappedIndex = m_categoryOrder.indexOf(i);
for anything so we can save the lookup :-)

review: Needs Fixing
Revision history for this message
Albert Astals Cid (aacid) wrote :

Also
 std::vector<unsigned int> cat_order
parameter should be const & as discussed on IRC

review: Needs Fixing
250. By Paweł Stołowski

Act on review commetns.

251. By Paweł Stołowski

Fixed RoleRendererHint index.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:249
http://jenkins.qa.ubuntu.com/job/unity8-ci/1322/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-saucy/4813
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-touch/2661
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/unity-phablet-qmluitests-saucy/2188
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-saucy-amd64-ci/345
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-saucy-armhf-ci/1322
        deb: http://jenkins.qa.ubuntu.com/job/unity8-saucy-armhf-ci/1322/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-saucy-i386-ci/1321
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-saucy/991
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-saucy-amd64/688
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-saucy-amd64/688/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-saucy-armhf/2663
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-saucy-armhf/2663/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-maguro/2204
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-mako/2217

Click here to trigger a rebuild:
http://10.97.0.26:8080/job/unity8-ci/1322/rebuild

review: Needs Fixing (continuous-integration)
252. By Paweł Stołowski

Fixed beginMoveRows.

253. By Paweł Stołowski

Clear category order vector on categories model reset.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:252
http://jenkins.qa.ubuntu.com/job/unity8-ci/1326/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-saucy/4818
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-touch/2669/console
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/unity-phablet-qmluitests-saucy/2192
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-saucy-amd64-ci/349
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-saucy-armhf-ci/1326
        deb: http://jenkins.qa.ubuntu.com/job/unity8-saucy-armhf-ci/1326/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-saucy-i386-ci/1325
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-saucy/996
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-saucy-amd64/693
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-saucy-amd64/693/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-saucy-armhf/2671
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-saucy-armhf/2671/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-maguro/2210
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-mako/2223/console

Click here to trigger a rebuild:
http://10.97.0.26:8080/job/unity8-ci/1326/rebuild

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

FAILED: Continuous integration, rev:253
http://jenkins.qa.ubuntu.com/job/unity8-ci/1328/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-saucy/4821
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-touch/2673/console
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/unity-phablet-qmluitests-saucy/2194
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-saucy-amd64-ci/351
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-saucy-armhf-ci/1328
        deb: http://jenkins.qa.ubuntu.com/job/unity8-saucy-armhf-ci/1328/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-saucy-i386-ci/1327
    SUCCESS: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-saucy/999
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-saucy-amd64/696
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-saucy-amd64/696/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-saucy-armhf/2675
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-saucy-armhf/2675/artifact/work/output/*zip*/output.zip
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-maguro/2215/console
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-runner-mako/2228

Click here to trigger a rebuild:
http://10.97.0.26:8080/job/unity8-ci/1328/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Albert Astals Cid (aacid) wrote :

Looks good now

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugins/Unity/categories.cpp'
2--- plugins/Unity/categories.cpp 2013-10-02 13:02:16 +0000
3+++ plugins/Unity/categories.cpp 2013-10-09 11:01:57 +0000
4@@ -90,9 +90,37 @@
5 delete model;
6 }
7 m_results.clear();
8+ m_categoryOrder.clear();
9+
10 setModel(model);
11 }
12
13+void Categories::onCategoryOrderChanged(const std::vector<unsigned int>& cat_order)
14+{
15+ for (unsigned int pos = 0; pos<cat_order.size(); pos++)
16+ {
17+ unsigned int cat = cat_order[pos];
18+ const int old_pos = m_categoryOrder.indexOf(cat);
19+
20+ if (old_pos < 0) {
21+ qWarning() << "No such category index:" << cat;
22+ continue;
23+ }
24+
25+ if (static_cast<int>(pos) != old_pos) {
26+ int target_pos = pos;
27+ if (target_pos > old_pos)
28+ target_pos++;
29+ const bool status = beginMoveRows(QModelIndex(), old_pos, old_pos, QModelIndex(), target_pos);
30+ if (status)
31+ m_categoryOrder.move(old_pos, pos);
32+ else
33+ qWarning() << "beginMoveRows failed:" << old_pos << target_pos;
34+ endMoveRows();
35+ }
36+ }
37+}
38+
39 void
40 Categories::setUnityScope(const unity::dash::Scope::Ptr& scope)
41 {
42@@ -101,9 +129,9 @@
43 // no need to call this, we'll get notified
44 //setModel(m_unityScope->categories()->model());
45
46- m_categoriesChangedConnection.disconnect();
47- m_categoriesChangedConnection =
48- m_unityScope->categories()->model.changed.connect(sigc::mem_fun(this, &Categories::onCategoriesModelChanged));
49+ m_signals.disconnectAll();
50+ m_signals << m_unityScope->categories()->model.changed.connect(sigc::mem_fun(this, &Categories::onCategoriesModelChanged));
51+ m_signals << m_unityScope->category_order.changed.connect(sigc::mem_fun(this, &Categories::onCategoryOrderChanged));
52 }
53
54 void
55@@ -111,7 +139,9 @@
56 {
57 CategoryResults* results = qobject_cast<CategoryResults*>(sender());
58 if (results) {
59- m_updatedCategories << results->categoryIndex();
60+ if (!m_updatedCategories.contains(results->categoryIndex())) {
61+ m_updatedCategories << results->categoryIndex();
62+ }
63 m_timer.start();
64 }
65 }
66@@ -142,7 +172,8 @@
67 roles.append(Categories::RoleCount);
68 Q_FOREACH(int categoryIndex, m_updatedCategories) {
69 if (!m_results.contains(categoryIndex)) continue;
70- QModelIndex changedIndex = index(categoryIndex);
71+ const int realIndex = m_categoryOrder.indexOf(categoryIndex);
72+ const QModelIndex changedIndex = index(realIndex);
73 Q_EMIT dataChanged(changedIndex, changedIndex, roles);
74 }
75 m_updatedCategories.clear();
76@@ -196,48 +227,70 @@
77 return QVariant();
78 }
79
80+ if (m_categoryOrder.size() != rowCount())
81+ {
82+ // populate category order vector with 0..n
83+ m_categoryOrder.clear();
84+ const unsigned int lim = rowCount();
85+ for (unsigned int i = 0; i<lim; i++) {
86+ m_categoryOrder.append(i);
87+ }
88+ }
89+
90+ int realRow = index.row();
91+ if (index.row() < m_categoryOrder.size()) {
92+ realRow = m_categoryOrder[index.row()];
93+ } else {
94+ qWarning() << "Invalid index" << index.row();
95+ return QVariant();
96+ }
97+
98+ const QModelIndex realIndex = createIndex(realRow, index.column());
99+
100 switch (role) {
101 case RoleCategoryId:
102- return DeeListModel::data(index, CategoryColumn::ID);
103+ return DeeListModel::data(realIndex, CategoryColumn::ID);
104 case RoleName:
105- return DeeListModel::data(index, CategoryColumn::DISPLAY_NAME);
106+ return DeeListModel::data(realIndex, CategoryColumn::DISPLAY_NAME);
107 case RoleIcon:
108- return DeeListModel::data(index, CategoryColumn::ICON_HINT);
109+ return DeeListModel::data(realIndex, CategoryColumn::ICON_HINT);
110 case RoleRenderer:
111- return DeeListModel::data(index, CategoryColumn::RENDERER_NAME);
112+ return DeeListModel::data(realIndex, CategoryColumn::RENDERER_NAME);
113 case RoleContentType:
114 {
115- auto hints = DeeListModel::data(index, CategoryColumn::HINTS).toHash();
116+ auto hints = DeeListModel::data(realIndex, CategoryColumn::HINTS).toHash();
117 return hints.contains("content-type") ? hints["content-type"] : QVariant(QString("default"));
118 }
119 case RoleRendererHint:
120 {
121- auto hints = DeeListModel::data(index, CategoryColumn::HINTS).toHash();
122+ auto hints = DeeListModel::data(realIndex, CategoryColumn::HINTS).toHash();
123 return hints.contains("renderer-hint") ? hints["renderer-hint"] : QVariant(QString());
124 }
125 case RoleProgressSource:
126 {
127- auto hints = DeeListModel::data(index, CategoryColumn::HINTS).toHash();
128+ auto hints = DeeListModel::data(realIndex, CategoryColumn::HINTS).toHash();
129 return hints.contains("progress-source") ? hints["progress-source"] : QVariant();
130 }
131 case RoleHints:
132- return DeeListModel::data(index, CategoryColumn::HINTS);
133+ return DeeListModel::data(realIndex, CategoryColumn::HINTS);
134 case RoleResults:
135 if (m_overriddenCategories.size() > 0)
136 {
137- auto id = DeeListModel::data(index, CategoryColumn::ID).toString();
138+ auto id = DeeListModel::data(realIndex, CategoryColumn::ID).toString();
139 if (m_overriddenCategories.find(id) != m_overriddenCategories.end())
140 return QVariant::fromValue(m_overriddenCategories[id]);
141 }
142- return QVariant::fromValue(getResults(index.row()));
143+ return QVariant::fromValue(getResults(realRow));
144 case RoleCount:
145 if (m_overriddenCategories.size() > 0)
146 {
147- auto id = DeeListModel::data(index, CategoryColumn::ID).toString();
148+ auto id = DeeListModel::data(realIndex, CategoryColumn::ID).toString();
149 if (m_overriddenCategories.find(id) != m_overriddenCategories.end())
150+ {
151 return QVariant::fromValue(m_overriddenCategories[id]->rowCount());
152+ }
153 }
154- return QVariant::fromValue(getResults(index.row())->rowCount());
155+ return QVariant::fromValue(getResults(realRow)->rowCount());
156 default:
157 return QVariant();
158 }
159
160=== modified file 'plugins/Unity/categories.h'
161--- plugins/Unity/categories.h 2013-10-02 13:02:16 +0000
162+++ plugins/Unity/categories.h 2013-10-09 11:01:57 +0000
163@@ -32,6 +32,9 @@
164 #include <QSet>
165 #include <QTimer>
166
167+// local
168+#include "signalslist.h"
169+
170 class Categories : public DeeListModel
171 {
172 Q_OBJECT
173@@ -71,6 +74,7 @@
174
175 private:
176 void onCategoriesModelChanged(unity::glib::Object<DeeModel> model);
177+ void onCategoryOrderChanged(const std::vector<unsigned int>& cat_order);
178
179 DeeListModel* getResults(int index) const;
180
181@@ -80,7 +84,12 @@
182 QHash<int, QByteArray> m_roles;
183 QMap<QString, QAbstractItemModel*> m_overriddenCategories;
184 mutable QMap<int, DeeListModel*> m_results;
185- sigc::connection m_categoriesChangedConnection;
186+ SignalsList m_signals;
187+
188+ /* Category order array contains indices of actual categories in the underlying DeeListModel.
189+ It's used internally to reflect category order reported by scope.
190+ */
191+ mutable QList<unsigned int> m_categoryOrder;
192 };
193
194 #endif // CATEGORIES_H

Subscribers

People subscribed via source and target branches