Akonadi

entitymimetypefiltermodel.h
1/*
2 SPDX-FileCopyrightText: 2007 Bruno Virlet <bruno.virlet@gmail.com>
3 SPDX-FileCopyrightText: 2009 Stephen Kelly <steveire@gmail.com>
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
17namespace Akonadi
18{
19class 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 <bruno.virlet@gmail.com>
46 * @author Stephen Kelly <steveire@gmail.com>
47 * @since 4.4
48 */
49class AKONADICORE_EXPORT EntityMimeTypeFilterModel : public QSortFilterProxyModel
50{
52
53public:
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 */
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 */
72
73 /**
74 * Add mimetypes to filter out
75 *
76 * @param mimeTypes A list to exclude from the model.
77 */
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 [[nodiscard]] QStringList mimeTypeInclusionFilters() const;
98
99 /**
100 * Returns the list of mime type exclusion filters.
101 */
102 [[nodiscard]] 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 */
115
116 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
117
118 [[nodiscard]] bool hasChildren(const QModelIndex &parent = QModelIndex()) const override;
119
120 [[nodiscard]] bool canFetchMore(const QModelIndex &parent) const override;
121
122 [[nodiscard]] QModelIndexList match(const QModelIndex &start,
123 int role,
124 const QVariant &value,
125 int hits = 1,
127
128 [[nodiscard]] int columnCount(const QModelIndex &parent = QModelIndex()) const override;
129
130protected:
131 bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
132 bool filterAcceptsColumn(int sourceColumn, const QModelIndex &sourceParent) const override;
133
134private:
135 /// @cond PRIVATE
136 Q_DECLARE_PRIVATE(EntityMimeTypeFilterModel)
137 std::unique_ptr<EntityMimeTypeFilterModelPrivate> const d_ptr;
138 /// @endcond
139};
140
141}
void setHeaderGroup(EntityTreeModel::HeaderGroup headerGroup)
Sets the header set of the filter model.
QStringList mimeTypeInclusionFilters() const
Returns the list of mime type inclusion filters.
void addMimeTypeInclusionFilter(const QString &mimeType)
Add mime type to be shown by the filter.
void addMimeTypeExclusionFilter(const QString &mimeType)
Add mime type to be excluded by the filter.
void addMimeTypeInclusionFilters(const QStringList &mimeTypes)
Add mime types to be shown by the filter.
~EntityMimeTypeFilterModel() override
Destroys the entity mime type filter model.
void clearFilters()
Clear all mime type filters.
EntityMimeTypeFilterModel(QObject *parent=nullptr)
Creates a new entity mime type filter model.
QStringList mimeTypeExclusionFilters() const
Returns the list of mime type exclusion filters.
void addMimeTypeExclusionFilters(const QStringList &mimeTypes)
Add mimetypes to filter out.
HeaderGroup
Describes what header information the model shall return.
Q_SCRIPTABLE QString start(QString train="")
Helper integration between Akonadi and Qt.
Q_OBJECTQ_OBJECT
QSortFilterProxyModel(QObject *parent)
virtual Qt::ItemFlags flags(const QModelIndex &index) const const override
virtual QStringList mimeTypes() const const override
virtual QModelIndex parent(const QModelIndex &child) const const override
DisplayRole
typedef MatchFlags
Orientation
This file is part of the KDE documentation.
Documentation copyright © 1996-2025 The KDE developers.
Generated on Fri May 2 2025 11:53:09 by doxygen 1.13.2 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.