KPeople

personsmodel.h
1 /*
2  Persons Model
3  SPDX-FileCopyrightText: 2012 Martin Klapetek <[email protected]>
4  SPDX-FileCopyrightText: 2012 Aleix Pol Gonzalez <[email protected]>
5  SPDX-FileCopyrightText: 2013 David Edmundson <[email protected]>
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 
19 namespace KPeople
20 {
21 class ContactItem;
22 class PersonItem;
23 class MetaContact;
24 class 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  */
33 class 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)
38 public:
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 
49  UserRole = Qt::UserRole + 0x1000, ///< in case it's needed to extend, use this one to start from
50  };
51  Q_ENUM(Role)
52 
53  explicit PersonsModel(QObject *parent = nullptr);
54 
55  ~PersonsModel() override;
56 
57  int columnCount(const QModelIndex &parent = QModelIndex()) const override;
58  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
59  QModelIndex index(int row, int column = 0, const QModelIndex &parent = QModelIndex()) const override;
60  QModelIndex parent(const QModelIndex &index) const override;
61  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
62  QHash<int, QByteArray> roleNames() const override;
63 
64  /** @returns the index for a given @p personUri */
65  QModelIndex indexForPersonUri(const QString &personUri) const;
66 
67  /** Returns if all the backends have been initialized yet. */
68  bool isInitialized() const;
69 
70  /** Helper class to ease model access through QML */
71  Q_SCRIPTABLE QVariant get(int row, int role);
72 
73  /**
74  * Makes it possible to access custom properties that are not available to the model
75  *
76  * @returns the property for the contact at @p index defined by the @p key
77  */
78  QVariant contactCustomProperty(const QModelIndex &index, const QString &key) const;
79 
80 Q_SIGNALS:
81  /** Will emit when the model is finally initialized. @p success will specify if it succeeded */
82  void modelInitialized(bool success);
83 
84 private:
85  Q_DISABLE_COPY(PersonsModel)
86 
87  QScopedPointer<PersonsModelPrivate> const d_ptr;
88  Q_DECLARE_PRIVATE(PersonsModel)
89 };
90 }
91 
92 #endif // PERSONS_MODEL_H
DisplayRole
This class creates a model of all known contacts from all sources Contacts are represented as a tree ...
Definition: personsmodel.h:33
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Thu Jan 27 2022 22:42:01 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.