on xenial help sign in
Bugfixes.
2c12ffaPawel Stolowski
plugins/Unity/categories.cpp+43−6
@@ -22,6 +22,9 @@
22#include "categories.h"
22#include "categories.h"
23#include "categoryresults.h"
23#include "categoryresults.h"
24
24
25+// Qt
26+#include <QDebug>
27+
25// TODO: use something from libunity once it's public
28// TODO: use something from libunity once it's public
26enum CategoryColumn {
29enum CategoryColumn {
27 ID,
30 ID,
@@ -79,13 +82,28 @@ void Categories::onCategoriesModelChanged(unity::glib::Object<DeeModel> model)
79 delete model;
82 delete model;
80 }
83 }
81 m_results.clear();
84 m_results.clear();
85+
82 setModel(model);
86 setModel(model);
83}
87}
84
88
85void Categories::onCategoryOrderChanged(std::vector<unsigned int> cat_order)
89void Categories::onCategoryOrderChanged(std::vector<unsigned int> cat_order)
86{
90{
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);
95+
96+ if (old_pos < 0) {
97+ qWarning() << "No such category index:" << cat;
98+ continue;
99+ }
100+
101+ if (static_cast<int>(pos) != old_pos) {
102+ beginMoveRows(QModelIndex(), old_pos, old_pos, QModelIndex(), pos);
103+ m_categoryOrder.move(old_pos, pos);
104+ endMoveRows();
105+ }
106+ }
89}
107}
90
108
91void
109void
@@ -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);
127 break;
146 break;
128 }
147 }
@@ -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);
142 }
162 }
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();
192 }
212 }
193
213
194− auto realRow = m_unityScope->category_order()[index.row()];
214+ if (m_categoryOrder.size() != rowCount())
215+ {
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);
221+ }
222+ }
223+
224+ int realRow = index.row();
225+ if (index.row() < m_categoryOrder.size()) {
226+ realRow = m_categoryOrder[index.row()];
227+ } else {
228+ qWarning() << "Invalid index" << index.row();
229+ return QVariant();
230+ }
231+
195 const QModelIndex realIndex = createIndex(realRow, index.column());
232 const QModelIndex realIndex = createIndex(realRow, index.column());
196
233
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]);
224 }
261 }
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)
228 {
265 {
plugins/Unity/categories.h+1
@@ -85,6 +85,7 @@ private:
85 QMap<QString, QAbstractItemModel*> m_overriddenCategories;
85 QMap<QString, QAbstractItemModel*> m_overriddenCategories;
86 mutable QMap<int, DeeListModel*> m_results;
86 mutable QMap<int, DeeListModel*> m_results;
87 SignalsList m_signals;
87 SignalsList m_signals;
88+ mutable QList<unsigned int> m_categoryOrder;
88};
89};
89
90
90#endif // CATEGORIES_H
91#endif // CATEGORIES_H