[Qt5-feedback] Add internalVariant to QModelIndex

Matthias Hörmann hoermann at saltation.de
Tue Jul 12 15:53:13 CEST 2011


On Tuesday 12 July 2011 13:16:10 ext Nils Jeisecke wrote:
> Currently you can only store either a pointer or a 64bit integer
> inside a QModelIndex.
>
> Depending on the data the model is wrapping it can sometimes be quite
> hard to store all required information in one of those elements.

On Tue Jul 12 13:39:56 CEST 2011 Thiago Macieira wrote

> What can't you store with a pointer?

On Tue Jul 12 14:48:03 CEST 2011 Christoph Feck wrote

> Can you give us a use case?

The current problem with the design is the fact that there is some
kind of ASSERT in the code
that prevents you from using different pointer values in QModelIndex
instances referencing the
same item. This means you have to keep your instances around and can
not generate them
dynamically.

In one of our projects (an XML editor) we had this problem with a view
that was supposed to display all
possible cursor positions (before first child, between children, after
last child, in string,...). This tree is
very similar to the tree of all elements but not quite identical
(there are more cursor positions than elements).

QModelIndex' current design forced us to generate a permanent tree of
all possible cursor positions just
for the void* in QModelIndex as dynamically generated objects with the
same informational content were
rejected by the ASSERTS mentioned above (using two different pointers
pointing to two instances.

Of course the optimum here would be a nice type-safe API based on
templates but naturally that would
lead to problems with all the classes using QModelIndex. The current
state of the API is about as bad
as it gets for passing opaque information though other than having no
member reserved for that at all.


--
Mit freundlichen Grüßen,

Matthias Hörmann

fon: +49 (0) 521 - 329647-21
fax: +49 (0) 521 - 329647-40
email: mhoermann at saltation.de


---------------
saltation GmbH & Co. KG | Niederwall 43 | 33602 Bielefeld
Sitz Bielefeld | Amtsgericht Bielefeld HRA 15344
Persönlich haftende Gesellschafterin:
saltation Beteiligungs-GmbH | Niederwall 43 | 33602 Bielefeld
Sitz Bielefeld | Amtsgericht Bielefeld HRB 39339
Geschäftsführer: Daniel Brün
---------------


More information about the Qt5-feedback mailing list