Akonadi

selectionproxymodel.cpp
1 /*
2  SPDX-FileCopyrightText: 2009 Stephen Kelly <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 
7 #include "selectionproxymodel.h"
8 
9 #include "entitytreemodel.h"
10 
11 using namespace Akonadi;
12 
13 namespace Akonadi
14 {
15 class SelectionProxyModelPrivate
16 {
17 public:
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 
70 SelectionProxyModel::~SelectionProxyModel() = default;
71 
72 #include "moc_selectionproxymodel.cpp"
A proxy model used to reference count selected Akonadi::Collection in a view.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
void rootIndexAdded(const QModelIndex &newIndex, QPrivateSignal)
void rootIndexAboutToBeRemoved(const QModelIndex &removeRootIndex, QPrivateSignal)
SelectionProxyModel(QItemSelectionModel *selectionModel, QObject *parent=nullptr)
Creates a new selection proxy model.
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jun 30 2022 03:51:46 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.