LeechCraft 0.6.70-17793-g6e56308e78
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
tagsfiltermodel.cpp
Go to the documentation of this file.
1/**********************************************************************
2 * LeechCraft - modular cross-platform feature rich internet client.
3 * Copyright (C) 2006-2014 Georg Rudoy
4 *
5 * Distributed under the Boost Software License, Version 1.0.
6 * (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7 **********************************************************************/
8
9#include "tagsfiltermodel.h"
10#include <QRegularExpression>
11#include <QStringList>
13#include "util.h"
14
15namespace LC::Util
16{
19 , Separator_ { GetDefaultTagsSeparator () }
20 {
21 }
22
23 void TagsFilterModel::SetFilterString (const QString& string)
24 {
25 FilterTags_.clear ();
26 for (const auto& s : string.split (Separator_, Qt::SkipEmptyParts))
27 FilterTags_ << s.trimmed ();
28
30 }
31
32 void TagsFilterModel::SetSeparator (const QString& separator)
33 {
34 Separator_ = separator;
35 invalidateFilter ();
36 }
37
39 {
40 TagsMode_ = mode;
41 invalidateFilter ();
42 }
43
45 {
46 NormalMode_ = !tags;
47 invalidateFilter ();
48 }
49
50 bool TagsFilterModel::filterAcceptsRow (int sourceRow, const QModelIndex& index) const
51 {
52 if (NormalMode_)
53 return FixedStringFilterProxyModel::filterAcceptsRow (sourceRow, index);
54
55 return FilterTagsMode (sourceRow, index);
56 }
57
58 bool TagsFilterModel::FilterTagsMode (int sourceRow, const QModelIndex&) const
59 {
60 if (FilterTags_.isEmpty ())
61 return true;
62
63 const auto& itemTags = GetTagsForIndex (sourceRow);
64 const auto hasTag = [&] (const QString& tag) { return itemTags.contains (tag); };
65 switch (TagsMode_)
66 {
68 return std::ranges::any_of (FilterTags_, hasTag);
70 return std::ranges::all_of (FilterTags_, hasTag);
71 }
72
73 Unreachable ();
74 }
75}
bool filterAcceptsRow(int row, const QModelIndex &parent) const override
bool filterAcceptsRow(int, const QModelIndex &) const override
Reimplemented from QSortFilterProxyModel::filterAcceptsRow().
void SetTagsInclusionMode(TagsInclusionMode mode)
Sets the tags inclusion mode.
void SetTagsMode(bool enabled)
Sets whether the tags filtering mode is enabled.
TagsInclusionMode
Describes the modes of matching two sets of tags.
@ All
Filter string tags should be a subset of row tags.
@ Any
Tags intersection should be non-empty.
void SetFilterString(const QString &) override
void SetSeparator(const QString &separator)
Sets the separator for the tags.
TagsFilterModel(QObject *parent=nullptr)
Creates the model with the given parent.
virtual QStringList GetTagsForIndex(int row) const =0
Returns the list of tags for the given row.
void Unreachable()
Definition unreachable.h:15
QString GetDefaultTagsSeparator()
Definition util.cpp:14