mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-20 13:23:34 -07:00
Hide empty folders after filtering. Closes #74.
This commit is contained in:
parent
4612a5a882
commit
7780e9ad0a
2 changed files with 25 additions and 2 deletions
|
@ -75,8 +75,8 @@ QModelIndex TorrentContentFilterModel::parent(const QModelIndex& child) const
|
||||||
bool TorrentContentFilterModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
|
bool TorrentContentFilterModel::filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
|
||||||
{
|
{
|
||||||
if (m_model->itemType(m_model->index(source_row, 0, source_parent)) == TorrentContentModelItem::FolderType) {
|
if (m_model->itemType(m_model->index(source_row, 0, source_parent)) == TorrentContentModelItem::FolderType) {
|
||||||
// always accept folders, since we want to filter their children
|
// accept folders if they have at least one filtered item
|
||||||
return true;
|
return hasFiltered(m_model->index(source_row, 0, source_parent));
|
||||||
}
|
}
|
||||||
return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
|
return QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent);
|
||||||
}
|
}
|
||||||
|
@ -114,3 +114,25 @@ void TorrentContentFilterModel::selectNone()
|
||||||
}
|
}
|
||||||
emit dataChanged(index(0,0), index(rowCount(), columnCount()));
|
emit dataChanged(index(0,0), index(rowCount(), columnCount()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool TorrentContentFilterModel::hasFiltered(const QModelIndex& folder) const {
|
||||||
|
// this should be called only with folders
|
||||||
|
// check if the folder name itself matches the filter string
|
||||||
|
QString name = folder.data().toString();
|
||||||
|
if (name.contains(filterRegExp()))
|
||||||
|
return true;
|
||||||
|
for (int child = 0; child < m_model->rowCount(folder); child++) {
|
||||||
|
QModelIndex childIndex = m_model->index(child, 0, folder);
|
||||||
|
if (m_model->hasChildren(childIndex)) {
|
||||||
|
if (hasFiltered(childIndex))
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
name = childIndex.data().toString();
|
||||||
|
if (name.contains(filterRegExp()))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
|
@ -62,6 +62,7 @@ public slots:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TorrentContentModel* m_model;
|
TorrentContentModel* m_model;
|
||||||
|
bool hasFiltered(const QModelIndex& folder) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // TORRENTCONTENTFILTERMODEL_H
|
#endif // TORRENTCONTENTFILTERMODEL_H
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue