@@ -82,6 +82,12 @@ void Categories::onCategoriesModelChanged(unity::glib::Object<DeeModel> model)
8282 setModel(model);
8383}
8484
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+
8591void
8692Categories::setUnityScope(const unity::dash::Scope::Ptr& scope)
8793{
@@ -90,9 +96,9 @@ Categories::setUnityScope(const unity::dash::Scope::Ptr& scope)
9096 // no need to call this, we'll get notified
9197 //setModel(m_unityScope->categories()->model());
9298
93− m_categoriesChangedConnection.disconnect();
94− m_categoriesChangedConnection =
95− m_unityScope->categories()->model.changed.connect(sigc::mem_fun(this, &Categories::onCategoriesModelChanged));
99+ m_signals.disconnectAll();
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));
96102}
97103
98104void
@@ -185,45 +191,48 @@ Categories::data(const QModelIndex& index, int role) const
185191 return QVariant();
186192 }
187193
194+ auto realRow = m_unityScope->category_order()[index.row()];
195+ const QModelIndex realIndex = createIndex(realRow, index.column());
196+
188197 switch (role) {
189198 case RoleCategoryId:
190− return DeeListModel::data(index, CategoryColumn::ID);
199+ return DeeListModel::data(realIndex, CategoryColumn::ID);
191200 case RoleName:
192− return DeeListModel::data(index, CategoryColumn::DISPLAY_NAME);
201+ return DeeListModel::data(realIndex, CategoryColumn::DISPLAY_NAME);
193202 case RoleIcon:
194− return DeeListModel::data(index, CategoryColumn::ICON_HINT);
203+ return DeeListModel::data(realIndex, CategoryColumn::ICON_HINT);
195204 case RoleRenderer:
196− return DeeListModel::data(index, CategoryColumn::RENDERER_NAME);
205+ return DeeListModel::data(realIndex, CategoryColumn::RENDERER_NAME);
197206 case RoleContentType:
198207 {
199− auto hints = DeeListModel::data(index, CategoryColumn::HINTS).toHash();
208+ auto hints = DeeListModel::data(realIndex, CategoryColumn::HINTS).toHash();
200209 return hints.contains("content-type") ? hints["content-type"] : QVariant(QString("default"));
201210 }
202211 case RoleProgressSource:
203212 {
204− auto hints = DeeListModel::data(index, CategoryColumn::HINTS).toHash();
213+ auto hints = DeeListModel::data(realIndex, CategoryColumn::HINTS).toHash();
205214 return hints.contains("progress-source") ? hints["progress-source"] : QVariant();
206215 }
207216 case RoleHints:
208− return DeeListModel::data(index, CategoryColumn::HINTS);
217+ return DeeListModel::data(realIndex, CategoryColumn::HINTS);
209218 case RoleResults:
210219 if (m_overriddenCategories.size() > 0)
211220 {
212− auto id = DeeListModel::data(index, CategoryColumn::ID).toString();
221+ auto id = DeeListModel::data(realIndex, CategoryColumn::ID).toString();
213222 if (m_overriddenCategories.find(id) != m_overriddenCategories.end())
214223 return QVariant::fromValue(m_overriddenCategories[id]);
215224 }
216− return QVariant::fromValue(getResults(index.row()));
225+ return QVariant::fromValue(getResults(realIndex.row()));
217226 case RoleCount:
218227 if (m_overriddenCategories.size() > 0)
219228 {
220− auto id = DeeListModel::data(index, CategoryColumn::ID).toString();
229+ auto id = DeeListModel::data(realIndex, CategoryColumn::ID).toString();
221230 if (m_overriddenCategories.find(id) != m_overriddenCategories.end())
222231 return QVariant::fromValue(m_overriddenCategories[id]->rowCount());
223232 }
224− return QVariant::fromValue(getResults(index.row())->rowCount());
233+ return QVariant::fromValue(getResults(realIndex.row())->rowCount());
225234 case RoleCategoryIndex:
226− return QVariant::fromValue(index.row());
235+ return QVariant::fromValue(index.row()); // no remapping to realIndex
227236 default:
228237 return QVariant();
229238 }