Akonadi Contacts

collectionfiltermodel.cpp
1/*
2 This file is part of Akonadi Contact.
3
4 SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org>
5
6 SPDX-License-Identifier: LGPL-2.0-or-later
7*/
8
9#include "collectionfiltermodel_p.h"
10
11#include <Akonadi/EntityTreeModel>
12
13CollectionFilterModel::CollectionFilterModel(QObject *parent)
14 : QSortFilterProxyModel(parent)
15 , mRights(Akonadi::Collection::ReadOnly)
16{
17}
18
19void CollectionFilterModel::addContentMimeTypeFilter(const QString &mimeType)
20{
21 mContentMimeTypes.insert(mimeType);
22 invalidateFilter();
23}
24
25void CollectionFilterModel::setRightsFilter(Akonadi::Collection::Rights rights)
26{
27 mRights = rights;
28 invalidateFilter();
29}
30
31bool 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"
A widget for editing the display name of a contact.
QVariant data(int role) const const
bool intersects(const QSet< T > &other) const const
T value() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:05:46 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.