1 /***************************************************************************
2 * Copyright (C) 2011 by Janardhan Reddy *
3 * <annapareddyjanardhanreddy@gmail.com> *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
19 ***************************************************************************/
21 #ifndef KFILEITEMMODELFILTER_H
22 #define KFILEITEMMODELFILTER_H
24 #include "dolphin_export.h"
26 #include <QStringList>
29 class QRegularExpression
;
32 * @brief Allows to check whether an item of the KFileItemModel
33 * matches with a set filter-string.
35 * Currently the filter is only checked for the KFileItem::text()
36 * property of the KFileItem, but this might get extended in
39 class DOLPHIN_EXPORT KFileItemModelFilter
43 KFileItemModelFilter();
44 virtual ~KFileItemModelFilter();
47 * Sets the pattern that is used for a comparison with the item
48 * in KFileItemModelFilter::matches(). Per default the pattern
49 * defines a sub-string. As soon as the pattern contains at least
50 * a '*', '?' or '[' the pattern represents a regular expression.
52 void setPattern(const QString
& pattern
);
53 QString
pattern() const;
56 * Set the list of mimetypes that are used for comparison with the
57 * item in KFileItemModelFilter::matchesMimeType.
59 void setMimeTypes(const QStringList
& types
);
60 QStringList
mimeTypes() const;
63 * @return True if either the pattern or mimetype filters has been set.
65 bool hasSetFilters() const;
68 * @return True if the item matches with the pattern defined by
69 * @ref setPattern() or @ref setMimeTypes
71 bool matches(const KFileItem
& item
) const;
75 * @return True if item matches pattern set by @ref setPattern.
77 bool matchesPattern(const KFileItem
& item
) const;
80 * @return True if item matches mimetypes set by @ref setMimeTypes.
82 bool matchesType(const KFileItem
& item
) const;
84 bool m_useRegExp
; // If true, m_regExp is used for filtering,
85 // otherwise m_lowerCaseFilter is used.
86 QRegularExpression
*m_regExp
;
87 QString m_lowerCasePattern
; // Lowercase version of m_filter for
88 // faster comparison in matches().
89 QString m_pattern
; // Property set by setPattern().
90 QStringList m_mimeTypes
; // Property set by setMimeTypes()