[Kde-pim] New methods for Akonadi::EntityTreeModel

David Jarvie djarvie at kde.org
Sat May 8 17:17:02 BST 2010


On Saturday 08 May 2010 12:09:16 Stephen Kelly wrote:
> 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?

I see that you are constructing a Collection with the known ID, and then using modelIndexForCollection() to find the Collection with that index in the model. I wouldn't have thought that that would work, on my assumption that a Collection contains more than just the ID. If it does indeed work (as I presume it must if you put it in your suggested code), I don't think new methods are actually required. All that is needed is some more explanation in the apidox as to how to use modelIndexForCollection() and modelIndexesForItem() when an ID is known, but the Collection or Item instance is not known.

Cheers,
-- 
David Jarvie.
KDE developer.
KAlarm author -- http://www.astrojar.org.uk/kalarm
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-pim/attachments/20100508/ecd2ddf3/attachment.sig>
-------------- next part --------------
_______________________________________________
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