1/*
2 Copyright (c) 2007 Bruno Virlet <bruno.virlet@gmail.com>
3
4 This library is free software; you can redistribute it and/or modify it
5 under the terms of the GNU Library General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or (at your
7 option) any later version.
8
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12 License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to the
16 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 02110-1301, USA.
18*/
19
20#ifndef AKONADI_COLLECTIONFILTERPROXYMODEL_H
21#define AKONADI_COLLECTIONFILTERPROXYMODEL_H
22
23#include "akonadi_export.h"
24#include <QSortFilterProxyModel>
25
26namespace Akonadi {
27
28class CollectionModel;
29
30/**
31 * @short A proxy model that filters collections by mime type.
32 *
33 * This class can be used on top of a CollectionModel to filter out
34 * all collections that doesn't match a given mime type.
35 *
36 * For instance, a mail application will use addMimeType( "message/rfc822" ) to only show
37 * collections containing mail.
38 *
39 * @code
40 *
41 * Akonadi::CollectionModel *model = new Akonadi::CollectionModel( this );
42 *
43 * Akonadi::CollectionFilterProxyModel *proxy = new Akonadi::CollectionFilterProxyModel();
44 * proxy->addMimeTypeFilter( "message/rfc822" );
45 * proxy->setSourceModel( model );
46 *
47 * QTreeView *view = new QTreeView( this );
48 * view->setModel( proxy );
49 *
50 * @endcode
51 *
52 * @author Bruno Virlet <bruno.virlet@gmail.com>
53 */
54class AKONADI_EXPORT CollectionFilterProxyModel : public QSortFilterProxyModel
55{
56 Q_OBJECT
57
58public:
59 /**
60 * Creates a new collection proxy filter model.
61 *
62 * @param parent The parent object.
63 */
64 explicit CollectionFilterProxyModel(QObject *parent = 0);
65
66 /**
67 * Destroys the collection proxy filter model.
68 */
69 virtual ~CollectionFilterProxyModel();
70
71 /**
72 * Adds a list of mime types to be shown by the filter.
73 *
74 * @param mimeTypes A list of mime types to be shown.
75 */
76 void addMimeTypeFilters(const QStringList &mimeTypes);
77
78 /**
79 * Adds a mime type to be shown by the filter.
80 *
81 * @param mimeType A mime type to be shown.
82 */
83 void addMimeTypeFilter(const QString &mimeType);
84
85 /**
86 * Returns the list of mime type filters.
87 */
88 QStringList mimeTypeFilters() const;
89
90 /**
91 * Sets whether we want virtual collections to be filtered or not.
92 * By default, virtual collections are accepted.
93 *
94 * @param exclude If true, virtual collections aren't accepted.
95 *
96 * @since 4.7
97 */
98 void setExcludeVirtualCollections(bool exclude);
99 /*
100 * @since 4.12
101 */
102 bool excludeVirtualCollections() const;
103
104 /**
105 * Clears all mime type filters.
106 */
107 void clearFilters();
108
109 virtual Qt::ItemFlags flags(const QModelIndex &index) const;
110
111protected:
112 virtual bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const;
113
114private:
115 //@cond PRIVATE
116 class Private;
117 Private *const d;
118 //@endcond
119};
120
121}
122
123#endif
124