Akonadi

selectionproxymodel.h
1/*
2 SPDX-FileCopyrightText: 2009 Stephen Kelly <steveire@gmail.com>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include <KSelectionProxyModel>
10
11#include "akonadicore_export.h"
12
13#include <memory>
14
15namespace Akonadi
16{
17class SelectionProxyModelPrivate;
18
19/**
20 * @short A proxy model used to reference count selected Akonadi::Collection in a view
21 *
22 * Only selected Collections will be populated and monitored for changes. Unselected
23 * Collections will be ignored.
24 *
25 * This model extends KSelectionProxyModel to implement reference counting on the Collections
26 * in an EntityTreeModel. The EntityTreeModel must use LazyPopulation to enable
27 * SelectionProxyModel to work.
28 *
29 * By selecting a Collection, its reference count will be increased. A Collection in the
30 * EntityTreeModel which has a reference count of zero will ignore all signals from Monitor
31 * about items changed, inserted, removed etc, which can be expensive operations.
32 *
33 * Example:
34 *
35 * @code
36 *
37 * using namespace Akonadi;
38 *
39 * // itemView
40 * // ^
41 * // |
42 * // itemModel
43 * // |
44 * // flatModel
45 * // |
46 * // collectionView --> selectionModel
47 * // ^ ^
48 * // | |
49 * // collectionFilter |
50 * // \______________model
51 *
52 * EntityTreeModel *model = new EntityTreeModel( ... );
53 *
54 * // setup collection model
55 * EntityMimeTypeFilterModel *collectionFilter = new EntityMimeTypeFilterModel( this );
56 * collectionFilter->setSourceModel( model );
57 * collectionFilter->addMimeTypeInclusionFilter( Collection::mimeType() );
58 * collectionFilter->setHeaderGroup( EntityTreeModel::CollectionTreeHeaders );
59 *
60 * // setup collection view
61 * EntityTreeView *collectionView = new EntityTreeView( this );
62 * collectionView->setModel( collectionFilter );
63 *
64 * // setup selection model
65 * SelectionProxyModel *selectionModel = new SelectionProxyModel( collectionView->selectionModel(), this );
66 * selectionModel->setSourceModel( model );
67 *
68 * // setup item model
69 * KDescendantsProxyModel *flatModel = new KDescendantsProxyModel( this );
70 * flatModel->setSourceModel( selectionModel );
71 *
72 * EntityMimeTypeFilterModel *itemModel = new EntityMimeTypeFilterModel( this );
73 * itemModel->setSourceModel( flatModel );
74 * itemModel->setHeaderGroup( EntityTreeModel::ItemListHeaders );
75 * itemModel->addMimeTypeExclusionFilter( Collection::mimeType() );
76 *
77 * EntityListView *itemView = new EntityListView( this );
78 * itemView->setModel( itemModel );
79 * @endcode
80 *
81 * See \ref libakonadi_integration "Integration in your Application" for further guidance on the use of this class.
82
83 * @author Stephen Kelly <steveire@gmail.com>
84 * @since 4.4
85 */
86class AKONADICORE_EXPORT SelectionProxyModel : public KSelectionProxyModel
87{
88 Q_OBJECT
89
90public:
91 /**
92 * Creates a new selection proxy model.
93 *
94 * @param selectionModel The selection model of the source view.
95 * @param parent The parent object.
96 */
97 explicit SelectionProxyModel(QItemSelectionModel *selectionModel, QObject *parent = nullptr);
98 ~SelectionProxyModel() override;
99
100private:
101 /// @cond PRIVATE
102 Q_DECLARE_PRIVATE(SelectionProxyModel)
103 std::unique_ptr<SelectionProxyModelPrivate> const d_ptr;
104
105 Q_PRIVATE_SLOT(d_func(), void rootIndexAdded(const QModelIndex &))
106 Q_PRIVATE_SLOT(d_func(), void rootIndexAboutToBeRemoved(const QModelIndex &))
107 /// @endcond
108};
109
110}
A proxy model used to reference count selected Akonadi::Collection in a view.
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:13:38 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.