Fix BuddyFilterModel

Commit 6343515fed introduced equality
instead of substring comparison for filters. This broke the buddy
filter in the case of more than one buddy, because in such a case
the buddy list is a comma-separated string.

Fix this by splitting the buddy string, trimming the individual
strings and search in the list.

Fixes #969

Reported-by: <yrevawerd@gmail.com>
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2017-12-21 20:11:32 +01:00 committed by Lubomir I. Ivanov
parent e4530cd5ef
commit 935fb3c3df

View file

@ -228,10 +228,12 @@ bool BuddyFilterModel::doFilter(dive *d, QModelIndex &index0, QAbstractItemModel
return true; return true;
} }
// Checked means 'Show', Unchecked means 'Hide'. // Checked means 'Show', Unchecked means 'Hide'.
QString diveBuddy(d->buddy); QString persons = QString(d->buddy) + "," + QString(d->divemaster);
QString divemaster(d->divemaster); QStringList personsList = persons.split(',', QString::SkipEmptyParts);
for (QString &s: personsList)
s = s.trimmed();
// only show empty buddie dives if the user checked that. // only show empty buddie dives if the user checked that.
if (diveBuddy.isEmpty() && divemaster.isEmpty()) { if (personsList.isEmpty()) {
if (rowCount() > 0) if (rowCount() > 0)
return checkState[rowCount() - 1]; return checkState[rowCount() - 1];
else else
@ -242,7 +244,7 @@ bool BuddyFilterModel::doFilter(dive *d, QModelIndex &index0, QAbstractItemModel
QStringList buddyList = stringList(); QStringList buddyList = stringList();
// Ignore last item, since this is the "Show Empty Tags" entry // Ignore last item, since this is the "Show Empty Tags" entry
for (int i = 0; i < rowCount() - 1; i++) { for (int i = 0; i < rowCount() - 1; i++) {
if (checkState[i] && (diveBuddy == buddyList[i] || divemaster == buddyList[i])) if (checkState[i] && personsList.contains(buddyList[i], Qt::CaseInsensitive))
return true; return true;
} }
return false; return false;