Akonadi Contacts

contactstreemodel.h
1/*
2 This file is part of Akonadi Contact.
3
4 SPDX-FileCopyrightText: 2009 Stephen Kelly <steveire@gmail.com>
5 SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org>
6
7 SPDX-License-Identifier: LGPL-2.0-or-later
8*/
9
10#pragma once
11
12#include "akonadi-contact-core_export.h"
13
14#include <Akonadi/EntityTreeModel>
15
16#include <memory>
17
18namespace Akonadi
19{
20class ContactsTreeModelPrivate;
21
22/**
23 * @short A model for contacts and contact groups as available in Akonadi.
24 *
25 * This class provides a model for displaying the contacts and
26 * contact groups which are available from Akonadi.
27 *
28 * Example:
29 *
30 * @code
31 *
32 * // use a separated session for this model
33 * Akonadi::Session *session = new Akonadi::Session( "MySession" );
34 *
35 * Akonadi::ItemFetchScope scope;
36 * // fetch all content of the contacts, including images
37 * scope.fetchFullPayload( true );
38 * // fetch the EntityDisplayAttribute, which contains custom names and icons
39 * scope.fetchAttribute<Akonadi::EntityDisplayAttribute>();
40 *
41 * Akonadi::Monitor *monitor = new Akonadi::Monitor;
42 * monitor->setSession( session );
43 * // include fetching the collection tree
44 * monitor->fetchCollection( true );
45 * // set the fetch scope that shall be used
46 * monitor->setItemFetchScope( scope );
47 * // monitor all collections below the root collection for changes
48 * monitor->setCollectionMonitored( Akonadi::Collection::root() );
49 * // list only contacts and contact groups
50 * monitor->setMimeTypeMonitored( KContacts::Addressee::mimeType(), true );
51 * monitor->setMimeTypeMonitored( KContacts::ContactGroup::mimeType(), true );
52 *
53 * Akonadi::ContactsTreeModel *model = new Akonadi::ContactsTreeModel( monitor );
54 *
55 * Akonadi::ContactsTreeModel::Columns columns;
56 * columns << Akonadi::ContactsTreeModel::FullName;
57 * columns << Akonadi::ContactsTreeModel::AllEmails;
58 * model->setColumns( columns );
59 *
60 * Akonadi::EntityTreeView *view = new Akonadi::EntityTreeView;
61 * view->setModel( model );
62 *
63 * @endcode
64 *
65 * @author Tobias Koenig <tokoe@kde.org>
66 * @since 4.5
67 */
68class AKONADI_CONTACT_CORE_EXPORT ContactsTreeModel : public EntityTreeModel
69{
70 Q_OBJECT
71
72public:
73 /**
74 * Describes the columns that can be shown by the model.
75 */
76 enum Column {
77 /**
78 * Shows the formatted name or, if empty, the assembled name.
79 */
81
82 /**
83 * Shows the family name.
84 */
86
87 /**
88 * Shows the given name.
89 */
91
92 /**
93 * Shows the birthday.
94 */
96
97 /**
98 * Shows the formatted home address.
99 */
101
102 /**
103 * Shows the formatted business address.
104 */
106
107 /**
108 * Shows the phone numbers.
109 */
111
112 /**
113 * Shows the preferred email address.
114 */
116
117 /**
118 * Shows all email address.
119 */
121
122 /**
123 * Shows organization name.
124 */
126
127 /**
128 * Shows the role of a contact.
129 */
131
132 /**
133 * Shows homepage url.
134 */
136
137 /**
138 * Shows the note.
139 */
140 Note
141 };
142
143 /**
144 * Describes a list of columns of the contacts tree model.
145 */
147
148 /**
149 * Describes the role for contacts and contact groups.
150 */
151 enum Roles {
152 DateRole = EntityTreeModel::UserRole + 1, ///< The QDate object for the current index.
153 UserRole = DateRole + 42
154 };
155
156 /**
157 * Creates a new contacts tree model.
158 *
159 * @param monitor The Monitor whose entities should be represented in the model.
160 * @param parent The parent object.
161 */
162 explicit ContactsTreeModel(Monitor *monitor, QObject *parent = nullptr);
163
164 /**
165 * Destroys the contacts tree model.
166 */
168
169 /**
170 * Sets the @p columns that the model should show.
171 */
172 void setColumns(const Columns &columns);
173
174 /**
175 * Returns the columns that the model currently shows.
176 */
177 [[nodiscard]] Columns columns() const;
178
179 //@cond PRIVATE
180 [[nodiscard]] QVariant entityData(const Item &item, int column, int role = Qt::DisplayRole) const override;
181 [[nodiscard]] QVariant entityData(const Collection &collection, int column, int role = Qt::DisplayRole) const override;
182 [[nodiscard]] QVariant entityHeaderData(int section, Qt::Orientation orientation, int role, HeaderGroup headerGroup) const override;
183 [[nodiscard]] int entityColumnCount(HeaderGroup headerGroup) const override;
184 //@endcond
185
186private:
187 //@cond PRIVATE
188 std::unique_ptr<ContactsTreeModelPrivate> const d;
189 //@endcond
190};
191}
A model for contacts and contact groups as available in Akonadi.
~ContactsTreeModel() override
Destroys the contacts tree model.
Column
Describes the columns that can be shown by the model.
@ PreferredEmail
Shows the preferred email address.
@ GivenName
Shows the given name.
@ Homepage
Shows homepage url.
@ HomeAddress
Shows the formatted home address.
@ Role
Shows the role of a contact.
@ BusinessAddress
Shows the formatted business address.
@ Birthday
Shows the birthday.
@ FamilyName
Shows the family name.
@ AllEmails
Shows all email address.
@ PhoneNumbers
Shows the phone numbers.
@ FullName
Shows the formatted name or, if empty, the assembled name.
@ Organization
Shows organization name.
Roles
Describes the role for contacts and contact groups.
A widget for editing the display name of a contact.
DisplayRole
Orientation
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:13:20 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.