From 4dcb0b922ed1841d1c83b7935c9d935a154fdfc9 Mon Sep 17 00:00:00 2001 From: thalieht Date: Sun, 12 Aug 2018 17:40:17 +0300 Subject: [PATCH 1/2] Add regex option in the search filter's context menu In the search job widget. --- src/base/preferences.cpp | 10 ++++++++++ src/base/preferences.h | 2 ++ src/gui/search/searchjobwidget.cpp | 23 ++++++++++++++++++++++- src/gui/search/searchjobwidget.h | 1 + 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/src/base/preferences.cpp b/src/base/preferences.cpp index 61c6a3d32..39fd386ee 100644 --- a/src/base/preferences.cpp +++ b/src/base/preferences.cpp @@ -1429,6 +1429,16 @@ void Preferences::setSearchTabHeaderState(const QByteArray &state) setValue("SearchTab/qt5/HeaderState", state); } +bool Preferences::getRegexAsFilteringPatternForSearchJob() const +{ + return value("SearchTab/UseRegexAsFilteringPattern", false).toBool(); +} + +void Preferences::setRegexAsFilteringPatternForSearchJob(const bool checked) +{ + setValue("SearchTab/UseRegexAsFilteringPattern", checked); +} + QStringList Preferences::getSearchEngDisabled() const { return value("SearchEngines/disabledEngines").toStringList(); diff --git a/src/base/preferences.h b/src/base/preferences.h index 969c38553..b49765fc7 100644 --- a/src/base/preferences.h +++ b/src/base/preferences.h @@ -342,6 +342,8 @@ public: void setRssMainSplitterState(const QByteArray &state); QByteArray getSearchTabHeaderState() const; void setSearchTabHeaderState(const QByteArray &state); + bool getRegexAsFilteringPatternForSearchJob() const; + void setRegexAsFilteringPatternForSearchJob(bool checked); QStringList getSearchEngDisabled() const; void setSearchEngDisabled(const QStringList &engines); QString getTorImportLastContentDir() const; diff --git a/src/gui/search/searchjobwidget.cpp b/src/gui/search/searchjobwidget.cpp index 8be2a611d..3974685cc 100644 --- a/src/gui/search/searchjobwidget.cpp +++ b/src/gui/search/searchjobwidget.cpp @@ -131,6 +131,8 @@ SearchJobWidget::SearchJobWidget(SearchHandler *searchHandler, QWidget *parent) m_lineEditSearchResultsFilter = new LineEdit(this); m_lineEditSearchResultsFilter->setFixedWidth(Utils::Gui::scaledSize(this, 170)); m_lineEditSearchResultsFilter->setPlaceholderText(tr("Filter search results...")); + m_lineEditSearchResultsFilter->setContextMenuPolicy(Qt::CustomContextMenu); + connect(m_lineEditSearchResultsFilter, &QWidget::customContextMenuRequested, this, &SearchJobWidget::showFilterContextMenu); m_ui->horizontalLayout->insertWidget(0, m_lineEditSearchResultsFilter); connect(m_lineEditSearchResultsFilter, &LineEdit::textChanged, this, &SearchJobWidget::filterSearchResults); @@ -342,10 +344,29 @@ void SearchJobWidget::fillFilterComboBoxes() void SearchJobWidget::filterSearchResults(const QString &name) { - m_proxyModel->setFilterRegExp(QRegExp(name, Qt::CaseInsensitive)); + const QRegExp::PatternSyntax patternSyntax = Preferences::instance()->getRegexAsFilteringPatternForSearchJob() + ? QRegExp::RegExp : QRegExp::WildcardUnix; + m_proxyModel->setFilterRegExp(QRegExp(name, Qt::CaseInsensitive, patternSyntax)); updateResultsCount(); } +void SearchJobWidget::showFilterContextMenu(const QPoint &) +{ + const Preferences *pref = Preferences::instance(); + + QMenu *menu = m_lineEditSearchResultsFilter->createStandardContextMenu(); + menu->addSeparator(); + QAction *useRegexAct = new QAction(tr("Use regular expressions"), menu); + useRegexAct->setCheckable(true); + useRegexAct->setChecked(pref->getRegexAsFilteringPatternForSearchJob()); + menu->addAction(useRegexAct); + + connect(useRegexAct, &QAction::toggled, pref, &Preferences::setRegexAsFilteringPatternForSearchJob); + connect(useRegexAct, &QAction::toggled, this, [this]() { filterSearchResults(m_lineEditSearchResultsFilter->text()); }); + + menu->exec(QCursor::pos()); +} + QString SearchJobWidget::statusText(SearchJobWidget::Status st) { switch (st) { diff --git a/src/gui/search/searchjobwidget.h b/src/gui/search/searchjobwidget.h index 6e4872f1e..f31167ca7 100644 --- a/src/gui/search/searchjobwidget.h +++ b/src/gui/search/searchjobwidget.h @@ -96,6 +96,7 @@ private: void saveSettings() const; void updateFilter(); void filterSearchResults(const QString &name); + void showFilterContextMenu(const QPoint &); void displayToggleColumnsMenu(const QPoint&); void onItemDoubleClicked(const QModelIndex &index); void searchFinished(bool cancelled); From 400eafce2b392a4eb543ebc008ba320623fbdb2f Mon Sep 17 00:00:00 2001 From: thalieht Date: Sun, 12 Aug 2018 17:46:16 +0300 Subject: [PATCH 2/2] Rename 2 methods to eliminate ambiguity --- src/base/preferences.cpp | 4 ++-- src/base/preferences.h | 4 ++-- src/gui/mainwindow.cpp | 4 ++-- src/gui/transferlistwidget.cpp | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/base/preferences.cpp b/src/base/preferences.cpp index 39fd386ee..79617c6bd 100644 --- a/src/base/preferences.cpp +++ b/src/base/preferences.cpp @@ -1529,12 +1529,12 @@ void Preferences::setTransHeaderState(const QByteArray &state) setValue("TransferList/qt5/HeaderState", state); } -bool Preferences::getRegexAsFilteringPattern() const +bool Preferences::getRegexAsFilteringPatternForTransferList() const { return value("TransferList/UseRegexAsFilteringPattern", false).toBool(); } -void Preferences::setRegexAsFilteringPattern(const bool checked) +void Preferences::setRegexAsFilteringPatternForTransferList(const bool checked) { setValue("TransferList/UseRegexAsFilteringPattern", checked); } diff --git a/src/base/preferences.h b/src/base/preferences.h index b49765fc7..466305bb2 100644 --- a/src/base/preferences.h +++ b/src/base/preferences.h @@ -358,8 +358,8 @@ public: void setTransSelFilter(const int &index); QByteArray getTransHeaderState() const; void setTransHeaderState(const QByteArray &state); - bool getRegexAsFilteringPattern() const; - void setRegexAsFilteringPattern(bool checked); + bool getRegexAsFilteringPatternForTransferList() const; + void setRegexAsFilteringPatternForTransferList(bool checked); int getToolbarTextPosition() const; void setToolbarTextPosition(const int position); diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 7bb893e2a..a77be0461 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -710,10 +710,10 @@ void MainWindow::showFilterContextMenu(const QPoint &) menu->addSeparator(); QAction *useRegexAct = new QAction(tr("Use regular expressions"), menu); useRegexAct->setCheckable(true); - useRegexAct->setChecked(pref->getRegexAsFilteringPattern()); + useRegexAct->setChecked(pref->getRegexAsFilteringPatternForTransferList()); menu->addAction(useRegexAct); - connect(useRegexAct, &QAction::toggled, pref, &Preferences::setRegexAsFilteringPattern); + connect(useRegexAct, &QAction::toggled, pref, &Preferences::setRegexAsFilteringPatternForTransferList); connect(useRegexAct, &QAction::toggled, this, [this]() { m_transferListWidget->applyNameFilter(m_searchFilter->text()); }); menu->exec(QCursor::pos()); diff --git a/src/gui/transferlistwidget.cpp b/src/gui/transferlistwidget.cpp index 94fa159f4..99ca87d61 100644 --- a/src/gui/transferlistwidget.cpp +++ b/src/gui/transferlistwidget.cpp @@ -1188,7 +1188,7 @@ void TransferListWidget::applyTrackerFilter(const QStringList &hashes) void TransferListWidget::applyNameFilter(const QString &name) { - const QRegExp::PatternSyntax patternSyntax = Preferences::instance()->getRegexAsFilteringPattern() + const QRegExp::PatternSyntax patternSyntax = Preferences::instance()->getRegexAsFilteringPatternForTransferList() ? QRegExp::RegExp : QRegExp::WildcardUnix; m_sortFilterModel->setFilterRegExp(QRegExp(name, Qt::CaseInsensitive, patternSyntax)); }