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 <KLDAPWidgets/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 { Resource = Qt::UserRole, FullName };
29
30 explicit ResourceModel(const QStringList &headers, QObject *parent = nullptr);
31 ~ResourceModel() override;
32
33 [[nodiscard]] QVariant data(const QModelIndex &index, int role) const override;
34 [[nodiscard]] QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
35
36 [[nodiscard]] QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
37 [[nodiscard]] QModelIndex parent(const QModelIndex &index) const override;
38
39 [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override;
40 [[nodiscard]] int columnCount(const QModelIndex &parent = QModelIndex()) const override;
41
42 [[nodiscard]] Qt::ItemFlags flags(const QModelIndex &index) const override;
43
44 [[nodiscard]] bool removeRows(int position, int rows, const QModelIndex &parent = QModelIndex()) override;
45
46private:
47 ResourceItem *getItem(const QModelIndex &index) const;
48
49 ResourceItem::Ptr mRootItem;
50
51public:
52 /* Start search on LDAP Server with the given string.
53 * If the model is not ready to search, the string is cached and is executed afterwards.
54 */
55 void startSearch(const QString &);
56
57private:
58 /* Start search with cached string (stored in searchString)
59 *
60 */
61 void startSearch();
62
63 /* Search for collections of resources
64 *
65 */
66 KLDAPWidgets::LdapClientSearch *mLdapSearchCollections = nullptr;
67
68 /* Search for matching resources
69 *
70 */
71 KLDAPWidgets::LdapClientSearch *mLdapSearch = nullptr;
72
73 /* Map from dn of resource -> collectionItem
74 * A Resource can be part of different collection, so a QMuliMap is needed
75 *
76 */
77 QMultiMap<QString, ResourceItem::Ptr> mLdapCollectionsMap;
78
79 /* A Set of all collection ResourceItems
80 *
81 */
82 QSet<ResourceItem::Ptr> mLdapCollections;
83
84 /* Cached searchString (set by startSearch(QString))
85 *
86 */
87 QString mSearchString;
88
89 /* Is the search of collections ended
90 *
91 */
92 bool mFoundCollection = false;
93
94 /* List of all attributes in LDAP an the headers of the model
95 *
96 */
97 QStringList mHeaders;
98
99private:
100 /* Slot for founded collections
101 *
102 */
103 void slotLDAPCollectionData(const KLDAPWidgets::LdapResultObject::List &);
104
105 /* Slot for matching resources
106 *
107 */
108 void slotLDAPSearchData(const KLDAPWidgets::LdapResultObject::List &);
109};
110}
Q_OBJECTQ_OBJECT
QObject * parent() const const
T qobject_cast(QObject *object)
UserRole
typedef ItemFlags
Orientation
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:19:37 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.