Akonadi

entitymimetypefiltermodel.h
1 /*
2  SPDX-FileCopyrightText: 2007 Bruno Virlet <[email protected]>
3  SPDX-FileCopyrightText: 2009 Stephen Kelly <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #pragma once
9 
10 #include "akonadicore_export.h"
11 #include "entitytreemodel.h"
12 
13 #include <QSortFilterProxyModel>
14 
15 #include <memory>
16 
17 namespace Akonadi
18 {
19 class EntityMimeTypeFilterModelPrivate;
20 
21 /**
22  * @short A proxy model that filters entities by mime type.
23  *
24  * This class can be used on top of an EntityTreeModel to exclude entities by mimetype
25  * or to include only certain mimetypes.
26  *
27  * @code
28  *
29  * Akonadi::EntityTreeModel *model = new Akonadi::EntityTreeModel( this );
30  *
31  * Akonadi::EntityMimeTypeFilterModel *proxy = new Akonadi::EntityMimeTypeFilterModel();
32  * proxy->addMimeTypeInclusionFilter( "message/rfc822" );
33  * proxy->setSourceModel( model );
34  *
35  * Akonadi::EntityTreeView *view = new Akonadi::EntityTreeView( this );
36  * view->setModel( proxy );
37  *
38  * @endcode
39  *
40  * @li If a mimetype is in both the exclusion list and the inclusion list, it is excluded.
41  * @li If the mimeTypeInclusionFilter is empty, all mimetypes are
42  * accepted (except if they are in the exclusion filter of course).
43  *
44  *
45  * @author Bruno Virlet <[email protected]>
46  * @author Stephen Kelly <[email protected]>
47  * @since 4.4
48  */
49 class AKONADICORE_EXPORT EntityMimeTypeFilterModel : public QSortFilterProxyModel
50 {
51  Q_OBJECT
52 
53 public:
54  /**
55  * Creates a new entity mime type filter model.
56  *
57  * @param parent The parent object.
58  */
59  explicit EntityMimeTypeFilterModel(QObject *parent = nullptr);
60 
61  /**
62  * Destroys the entity mime type filter model.
63  */
64  ~EntityMimeTypeFilterModel() override;
65 
66  /**
67  * Add mime types to be shown by the filter.
68  *
69  * @param mimeTypes A list of mime types to be included.
70  */
71  void addMimeTypeInclusionFilters(const QStringList &mimeTypes);
72 
73  /**
74  * Add mimetypes to filter out
75  *
76  * @param mimeTypes A list to exclude from the model.
77  */
78  void addMimeTypeExclusionFilters(const QStringList &mimeTypes);
79 
80  /**
81  * Add mime type to be shown by the filter.
82  *
83  * @param mimeType A mime type to be shown.
84  */
85  void addMimeTypeInclusionFilter(const QString &mimeType);
86 
87  /**
88  * Add mime type to be excluded by the filter.
89  *
90  * @param mimeType A mime type to be excluded.
91  */
92  void addMimeTypeExclusionFilter(const QString &mimeType);
93 
94  /**
95  * Returns the list of mime type inclusion filters.
96  */
97  Q_REQUIRED_RESULT QStringList mimeTypeInclusionFilters() const;
98 
99  /**
100  * Returns the list of mime type exclusion filters.
101  */
102  Q_REQUIRED_RESULT QStringList mimeTypeExclusionFilters() const;
103 
104  /**
105  * Clear all mime type filters.
106  */
107  void clearFilters();
108 
109  /**
110  * Sets the header @p set of the filter model.
111  * @param headerGroup the header to set.
112  * \sa EntityTreeModel::HeaderGroup
113  */
114  void setHeaderGroup(EntityTreeModel::HeaderGroup headerGroup);
115 
116  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
117 
118  Q_REQUIRED_RESULT bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
119 
120  Q_REQUIRED_RESULT bool canFetchMore(const QModelIndex &parent) const override;
121 
122  Q_REQUIRED_RESULT QModelIndexList match(const QModelIndex &start,
123  int role,
124  const QVariant &value,
125  int hits = 1,
127 
128  Q_REQUIRED_RESULT int columnCount(const QModelIndex &parent = QModelIndex()) const override;
129 
130 protected:
131  bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
132  bool filterAcceptsColumn(int sourceColumn, const QModelIndex &sourceParent) const override;
133 
134 private:
135  /// @cond PRIVATE
136  Q_DECLARE_PRIVATE(EntityMimeTypeFilterModel)
137  std::unique_ptr<EntityMimeTypeFilterModelPrivate> const d_ptr;
138  /// @endcond
139 };
140 
141 }
142 
DisplayRole
Q_SCRIPTABLE Q_NOREPLY void start()
A proxy model that filters entities by mime type.
Orientation
typedef MatchFlags
HeaderGroup
Describes what header information the model shall return.
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jul 2 2022 06:41:47 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.