mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-18 14:38:04 -06:00
Merge label filter into TransferListSortModel
This also fixes a bug that when label filter contains special symbols from regex, the label filter may match torrents with multiple different labels.
This commit is contained in:
@@ -45,6 +45,22 @@ void TransferListSortModel::setStatusFilter(const TorrentFilter::TorrentFilter &
|
||||
}
|
||||
}
|
||||
|
||||
void TransferListSortModel::setLabelFilter(QString const& label) {
|
||||
if (!labelFilterEnabled || labelFilter != label) {
|
||||
labelFilterEnabled = true;
|
||||
labelFilter = label;
|
||||
invalidateFilter();
|
||||
}
|
||||
}
|
||||
|
||||
void TransferListSortModel::disableLabelFilter() {
|
||||
if (labelFilterEnabled) {
|
||||
labelFilterEnabled = false;
|
||||
labelFilter = QString();
|
||||
invalidateFilter();
|
||||
}
|
||||
}
|
||||
|
||||
bool TransferListSortModel::lessThan(const QModelIndex &left, const QModelIndex &right) const {
|
||||
const int column = sortColumn();
|
||||
|
||||
@@ -180,6 +196,7 @@ bool TransferListSortModel::lessThan(const QModelIndex &left, const QModelIndex
|
||||
|
||||
bool TransferListSortModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const {
|
||||
return matchStatusFilter(sourceRow, sourceParent)
|
||||
&& matchLabelFilter(sourceRow, sourceParent)
|
||||
&& QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent);
|
||||
}
|
||||
|
||||
@@ -225,3 +242,14 @@ bool TransferListSortModel::matchStatusFilter(int sourceRow, const QModelIndex &
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool TransferListSortModel::matchLabelFilter(int sourceRow, const QModelIndex &sourceParent) const {
|
||||
if (!labelFilterEnabled)
|
||||
return true;
|
||||
|
||||
QAbstractItemModel *model = sourceModel();
|
||||
if (!model)
|
||||
return false;
|
||||
|
||||
return model->index(sourceRow, TorrentModelItem::TR_LABEL, sourceParent).data().toString() == labelFilter;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user