Incidenceeditor

resourcemodel.h
1/*
2 * SPDX-FileCopyrightText: 2014 Sandro Knauß <knauss@kolabsys.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
5 *
6 */
7
8#pragma once
9
10#include "resourceitem.h"
11
12#include <KLDAPCore/LdapClientSearch>
13
14#include <QAbstractItemModel>
15#include <QModelIndex>
16#include <QSet>
17
18namespace IncidenceEditorNG
19{
20class ResourceModel : public QAbstractItemModel
21{
23
24public:
25 /* Copied from https://doc.qt.io/qt-5/qtwidgets-itemviews-editabletreemodel-example.html:
26 * Editable Tree Model Example
27 */
28 enum Roles {
30 FullName
31 };
32
33 explicit ResourceModel(const QStringList &headers, QObject *parent = nullptr);
34 ~ResourceModel() override;
35
36 [[nodiscard]] QVariant data(const QModelIndex &index, int role) const override;
37 [[nodiscard]] QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
38
39 [[nodiscard]] QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
40 [[nodiscard]] QModelIndex parent(const QModelIndex &index) const override;
41
42 [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override;
43 [[nodiscard]] int columnCount(const QModelIndex &parent = QModelIndex()) const override;
44
45 [[nodiscard]] Qt::ItemFlags flags(const QModelIndex &index) const override;
46
47 [[nodiscard]] bool removeRows(int position, int rows, const QModelIndex &parent = QModelIndex()) override;
48
49private:
50 ResourceItem *getItem(const QModelIndex &index) const;
51
52 ResourceItem::Ptr mRootItem;
53
54public:
55 /* Start search on LDAP Server with the given string.
56 * If the model is not ready to search, the string is cached and is executed afterwards.
57 */
58 void startSearch(const QString &);
59
60private:
61 /* Start search with cached string (stored in searchString)
62 *
63 */
64 void startSearch();
65
66 /* Search for collections of resources
67 *
68 */
69 KLDAPCore::LdapClientSearch *mLdapSearchCollections = nullptr;
70
71 /* Search for matching resources
72 *
73 */
74 KLDAPCore::LdapClientSearch *mLdapSearch = nullptr;
75
76 /* Map from dn of resource -> collectionItem
77 * A Resource can be part of different collection, so a QMuliMap is needed
78 *
79 */
80 QMultiMap<QString, ResourceItem::Ptr> mLdapCollectionsMap;
81
82 /* A Set of all collection ResourceItems
83 *
84 */
85 QSet<ResourceItem::Ptr> mLdapCollections;
86
87 /* Cached searchString (set by startSearch(QString))
88 *
89 */
90 QString mSearchString;
91
92 /* Is the search of collections ended
93 *
94 */
95 bool mFoundCollection = false;
96
97 /* List of all attributes in LDAP an the headers of the model
98 *
99 */
100 QStringList mHeaders;
101
102private:
103 /* Slot for founded collections
104 *
105 */
106 void slotLDAPCollectionData(const KLDAPCore::LdapResultObject::List &);
107
108 /* Slot for matching resources
109 *
110 */
111 void slotLDAPSearchData(const KLDAPCore::LdapResultObject::List &);
112};
113}
Q_OBJECTQ_OBJECT
QObject * parent() const const
UserRole
typedef ItemFlags
Orientation
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:58:15 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.