Akonadi

recursivecollectionfilterproxymodel.cpp
1/*
2 SPDX-FileCopyrightText: 2009 Stephen Kelly <steveire@gmail.com>
3 SPDX-FileCopyrightText: 2012-2024 Laurent Montel <montel@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "recursivecollectionfilterproxymodel.h"
9
10#include "collectionutils.h"
11#include "entitytreemodel.h"
12#include "mimetypechecker.h"
13
14using namespace Akonadi;
15
16namespace Akonadi
17{
18class RecursiveCollectionFilterProxyModelPrivate
19{
22
23public:
24 explicit RecursiveCollectionFilterProxyModelPrivate(RecursiveCollectionFilterProxyModel *model)
25 : q_ptr(model)
26 {
27 }
28
29 QSet<QString> includedMimeTypes;
31 QString pattern;
32 bool checkOnlyChecked = false;
33 bool excludeUnifiedMailBox = false;
34};
35
36} // namespace Akonadi
37
39 : QSortFilterProxyModel(parent)
40 , d_ptr(new RecursiveCollectionFilterProxyModelPrivate(this))
41{
43}
44
46
47bool RecursiveCollectionFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const
48{
50
51 const QModelIndex rowIndex = sourceModel()->index(sourceRow, 0, sourceParent);
53 if (!collection.isValid()) {
54 return false;
55 }
56 if (CollectionUtils::isUnifiedMailbox(collection)) {
57 return false;
58 }
59 const bool checked = (rowIndex.data(Qt::CheckStateRole).toInt() == Qt::Checked);
60 const bool isCheckable = sourceModel()->flags(rowIndex) & Qt::ItemIsUserCheckable;
61 if (isCheckable && (d->checkOnlyChecked && !checked)) {
62 return false;
63 }
64
65 const bool collectionWanted = d->checker.isWantedCollection(collection);
66 if (collectionWanted) {
67 if (!d->pattern.isEmpty()) {
68 const QString text = rowIndex.data(Qt::DisplayRole).toString();
69 return text.contains(d->pattern, Qt::CaseInsensitive);
70 }
71 }
72 return collectionWanted;
73}
74
76{
78 d->includedMimeTypes << mimeType;
79 d->checker.setWantedMimeTypes(d->includedMimeTypes.values());
81}
82
84{
86 d->includedMimeTypes.unite(QSet<QString>(mimeTypes.begin(), mimeTypes.end()));
87 d->checker.setWantedMimeTypes(d->includedMimeTypes.values());
89}
90
92{
94 d->includedMimeTypes.clear();
95 d->checker.setWantedMimeTypes(QStringList());
97}
98
100{
102 d->includedMimeTypes = QSet<QString>(mimeTypes.begin(), mimeTypes.end());
103 d->checker.setWantedMimeTypes(d->includedMimeTypes.values());
105}
106
112
113int Akonadi::RecursiveCollectionFilterProxyModel::columnCount(const QModelIndex &index) const
114{
115 // Optimization: we know that we're not changing the number of columns, so skip QSortFilterProxyModel
116 return sourceModel()->columnCount(mapToSource(index));
117}
118
120{
122 if (d->pattern != pattern) {
123 d->pattern = pattern;
124 invalidate();
125 }
126}
127
129{
131 if (d->checkOnlyChecked != checked) {
132 d->checkOnlyChecked = checked;
133 invalidate();
134 }
135}
136
138{
140 if (d->excludeUnifiedMailBox != exclude) {
141 d->excludeUnifiedMailBox = exclude;
142 invalidate();
143 }
144}
145
146#include "moc_recursivecollectionfilterproxymodel.cpp"
Represents a collection of PIM items.
Definition collection.h:62
@ CollectionRole
The collection.
Helper for checking MIME types of Collections and Items.
A model to filter out collections of non-matching content types.
void setSearchPattern(const QString &pattern)
Add search pattern.
void setIncludeCheckedOnly(bool checked)
Show only checked item.
void addContentMimeTypeInclusionFilters(const QStringList &mimeTypes)
Add content mime types to be shown by the filter.
void setContentMimeTypeInclusionFilters(const QStringList &mimeTypes)
Replace the content mime types to be shown by the filter.
RecursiveCollectionFilterProxyModel(QObject *parent=nullptr)
Creates a new recursive collection filter proxy model.
QStringList contentMimeTypeInclusionFilters() const
Returns the currently included mimetypes in the filter.
~RecursiveCollectionFilterProxyModel() override
Destroys the recursive collection filter proxy model.
void addContentMimeTypeInclusionFilter(const QString &mimeType)
Add content mime type to be shown by the filter.
void setExcludeUnifiedMailBox(bool exclude)
Don't show unified mailbox.
Helper integration between Akonadi and Qt.
iterator begin()
iterator end()
QVariant data(int role) const const
virtual QStringList mimeTypes() const const override
void setRecursiveFilteringEnabled(bool recursive)
bool contains(QChar ch, Qt::CaseSensitivity cs) const const
CaseInsensitive
CheckStateRole
ItemIsUserCheckable
QString toString() const const
T value() const const
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:29 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.