Git commit 9f93fa8921c90119e3d1e0ddd58a3d316c6fba60 by Robby Stephenson. Committed on 16/03/2022 at 01:15. Pushed by rstephenson into branch 'master'.
Add option for using regular expressions in the quick filter BUG: 450018 FIXED-IN: 3.5 M +4 -0 ChangeLog M +2 -1 doc/configuration.docbook M +3 -0 src/config/tellico_config.kcfg M +8 -0 src/configdialog.cpp M +1 -0 src/configdialog.h M +2 -2 src/filter.cpp M +1 -1 src/filter.h M +1 -1 src/mainwindow.cpp M +13 -1 src/tests/filtertest.cpp https://invent.kde.org/office/tellico/commit/9f93fa8921c90119e3d1e0ddd58a3d316c6fba60 diff --git a/ChangeLog b/ChangeLog index e6365f2d..87785153 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2022-03-15 Robby Stephenson <ro...@periapsis.org> + + * Added option for using regular expressions in quick filter (Bug 450517). + 2022-03-13 Robby Stephenson <ro...@periapsis.org> * Added data source for arcade-history.com (Bug 450058). diff --git a/doc/configuration.docbook b/doc/configuration.docbook index 748036be..450ecda4 100644 --- a/doc/configuration.docbook +++ b/doc/configuration.docbook @@ -37,7 +37,8 @@ in the data files, or saved separately in the &appname; application folder. Also is started, it can automatically reopen the last data file that was open. The <guilabel>Tip of the Day</guilabel> dialog contains helpful hints on using &appname; and appears at program startup. You may want to read through some of the hints and -then disable the dialog. +then disable the dialog. The <interface>Quick Filter</interface> in the toolbar is useful +for easily filtering through your collection and can utilize regular expressions. </para> <para> diff --git a/src/config/tellico_config.kcfg b/src/config/tellico_config.kcfg index c50bd76c..46f0cc96 100644 --- a/src/config/tellico_config.kcfg +++ b/src/config/tellico_config.kcfg @@ -109,6 +109,9 @@ <entry key="Enable Webcam" type="Bool"> <default>true</default> </entry> + <entry key="Quick Filter RegExp" type="Bool"> + <default>false</default> + </entry> </group> <group name="Printing"> diff --git a/src/configdialog.cpp b/src/configdialog.cpp index a47404cf..21db01cf 100644 --- a/src/configdialog.cpp +++ b/src/configdialog.cpp @@ -215,6 +215,12 @@ void ConfigDialog::initGeneralPage(QFrame* frame) { l->addWidget(m_cbOpenLastFile); connect(m_cbOpenLastFile, &QAbstractButton::clicked, this, &ConfigDialog::slotModified); + m_cbQuickFilterRegExp = new QCheckBox(i18n("&Enable regular expressions in quick filter"), frame); + m_cbQuickFilterRegExp->setWhatsThis(i18n("If checked, the quick filter will " + "interpret text as a regular expression.")); + l->addWidget(m_cbQuickFilterRegExp); + connect(m_cbQuickFilterRegExp, &QAbstractButton::clicked, this, &ConfigDialog::slotModified); + m_cbShowTipDay = new QCheckBox(i18n("&Show \"Tip of the Day\" at startup"), frame); m_cbShowTipDay->setWhatsThis(i18n("If checked, the \"Tip of the Day\" will be " "shown at program start-up.")); @@ -683,6 +689,7 @@ void ConfigDialog::readGeneralConfig() { m_modifying = true; m_cbShowTipDay->setChecked(Config::showTipOfDay()); + m_cbQuickFilterRegExp->setChecked(Config::quickFilterRegExp()); m_cbOpenLastFile->setChecked(Config::reopenLastFile()); #ifdef ENABLE_WEBCAM m_cbEnableWebcam->setChecked(Config::enableWebcam()); @@ -781,6 +788,7 @@ void ConfigDialog::saveConfiguration() { void ConfigDialog::saveGeneralConfig() { Config::setShowTipOfDay(m_cbShowTipDay->isChecked()); + Config::setQuickFilterRegExp(m_cbQuickFilterRegExp->isChecked()); Config::setEnableWebcam(m_cbEnableWebcam->isChecked()); int imageLocation; diff --git a/src/configdialog.h b/src/configdialog.h index 3776d02e..9c8ed175 100644 --- a/src/configdialog.h +++ b/src/configdialog.h @@ -171,6 +171,7 @@ private: QRadioButton* m_rbImageInAppDir; QRadioButton* m_rbImageInLocalDir; QCheckBox* m_cbOpenLastFile; + QCheckBox* m_cbQuickFilterRegExp; QCheckBox* m_cbShowTipDay; QCheckBox* m_cbEnableWebcam; QCheckBox* m_cbCapitalize; diff --git a/src/filter.cpp b/src/filter.cpp index 8f8c0d72..f3f4bc6c 100644 --- a/src/filter.cpp +++ b/src/filter.cpp @@ -317,14 +317,14 @@ bool Filter::operator==(const Filter& other) const { *static_cast<const QList<FilterRule*>*>(this) == static_cast<const QList<FilterRule*>&>(other); } -void Filter::populateQuickFilter(FilterPtr filter_, const QString& fieldName_, const QString& text_) { +void Filter::populateQuickFilter(FilterPtr filter_, const QString& fieldName_, const QString& text_, bool allowRegExp_) { Q_ASSERT(filter_); if(text_.isEmpty()) return; // if the text contains any non-word characters, assume it's a regexp // but \W in qt is letter, number, or '_', I want to be a bit less strict static const QRegularExpression rx(QLatin1String("[^\\w\\s\\-']")); - if(rx.match(text_).hasMatch()) { + if(allowRegExp_ && rx.match(text_).hasMatch()) { QString text = text_; QRegularExpression tx(text); if(!tx.isValid()) { diff --git a/src/filter.h b/src/filter.h index f1c4dc85..d7370daf 100644 --- a/src/filter.h +++ b/src/filter.h @@ -142,7 +142,7 @@ public: bool operator==(const Filter& other) const; - static void populateQuickFilter(FilterPtr filter, const QString& fieldName, const QString& text); + static void populateQuickFilter(FilterPtr filter, const QString& fieldName, const QString& text, bool allowRegExp); private: Filter& operator=(const Filter& other); diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index a2b9757c..f202abfd 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1777,7 +1777,7 @@ void MainWindow::setFilter(const QString& text_) { fieldName = Data::Document::self()->collection()->fieldNameByTitle(fieldName); } } - Filter::populateQuickFilter(filter, fieldName, text); + Filter::populateQuickFilter(filter, fieldName, text, Config::quickFilterRegExp()); // also want to update the line edit in case the filter was set by DBUS if(m_quickFilter->text() != text_) { m_quickFilter->setText(text_); diff --git a/src/tests/filtertest.cpp b/src/tests/filtertest.cpp index 3f5fb786..8d3a1e8d 100644 --- a/src/tests/filtertest.cpp +++ b/src/tests/filtertest.cpp @@ -340,6 +340,18 @@ void FilterTest::testQuickFilter() { Tellico::FilterPtr filter(new Tellico::Filter(Tellico::Filter::MatchAll)); QString fieldName; // empty means any field - Tellico::Filter::populateQuickFilter(filter, fieldName, QStringLiteral("C++")); + Tellico::Filter::populateQuickFilter(filter, fieldName, QStringLiteral("C++"), true /* allow regexps */); QVERIFY(filter->matches(entry)); + + entry->setField(QStringLiteral("title"), QStringLiteral("Coding Standards")); + QVERIFY(filter->matches(entry)); // still matches due to c++ being interpreted as a regexp + + Tellico::FilterPtr filter2(new Tellico::Filter(Tellico::Filter::MatchAll)); + + Tellico::Filter::populateQuickFilter(filter2, fieldName, QStringLiteral("C++"), false /* allow regexps */); + entry->setField(QStringLiteral("title"), QStringLiteral("C++ Coding Standards")); + QVERIFY(filter2->matches(entry)); + + entry->setField(QStringLiteral("title"), QStringLiteral("Coding Standards")); + QVERIFY(!filter2->matches(entry)); // no longer matches }