2 * SPDX-FileCopyrightText: 2011 Janardhan Reddy <annapareddyjanardhanreddy@gmail.com>
4 * SPDX-License-Identifier: GPL-2.0-or-later
7 #ifndef KFILEITEMMODELFILTER_H
8 #define KFILEITEMMODELFILTER_H
10 #include "dolphin_export.h"
12 #include <QStringList>
15 class QRegularExpression
;
18 * @brief Allows to check whether an item of the KFileItemModel
19 * matches with a set filter-string.
21 * Currently the filter is only checked for the KFileItem::text()
22 * property of the KFileItem, but this might get extended in
25 class DOLPHIN_EXPORT KFileItemModelFilter
29 KFileItemModelFilter();
30 virtual ~KFileItemModelFilter();
33 * Sets the pattern that is used for a comparison with the item
34 * in KFileItemModelFilter::matches(). Per default the pattern
35 * defines a sub-string. As soon as the pattern contains at least
36 * a '*', '?' or '[' the pattern represents a regular expression.
38 void setPattern(const QString
& pattern
);
39 QString
pattern() const;
42 * Set the list of mimetypes that are used for comparison with the
43 * item in KFileItemModelFilter::matchesMimeType.
45 void setMimeTypes(const QStringList
& types
);
46 QStringList
mimeTypes() const;
49 * @return True if either the pattern or mimetype filters has been set.
51 bool hasSetFilters() const;
54 * @return True if the item matches with the pattern defined by
55 * @ref setPattern() or @ref setMimeTypes
57 bool matches(const KFileItem
& item
) const;
61 * @return True if item matches pattern set by @ref setPattern.
63 bool matchesPattern(const KFileItem
& item
) const;
66 * @return True if item matches mimetypes set by @ref setMimeTypes.
68 bool matchesType(const KFileItem
& item
) const;
70 bool m_useRegExp
; // If true, m_regExp is used for filtering,
71 // otherwise m_lowerCaseFilter is used.
72 QRegularExpression
*m_regExp
;
73 QString m_lowerCasePattern
; // Lowercase version of m_filter for
74 // faster comparison in matches().
75 QString m_pattern
; // Property set by setPattern().
76 QStringList m_mimeTypes
; // Property set by setMimeTypes()