Akonadi

trashfilterproxymodel.cpp
1 /*
2  Copyright (c) 2011 Christian Mollekopf <[email protected]>
3 
4  This library is free software; you can redistribute it and/or modify it
5  under the terms of the GNU Library General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or (at your
7  option) any later version.
8 
9  This library is distributed in the hope that it will be useful, but WITHOUT
10  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
12  License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to the
16  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  02110-1301, USA.
18 */
19 #include "trashfilterproxymodel.h"
20 #include "entitydeletedattribute.h"
21 #include "item.h"
22 #include "entitytreemodel.h"
23 
24 using namespace Akonadi;
25 
26 class TrashFilterProxyModel::TrashFilterProxyModelPrivate
27 {
28 public:
29  TrashFilterProxyModelPrivate()
30  {
31  }
32  bool mTrashIsShown = false;
33 };
34 
35 TrashFilterProxyModel::TrashFilterProxyModel(QObject *parent)
36  : QSortFilterProxyModel(parent)
37  , d_ptr(new TrashFilterProxyModelPrivate())
38 {
39  setRecursiveFilteringEnabled(true);
40 }
41 
42 TrashFilterProxyModel::~TrashFilterProxyModel()
43 {
44  delete d_ptr;
45 }
46 
47 void TrashFilterProxyModel::showTrash(bool enable)
48 {
50  d->mTrashIsShown = enable;
51  invalidateFilter();
52 }
53 
54 bool TrashFilterProxyModel::trashIsShown() const
55 {
56  Q_D(const TrashFilterProxyModel);
57  return d->mTrashIsShown;
58 }
59 
60 bool TrashFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
61 {
62  Q_D(const TrashFilterProxyModel);
63  const QModelIndex &index = sourceModel()->index(sourceRow, 0, sourceParent);
64  const Item &item = index.data(EntityTreeModel::ItemRole).value<Item>();
65  if (item.isValid()) {
66  if (item.hasAttribute<EntityDeletedAttribute>()) {
67  return d->mTrashIsShown;
68  }
69  }
70  const Collection &collection = index.data(EntityTreeModel::CollectionRole).value<Collection>();
71  if (collection.isValid()) {
72  if (collection.hasAttribute<EntityDeletedAttribute>()) {
73  return d->mTrashIsShown;
74  }
75  }
76  return !d->mTrashIsShown;
77 }
bool isValid() const
Returns whether the collection is valid.
Definition: collection.cpp:137
Represents a collection of PIM items.
Definition: collection.h:76
T value() const const
bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override
Sort filter criterias, according to how expensive the operation is.
An Attribute that marks that an entity was marked as deleted.
bool hasAttribute(const QByteArray &name) const
Returns true if the collection has an attribute of the given type name, false otherwise.
Definition: collection.cpp:177
QVariant data(int role) const const
Helper integration between Akonadi and Qt.
Filter model which hides/shows entities marked as trash.
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jun 5 2020 23:08:56 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.