parent
e72b001d02
commit
78a9cb35a3
|
@ -246,7 +246,7 @@ FilterTree *FilterParser::createSearchTermTreeNode(const QString &column, const
|
|||
cmp = new FilterParserTextNeComparator(value);
|
||||
}
|
||||
else {
|
||||
cmp = new FilterParserDefaultComparator(value);
|
||||
cmp = new FilterParserTextContainsComparator(value);
|
||||
}
|
||||
}
|
||||
else if (Song::kIntSearchColumns.contains(column, Qt::CaseInsensitive)) {
|
||||
|
@ -363,7 +363,7 @@ FilterTree *FilterParser::createSearchTermTreeNode(const QString &column, const
|
|||
return new FilterColumnTerm(column, cmp);
|
||||
}
|
||||
|
||||
return new FilterTerm(Song::kTextSearchColumns, new FilterParserDefaultComparator(value));
|
||||
return new FilterTerm(new FilterParserTextContainsComparator(value));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -38,16 +38,16 @@ class FilterParserSearchTermComparator {
|
|||
};
|
||||
|
||||
// "compares" by checking if the field contains the search term
|
||||
class FilterParserDefaultComparator : public FilterParserSearchTermComparator {
|
||||
class FilterParserTextContainsComparator : public FilterParserSearchTermComparator {
|
||||
public:
|
||||
explicit FilterParserDefaultComparator(const QString &search_term) : search_term_(search_term) {}
|
||||
explicit FilterParserTextContainsComparator(const QString &search_term) : search_term_(search_term) {}
|
||||
bool Matches(const QVariant &value) const override {
|
||||
return value.toString().contains(search_term_, Qt::CaseInsensitive);
|
||||
return value.metaType().id() == QMetaType::QString && value.toString().contains(search_term_, Qt::CaseInsensitive);
|
||||
}
|
||||
private:
|
||||
QString search_term_;
|
||||
|
||||
Q_DISABLE_COPY(FilterParserDefaultComparator)
|
||||
Q_DISABLE_COPY(FilterParserTextContainsComparator)
|
||||
};
|
||||
|
||||
class FilterParserTextEqComparator : public FilterParserSearchTermComparator {
|
||||
|
|
|
@ -67,19 +67,27 @@ class NopFilter : public FilterTree {
|
|||
// Filter that applies a SearchTermComparator to all fields
|
||||
class FilterTerm : public FilterTree {
|
||||
public:
|
||||
explicit FilterTerm(const QStringList &columns, FilterParserSearchTermComparator *comparator) : columns_(columns), cmp_(comparator) {}
|
||||
explicit FilterTerm(FilterParserSearchTermComparator *comparator) : cmp_(comparator) {}
|
||||
|
||||
FilterType type() const override { return FilterType::Term; }
|
||||
|
||||
bool accept(const Song &song) const override {
|
||||
for (const QString &column : columns_) {
|
||||
if (cmp_->Matches(DataFromColumn(column, song))) return true;
|
||||
}
|
||||
|
||||
if (cmp_->Matches(song.PrettyTitle())) return true;
|
||||
if (cmp_->Matches(song.album())) return true;
|
||||
if (cmp_->Matches(song.artist())) return true;
|
||||
if (cmp_->Matches(song.albumartist())) return true;
|
||||
if (cmp_->Matches(song.composer())) return true;
|
||||
if (cmp_->Matches(song.performer())) return true;
|
||||
if (cmp_->Matches(song.grouping())) return true;
|
||||
if (cmp_->Matches(song.genre())) return true;
|
||||
if (cmp_->Matches(song.comment())) return true;
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
const QStringList columns_;
|
||||
QScopedPointer<FilterParserSearchTermComparator> cmp_;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue