File indexing completed on 2024-06-23 05:06:41
0001 /* 0002 SPDX-FileCopyrightText: 2007 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include "akonadicore_export.h" 0010 #include <QSortFilterProxyModel> 0011 0012 #include <memory> 0013 0014 namespace Akonadi 0015 { 0016 class AgentFilterProxyModelPrivate; 0017 0018 /** 0019 * @short A proxy model for filtering AgentType or AgentInstance 0020 * 0021 * This filter proxy model works on top of a AgentTypeModel or AgentInstanceModel 0022 * and can be used to show only AgentType or AgentInstance objects 0023 * which provide a given mime type or capability. 0024 * 0025 * @code 0026 * 0027 * // Show only running agent instances that provide contacts 0028 * Akonadi::AgentInstanceModel *model = new Akonadi::AgentInstanceModel( this ); 0029 * 0030 * Akonadi::AgentFilterProxyModel *proxy = new Akonadi::AgentFilterProxyModel( this ); 0031 * proxy->addMimeTypeFilter( "text/directory" ); 0032 * 0033 * proxy->setSourceModel( model ); 0034 * 0035 * QListView *view = new QListView( this ); 0036 * view->setModel( proxy ); 0037 * 0038 * @endcode 0039 * 0040 * @author Volker Krause <vkrause@kde.org> 0041 */ 0042 class AKONADICORE_EXPORT AgentFilterProxyModel : public QSortFilterProxyModel 0043 { 0044 Q_OBJECT 0045 public: 0046 /** 0047 * Create a new agent filter proxy model. 0048 * By default no filtering is done. 0049 * @param parent parent object 0050 */ 0051 explicit AgentFilterProxyModel(QObject *parent = nullptr); 0052 0053 /** 0054 * Destroys the agent filter proxy model. 0055 */ 0056 ~AgentFilterProxyModel() override; 0057 0058 /** 0059 * Accept agents supporting @p mimeType. 0060 */ 0061 void addMimeTypeFilter(const QString &mimeType); 0062 0063 /** 0064 * Accept agents with the given @p capability. 0065 */ 0066 void addCapabilityFilter(const QString &capability); 0067 0068 /** 0069 * Clear the filters ( mimeTypes & capabilities ). 0070 */ 0071 void clearFilters(); 0072 0073 /** 0074 * Excludes agents with the given @p capability. 0075 * @param capability undesired agent capability 0076 * @since 4.6 0077 */ 0078 void excludeCapabilities(const QString &capability); 0079 0080 protected: 0081 bool filterAcceptsRow(int row, const QModelIndex &parent) const override; 0082 0083 private: 0084 /// @cond PRIVATE 0085 std::unique_ptr<AgentFilterProxyModelPrivate> const d; 0086 /// @endcond 0087 }; 0088 0089 }