30 #include <QStringList>
39 : QSortFilterProxyModel (parent)
42 , TagsMode_ (TagsInclusionMode::All)
46 void TagsFilterModel::SetSeparator (
const QString& separator)
48 Separator_ = separator;
50 if (dynamicSortFilter ())
54 void TagsFilterModel::SetTagsInclusionMode (TagsFilterModel::TagsInclusionMode mode)
58 if (dynamicSortFilter ())
62 void TagsFilterModel::setTagsMode (
bool tags)
66 if (dynamicSortFilter ())
70 void TagsFilterModel::enableTagsMode ()
75 void TagsFilterModel::disableTagsMode ()
80 bool TagsFilterModel::filterAcceptsRow (
int source_row,
const QModelIndex& index)
const
84 if (index.isValid () && sourceModel ()->rowCount (index))
87 const auto& pattern = filterRegExp ().pattern ();
88 if (pattern.isEmpty ())
91 for (
int i = 0, cc = sourceModel ()->columnCount (index); i < cc; ++i)
93 const auto& rowIdx = sourceModel ()->index (source_row, i, index);
94 const auto& str = rowIdx.data ().toString ();
95 if (str.contains (pattern) || filterRegExp ().exactMatch (str))
103 QStringList filterTags;
104 const auto& pattern = filterRegExp ().pattern ();
105 for (
const auto& s : pattern.split (Separator_, QString::SkipEmptyParts))
106 filterTags << s.trimmed ();
108 if (!filterTags.size ())
111 const auto& itemTags = GetTagsForIndex (source_row);
112 for (
int i = 0; i < filterTags.size (); ++i)
115 for (
int j = 0; j < itemTags.size (); ++j)
116 if (itemTags.at (j).contains (filterTags.at (i)))
123 else if (TagsMode_ == TagsInclusionMode::Any)