Commit cea5b087 authored by Daniel Vrátil's avatar Daniel Vrátil 🤖

ETM: add updatedCollection() methods

Inspired by MailCommon::MailUtil::updatedCollection() this function returns
an ETM Collection based on collection ID. This is much faster equivalent to
using indexForCollection() and then retrieving the Collection via QModelIndex
data.
parent 04a51677
cmake_minimum_required(VERSION 3.0)
set(PIM_VERSION "5.6.40")
set(PIM_VERSION "5.6.42")
project(Akonadi VERSION ${PIM_VERSION})
......
......@@ -1208,4 +1208,28 @@ QModelIndexList EntityTreeModel::modelIndexesForItem(const QAbstractItemModel *m
return proxyList;
}
Collection EntityTreeModel::updatedCollection(const QAbstractItemModel *model,
qint64 collectionId)
{
const QAbstractProxyModel *proxy = qobject_cast<const QAbstractProxyModel*>(model);
const QAbstractItemModel *_model = model;
while (proxy) {
auto _model = proxy->sourceModel();
proxy = qobject_cast<const QAbstractProxyModel*>(_model);
}
auto etm = qobject_cast<const EntityTreeModel*>(_model);
if (etm) {
return etm->d_ptr->m_collections.value(collectionId);
} else {
return Collection{ collectionId };
}
}
Collection EntityTreeModel::updatedCollection(const QAbstractItemModel *model,
const Collection &collection)
{
return updatedCollection(model, collection.id());
}
#include "moc_entitytreemodel.cpp"
......@@ -614,6 +614,15 @@ public:
*/
static QModelIndexList modelIndexesForItem(const QAbstractItemModel *model, const Item &item);
/**
* Returns an Akonadi::Collection from the @p model based on given @p collectionId.
*
* This is faster and simpler than retrieving a full Collection from the ETM
* by using modelIndexForCollection() and then querying for the index data.
*/
static Collection updatedCollection(const QAbstractItemModel *model, qint64 collectionId);
static Collection updatedCollection(const QAbstractItemModel *model, const Collection &col);
Q_SIGNALS:
/**
* Signal emitted when the collection tree has been fetched for the first time.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment