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 Vladimir Golovnev (Glassez)
commit 2aa7a7f453
No known key found for this signature in database
GPG key ID: 52A2C7DEE2DFA6F7
4 changed files with 8 additions and 5 deletions

View file

@ -60,7 +60,9 @@ public:
StalledDownloading, StalledDownloading,
Checking, Checking,
Moving, Moving,
Errored Errored,
_Count
}; };
// These mean any permutation, including no category / tag. // 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); connect(pref, &Preferences::changed, this, &StatusFilterWidget::configure);
const int storedRow = pref->getTransSelFilter(); 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); setCurrentRow(TorrentFilter::All, QItemSelectionModel::SelectCurrent);
else else
setCurrentRow(storedRow, QItemSelectionModel::SelectCurrent); setCurrentRow(storedRow, QItemSelectionModel::SelectCurrent);

View file

@ -1330,9 +1330,10 @@ void TransferListWidget::applyFilter(const QString &name, const TransferListMode
m_sortFilterModel->setFilterRegularExpression(QRegularExpression(pattern, QRegularExpression::CaseInsensitiveOption)); 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 // Select first item if nothing is selected
if (selectionModel()->selectedRows(0).empty() && (m_sortFilterModel->rowCount() > 0)) if (selectionModel()->selectedRows(0).empty() && (m_sortFilterModel->rowCount() > 0))
{ {

View file

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