diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-05-16 20:19:40 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-05-16 12:40:08 -0700 |
commit | a7440ce2779734a59a7495ef44b9d62da4aa9eee (patch) | |
tree | ad0ba5c2d254d4d0778acb89e3bbf15135180604 /core | |
parent | 04b6bb8cc946486efa174722b75378028105250b (diff) | |
download | subsurface-a7440ce2779734a59a7495ef44b9d62da4aa9eee.tar.gz |
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>
Diffstat (limited to 'core')
-rw-r--r-- | core/divefilter.cpp | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/core/divefilter.cpp b/core/divefilter.cpp index 89fbd731d..fae6c1760 100644 --- a/core/divefilter.cpp +++ b/core/divefilter.cpp @@ -2,7 +2,8 @@ #include "divefilter.h" #include "divelist.h" -#include "qthelper.h" +#include "gettextfromc.h" +#include "tag.h" #include "subsurface-qt/divelistnotifier.h" 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 // 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); }); } -bool hasTags(const QStringList &tags, const struct dive *d) +static bool hasTags(const QStringList &tags, const struct dive *d) { if (tags.isEmpty()) return true; - QStringList dive_tags = get_taglist_string(d->tag_list).split(","); - dive_tags.append(gettextFromC::tr(divemode_text_ui[d->dc.divemode])); - return check(tags, dive_tags); + return check(tags, getTagList(d)); } -bool hasPersons(const QStringList &people, const struct dive *d) +static bool hasPersons(const QStringList &people, const struct dive *d) { if (people.isEmpty()) return true; @@ -220,9 +228,7 @@ namespace { { if (tags.isEmpty()) return true; - QStringList dive_tags = get_taglist_string(d->tag_list).split(","); - dive_tags.append(gettextFromC::tr(divemode_text_ui[d->dc.divemode])); - return check(tags, dive_tags, mode, stringMode); + return check(tags, getTagList(d), mode, stringMode); } bool hasPersons(const QStringList &people, const struct dive *d, FilterData::Mode mode, StringFilterMode stringMode) |