10#include <QRegularExpression>
18 : QSortFilterProxyModel (parent)
25 Separator_ = separator;
27 if (dynamicSortFilter ())
35 if (dynamicSortFilter ())
43 if (dynamicSortFilter ())
50 FilterNormalMode (sourceRow, index) :
51 FilterTagsMode (sourceRow, index);
54 bool TagsFilterModel::FilterNormalMode (
int sourceRow,
const QModelIndex& index)
const
56 if (index.isValid () && sourceModel ()->rowCount (index))
59 const auto& pattern = filterRegularExpression ().pattern ();
60 if (pattern.isEmpty ())
63 for (
int i = 0, cc = sourceModel ()->columnCount (index); i < cc; ++i)
65 const auto& rowIdx = sourceModel ()->index (sourceRow, i, index);
66 const auto& str = rowIdx.data ().toString ();
67 if (str.contains (pattern) || filterRegularExpression ().match (str).hasMatch ())
74 bool TagsFilterModel::FilterTagsMode (
int sourceRow,
const QModelIndex&)
const
77 const auto& pattern = filterRegularExpression ().pattern ();
78 for (
const auto& s : QStringView { pattern }.split (Separator_, Qt::SkipEmptyParts))
79 filterTags << s.trimmed ();
81 if (filterTags.isEmpty ())
85 const auto hasTag = [&] (QStringView tag) {
return itemTags.contains (tag); };
89 return std::any_of (filterTags.begin (), filterTags.end (), hasTag);
91 return std::all_of (filterTags.begin (), filterTags.end (), hasTag);
QString GetDefaultTagsSeparator()