on xenial help sign in
Handle category order change.
e14c736Pawel Stolowski
plugins/Unity/categories.cpp+24−15
@@ -82,6 +82,12 @@ void Categories::onCategoriesModelChanged(unity::glib::Object<DeeModel> model)
82 setModel(model);
82 setModel(model);
83}
83}
84
84
85+void Categories::onCategoryOrderChanged(std::vector<unsigned int> cat_order)
86+{
87+ const QList<QPersistentModelIndex> pindex = QList<QPersistentModelIndex>();
88+ Q_EMIT layoutChanged(pindex, QAbstractItemModel::VerticalSortHint);
89+}
90+
85void
91void
86Categories::setUnityScope(const unity::dash::Scope::Ptr& scope)
92Categories::setUnityScope(const unity::dash::Scope::Ptr& scope)
87{
93{
@@ -90,9 +96,9 @@ Categories::setUnityScope(const unity::dash::Scope::Ptr& scope)
90 // no need to call this, we'll get notified
96 // no need to call this, we'll get notified
91 //setModel(m_unityScope->categories()->model());
97 //setModel(m_unityScope->categories()->model());
92
98
93− m_categoriesChangedConnection.disconnect();
99+ m_signals.disconnectAll();
94− m_categoriesChangedConnection =
95− m_unityScope->categories()->model.changed.connect(sigc::mem_fun(this, &Categories::onCategoriesModelChanged));
100+ m_signals << m_unityScope->categories()->model.changed.connect(sigc::mem_fun(this, &Categories::onCategoriesModelChanged));
101+ m_signals << m_unityScope->category_order.changed.connect(sigc::mem_fun(this, &Categories::onCategoryOrderChanged));
96}
102}
97
103
98void
104void
@@ -185,45 +191,48 @@ Categories::data(const QModelIndex& index, int role) const
185 return QVariant();
191 return QVariant();
186 }
192 }
187
193
194+ auto realRow = m_unityScope->category_order()[index.row()];
195+ const QModelIndex realIndex = createIndex(realRow, index.column());
196+
188 switch (role) {
197 switch (role) {
189 case RoleCategoryId:
198 case RoleCategoryId:
190− return DeeListModel::data(index, CategoryColumn::ID);
199+ return DeeListModel::data(realIndex, CategoryColumn::ID);
191 case RoleName:
200 case RoleName:
192− return DeeListModel::data(index, CategoryColumn::DISPLAY_NAME);
201+ return DeeListModel::data(realIndex, CategoryColumn::DISPLAY_NAME);
193 case RoleIcon:
202 case RoleIcon:
194− return DeeListModel::data(index, CategoryColumn::ICON_HINT);
203+ return DeeListModel::data(realIndex, CategoryColumn::ICON_HINT);
195 case RoleRenderer:
204 case RoleRenderer:
196− return DeeListModel::data(index, CategoryColumn::RENDERER_NAME);
205+ return DeeListModel::data(realIndex, CategoryColumn::RENDERER_NAME);
197 case RoleContentType:
206 case RoleContentType:
198 {
207 {
199− auto hints = DeeListModel::data(index, CategoryColumn::HINTS).toHash();
208+ auto hints = DeeListModel::data(realIndex, CategoryColumn::HINTS).toHash();
200 return hints.contains("content-type") ? hints["content-type"] : QVariant(QString("default"));
209 return hints.contains("content-type") ? hints["content-type"] : QVariant(QString("default"));
201 }
210 }
202 case RoleProgressSource:
211 case RoleProgressSource:
203 {
212 {
204− auto hints = DeeListModel::data(index, CategoryColumn::HINTS).toHash();
213+ auto hints = DeeListModel::data(realIndex, CategoryColumn::HINTS).toHash();
205 return hints.contains("progress-source") ? hints["progress-source"] : QVariant();
214 return hints.contains("progress-source") ? hints["progress-source"] : QVariant();
206 }
215 }
207 case RoleHints:
216 case RoleHints:
208− return DeeListModel::data(index, CategoryColumn::HINTS);
217+ return DeeListModel::data(realIndex, CategoryColumn::HINTS);
209 case RoleResults:
218 case RoleResults:
210 if (m_overriddenCategories.size() > 0)
219 if (m_overriddenCategories.size() > 0)
211 {
220 {
212− auto id = DeeListModel::data(index, CategoryColumn::ID).toString();
221+ auto id = DeeListModel::data(realIndex, CategoryColumn::ID).toString();
213 if (m_overriddenCategories.find(id) != m_overriddenCategories.end())
222 if (m_overriddenCategories.find(id) != m_overriddenCategories.end())
214 return QVariant::fromValue(m_overriddenCategories[id]);
223 return QVariant::fromValue(m_overriddenCategories[id]);
215 }
224 }
216− return QVariant::fromValue(getResults(index.row()));
225+ return QVariant::fromValue(getResults(realIndex.row()));
217 case RoleCount:
226 case RoleCount:
218 if (m_overriddenCategories.size() > 0)
227 if (m_overriddenCategories.size() > 0)
219 {
228 {
220− auto id = DeeListModel::data(index, CategoryColumn::ID).toString();
229+ auto id = DeeListModel::data(realIndex, CategoryColumn::ID).toString();
221 if (m_overriddenCategories.find(id) != m_overriddenCategories.end())
230 if (m_overriddenCategories.find(id) != m_overriddenCategories.end())
222 return QVariant::fromValue(m_overriddenCategories[id]->rowCount());
231 return QVariant::fromValue(m_overriddenCategories[id]->rowCount());
223 }
232 }
224− return QVariant::fromValue(getResults(index.row())->rowCount());
233+ return QVariant::fromValue(getResults(realIndex.row())->rowCount());
225 case RoleCategoryIndex:
234 case RoleCategoryIndex:
226− return QVariant::fromValue(index.row());
235+ return QVariant::fromValue(index.row()); // no remapping to realIndex
227 default:
236 default:
228 return QVariant();
237 return QVariant();
229 }
238 }
plugins/Unity/categories.h+5−1
@@ -32,6 +32,9 @@
32#include <QSet>
32#include <QSet>
33#include <QTimer>
33#include <QTimer>
34
34
35+// local
36+#include "signalslist.h"
37+
35class Categories : public DeeListModel
38class Categories : public DeeListModel
36{
39{
37 Q_OBJECT
40 Q_OBJECT
@@ -71,6 +74,7 @@ private Q_SLOTS:
71
74
72private:
75private:
73 void onCategoriesModelChanged(unity::glib::Object<DeeModel> model);
76 void onCategoriesModelChanged(unity::glib::Object<DeeModel> model);
77+ void onCategoryOrderChanged(std::vector<unsigned int> cat_order);
74
78
75 DeeListModel* getResults(int index) const;
79 DeeListModel* getResults(int index) const;
76
80
@@ -80,7 +84,7 @@ private:
80 QHash<int, QByteArray> m_roles;
84 QHash<int, QByteArray> m_roles;
81 QMap<QString, QAbstractItemModel*> m_overriddenCategories;
85 QMap<QString, QAbstractItemModel*> m_overriddenCategories;
82 mutable QMap<int, DeeListModel*> m_results;
86 mutable QMap<int, DeeListModel*> m_results;
83− sigc::connection m_categoriesChangedConnection;
87+ SignalsList m_signals;
84};
88};
85
89
86#endif // CATEGORIES_H
90#endif // CATEGORIES_H