KPeople

personsmodel.h
1/*
2 Persons Model
3 SPDX-FileCopyrightText: 2012 Martin Klapetek <martin.klapetek@gmail.com>
4 SPDX-FileCopyrightText: 2012 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
5 SPDX-FileCopyrightText: 2013 David Edmundson <davidedmundson@kde.org>
6
7 SPDX-License-Identifier: LGPL-2.1-or-later
8*/
9
10#ifndef PERSONS_MODEL_H
11#define PERSONS_MODEL_H
12
13#include <kpeople/kpeople_export.h>
14
15#include "global.h"
16
17#include <QAbstractItemModel>
18
19namespace KPeople
20{
21class ContactItem;
22class PersonItem;
23class MetaContact;
24class PersonsModelPrivate;
25
26/**
27 * This class creates a model of all known contacts from all sources
28 * Contacts are represented as a tree where the top level represents a "person" which is an
29 * amalgamation of all the sub-contacts
30 *
31 * @since 5.8
32 */
33class KPEOPLE_EXPORT PersonsModel : public QAbstractItemModel
34{
35 Q_OBJECT
36 /** specifies whether the model has already been initialized */
37 Q_PROPERTY(bool isInitialized READ isInitialized NOTIFY modelInitialized)
38public:
39 enum Role {
40 FormattedNameRole = Qt::DisplayRole, // QString best name for this person
41 PhotoRole = Qt::DecorationRole, // QPixmap best photo for this person
42 PersonUriRole = Qt::UserRole, // QString ID of this person
43 PersonVCardRole, // AbstractContact::Ptr
44 ContactsVCardRole, // AbstractContact::List (FIXME or map?)
45
46 GroupsRole, /// groups QStringList
48 PhotoImageProviderUri, ///< Provide a URL to use with QtQuick's Image.source, similar to the Photo Role. @since 5.93
49
50 UserRole = Qt::UserRole + 0x1000, ///< in case it's needed to extend, use this one to start from
51 };
52 Q_ENUM(Role)
53
54 explicit PersonsModel(QObject *parent = nullptr);
55
56 ~PersonsModel() override;
57
58 int columnCount(const QModelIndex &parent = QModelIndex()) const override;
59 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
60 QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const override;
61 QModelIndex parent(const QModelIndex &index) const override;
62 int rowCount(const QModelIndex &parent = QModelIndex()) const override;
63 QHash<int, QByteArray> roleNames() const override;
64
65 /** @returns the index for a given @p personUri */
66 QModelIndex indexForPersonUri(const QString &personUri) const;
67
68 /** Returns if all the backends have been initialized yet. */
69 bool isInitialized() const;
70
71 /** Helper class to ease model access through QML */
72 Q_SCRIPTABLE QVariant get(int row, int role);
73
74 /**
75 * Makes it possible to access custom properties that are not available to the model
76 *
77 * @returns the property for the contact at @p index defined by the @p key
78 */
79 QVariant contactCustomProperty(const QModelIndex &index, const QString &key) const;
80
81Q_SIGNALS:
82 /** Will emit when the model is finally initialized. @p success will specify if it succeeded */
83 void modelInitialized(bool success);
84
85private:
86 Q_DISABLE_COPY(PersonsModel)
87
89 Q_DECLARE_PRIVATE(PersonsModel)
90};
91}
92
93#endif // PERSONS_MODEL_H
This class creates a model of all known contacts from all sources Contacts are represented as a tree ...
void modelInitialized(bool success)
Will emit when the model is finally initialized.
@ PhotoImageProviderUri
Provide a URL to use with QtQuick's Image.source, similar to the Photo Role.
@ PhoneNumberRole
groups QStringList
DisplayRole
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:17:46 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.