File indexing completed on 2024-06-23 05:06:42
0001 /* 0002 SPDX-FileCopyrightText: 2007 Bruno Virlet <bruno.virlet@gmail.com> 0003 SPDX-FileCopyrightText: 2009 Stephen Kelly <steveire@gmail.com> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #pragma once 0009 0010 #include "akonadicore_export.h" 0011 #include "entitytreemodel.h" 0012 0013 #include <QSortFilterProxyModel> 0014 0015 #include <memory> 0016 0017 namespace Akonadi 0018 { 0019 class EntityMimeTypeFilterModelPrivate; 0020 0021 /** 0022 * @short A proxy model that filters entities by mime type. 0023 * 0024 * This class can be used on top of an EntityTreeModel to exclude entities by mimetype 0025 * or to include only certain mimetypes. 0026 * 0027 * @code 0028 * 0029 * Akonadi::EntityTreeModel *model = new Akonadi::EntityTreeModel( this ); 0030 * 0031 * Akonadi::EntityMimeTypeFilterModel *proxy = new Akonadi::EntityMimeTypeFilterModel(); 0032 * proxy->addMimeTypeInclusionFilter( "message/rfc822" ); 0033 * proxy->setSourceModel( model ); 0034 * 0035 * Akonadi::EntityTreeView *view = new Akonadi::EntityTreeView( this ); 0036 * view->setModel( proxy ); 0037 * 0038 * @endcode 0039 * 0040 * @li If a mimetype is in both the exclusion list and the inclusion list, it is excluded. 0041 * @li If the mimeTypeInclusionFilter is empty, all mimetypes are 0042 * accepted (except if they are in the exclusion filter of course). 0043 * 0044 * 0045 * @author Bruno Virlet <bruno.virlet@gmail.com> 0046 * @author Stephen Kelly <steveire@gmail.com> 0047 * @since 4.4 0048 */ 0049 class AKONADICORE_EXPORT EntityMimeTypeFilterModel : public QSortFilterProxyModel 0050 { 0051 Q_OBJECT 0052 0053 public: 0054 /** 0055 * Creates a new entity mime type filter model. 0056 * 0057 * @param parent The parent object. 0058 */ 0059 explicit EntityMimeTypeFilterModel(QObject *parent = nullptr); 0060 0061 /** 0062 * Destroys the entity mime type filter model. 0063 */ 0064 ~EntityMimeTypeFilterModel() override; 0065 0066 /** 0067 * Add mime types to be shown by the filter. 0068 * 0069 * @param mimeTypes A list of mime types to be included. 0070 */ 0071 void addMimeTypeInclusionFilters(const QStringList &mimeTypes); 0072 0073 /** 0074 * Add mimetypes to filter out 0075 * 0076 * @param mimeTypes A list to exclude from the model. 0077 */ 0078 void addMimeTypeExclusionFilters(const QStringList &mimeTypes); 0079 0080 /** 0081 * Add mime type to be shown by the filter. 0082 * 0083 * @param mimeType A mime type to be shown. 0084 */ 0085 void addMimeTypeInclusionFilter(const QString &mimeType); 0086 0087 /** 0088 * Add mime type to be excluded by the filter. 0089 * 0090 * @param mimeType A mime type to be excluded. 0091 */ 0092 void addMimeTypeExclusionFilter(const QString &mimeType); 0093 0094 /** 0095 * Returns the list of mime type inclusion filters. 0096 */ 0097 [[nodiscard]] QStringList mimeTypeInclusionFilters() const; 0098 0099 /** 0100 * Returns the list of mime type exclusion filters. 0101 */ 0102 [[nodiscard]] QStringList mimeTypeExclusionFilters() const; 0103 0104 /** 0105 * Clear all mime type filters. 0106 */ 0107 void clearFilters(); 0108 0109 /** 0110 * Sets the header @p set of the filter model. 0111 * @param headerGroup the header to set. 0112 * \sa EntityTreeModel::HeaderGroup 0113 */ 0114 void setHeaderGroup(EntityTreeModel::HeaderGroup headerGroup); 0115 0116 QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; 0117 0118 [[nodiscard]] bool hasChildren(const QModelIndex &parent = QModelIndex()) const override; 0119 0120 [[nodiscard]] bool canFetchMore(const QModelIndex &parent) const override; 0121 0122 [[nodiscard]] QModelIndexList match(const QModelIndex &start, 0123 int role, 0124 const QVariant &value, 0125 int hits = 1, 0126 Qt::MatchFlags flags = Qt::MatchFlags(Qt::MatchStartsWith | Qt::MatchWrap)) const override; 0127 0128 [[nodiscard]] int columnCount(const QModelIndex &parent = QModelIndex()) const override; 0129 0130 protected: 0131 bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override; 0132 bool filterAcceptsColumn(int sourceColumn, const QModelIndex &sourceParent) const override; 0133 0134 private: 0135 /// @cond PRIVATE 0136 Q_DECLARE_PRIVATE(EntityMimeTypeFilterModel) 0137 std::unique_ptr<EntityMimeTypeFilterModelPrivate> const d_ptr; 0138 /// @endcond 0139 }; 0140 0141 }