Akonadi

entityrightsfiltermodel.h
1/*
2 SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#pragma once
8
9#include "akonadicore_export.h"
10#include "entitytreemodel.h"
11
12#include <QSortFilterProxyModel>
13
14#include <memory>
15
16namespace Akonadi
17{
18class EntityRightsFilterModelPrivate;
19
20/**
21 * @short A proxy model that filters entities by access rights.
22 *
23 * This class can be used on top of an EntityTreeModel to exclude entities by access type
24 * or to include only certain entities with special access rights.
25 *
26 * @code
27 *
28 * using namespace Akonadi;
29 *
30 * EntityTreeModel *model = new EntityTreeModel( this );
31 *
32 * EntityRightsFilterModel *filter = new EntityRightsFilterModel();
33 * filter->setAccessRights( Collection::CanCreateItem | Collection::CanCreateCollection );
34 * filter->setSourceModel( model );
35 *
36 * EntityTreeView *view = new EntityTreeView( this );
37 * view->setModel( filter );
38 *
39 * @endcode
40 *
41 * @li For collections the access rights are checked against the collections own rights.
42 * @li For items the access rights are checked against the item's parent collection rights.
43 *
44 * @author Tobias Koenig <tokoe@kde.org>
45 * @since 4.6
46 */
47class AKONADICORE_EXPORT EntityRightsFilterModel : public QSortFilterProxyModel
48{
49 Q_OBJECT
50
51public:
52 /**
53 * Creates a new entity rights filter model.
54 *
55 * @param parent The parent object.
56 */
57 explicit EntityRightsFilterModel(QObject *parent = nullptr);
58
59 /**
60 * Destroys the entity rights filter model.
61 */
63
64 /**
65 * Sets the access @p rights the entities shall be filtered
66 * against. If no rights are set explicitly, Collection::AllRights
67 * is assumed.
68 * @param rights the access rights filter values
69 */
70 void setAccessRights(Collection::Rights rights);
71
72 /**
73 * Returns the access rights that are used for filtering.
74 */
75 [[nodiscard]] Collection::Rights accessRights() const;
76
77 /**
78 * @reimp
79 */
80 [[nodiscard]] Qt::ItemFlags flags(const QModelIndex &index) const override;
81
82 /**
83 * @reimp
84 */
85 [[nodiscard]] QModelIndexList match(const QModelIndex &start,
86 int role,
87 const QVariant &value,
88 int hits = 1,
90
91protected:
92 bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
93
94private:
95 /// @cond PRIVATE
96 Q_DECLARE_PRIVATE(EntityRightsFilterModel)
97 std::unique_ptr<EntityRightsFilterModelPrivate> const d_ptr;
98 /// @endcond
99};
100
101}
A proxy model that filters entities by access rights.
~EntityRightsFilterModel() override
Destroys the entity rights filter model.
Q_SCRIPTABLE Q_NOREPLY void start()
Helper integration between Akonadi and Qt.
typedef ItemFlags
typedef MatchFlags
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 19 2024 11:58:37 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.