Akonadi

collectionfilterproxymodel.h
1 /*
2  SPDX-FileCopyrightText: 2007 Bruno Virlet <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #pragma once
8 
9 #include "akonadicore_export.h"
10 #include <QSortFilterProxyModel>
11 
12 #include <memory>
13 
14 namespace Akonadi
15 {
16 class CollectionModel;
17 class CollectionFilterProxyModelPrivate;
18 
19 /**
20  * @short A proxy model that filters collections by mime type.
21  *
22  * This class can be used on top of a CollectionModel to filter out
23  * all collections that doesn't match a given mime type.
24  *
25  * For instance, a mail application will use addMimeType( "message/rfc822" ) to only show
26  * collections containing mail.
27  *
28  * @code
29  *
30  * Akonadi::CollectionModel *model = new Akonadi::CollectionModel( this );
31  *
32  * Akonadi::CollectionFilterProxyModel *proxy = new Akonadi::CollectionFilterProxyModel();
33  * proxy->addMimeTypeFilter( "message/rfc822" );
34  * proxy->setSourceModel( model );
35  *
36  * QTreeView *view = new QTreeView( this );
37  * view->setModel( proxy );
38  *
39  * @endcode
40  *
41  * @author Bruno Virlet <[email protected]>
42  */
43 class AKONADICORE_EXPORT CollectionFilterProxyModel : public QSortFilterProxyModel
44 {
45  Q_OBJECT
46 
47 public:
48  /**
49  * Creates a new collection proxy filter model.
50  *
51  * @param parent The parent object.
52  */
53  explicit CollectionFilterProxyModel(QObject *parent = nullptr);
54 
55  /**
56  * Destroys the collection proxy filter model.
57  */
58  ~CollectionFilterProxyModel() override;
59 
60  /**
61  * Adds a list of mime types to be shown by the filter.
62  *
63  * @param mimeTypes A list of mime types to be shown.
64  */
65  void addMimeTypeFilters(const QStringList &mimeTypes);
66 
67  /**
68  * Adds a mime type to be shown by the filter.
69  *
70  * @param mimeType A mime type to be shown.
71  */
72  void addMimeTypeFilter(const QString &mimeType);
73 
74  /**
75  * Returns the list of mime type filters.
76  */
77  Q_REQUIRED_RESULT QStringList mimeTypeFilters() const;
78 
79  /**
80  * Sets whether we want virtual collections to be filtered or not.
81  * By default, virtual collections are accepted.
82  *
83  * @param exclude If true, virtual collections aren't accepted.
84  *
85  * @since 4.7
86  */
87  void setExcludeVirtualCollections(bool exclude);
88  /*
89  * @since 4.12
90  */
91  Q_REQUIRED_RESULT bool excludeVirtualCollections() const;
92 
93  /**
94  * Clears all mime type filters.
95  */
96  void clearFilters();
97 
98  Q_REQUIRED_RESULT Qt::ItemFlags flags(const QModelIndex &index) const override;
99 
100 protected:
101  bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
102 
103 private:
104  /// @cond PRIVATE
105  friend class CollectionFilterProxyModelPrivate;
106  std::unique_ptr<CollectionFilterProxyModelPrivate> const d;
107  /// @endcond
108 };
109 
110 }
111 
A proxy model that filters collections by mime type.
typedef ItemFlags
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jun 30 2022 03:51:45 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.