Akonadi::FavoriteCollectionsModel Class

class Akonadi::FavoriteCollectionsModel

A model that lists a set of favorite collections. More...

Header: #include <Akonadi/FavoriteCollectionsModel>
CMake: find_package(KPim6 REQUIRED COMPONENTS AkonadiCore)
target_link_libraries(mytarget PRIVATE KPim6::AkonadiCore)

Public Functions

FavoriteCollectionsModel(QAbstractItemModel *model, const KConfigGroup &group, QObject *parent = nullptr)
virtual ~FavoriteCollectionsModel() override
QList<Akonadi::Collection::Id> collectionIds() const
QString favoriteLabel(const Akonadi::Collection &col)

Reimplemented Public Functions

virtual Qt::ItemFlags flags(const QModelIndex &index) const override
virtual QStringList mimeTypes() const override

Public Slots

void addCollection(const Akonadi::Collection &collection)
void removeCollection(const Akonadi::Collection &collection)
void setCollections(const Akonadi::Collection::List &collections)
void setFavoriteLabel(const Akonadi::Collection &collection, const QString &label)

Detailed Description

In some applications you want to provide fast access to a list of often used collections (e.g. Inboxes from different email accounts in a mail application). Therefore you can use the FavoriteCollectionsModel which stores the list of favorite collections in a given configuration file.

Example:

 using namespace Akonadi;

 EntityTreeModel *sourceModel = new EntityTreeModel( ... );

 const KConfigGroup group = KGlobal::config()->group( "Favorite Collections" );

 FavoriteCollectionsModel *model = new FavoriteCollectionsModel( sourceModel, group, this );

 EntityListView *view = new EntityListView( this );
 view->setModel( model );

Author: Kevin Ottens <ervin@kde.org>

Member Function Documentation

FavoriteCollectionsModel::FavoriteCollectionsModel(QAbstractItemModel *model, const KConfigGroup &group, QObject *parent = nullptr)

Creates a new favorite collections model.

model The source model where the favorite collections come from. group The config group that shall be used to save the selection of favorite collections. parent The parent object.

[override virtual noexcept] FavoriteCollectionsModel::~FavoriteCollectionsModel()

Destroys the favorite collections model.

[slot] void FavoriteCollectionsModel::addCollection(const Akonadi::Collection &collection)

Adds a collection to the list of favorite collections.

QList<Akonadi::Collection::Id> FavoriteCollectionsModel::collectionIds() const

Returns the list of ids of favorite collections set on the FavoriteCollectionsModel.

Note that if you want Collections with actual data you should use something like this instead:

 FavoriteCollectionsModel* favs = getFavsModel();
 Collection::List cols;
 const int rowCount = favs->rowCount();
 for (int row = 0; row < rowcount; ++row) {
   static const int column = 0;
   const QModelIndex index = favs->index(row, column);
   const Collection col = index.data(EntityTreeModel::CollectionRole).value<Collection>();
   cols << col;
 }

Note: Due to the asynchronous nature of the model, this method returns collection ids of collections which may not be in the model yet. If you want the ids of the collections that are actually in the model, use a loop similar to above with the CollectionIdRole.

QString FavoriteCollectionsModel::favoriteLabel(const Akonadi::Collection &col)

Return associate label for collection

See also setFavoriteLabel().

[override virtual] Qt::ItemFlags FavoriteCollectionsModel::flags(const QModelIndex &index) const

[override virtual] QStringList FavoriteCollectionsModel::mimeTypes() const

[slot] void FavoriteCollectionsModel::removeCollection(const Akonadi::Collection &collection)

Removes a collection from the list of favorite collections.

[slot] void FavoriteCollectionsModel::setCollections(const Akonadi::Collection::List &collections)

Sets the collections as favorite collections.

[slot] void FavoriteCollectionsModel::setFavoriteLabel(const Akonadi::Collection &collection, const QString &label)

Sets a custom label that will be used when showing the favorite collection.

See also favoriteLabel().