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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
/*
Copyright (c) 2007 Bruno Virlet <bruno.virlet@gmail.com>
This library is free software; you can redistribute it and/or modify it
under the terms of the GNU Library General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at your
option) any later version.
This library is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301, USA.
*/
#ifndef AKONADI_COLLECTIONFILTERPROXYMODEL_H
#define AKONADI_COLLECTIONFILTERPROXYMODEL_H
#include "akonadi_export.h"
#include <QtGui/QSortFilterProxyModel>
namespace Akonadi {
class CollectionModel;
/**
* @short A proxy model that filters collections by mime type.
*
* This class can be used on top of a CollectionModel to filter out
* all collections that doesn't match a given mime type.
*
* For instance, a mail application will use addMimeType( "message/rfc822" ) to only show
* collections containing mail.
*
* @code
*
* Akonadi::CollectionModel *model = new Akonadi::CollectionModel( this );
*
* Akonadi::CollectionFilterProxyModel *proxy = new Akonadi::CollectionFilterProxyModel();
* proxy->addMimeTypeFilter( "message/rfc822" );
* proxy->setSourceModel( model );
*
* QTreeView *view = new QTreeView( this );
* view->setModel( proxy );
*
* @endcode
*
* @author Bruno Virlet <bruno.virlet@gmail.com>
*/
class AKONADI_EXPORT CollectionFilterProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
/**
* Creates a new collection proxy filter model.
*
* @param parent The parent object.
*/
explicit CollectionFilterProxyModel( QObject *parent = 0 );
/**
* Destroys the collection proxy filter model.
*/
virtual ~CollectionFilterProxyModel();
/**
* Adds a list of mime types to be shown by the filter.
*
* @param mimeTypes A list of mime types to be shown.
*/
void addMimeTypeFilters( const QStringList &mimeTypes );
/**
* Adds a mime type to be shown by the filter.
*
* @param mimeType A mime type to be shown.
*/
void addMimeTypeFilter( const QString &mimeType );
/**
* Returns the list of mime type filters.
*/
QStringList mimeTypeFilters() const;
/**
* Sets whether we want virtual collections to be filtered or not.
* By default, virtual collections are accepted.
*
* @param exclude If true, virtual collections aren't accepted.
*
* @since 4.7
*/
void setExcludeVirtualCollections( bool exclude );
/**
* Clears all mime type filters.
*/
void clearFilters();
virtual Qt::ItemFlags flags( const QModelIndex& index ) const;
protected:
virtual bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent ) const;
private:
//@cond PRIVATE
class Private;
Private* const d;
//@endcond
};
}
#endif
|