Akonadi Contacts

collectionfiltermodel.cpp
1 /*
2  This file is part of Akonadi Contact.
3 
4  Copyright (c) 2009 Tobias Koenig <[email protected]>
5 
6  This library is free software; you can redistribute it and/or modify it
7  under the terms of the GNU Library General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or (at your
9  option) any later version.
10 
11  This library is distributed in the hope that it will be useful, but WITHOUT
12  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14  License for more details.
15 
16  You should have received a copy of the GNU Library General Public License
17  along with this library; see the file COPYING.LIB. If not, write to the
18  Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  02110-1301, USA.
20 */
21 
22 #include "collectionfiltermodel_p.h"
23 
24 #include <entitytreemodel.h>
25 
26 CollectionFilterModel::CollectionFilterModel(QObject *parent)
27  : QSortFilterProxyModel(parent)
28  , mRights(Akonadi::Collection::ReadOnly)
29 {
30 }
31 
32 void CollectionFilterModel::addContentMimeTypeFilter(const QString &mimeType)
33 {
34  mContentMimeTypes.insert(mimeType);
35  invalidateFilter();
36 }
37 
38 void CollectionFilterModel::setRightsFilter(Akonadi::Collection::Rights rights)
39 {
40  mRights = rights;
41  invalidateFilter();
42 }
43 
44 bool CollectionFilterModel::filterAcceptsRow(int row, const QModelIndex &parent) const
45 {
46  bool accepted = true;
47 
48  const QModelIndex index = sourceModel()->index(row, 0, parent);
50  if (!collection.isValid()) {
51  return false;
52  }
53 
54  if (!mContentMimeTypes.isEmpty()) {
55 #if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
56  const QSet<QString> contentMimeTypes = collection.contentMimeTypes().toSet();
57 #else
58  const auto collectionMimeTypesSet = collection.contentMimeTypes();
59  const QSet<QString> contentMimeTypes = QSet<QString>(collectionMimeTypesSet.begin(), collectionMimeTypesSet.end());
60 #endif
61  accepted = accepted && contentMimeTypes.intersects(mContentMimeTypes);
62  }
63 
64  if (mRights != Akonadi::Collection::ReadOnly) {
65  accepted = accepted && (collection.rights() & mRights);
66  }
67 
68  return accepted;
69 }
70 
71 #include "moc_collectionfiltermodel_p.cpp"
bool isValid() const
T value() const const
QSet< T > toSet() const const
Rights rights() const
QVariant data(int role) const const
bool intersects(const QSet< T > &other) const const
QStringList contentMimeTypes() const
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jul 3 2020 23:07:31 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.