Browse Source

Merge pull request #8538 from thalieht/searchFilter

Add a name filter for search results
adaptive-webui-19844
sledgehammer999 6 years ago committed by GitHub
parent
commit
6c9a4df515
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/gui/mainwindow.cpp
  2. 19
      src/gui/search/searchjobwidget.cpp
  3. 4
      src/gui/search/searchjobwidget.h
  4. 16
      src/gui/search/searchwidget.cpp
  5. 3
      src/gui/search/searchwidget.h

2
src/gui/mainwindow.cpp

@ -890,7 +890,7 @@ void MainWindow::createKeyboardShortcuts() @@ -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);

19
src/gui/search/searchjobwidget.cpp

@ -49,9 +49,11 @@ @@ -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) @@ -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 @@ -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() @@ -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) {

4
src/gui/search/searchjobwidget.h

@ -41,6 +41,7 @@ class QStandardItemModel; @@ -41,6 +41,7 @@ class QStandardItemModel;
template <typename T> class CachedSettingValue;
class LineEdit;
class SearchHandler;
class SearchListDelegate;
class SearchSortModel;
@ -78,6 +79,7 @@ public: @@ -78,6 +79,7 @@ public:
Status status() const;
int visibleResultsCount() const;
LineEdit *lineEditSearchResultsFilter() const;
void cancelSearch();
@ -93,6 +95,7 @@ private: @@ -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: @@ -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;
};

16
src/gui/search/searchwidget.cpp

@ -41,6 +41,7 @@ @@ -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) @@ -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) @@ -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);

3
src/gui/search/searchwidget.h

@ -33,6 +33,7 @@ @@ -33,6 +33,7 @@
#include <QPointer>
#include <QWidget>
class QShortcut;
class QSignalMapper;
class QTabWidget;
@ -68,6 +69,7 @@ private: @@ -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: @@ -85,4 +87,5 @@ private:
QList<SearchJobWidget *> m_allTabs; // To store all tabs
MainWindow *m_mainWindow;
bool m_isNewQueryString;
QShortcut *m_focusSearchHotkey;
};

Loading…
Cancel
Save