Akonadi

entityrightsfiltermodel.h
1 /*
2  SPDX-FileCopyrightText: 2009 Tobias Koenig <[email protected]>
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 
16 namespace Akonadi
17 {
18 class 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 <[email protected]>
45  * @since 4.6
46  */
47 class AKONADICORE_EXPORT EntityRightsFilterModel : public QSortFilterProxyModel
48 {
49  Q_OBJECT
50 
51 public:
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  */
62  ~EntityRightsFilterModel() override;
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  Q_REQUIRED_RESULT Collection::Rights accessRights() const;
76 
77  /**
78  * @reimp
79  */
80  Q_REQUIRED_RESULT Qt::ItemFlags flags(const QModelIndex &index) const override;
81 
82  /**
83  * @reimp
84  */
85  Q_REQUIRED_RESULT QModelIndexList match(const QModelIndex &start,
86  int role,
87  const QVariant &value,
88  int hits = 1,
90 
91 protected:
92  bool filterAcceptsRow(int sourceRow, const QModelIndex &sourceParent) const override;
93 
94 private:
95  /// @cond PRIVATE
96  Q_DECLARE_PRIVATE(EntityRightsFilterModel)
97  std::unique_ptr<EntityRightsFilterModelPrivate> const d_ptr;
98  /// @endcond
99 };
100 
101 }
102 
Q_SCRIPTABLE Q_NOREPLY void start()
A proxy model that filters entities by access rights.
typedef ItemFlags
typedef MatchFlags
Helper integration between Akonadi and Qt.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat Jul 2 2022 06:41:47 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.