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

Kevin Krammer kevin.krammer at gmx.at
Sat May 8 18:39:38 BST 2010


On Saturday, 2010-05-08, David Jarvie wrote:
> 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#a5a06470b25432e
> > 5cfd953843f7968810
> > 
> > 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.

It can contain more.
The ID is the most basic information, a "full" instance also has a name, a 
list of content MIME types, remote Id (if it has been delivered by a 
resource), etc.

If you have the ID and you want the full instance, you can always use the 
basic instance to get the other information via a fetch job, e.g.

Collection collection( id );
CollectionFetchJob *job = new CollectionFetchJob( collection, 
CollectionFetchJob::Base );

(similar for an Item)

Cheers,
Kevin
-- 
Kevin Krammer, KDE developer, xdg-utils developer
KDE user support, developer mentoring
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-pim/attachments/20100508/4500c11c/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