mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
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>
This commit is contained in:
parent
e754b2df84
commit
fd7dd5421b
2 changed files with 66 additions and 3 deletions
|
@ -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"
|
||||
|
|
|
@ -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>
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue