filter: properly search for tags

The old code used get_taglist_string() and split the resulting
string at commas to get the list of tags. This was wrong for two
reasons:
1) It was buggy. Every tag but the first would start with a leading
   space and thus not be found.
2) It was inefficient. The tag list was concatenated, just to be split
   again.

Turn the tag list directly into a QStringList and remove whitespace
for good measure.

Fixes #2842.

Reported-by: Hartley Horwitz <hhrwtz@gmail.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-05-16 20:19:40 +02:00 committed by Dirk Hohndel
parent 04b6bb8cc9
commit a7440ce277
2 changed files with 16 additions and 9 deletions

View file

@ -1,3 +1,4 @@
Filter: fix searching for tags [#2842]
Desktop: fix plotting of thumbnails on profile [#2833] Desktop: fix plotting of thumbnails on profile [#2833]
Core: always include BT/BLE name, even for devices no recognized as dive computer Core: always include BT/BLE name, even for devices no recognized as dive computer
Core: fix failure to recognize several Aqualung BLE dive computers Core: fix failure to recognize several Aqualung BLE dive computers

View file

@ -2,7 +2,8 @@
#include "divefilter.h" #include "divefilter.h"
#include "divelist.h" #include "divelist.h"
#include "qthelper.h" #include "gettextfromc.h"
#include "tag.h"
#include "subsurface-qt/divelistnotifier.h" #include "subsurface-qt/divelistnotifier.h"
static void updateDiveStatus(dive *d, bool newStatus, ShownChange &change) static void updateDiveStatus(dive *d, bool newStatus, ShownChange &change)
@ -15,6 +16,15 @@ static void updateDiveStatus(dive *d, bool newStatus, ShownChange &change)
} }
} }
static QStringList getTagList(const dive *d)
{
QStringList res;
for (const tag_entry *tag = d->tag_list; tag; tag = tag->next)
res.push_back(QString(tag->tag->name).trimmed());
res.append(gettextFromC::tr(divemode_text_ui[d->dc.divemode]));
return res;
}
#ifdef SUBSURFACE_MOBILE #ifdef SUBSURFACE_MOBILE
// Check if a string-list contains at least one string that starts with the second argument. // Check if a string-list contains at least one string that starts with the second argument.
@ -31,16 +41,14 @@ static bool check(const QStringList &items, const QStringList &list)
{ return listContainsSuperstring(list, item); }); { return listContainsSuperstring(list, item); });
} }
bool hasTags(const QStringList &tags, const struct dive *d) static bool hasTags(const QStringList &tags, const struct dive *d)
{ {
if (tags.isEmpty()) if (tags.isEmpty())
return true; return true;
QStringList dive_tags = get_taglist_string(d->tag_list).split(","); return check(tags, getTagList(d));
dive_tags.append(gettextFromC::tr(divemode_text_ui[d->dc.divemode]));
return check(tags, dive_tags);
} }
bool hasPersons(const QStringList &people, const struct dive *d) static bool hasPersons(const QStringList &people, const struct dive *d)
{ {
if (people.isEmpty()) if (people.isEmpty())
return true; return true;
@ -220,9 +228,7 @@ namespace {
{ {
if (tags.isEmpty()) if (tags.isEmpty())
return true; return true;
QStringList dive_tags = get_taglist_string(d->tag_list).split(","); return check(tags, getTagList(d), mode, stringMode);
dive_tags.append(gettextFromC::tr(divemode_text_ui[d->dc.divemode]));
return check(tags, dive_tags, mode, stringMode);
} }
bool hasPersons(const QStringList &people, const struct dive *d, FilterData::Mode mode, StringFilterMode stringMode) bool hasPersons(const QStringList &people, const struct dive *d, FilterData::Mode mode, StringFilterMode stringMode)