[Kde-pim] New methods for Akonadi::EntityTreeModel
Stephen Kelly
steveire at gmail.com
Sat May 8 12:09:16 BST 2010
Kevin Krammer wrote:
> On Saturday, 2010-05-08, David Jarvie wrote:
>> I'd like to add two new methods to Akonadi::EntityTreeModel, to fetch the
>> Collection or Item corresponding to a given Id. This is something I need
>> to do quite frequently in KAlarm, and, since this is an easy lookup in
>> EntityTreeModel, it seems a good idea to provide simple methods to do
>> this, rather than having to search the model for the Id and then fetch
>> the Collection or Item via the data() method.
>
> Hmm, this has the advantage over direct retrieval of being synchronous but
> it only works for entities that are already in the model, while explicit
> retrieval works as long as the entity exists at all.
>
> But if this is a common use case, i.e. to have the id, knowing that it is
> in the model but not having the entity itself, then why not.
I would prefer you to do something like this:
Collection::Id id = getId();
// Might be an EntityTreeModel or a proxy on top of it:
QAbstractItemModel *model = getModel();
QModelIndex colIndex = EntityTreeModel::modelIndexForCollection(model,
Collection(id));
if (!colIndex)
// Collection with that id is not in the model.
return;
Collection fullCollection = colIndex.value<Collection>();
This has the advantage that it works even if the model you have is a proxy
model. Obviously the index will be invalid if you use a proxy model which
shows only items in this case. I'm guessing you'll end up using either a etm
instance or a EntityMimeTypeFilterModel which contains only a collection
tree.
http://api.kde.org/4.x-api/kdepimlibs-
apidocs/akonadi/html/classAkonadi_1_1EntityTreeModel.html#a5a06470b25432e5cfd953843f7968810
Does that work for you?
Steve.
>
> Cheers,
> Kevin
>
_______________________________________________
KDE PIM mailing list kde-pim at kde.org
https://mail.kde.org/mailman/listinfo/kde-pim
KDE PIM home page at http://pim.kde.org/
More information about the kde-pim
mailing list