on xenial help sign in
Bugfixes.
commit2c12ffae161ba586a8d7ac5ee9598aec16d19c98 authorPawel Stolowski <pawel.stolowski@canonical.com> dateMon 26 Aug 2013, 17:25 (13 years ago) parent3d1456b
2 files changed+44−6
plugins/Unity/categories.cpp+43−6 plugins/Unity/categories.h+1
plugins/Unity/categories.cpp+43−6
@@ -22,6 +22,9 @@
2222#include "categories.h"
2323#include "categoryresults.h"
2424
25+// Qt
26+#include <QDebug>
27+
2528// TODO: use something from libunity once it's public
2629enum CategoryColumn {
2730 ID,
@@ -79,13 +82,28 @@ void Categories::onCategoriesModelChanged(unity::glib::Object<DeeModel> model)
7982 delete model;
8083 }
8184 m_results.clear();
85+
8286 setModel(model);
8387}
8488
8589void Categories::onCategoryOrderChanged(std::vector<unsigned int> cat_order)
8690{
87− const QList<QPersistentModelIndex> pindex = QList<QPersistentModelIndex>();
88− Q_EMIT layoutChanged(pindex, QAbstractItemModel::VerticalSortHint);
91+ for (unsigned int pos = 0; pos<cat_order.size(); pos++)
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+ }
89107}
90108
91109void
@@ -120,9 +138,10 @@ void Categories::onRowCountChanged()
120138 for (int i = 0; i < rowCount(); i++) {
121139 auto id = data(index(i), RoleCategoryId).toString();
122140 if (id != iter.key()) continue;
141+ const int realIndex = m_categoryOrder.indexOf(i);
123142 QVector<int> roles;
124143 roles.append(RoleCount);
125− QModelIndex changedIndex = index(i);
144+ QModelIndex changedIndex = index(realIndex);
126145 Q_EMIT dataChanged(changedIndex, changedIndex, roles);
127146 break;
128147 }
@@ -137,7 +156,8 @@ Categories::onEmitCountChanged()
137156 roles.append(Categories::RoleCount);
138157 Q_FOREACH(int categoryIndex, m_updatedCategories) {
139158 if (!m_results.contains(categoryIndex)) continue;
140− QModelIndex changedIndex = index(categoryIndex);
159+ const int realIndex = m_categoryOrder.indexOf(categoryIndex);
160+ const QModelIndex changedIndex = index(realIndex);
141161 Q_EMIT dataChanged(changedIndex, changedIndex, roles);
142162 }
143163 m_updatedCategories.clear();
@@ -191,7 +211,24 @@ Categories::data(const QModelIndex& index, int role) const
191211 return QVariant();
192212 }
193213
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+
195232 const QModelIndex realIndex = createIndex(realRow, index.column());
196233
197234 switch (role) {
@@ -222,7 +259,7 @@ Categories::data(const QModelIndex& index, int role) const
222259 if (m_overriddenCategories.find(id) != m_overriddenCategories.end())
223260 return QVariant::fromValue(m_overriddenCategories[id]);
224261 }
225− return QVariant::fromValue(getResults(realIndex.row()));
262+ return QVariant::fromValue(getResults(realRow));
226263 case RoleCount:
227264 if (m_overriddenCategories.size() > 0)
228265 {
plugins/Unity/categories.h+1
@@ -85,6 +85,7 @@ private:
8585 QMap<QString, QAbstractItemModel*> m_overriddenCategories;
8686 mutable QMap<int, DeeListModel*> m_results;
8787 SignalsList m_signals;
88+ mutable QList<unsigned int> m_categoryOrder;
8889};
8990
9091#endif // CATEGORIES_H