File indexing completed on 2024-09-22 04:41:03
0001 /* 0002 SPDX-FileCopyrightText: 2009 Stephen Kelly <steveire@gmail.com> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <KSelectionProxyModel> 0010 0011 #include "akonadicore_export.h" 0012 0013 #include <memory> 0014 0015 namespace Akonadi 0016 { 0017 class SelectionProxyModelPrivate; 0018 0019 /** 0020 * @short A proxy model used to reference count selected Akonadi::Collection in a view 0021 * 0022 * Only selected Collections will be populated and monitored for changes. Unselected 0023 * Collections will be ignored. 0024 * 0025 * This model extends KSelectionProxyModel to implement reference counting on the Collections 0026 * in an EntityTreeModel. The EntityTreeModel must use LazyPopulation to enable 0027 * SelectionProxyModel to work. 0028 * 0029 * By selecting a Collection, its reference count will be increased. A Collection in the 0030 * EntityTreeModel which has a reference count of zero will ignore all signals from Monitor 0031 * about items changed, inserted, removed etc, which can be expensive operations. 0032 * 0033 * Example: 0034 * 0035 * @code 0036 * 0037 * using namespace Akonadi; 0038 * 0039 * // itemView 0040 * // ^ 0041 * // | 0042 * // itemModel 0043 * // | 0044 * // flatModel 0045 * // | 0046 * // collectionView --> selectionModel 0047 * // ^ ^ 0048 * // | | 0049 * // collectionFilter | 0050 * // \______________model 0051 * 0052 * EntityTreeModel *model = new EntityTreeModel( ... ); 0053 * 0054 * // setup collection model 0055 * EntityMimeTypeFilterModel *collectionFilter = new EntityMimeTypeFilterModel( this ); 0056 * collectionFilter->setSourceModel( model ); 0057 * collectionFilter->addMimeTypeInclusionFilter( Collection::mimeType() ); 0058 * collectionFilter->setHeaderGroup( EntityTreeModel::CollectionTreeHeaders ); 0059 * 0060 * // setup collection view 0061 * EntityTreeView *collectionView = new EntityTreeView( this ); 0062 * collectionView->setModel( collectionFilter ); 0063 * 0064 * // setup selection model 0065 * SelectionProxyModel *selectionModel = new SelectionProxyModel( collectionView->selectionModel(), this ); 0066 * selectionModel->setSourceModel( model ); 0067 * 0068 * // setup item model 0069 * KDescendantsProxyModel *flatModel = new KDescendantsProxyModel( this ); 0070 * flatModel->setSourceModel( selectionModel ); 0071 * 0072 * EntityMimeTypeFilterModel *itemModel = new EntityMimeTypeFilterModel( this ); 0073 * itemModel->setSourceModel( flatModel ); 0074 * itemModel->setHeaderGroup( EntityTreeModel::ItemListHeaders ); 0075 * itemModel->addMimeTypeExclusionFilter( Collection::mimeType() ); 0076 * 0077 * EntityListView *itemView = new EntityListView( this ); 0078 * itemView->setModel( itemModel ); 0079 * @endcode 0080 * 0081 * See \ref libakonadi_integration "Integration in your Application" for further guidance on the use of this class. 0082 0083 * @author Stephen Kelly <steveire@gmail.com> 0084 * @since 4.4 0085 */ 0086 class AKONADICORE_EXPORT SelectionProxyModel : public KSelectionProxyModel 0087 { 0088 Q_OBJECT 0089 0090 public: 0091 /** 0092 * Creates a new selection proxy model. 0093 * 0094 * @param selectionModel The selection model of the source view. 0095 * @param parent The parent object. 0096 */ 0097 explicit SelectionProxyModel(QItemSelectionModel *selectionModel, QObject *parent = nullptr); 0098 ~SelectionProxyModel() override; 0099 0100 private: 0101 /// @cond PRIVATE 0102 Q_DECLARE_PRIVATE(SelectionProxyModel) 0103 std::unique_ptr<SelectionProxyModelPrivate> const d_ptr; 0104 0105 Q_PRIVATE_SLOT(d_func(), void rootIndexAdded(const QModelIndex &)) 0106 Q_PRIVATE_SLOT(d_func(), void rootIndexAboutToBeRemoved(const QModelIndex &)) 0107 /// @endcond 0108 }; 0109 0110 }