mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Mobile: decouple full text search from DiveObjectHelper
1) The full text search was looping over the DiveListModel when it could simply loop over the core model. Do that instead. 2) Don't generate a DiveObjectHelper to do a full text search. Currently this is harmless as the DiveObjectHelper is only a disguised "dive *". But from a conceptual point of view, it represents the full representation of a dive and we don't want to generate that in a tight loop. This will help in 1) Making the DiveObjectHelper a non-reference object. 2) Moving fulltext search to the core and thus making it available to desktop and more performant. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
36aab0fe95
commit
37a3daf2dd
3 changed files with 23 additions and 7 deletions
|
@ -1403,6 +1403,23 @@ QString getUUID()
|
|||
return uuidString;
|
||||
}
|
||||
|
||||
static bool contains(const char *s, const QString &filterstring, Qt::CaseSensitivity cs)
|
||||
{
|
||||
return !empty_string(s) && QString(s).contains(filterstring, cs);
|
||||
}
|
||||
|
||||
bool diveContainsText(const struct dive *d, const QString &filterstring, Qt::CaseSensitivity cs, bool includeNotes)
|
||||
{
|
||||
if (!d)
|
||||
return false;
|
||||
return contains(get_dive_location(d), filterstring, cs) ||
|
||||
(d->divetrip && contains(d->divetrip->location, filterstring, cs)) ||
|
||||
contains(d->buddy, filterstring, cs) ||
|
||||
contains(d->divemaster, filterstring, cs) ||
|
||||
contains(d->suit, filterstring, cs) ||
|
||||
get_taglist_string(d->tag_list).contains(filterstring, cs) ||
|
||||
(includeNotes && contains(d->notes, filterstring, cs));
|
||||
}
|
||||
int parse_seabear_header(const char *filename, char **params, int pnr)
|
||||
{
|
||||
QFile f(filename);
|
||||
|
|
|
@ -79,6 +79,7 @@ QLocale getLocale();
|
|||
QVector<QPair<QString, int>> selectedDivesGasUsed();
|
||||
QString getUserAgent();
|
||||
QString printGPSCoords(const location_t *loc);
|
||||
bool diveContainsText(const struct dive *d, const QString &filterstring, Qt::CaseSensitivity cs, bool includeNotes);
|
||||
|
||||
#if defined __APPLE__
|
||||
#define TITLE_OR_TEXT(_t, _m) "", _t + "\n" + _m
|
||||
|
|
|
@ -20,19 +20,17 @@ void DiveListSortModel::updateFilterState()
|
|||
bool includeNotes = qPrefGeneral::filterFullTextNotes();
|
||||
Qt::CaseSensitivity cs = qPrefGeneral::filterCaseSensitive() ? Qt::CaseSensitive : Qt::CaseInsensitive;
|
||||
|
||||
// get the underlying model and re-calculate the filter value for each dive
|
||||
DiveListModel *mySourceModel = qobject_cast<DiveListModel *>(sourceModel());
|
||||
for (int i = 0; i < mySourceModel->rowCount(); i++) {
|
||||
DiveObjectHelper *d = mySourceModel->at(i);
|
||||
QString fullText = includeNotes? d->fullText() : d->fullTextNoNotes();
|
||||
d->getDive()->hidden_by_filter = !fullText.contains(filterString, cs);
|
||||
}
|
||||
int i;
|
||||
struct dive *d;
|
||||
for_each_dive(i, d)
|
||||
d->hidden_by_filter = !diveContainsText(d, filterString, cs, includeNotes);
|
||||
}
|
||||
|
||||
void DiveListSortModel::setSourceModel(QAbstractItemModel *sourceModel)
|
||||
{
|
||||
QSortFilterProxyModel::setSourceModel(sourceModel);
|
||||
}
|
||||
|
||||
void DiveListSortModel::setFilter(QString f)
|
||||
{
|
||||
filterString = f;
|
||||
|
|
Loading…
Add table
Reference in a new issue