Akonadi

selectionproxymodel.cpp
1/*
2 SPDX-FileCopyrightText: 2009 Stephen Kelly <steveire@gmail.com>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "selectionproxymodel.h"
8
9#include "entitytreemodel.h"
10
11using namespace Akonadi;
12
13namespace Akonadi
14{
15class SelectionProxyModelPrivate
16{
17public:
18 explicit SelectionProxyModelPrivate(SelectionProxyModel *selectionProxyModel)
19 : q_ptr(selectionProxyModel)
20 {
22 const auto indexes = q->sourceRootIndexes();
23 for (const auto &rootIndex : indexes) {
24 rootIndexAdded(rootIndex);
25 }
26 }
27 ~SelectionProxyModelPrivate()
28 {
30 const auto indexes = q->sourceRootIndexes();
31 for (const auto &rootIndex : indexes) {
32 rootIndexAboutToBeRemoved(rootIndex);
33 }
34 }
35
36 /**
37 Increases the refcount of the Collection in @p newRootIndex
38 */
39 void rootIndexAdded(const QModelIndex &newRootIndex)
40 {
42 // newRootIndex is already in the sourceModel.
43 q->sourceModel()->setData(newRootIndex, QVariant(), EntityTreeModel::CollectionRefRole);
44 q->sourceModel()->fetchMore(newRootIndex);
45 }
46
47 /**
48 Decreases the refcount of the Collection in @p removedRootIndex
49 */
50 void rootIndexAboutToBeRemoved(const QModelIndex &removedRootIndex)
51 {
53 q->sourceModel()->setData(removedRootIndex, QVariant(), EntityTreeModel::CollectionDerefRole);
54 }
55
56 Q_DECLARE_PUBLIC(SelectionProxyModel)
57 SelectionProxyModel *const q_ptr;
58};
59
60} // namespace Akonadi
61
63 : KSelectionProxyModel(selectionModel, parent)
64 , d_ptr(new SelectionProxyModelPrivate(this))
65{
66 connect(this, SIGNAL(rootIndexAdded(QModelIndex)), SLOT(rootIndexAdded(QModelIndex))); // clazy:exclude=old-style-connect
67 connect(this, SIGNAL(rootIndexAboutToBeRemoved(QModelIndex)), SLOT(rootIndexAboutToBeRemoved(QModelIndex))); // clazy:exclude=old-style-connect
68}
69
70SelectionProxyModel::~SelectionProxyModel() = default;
71
72#include "moc_selectionproxymodel.cpp"
A proxy model used to reference count selected Akonadi::Collection in a view.
SelectionProxyModel(QItemSelectionModel *selectionModel, QObject *parent=nullptr)
Creates a new selection proxy model.
void rootIndexAdded(const QModelIndex &newIndex, QPrivateSignal)
void rootIndexAboutToBeRemoved(const QModelIndex &removeRootIndex, QPrivateSignal)
Helper integration between Akonadi and Qt.
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 26 2024 11:52:52 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.