summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-02-19 20:13:33 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-03-01 10:21:44 -0800
commitfd7dd5421b1af258831b9c834e32f27ebd976472 (patch)
treea25112e48e3ea63973a106fade44a61f8f6264ea /core
parente754b2df846751fee7f93f7a684e7a1126a025a2 (diff)
downloadsubsurface-fd7dd5421b1af258831b9c834e32f27ebd976472.tar.gz
filter: implement full-text filtering in mobile version of DiveFilter
In analogy to the desktop version, use the fulltext index in DiveFilter. This code is not yet executed. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-rw-r--r--core/divefilter.cpp49
-rw-r--r--core/divefilter.h20
2 files changed, 66 insertions, 3 deletions
diff --git a/core/divefilter.cpp b/core/divefilter.cpp
index 2aec89dc5..31ab08ba2 100644
--- a/core/divefilter.cpp
+++ b/core/divefilter.cpp
@@ -15,28 +15,73 @@ static void updateDiveStatus(dive *d, bool newStatus, ShownChange &change)
#ifdef SUBSURFACE_MOBILE
+DiveFilter *DiveFilter::instance()
+{
+ static DiveFilter self;
+ return &self;
+}
+
DiveFilter::DiveFilter()
{
}
-ShownChange DiveFilter::update(const QVector<dive *> &) const
+ShownChange DiveFilter::update(const QVector<dive *> &dives) const
{
+ dive *old_current = current_dive;
+
ShownChange res;
+ switch (filterData.mode) {
+ default:
+ case FilterData::Mode::NONE:
+ for (dive *d: dives)
+ updateDiveStatus(d, true, res);
+ break;
+ case FilterData::Mode::FULLTEXT:
+ for (dive *d: dives)
+ updateDiveStatus(d, fulltext_dive_matches(d, filterData.fullText, StringFilterMode::STARTSWITH), res);
+ break;
+ }
+
+ res.currentChanged = old_current != current_dive;
return res;
}
ShownChange DiveFilter::updateAll() const
{
+ dive *old_current = current_dive;
+
ShownChange res;
+ int i;
+ dive *d;
+ switch (filterData.mode) {
+ default:
+ case FilterData::Mode::NONE:
+ for_each_dive(i, d)
+ updateDiveStatus(d, true, res);
+ break;
+ case FilterData::Mode::FULLTEXT: {
+ FullTextResult ft = fulltext_find_dives(filterData.fullText, StringFilterMode::STARTSWITH);
+ for_each_dive(i, d)
+ updateDiveStatus(d, ft.dive_matches(d), res);
+ break;
+ }
+ }
+
+ res.currentChanged = old_current != current_dive;
return res;
}
+void DiveFilter::setFilter(const FilterData &data)
+{
+ filterData = data;
+ //emit diveListNotifier.filterReset(); // Not yet using common models
+}
+
#else // SUBSURFACE_MOBILE
#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"
diff --git a/core/divefilter.h b/core/divefilter.h
index ca17e3741..05add693e 100644
--- a/core/divefilter.h
+++ b/core/divefilter.h
@@ -4,6 +4,8 @@
#define DIVE_FILTER_H
#include <QVector>
+#include "fulltext.h"
+
struct dive;
// Structure describing changes of shown status upon applying the filter
@@ -18,19 +20,35 @@ struct ShownChange {
// This should be unified in the future.
#ifdef SUBSURFACE_MOBILE
+struct FilterData {
+ // On mobile, we support searching fulltext (all fields), people (buddies and divemasters) and tags
+ enum class Mode {
+ NONE = 0,
+ FULLTEXT = 1,
+ PEOPLE = 2,
+ TAGS = 3
+ };
+
+ Mode mode = Mode::NONE;
+ FullTextQuery fullText; // For fulltext
+ QString text; // For people and tags
+};
+
class DiveFilter {
public:
static DiveFilter *instance();
ShownChange update(const QVector<dive *> &dives) const; // Update filter status of given dives and return dives whose status changed
ShownChange updateAll() const; // Update filter status of all dives and return dives whose status changed
+ void setFilter(const FilterData &data);
private:
DiveFilter();
+
+ FilterData filterData;
};
#else
-#include "fulltext.h"
#include <QDateTime>
#include <QStringList>