Browse Source

Turn isSpecialItem() into a CategoryFilterModel static method.

adaptive-webui-19844
Frédéric Brière 8 years ago
parent
commit
722c928ab5
  1. 7
      src/gui/categoryfiltermodel.cpp
  2. 2
      src/gui/categoryfiltermodel.h
  3. 11
      src/gui/categoryfilterwidget.cpp

7
src/gui/categoryfiltermodel.cpp

@ -195,6 +195,13 @@ CategoryFilterModel::~CategoryFilterModel() @@ -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;

2
src/gui/categoryfiltermodel.h

@ -48,6 +48,8 @@ public: @@ -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;

11
src/gui/categoryfilterwidget.cpp

@ -54,13 +54,6 @@ namespace @@ -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) @@ -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() @@ -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();

Loading…
Cancel
Save