Discussion:
[Wt-interest] ItemDelegate shared for multiple columns
Aarón Bueno Villares
2016-02-25 18:23:44 UTC
Permalink
Since Wt makes some lifecycle management of its WObjects, I want to know if
a WAbstractItemDelegate (or any of its derived class of course), can be
shared between different columns, for example, if the content to be
rendered is similar, or must each column have its own delegate?

My concerns are the following ones:

*) If I create a WItemDelegate without a parent, does the view became
the owner of the newly inserted delegated? I assume that, if I used the
same delegate for more than one column, after the first insertion the
delegate already has a parent and there is no re-parenting.

*) In such a case of sharing, if the view is destroyed, does the view
try to delete each delegate for each column, or there's no risk of a
delegated being destroyed twice?

In conclusion, is it safe to use a same delegate object for more than one
column? and even for different views?

Best regards,
Koen Deforche
2016-02-26 08:25:40 UTC
Permalink
Hey Aaron,
Post by Aarón Bueno Villares
Since Wt makes some lifecycle management of its WObjects, I want to know
if a WAbstractItemDelegate (or any of its derived class of course), can be
shared between different columns, for example, if the content to be
rendered is similar, or must each column have its own delegate?
Yes, it can.
Post by Aarón Bueno Villares
*) If I create a WItemDelegate without a parent, does the view became
the owner of the newly inserted delegated? I assume that, if I used the
same delegate for more than one column, after the first insertion the
delegate already has a parent and there is no re-parenting.
True.
Post by Aarón Bueno Villares
*) In such a case of sharing, if the view is destroyed, does the view
try to delete each delegate for each column, or there's no risk of a
delegated being destroyed twice?
There is no risk: the deleting of the item delegate will be done at the
level of the WObject (parent) deleting any remaining children WObjects when
it itself gets deleted.
Post by Aarón Bueno Villares
In conclusion, is it safe to use a same delegate object for more than one
column? and even for different views?
Yes and yes.

Regards,
koen

PS questions like these should be solved when we release wt4 -- which
adopts standard c++11 pointers (std::unique_ptr<> and std::shared_ptr<> and
non-owning raw pointers) in the API. In this case, an item delegate is a
shared_ptr<>.

Loading...