mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-01-12 15:14:28 +08:00
Merge pull request #8538 from thalieht/searchFilter
Add a name filter for search results
This commit is contained in:
commit
6c9a4df515
@ -890,7 +890,7 @@ void MainWindow::createKeyboardShortcuts()
|
||||
connect(switchRSSShortcut, &QShortcut::activated, this, static_cast<Func>(&MainWindow::displayRSSTab));
|
||||
QShortcut *switchExecutionLogShortcut = new QShortcut(Qt::ALT + Qt::Key_4, this);
|
||||
connect(switchExecutionLogShortcut, &QShortcut::activated, this, &MainWindow::displayExecutionLogTab);
|
||||
QShortcut *switchSearchFilterShortcut = new QShortcut(QKeySequence::Find, this);
|
||||
QShortcut *switchSearchFilterShortcut = new QShortcut(QKeySequence::Find, m_transferListWidget);
|
||||
connect(switchSearchFilterShortcut, &QShortcut::activated, this, &MainWindow::focusSearchFilter);
|
||||
|
||||
m_ui->actionDocumentation->setShortcut(QKeySequence::HelpContents);
|
||||
|
@ -49,9 +49,11 @@
|
||||
#include "base/utils/misc.h"
|
||||
#include "addnewtorrentdialog.h"
|
||||
#include "guiiconprovider.h"
|
||||
#include "lineedit.h"
|
||||
#include "searchlistdelegate.h"
|
||||
#include "searchsortmodel.h"
|
||||
#include "ui_searchjobwidget.h"
|
||||
#include "utils.h"
|
||||
|
||||
SearchJobWidget::SearchJobWidget(SearchHandler *searchHandler, QWidget *parent)
|
||||
: QWidget(parent)
|
||||
@ -126,6 +128,12 @@ SearchJobWidget::SearchJobWidget(SearchHandler *searchHandler, QWidget *parent)
|
||||
|
||||
updateFilter();
|
||||
|
||||
m_lineEditSearchResultsFilter = new LineEdit(this);
|
||||
m_lineEditSearchResultsFilter->setFixedWidth(Utils::Gui::scaledSize(this, 170));
|
||||
m_lineEditSearchResultsFilter->setPlaceholderText(tr("Filter search results..."));
|
||||
m_ui->horizontalLayout->insertWidget(0, m_lineEditSearchResultsFilter);
|
||||
|
||||
connect(m_lineEditSearchResultsFilter, &LineEdit::textChanged, this, &SearchJobWidget::filterSearchResults);
|
||||
connect(m_ui->filterMode, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged)
|
||||
, this, &SearchJobWidget::updateFilter);
|
||||
connect(m_ui->minSeeds, &QAbstractSpinBox::editingFinished, this, &SearchJobWidget::updateFilter);
|
||||
@ -190,6 +198,11 @@ int SearchJobWidget::visibleResultsCount() const
|
||||
return m_proxyModel->rowCount();
|
||||
}
|
||||
|
||||
LineEdit *SearchJobWidget::lineEditSearchResultsFilter() const
|
||||
{
|
||||
return m_lineEditSearchResultsFilter;
|
||||
}
|
||||
|
||||
void SearchJobWidget::cancelSearch()
|
||||
{
|
||||
m_searchHandler->cancelSearch();
|
||||
@ -327,6 +340,12 @@ void SearchJobWidget::fillFilterComboBoxes()
|
||||
m_ui->filterMode->setCurrentIndex((index == -1) ? 0 : index);
|
||||
}
|
||||
|
||||
void SearchJobWidget::filterSearchResults(const QString &name)
|
||||
{
|
||||
m_proxyModel->setFilterRegExp(QRegExp(name, Qt::CaseInsensitive));
|
||||
updateResultsCount();
|
||||
}
|
||||
|
||||
QString SearchJobWidget::statusText(SearchJobWidget::Status st)
|
||||
{
|
||||
switch (st) {
|
||||
|
@ -41,6 +41,7 @@ class QStandardItemModel;
|
||||
|
||||
template <typename T> class CachedSettingValue;
|
||||
|
||||
class LineEdit;
|
||||
class SearchHandler;
|
||||
class SearchListDelegate;
|
||||
class SearchSortModel;
|
||||
@ -78,6 +79,7 @@ public:
|
||||
|
||||
Status status() const;
|
||||
int visibleResultsCount() const;
|
||||
LineEdit *lineEditSearchResultsFilter() const;
|
||||
|
||||
void cancelSearch();
|
||||
|
||||
@ -93,6 +95,7 @@ private:
|
||||
void loadSettings();
|
||||
void saveSettings() const;
|
||||
void updateFilter();
|
||||
void filterSearchResults(const QString &name);
|
||||
void displayToggleColumnsMenu(const QPoint&);
|
||||
void onItemDoubleClicked(const QModelIndex &index);
|
||||
void searchFinished(bool cancelled);
|
||||
@ -115,6 +118,7 @@ private:
|
||||
QStandardItemModel *m_searchListModel;
|
||||
SearchSortModel *m_proxyModel;
|
||||
SearchListDelegate *m_searchDelegate;
|
||||
LineEdit *m_lineEditSearchResultsFilter;
|
||||
Status m_status = Status::Ongoing;
|
||||
bool m_noSearchResults = true;
|
||||
};
|
||||
|
@ -41,6 +41,7 @@
|
||||
#include <QMimeData>
|
||||
#include <QProcess>
|
||||
#include <QRegularExpression>
|
||||
#include <QShortcut>
|
||||
#include <QSignalMapper>
|
||||
#include <QSortFilterProxyModel>
|
||||
#include <QStandardItemModel>
|
||||
@ -154,6 +155,9 @@ SearchWidget::SearchWidget(MainWindow *mainWindow)
|
||||
, this, &SearchWidget::selectMultipleBox);
|
||||
connect(m_ui->selectPlugin, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged)
|
||||
, this, &SearchWidget::fillCatCombobox);
|
||||
|
||||
m_focusSearchHotkey = new QShortcut(QKeySequence::Find, this);
|
||||
connect(m_focusSearchHotkey, &QShortcut::activated, this, &SearchWidget::toggleFocusBetweenLineEdits);
|
||||
}
|
||||
|
||||
void SearchWidget::fillCatCombobox()
|
||||
@ -260,6 +264,18 @@ void SearchWidget::selectMultipleBox(int index)
|
||||
on_pluginsButton_clicked();
|
||||
}
|
||||
|
||||
void SearchWidget::toggleFocusBetweenLineEdits()
|
||||
{
|
||||
if (m_ui->lineEditSearchPattern->hasFocus() && m_currentSearchTab) {
|
||||
m_currentSearchTab->lineEditSearchResultsFilter()->setFocus();
|
||||
m_currentSearchTab->lineEditSearchResultsFilter()->selectAll();
|
||||
}
|
||||
else {
|
||||
m_ui->lineEditSearchPattern->setFocus();
|
||||
m_ui->lineEditSearchPattern->selectAll();
|
||||
}
|
||||
}
|
||||
|
||||
void SearchWidget::on_pluginsButton_clicked()
|
||||
{
|
||||
new PluginSelectDialog(SearchPluginManager::instance(), this);
|
||||
|
@ -33,6 +33,7 @@
|
||||
#include <QPointer>
|
||||
#include <QWidget>
|
||||
|
||||
class QShortcut;
|
||||
class QSignalMapper;
|
||||
class QTabWidget;
|
||||
|
||||
@ -68,6 +69,7 @@ private:
|
||||
void resultsCountUpdated();
|
||||
void tabStatusChanged(QWidget *tab);
|
||||
void selectMultipleBox(int index);
|
||||
void toggleFocusBetweenLineEdits();
|
||||
|
||||
void fillCatCombobox();
|
||||
void fillPluginComboBox();
|
||||
@ -85,4 +87,5 @@ private:
|
||||
QList<SearchJobWidget *> m_allTabs; // To store all tabs
|
||||
MainWindow *m_mainWindow;
|
||||
bool m_isNewQueryString;
|
||||
QShortcut *m_focusSearchHotkey;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user