Akonadi

trashfilterproxymodel.cpp
1 /*
2  SPDX-FileCopyrightText: 2011 Christian Mollekopf <[email protected]>
3 
4  SPDX-License-Identifier: LGPL-2.0-or-later
5 */
6 #include "trashfilterproxymodel.h"
7 #include "entitydeletedattribute.h"
8 #include "entitytreemodel.h"
9 #include "item.h"
10 
11 using namespace Akonadi;
12 
13 class Akonadi::TrashFilterProxyModelPrivate
14 {
15 public:
16  TrashFilterProxyModelPrivate()
17  {
18  }
19  bool mTrashIsShown = false;
20 };
21 
22 TrashFilterProxyModel::TrashFilterProxyModel(QObject *parent)
23  : QSortFilterProxyModel(parent)
24  , d_ptr(new TrashFilterProxyModelPrivate())
25 {
26  setRecursiveFilteringEnabled(true);
27 }
28 
29 TrashFilterProxyModel::~TrashFilterProxyModel() = default;
30 
31 void TrashFilterProxyModel::showTrash(bool enable)
32 {
34  d->mTrashIsShown = enable;
36 }
37 
38 bool TrashFilterProxyModel::trashIsShown() const
39 {
41  return d->mTrashIsShown;
42 }
43 
44 bool TrashFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
45 {
47  const QModelIndex &index = sourceModel()->index(sourceRow, 0, sourceParent);
49  if (item.isValid()) {
51  return d->mTrashIsShown;
52  }
53  }
55  if (collection.isValid()) {
56  if (collection.hasAttribute<EntityDeletedAttribute>()) {
57  return d->mTrashIsShown;
58  }
59  }
60  return !d->mTrashIsShown;
61 }
bool isValid() const
Returns whether the item is valid.
Definition: item.cpp:88
Filter model which hides/shows entities marked as trash.
T value() const const
Represents a collection of PIM items.
Definition: collection.h:61
QVariant data(int role) const const
@ CollectionRole
The collection.
bool hasAttribute(const QByteArray &name) const
Returns true if the collection has an attribute of the given type name, false otherwise.
Definition: collection.cpp:161
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const const override
bool hasAttribute(const QByteArray &name) const
Returns true if the item has an attribute of the given type name, false otherwise.
Definition: item.cpp:128
An Attribute that marks that an entity was marked as deleted.
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
Sort filter criteria, according to how expensive the operation is.
Represents a PIM item stored in Akonadi storage.
Definition: item.h:104
Q_D(Todo)
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jun 25 2022 06:00:33 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.