]> cloud.milkyroute.net Git - dolphin.git/blob - src/kitemviews/private/kfileitemmodelfilter.h
Clazy fix
[dolphin.git] / src / kitemviews / private / kfileitemmodelfilter.h
1 /*
2 * SPDX-FileCopyrightText: 2011 Janardhan Reddy <annapareddyjanardhanreddy@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7 #ifndef KFILEITEMMODELFILTER_H
8 #define KFILEITEMMODELFILTER_H
9
10 #include "dolphin_export.h"
11
12 #include <QStringList>
13
14 class KFileItem;
15 class QRegularExpression;
16
17 /**
18 * @brief Allows to check whether an item of the KFileItemModel
19 * matches with a set filter-string.
20 *
21 * Currently the filter is only checked for the KFileItem::text()
22 * property of the KFileItem, but this might get extended in
23 * future.
24 */
25 class DOLPHIN_EXPORT KFileItemModelFilter
26 {
27 public:
28 KFileItemModelFilter();
29 virtual ~KFileItemModelFilter();
30
31 /**
32 * Sets the pattern that is used for a comparison with the item
33 * in KFileItemModelFilter::matches(). Per default the pattern
34 * defines a sub-string. As soon as the pattern contains at least
35 * a '*', '?' or '[' the pattern represents a regular expression.
36 */
37 void setPattern(const QString &pattern);
38 QString pattern() const;
39
40 /**
41 * Set the list of mimetypes that are used for comparison with the
42 * item in KFileItemModelFilter::matchesMimeType.
43 */
44 void setMimeTypes(const QStringList &types);
45 QStringList mimeTypes() const;
46
47 /**
48 * Set the list of mimetypes that are used for comparison and excluded with the
49 * item in KFileItemModelFilter::matchesMimeType.
50 */
51 void setExcludeMimeTypes(const QStringList &types);
52 QStringList excludeMimeTypes() const;
53
54 /**
55 * @return True if either the pattern or mimetype filters has been set.
56 */
57 bool hasSetFilters() const;
58
59 /**
60 * @return True if the item matches with the pattern defined by
61 * @ref setPattern() or @ref setMimeTypes
62 */
63 bool matches(const KFileItem &item) const;
64
65 private:
66 /**
67 * @return True if item matches pattern set by @ref setPattern.
68 */
69 bool matchesPattern(const KFileItem &item) const;
70
71 /**
72 * @return True if item matches mimetypes set by @ref setMimeTypes.
73 */
74 bool matchesType(const KFileItem &item) const;
75
76 bool m_useRegExp; // If true, m_regExp is used for filtering,
77 // otherwise m_lowerCaseFilter is used.
78 QRegularExpression *m_regExp;
79 QString m_lowerCasePattern; // Lowercase version of m_filter for
80 // faster comparison in matches().
81 QString m_pattern; // Property set by setPattern().
82 QStringList m_mimeTypes; // Property set by setMimeTypes()
83 QStringList m_excludeMimeTypes; // Property set by setExcludeMimeTypes()
84 };
85 #endif