Turn isSpecialItem() into a CategoryFilterModel static method.

This commit is contained in:
Frédéric Brière 2017-05-03 12:21:29 -04:00
parent f53a403a7b
commit 722c928ab5
3 changed files with 11 additions and 9 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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<CategoryFilterModel *>(model())->categoryName(selectedRows.first()));
updateGeometry();