@@ -22,6 +22,9 @@
22#include "categories.h"
22#include "categories.h"
23#include "categoryresults.h"
23#include "categoryresults.h"
25// TODO: use something from libunity once it's public
28// TODO: use something from libunity once it's public
26enum CategoryColumn {
29enum CategoryColumn {
@@ -79,13 +82,28 @@ void Categories::onCategoriesModelChanged(unity::glib::Object<DeeModel> model)
79 delete model;
82 delete model;
81 m_results.clear();
84 m_results.clear();
82 setModel(model);
86 setModel(model);
85void Categories::onCategoryOrderChanged(std::vector<unsigned int> cat_order)
89void Categories::onCategoryOrderChanged(std::vector<unsigned int> cat_order)
87− const QList<QPersistentModelIndex> pindex = QList<QPersistentModelIndex>();
91+ for (unsigned int pos = 0; pos<cat_order.size(); pos++)
88− Q_EMIT layoutChanged(pindex, QAbstractItemModel::VerticalSortHint);
92+ {
93+ unsigned int cat = cat_order[pos];
94+ const int old_pos = m_categoryOrder.indexOf(cat);
97+ qWarning() << "No such category index:" << cat;
101+ if (static_cast<int>(pos) != old_pos) {
102+ beginMoveRows(QModelIndex(), old_pos, old_pos, QModelIndex(), pos);
103+ m_categoryOrder.move(old_pos, pos);
@@ -120,9 +138,10 @@ void Categories::onRowCountChanged()
120 for (int i = 0; i < rowCount(); i++) {
138 for (int i = 0; i < rowCount(); i++) {
121 auto id = data(index(i), RoleCategoryId).toString();
139 auto id = data(index(i), RoleCategoryId).toString();
122 if (id != iter.key()) continue;
140 if (id != iter.key()) continue;
141+ const int realIndex = m_categoryOrder.indexOf(i);
123 QVector<int> roles;
142 QVector<int> roles;
124 roles.append(RoleCount);
143 roles.append(RoleCount);
125− QModelIndex changedIndex = index(i);
144+ QModelIndex changedIndex = index(realIndex);
126 Q_EMIT dataChanged(changedIndex, changedIndex, roles);
145 Q_EMIT dataChanged(changedIndex, changedIndex, roles);
@@ -137,7 +156,8 @@ Categories::onEmitCountChanged()
137 roles.append(Categories::RoleCount);
156 roles.append(Categories::RoleCount);
138 Q_FOREACH(int categoryIndex, m_updatedCategories) {
157 Q_FOREACH(int categoryIndex, m_updatedCategories) {
139 if (!m_results.contains(categoryIndex)) continue;
158 if (!m_results.contains(categoryIndex)) continue;
159+ const int realIndex = m_categoryOrder.indexOf(categoryIndex);
140− QModelIndex changedIndex = index(categoryIndex);
160+ const QModelIndex changedIndex = index(realIndex);
141 Q_EMIT dataChanged(changedIndex, changedIndex, roles);
161 Q_EMIT dataChanged(changedIndex, changedIndex, roles);
143 m_updatedCategories.clear();
163 m_updatedCategories.clear();
@@ -191,7 +211,24 @@ Categories::data(const QModelIndex& index, int role) const
191 return QVariant();
211 return QVariant();
194− auto realRow = m_unityScope->category_order()[index.row()];
214+ if (m_categoryOrder.size() != rowCount())
216+ // populate category order vector with 0..n
217+ m_categoryOrder.clear();
218+ const unsigned int lim = rowCount();
219+ for (unsigned int i = 0; i<lim; i++) {
220+ m_categoryOrder.append(i);
224+ int realRow = index.row();
225+ if (index.row() < m_categoryOrder.size()) {
226+ realRow = m_categoryOrder[index.row()];
228+ qWarning() << "Invalid index" << index.row();
195 const QModelIndex realIndex = createIndex(realRow, index.column());
232 const QModelIndex realIndex = createIndex(realRow, index.column());
197 switch (role) {
234 switch (role) {
@@ -222,7 +259,7 @@ Categories::data(const QModelIndex& index, int role) const
222 if (m_overriddenCategories.find(id) != m_overriddenCategories.end())
259 if (m_overriddenCategories.find(id) != m_overriddenCategories.end())
223 return QVariant::fromValue(m_overriddenCategories[id]);
260 return QVariant::fromValue(m_overriddenCategories[id]);
225− return QVariant::fromValue(getResults(realIndex.row()));
262+ return QVariant::fromValue(getResults(realRow));
226 case RoleCount:
263 case RoleCount:
227 if (m_overriddenCategories.size() > 0)
264 if (m_overriddenCategories.size() > 0)