Prevent invalid status filter index from being used

PR #20714.
Closes #20701.
This commit is contained in:
Vladimir Golovnev 2024-04-18 07:59:24 +03:00 committed by GitHub
parent d7cded54e4
commit ace5286402
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 8 additions and 5 deletions

View file

@ -61,7 +61,9 @@ public:
StalledDownloading,
Checking,
Moving,
Errored
Errored,
_Count
};
// These mean any permutation, including no category / tag.

View file

@ -95,7 +95,7 @@ StatusFilterWidget::StatusFilterWidget(QWidget *parent, TransferListWidget *tran
connect(pref, &Preferences::changed, this, &StatusFilterWidget::configure);
const int storedRow = pref->getTransSelFilter();
if (item((storedRow < count()) ? storedRow : 0)->isHidden())
if (item(((storedRow >= 0) && (storedRow < count())) ? storedRow : 0)->isHidden())
setCurrentRow(TorrentFilter::All, QItemSelectionModel::SelectCurrent);
else
setCurrentRow(storedRow, QItemSelectionModel::SelectCurrent);

View file

@ -1353,9 +1353,10 @@ void TransferListWidget::applyFilter(const QString &name, const TransferListMode
m_sortFilterModel->setFilterRegularExpression(QRegularExpression(pattern, QRegularExpression::CaseInsensitiveOption));
}
void TransferListWidget::applyStatusFilter(int f)
void TransferListWidget::applyStatusFilter(const int filterIndex)
{
m_sortFilterModel->setStatusFilter(static_cast<TorrentFilter::Type>(f));
const auto filterType = static_cast<TorrentFilter::Type>(filterIndex);
m_sortFilterModel->setStatusFilter(((filterType >= TorrentFilter::All) && (filterType < TorrentFilter::_Count)) ? filterType : TorrentFilter::All);
// Select first item if nothing is selected
if (selectionModel()->selectedRows(0).empty() && (m_sortFilterModel->rowCount() > 0))
{

View file

@ -95,7 +95,7 @@ public slots:
void previewSelectedTorrents();
void hideQueuePosColumn(bool hide);
void applyFilter(const QString &name, const TransferListModel::Column &type);
void applyStatusFilter(int f);
void applyStatusFilter(int filterIndex);
void applyCategoryFilter(const QString &category);
void applyTagFilter(const std::optional<Tag> &tag);
void applyTrackerFilterAll();