Commit 43770644 authored by David Edmundson's avatar David Edmundson
Browse files

[sidebar] Make SubcategoryModel dynamic

The current code was made of a model that copied data when a new parent
was selected. This is more work, but more importantly not dynamic to any
changes in the source model.

KSelectionProxyModel can do all of this for us.
parent 8e14096d
......@@ -79,9 +79,13 @@ void FocusHackWidget::focusPrevious()
SubcategoryModel::SubcategoryModel(QAbstractItemModel *parentModel, QObject *parent)
: QStandardItemModel(parent),
: KSelectionProxyModel(nullptr, parent),
setSelectionModel(new QItemSelectionModel(parentModel, this));
QString SubcategoryModel::title() const
......@@ -90,23 +94,7 @@ QString SubcategoryModel::title() const
void SubcategoryModel::setParentIndex(const QModelIndex &activeModule)
//make the view receive a single signal when the new subcategory is loaded,
//never make the view believe there are zero items if this is not the final count
//this avoids the brief flash it had
const int subRows = activeModule.isValid() ? m_parentModel->rowCount(activeModule) : 0;
if ( subRows > 1) {
for (int i = 0; i < subRows; ++i) {
const QModelIndex& index = m_parentModel->index(i, 0, activeModule);
QStandardItem *item = new QStandardItem(m_parentModel->data(index, Qt::DecorationRole).value<QIcon>(), m_parentModel->data(index, Qt::DisplayRole).toString());
item->setData(, Qt::UserRole);
selectionModel()->select(activeModule, QItemSelectionModel::ClearAndSelect);
m_title =;
emit titleChanged();
......@@ -22,7 +22,7 @@
#include "BaseMode.h"
#include <QWidget>
#include <QStandardItemModel>
#include <KSelectionProxyModel>
class ModuleView;
class KAboutData;
......@@ -42,7 +42,7 @@ public Q_SLOTS:
void focusPrevious();
class SubcategoryModel : public QStandardItemModel
class SubcategoryModel : public KSelectionProxyModel
Q_PROPERTY(QString title READ title NOTIFY titleChanged)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment