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

KDE's Doxygen guidelines are available online.