diff --git a/src/gui/categoryfiltermodel.cpp b/src/gui/categoryfiltermodel.cpp index 715bdd7af..0968761ae 100644 --- a/src/gui/categoryfiltermodel.cpp +++ b/src/gui/categoryfiltermodel.cpp @@ -195,6 +195,13 @@ CategoryFilterModel::~CategoryFilterModel() delete m_rootItem; } +bool CategoryFilterModel::isSpecialItem(const QModelIndex &index) +{ + // the first two items at first level are special items: + // 'All' and 'Uncategorized' + return (!index.parent().isValid() && (index.row() <= 1)); +} + int CategoryFilterModel::columnCount(const QModelIndex &) const { return 1; diff --git a/src/gui/categoryfiltermodel.h b/src/gui/categoryfiltermodel.h index df92eab57..bf186faae 100644 --- a/src/gui/categoryfiltermodel.h +++ b/src/gui/categoryfiltermodel.h @@ -48,6 +48,8 @@ public: explicit CategoryFilterModel(QObject *parent = nullptr); ~CategoryFilterModel(); + static bool isSpecialItem(const QModelIndex &index); + int columnCount(const QModelIndex &parent = QModelIndex()) const override; QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; Qt::ItemFlags flags(const QModelIndex &index) const override; diff --git a/src/gui/categoryfilterwidget.cpp b/src/gui/categoryfilterwidget.cpp index 0da279b25..bf7952322 100644 --- a/src/gui/categoryfilterwidget.cpp +++ b/src/gui/categoryfilterwidget.cpp @@ -54,13 +54,6 @@ namespace return categoryFilter; } - - bool isSpecialItem(const QModelIndex &index) - { - // the first two items at first level are special items: - // 'All' and 'Uncategorized' - return (!index.parent().isValid() && (index.row() <= 1)); - } } CategoryFilterWidget::CategoryFilterWidget(QWidget *parent) @@ -115,7 +108,7 @@ void CategoryFilterWidget::showMenu(QPoint) connect(addAct, SIGNAL(triggered()), SLOT(addCategory())); auto selectedRows = selectionModel()->selectedRows(); - if (!selectedRows.empty() && !isSpecialItem(selectedRows.first())) { + if (!selectedRows.empty() && !CategoryFilterModel::isSpecialItem(selectedRows.first())) { if (BitTorrent::Session::instance()->isSubcategoriesEnabled()) { QAction *addSubAct = menu.addAction( GuiIconProvider::instance()->getIcon("list-add") @@ -238,7 +231,7 @@ void CategoryFilterWidget::addSubcategory() void CategoryFilterWidget::removeCategory() { auto selectedRows = selectionModel()->selectedRows(); - if (!selectedRows.empty() && !isSpecialItem(selectedRows.first())) { + if (!selectedRows.empty() && !CategoryFilterModel::isSpecialItem(selectedRows.first())) { BitTorrent::Session::instance()->removeCategory( static_cast(model())->categoryName(selectedRows.first())); updateGeometry();