diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-02-16 22:31:06 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-03-01 10:21:44 -0800 |
commit | 2bd4c6f6ec8bdd65af28a5158a456f03171d2c0a (patch) | |
tree | 8ca0111d6c93c33394a40e2aee8a66f399e91f40 /core | |
parent | 68d6a75ea38932a4dbd6db4a2dc53e520f32b7e1 (diff) | |
download | subsurface-2bd4c6f6ec8bdd65af28a5158a456f03171d2c0a.tar.gz |
filter: connect fulltext filter to frontend
There are now three filter modes:
1) Dive site
2) Fulltext
3) Normal
When doing a fulltext search, get the dives that match the
fulltext filter and then apply the other filters on that list.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-rw-r--r-- | core/divefilter.cpp | 42 | ||||
-rw-r--r-- | core/divefilter.h | 11 |
2 files changed, 37 insertions, 16 deletions
diff --git a/core/divefilter.cpp b/core/divefilter.cpp index 1372f5a0f..2953d2e65 100644 --- a/core/divefilter.cpp +++ b/core/divefilter.cpp @@ -21,14 +21,14 @@ ShownChange DiveFilter::updateAll() const #include "desktop-widgets/mapwidget.h" #include "desktop-widgets/mainwindow.h" #include "desktop-widgets/divelistview.h" +#include "core/fulltext.h" #include "core/qthelper.h" #include "core/trip.h" #include "core/divesite.h" #include "qt-models/filtermodels.h" -void DiveFilter::updateDiveStatus(dive *d, ShownChange &change) const +void DiveFilter::updateDiveStatus(dive *d, bool newStatus, ShownChange &change) const { - bool newStatus = showDive(d); if (filter_dive(d, newStatus)) { if (newStatus) change.newShown.push_back(d); @@ -40,9 +40,17 @@ void DiveFilter::updateDiveStatus(dive *d, ShownChange &change) const ShownChange DiveFilter::update(const QVector<dive *> &dives) const { dive *old_current = current_dive; + ShownChange res; - for (dive *d: dives) - updateDiveStatus(d, res); + bool doDS = diveSiteMode(); + bool doFullText = filterData.fullText.doit(); + for (dive *d: dives) { + // There are three modes: divesite, fulltext, normal + bool newStatus = doDS ? dive_sites.contains(d->dive_site) : + doFullText ? fulltext_dive_matches(d, filterData.fullText, filterData.fulltextStringMode) && showDive(d) : + showDive(d); + updateDiveStatus(d, newStatus, res); + } res.currentChanged = old_current != current_dive; return res; } @@ -50,9 +58,28 @@ ShownChange DiveFilter::update(const QVector<dive *> &dives) const ShownChange DiveFilter::updateAll() const { dive *old_current = current_dive; + ShownChange res; - for (int i = 0; i < dive_table.nr; ++i) - updateDiveStatus(get_dive(i), res); + int i; + dive *d; + // There are three modes: divesite, fulltext, normal + if (diveSiteMode()) { + for_each_dive(i, d) { + bool newStatus = dive_sites.contains(d->dive_site); + updateDiveStatus(d, newStatus, res); + } + } else if (filterData.fullText.doit()) { + FullTextResult ft = fulltext_find_dives(filterData.fullText, filterData.fulltextStringMode); + for_each_dive(i, d) { + bool newStatus = ft.dive_matches(d) && showDive(d); + updateDiveStatus(d, newStatus, res); + } + } else { + for_each_dive(i, d) { + bool newStatus = showDive(d); + updateDiveStatus(d, newStatus, res); + } + } res.currentChanged = old_current != current_dive; return res; } @@ -161,9 +188,6 @@ DiveFilter::DiveFilter() : diveSiteRefCount(0) bool DiveFilter::showDive(const struct dive *d) const { - if (diveSiteMode()) - return dive_sites.contains(d->dive_site); - if (!filterData.validFilter) return true; diff --git a/core/divefilter.h b/core/divefilter.h index 129fe0888..d035bbfcb 100644 --- a/core/divefilter.h +++ b/core/divefilter.h @@ -13,12 +13,6 @@ struct ShownChange { bool currentChanged; }; -enum class StringFilterMode { - SUBSTRING = 0, - STARTSWITH = 1, - EXACT = 2 -}; - // The dive filter for mobile is currently much simpler than for desktop. // Therefore, for now we have two completely separate implementations. // This should be unified in the future. @@ -36,6 +30,7 @@ private: #else +#include "fulltext.h" #include <QDateTime> #include <QStringList> @@ -72,12 +67,14 @@ struct FilterData { QStringList suit; QStringList dnotes; QStringList equipment; + FullTextQuery fullText; Mode tagsMode = Mode::ALL_OF; Mode peopleMode = Mode::ALL_OF; Mode locationMode = Mode::ANY_OF; Mode dnotesMode = Mode::ALL_OF; Mode suitMode = Mode::ANY_OF; Mode equipmentMode = Mode::ALL_OF; + StringFilterMode fulltextStringMode = StringFilterMode::STARTSWITH; StringFilterMode tagsStringMode = StringFilterMode::SUBSTRING; StringFilterMode peopleStringMode = StringFilterMode::SUBSTRING; StringFilterMode locationStringMode = StringFilterMode::SUBSTRING; @@ -102,7 +99,7 @@ public: ShownChange updateAll() const; // Update filter status of all dives and return dives whose status changed private: DiveFilter(); - void updateDiveStatus(dive *d, ShownChange &change) const; + void updateDiveStatus(dive *d, bool newStatus, ShownChange &change) const; bool showDive(const struct dive *d) const; // Should that dive be shown? QVector<dive_site *> dive_sites; |