Akonadi::ContactsTreeModel Class
A model for contacts and contact groups as available in Akonadi. More...
| Header: | #include <Akonadi/ContactsTreeModel> |
| CMake: | find_package(KPim6AkonadiContactCore REQUIRED)target_link_libraries(mytarget PRIVATE KPim6::AkonadiContactCore) |
Public Types
| enum | Column { FullName, FamilyName, GivenName, Birthday, HomeAddress, …, Note } |
| enum | Roles { DateRole, AddresseeRole, UserRole } |
Public Functions
| ContactsTreeModel(Akonadi::Monitor *monitor, QObject *parent = nullptr) | |
| virtual | ~ContactsTreeModel() override |
| Akonadi::ContactsTreeModel::Columns | columns() const |
| void | setColumns(const Akonadi::ContactsTreeModel::Columns &columns) |
Reimplemented Public Functions
| virtual int | entityColumnCount(Akonadi::EntityTreeModel::HeaderGroup headerGroup) const override |
| virtual QVariant | entityData(const Akonadi::Collection &collection, int column, int role = Qt::DisplayRole) const override |
| virtual QVariant | entityData(const Akonadi::Item &item, int column, int role = Qt::DisplayRole) const override |
| virtual QVariant | entityHeaderData(int section, Qt::Orientation orientation, int role, Akonadi::EntityTreeModel::HeaderGroup headerGroup) const override |
| virtual QHash<int, QByteArray> | roleNames() const override |
Detailed Description
This class provides a model for displaying the contacts and contact groups which are available from Akonadi.
Example:
// use a separated session for this model
Akonadi::Session *session = new Akonadi::Session( "MySession" );
Akonadi::ItemFetchScope scope;
// fetch all content of the contacts, including images
scope.fetchFullPayload( true );
// fetch the EntityDisplayAttribute, which contains custom names and icons
scope.fetchAttribute<Akonadi::EntityDisplayAttribute>();
Akonadi::Monitor *monitor = new Akonadi::Monitor;
monitor->setSession( session );
// include fetching the collection tree
monitor->fetchCollection( true );
// set the fetch scope that shall be used
monitor->setItemFetchScope( scope );
// monitor all collections below the root collection for changes
monitor->setCollectionMonitored( Akonadi::Collection::root() );
// list only contacts and contact groups
monitor->setMimeTypeMonitored( KContacts::Addressee::mimeType(), true );
monitor->setMimeTypeMonitored( KContacts::ContactGroup::mimeType(), true );
Akonadi::ContactsTreeModel *model = new Akonadi::ContactsTreeModel( monitor );
Akonadi::ContactsTreeModel::Columns columns;
columns << Akonadi::ContactsTreeModel::FullName;
columns << Akonadi::ContactsTreeModel::AllEmails;
model->setColumns( columns );
Akonadi::EntityTreeView *view = new Akonadi::EntityTreeView;
view->setModel( model );
Author: Tobias Koenig <tokoe@kde.org>
Member Type Documentation
enum ContactsTreeModel::Column
Describes the columns that can be shown by the model.
enum ContactsTreeModel::Roles
Describes the role for contacts and contact groups.
Member Function Documentation
[explicit] ContactsTreeModel::ContactsTreeModel(Akonadi::Monitor *monitor, QObject *parent = nullptr)
Creates a new contacts tree model.
monitor The Monitor whose entities should be represented in the model. parent The parent object.
[override virtual noexcept] ContactsTreeModel::~ContactsTreeModel()
Destroys the contacts tree model.
Akonadi::ContactsTreeModel::Columns ContactsTreeModel::columns() const
Returns the columns that the model currently shows.
See also setColumns().
[override virtual] int ContactsTreeModel::entityColumnCount(Akonadi::EntityTreeModel::HeaderGroup headerGroup) const
Returns the number of columns for the given header group.
headerGroup The header group.
\returnsThe number of columns.
[override virtual] QVariant ContactsTreeModel::entityData(const Akonadi::Collection &collection, int column, int role = Qt::DisplayRole) const
Returns the data for the given collection.
collection The collection. column The column index. role The data role.
\returnsThe variant data for the collection.
[override virtual] QVariant ContactsTreeModel::entityData(const Akonadi::Item &item, int column, int role = Qt::DisplayRole) const
Returns the data for the given contact item.
item The contact item. column The column index. role The data role.
\returnsThe variant data for the item.
[override virtual] QVariant ContactsTreeModel::entityHeaderData(int section, Qt::Orientation orientation, int role, Akonadi::EntityTreeModel::HeaderGroup headerGroup) const
Returns the header data for the given section.
section The section index. orientation The orientation (horizontal or vertical). role The data role. headerGroup The header group.
\returnsThe variant data for the header.
[override virtual] QHash<int, QByteArray> ContactsTreeModel::roleNames() const
Returns the role names for the model.
\returnsA hash map of role IDs to role names.
void ContactsTreeModel::setColumns(const Akonadi::ContactsTreeModel::Columns &columns)
Sets the columns that the model should show.
See also columns().