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