Akonadi Contacts

collectionfiltermodel.cpp
1 /*
2  This file is part of Akonadi Contact.
3 
4  SPDX-FileCopyrightText: 2009 Tobias Koenig <[email protected]>
5 
6  SPDX-License-Identifier: LGPL-2.0-or-later
7 */
8 
9 #include "collectionfiltermodel_p.h"
10 
11 #include <entitytreemodel.h>
12 
13 CollectionFilterModel::CollectionFilterModel(QObject *parent)
14  : QSortFilterProxyModel(parent)
15  , mRights(Akonadi::Collection::ReadOnly)
16 {
17 }
18 
19 void CollectionFilterModel::addContentMimeTypeFilter(const QString &mimeType)
20 {
21  mContentMimeTypes.insert(mimeType);
22  invalidateFilter();
23 }
24 
25 void CollectionFilterModel::setRightsFilter(Akonadi::Collection::Rights rights)
26 {
27  mRights = rights;
28  invalidateFilter();
29 }
30 
31 bool CollectionFilterModel::filterAcceptsRow(int row, const QModelIndex &parent) const
32 {
33  bool accepted = true;
34 
35  const QModelIndex index = sourceModel()->index(row, 0, parent);
37  if (!collection.isValid()) {
38  return false;
39  }
40 
41  if (!mContentMimeTypes.isEmpty()) {
42  const auto collectionMimeTypesSet = collection.contentMimeTypes();
43  const QSet<QString> contentMimeTypes = QSet<QString>(collectionMimeTypesSet.begin(), collectionMimeTypesSet.end());
44  accepted = accepted && contentMimeTypes.intersects(mContentMimeTypes);
45  }
46 
47  if (mRights != Akonadi::Collection::ReadOnly) {
48  accepted = accepted && (collection.rights() & mRights);
49  }
50 
51  return accepted;
52 }
53 
54 #include "moc_collectionfiltermodel_p.cpp"
T value() const 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-2021 The KDE developers.
Generated on Wed Jun 23 2021 23:09:24 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.