group layers design
Bart Coppens
kde at bartcoppens.be
Sat Dec 24 14:10:27 CET 2005
On Saturday 24 December 2005 12:00, Gábor Lehel wrote:
> - KisLayer has methods prevSibling() and nextSibling() -- I think it'd
> be excessive and inefficient (and require housekeeping to keep it all
> consistent) to have m_prevSibling and m_nexSibling to store these,
> when you could just find out via the parent(); but this needs parent()
> to be of a type that's guarenteed to have the info (either m_layers
> accessible, or KisLayerSP itemAtIndex(int i) / int
> indexOfItem(KisLayerSP), or something of the sort).
Well whereas I don't really oppose a doubly linked list internally, I can see
the point that it's indeed some housekeeping. But the point was made over irc
that just having a list of layers in the parent would make this quite
inefficient. That's why maybe we should add some kind of methods index() +
setIndex(int) to KisLayer, that return and set the position of the layer in
its parent layer. This way, KisGroupLayer can, in constant time if it uses a
regular vector, return next and previous siblings of the layer. This also
makes sense from a design point of view, since _all_ layers are the child of
some other layer and thus have an index in it (except, of course, the root
layer, but that's a special case anyway).
> - Only KisGroupLayers can have child layers; this means no
> add/removeLayer() methods in KisLayer. If you have a KisLayer and want
> to add sublayers, you have to dynamic_cast. parent()s of layers are
> forced/guarenteed to be KisGroupLayers. [...]
This seems like the most clean solution at the moment without further
complicating matters. If need be we can later on always add some kind of
interface class 'KisChildHavingLayer' or so, having the needed methods, which
KisGroupLayer and KisVWLT could both derive from. Then we just say that every
layer is the child of such a class, and be done with it.
> - As above, except also have virtual bool supportsChildLayers(), which
> you can check before adding child layers.
I think this is a good idea in any case, since you could use this anyway when
you need to move layers around in the layerbox and would like to find out if
you can move a layer to be the child of another. Constantly dynamic_casting
wouldn't be needed then with this function, so that it would look a bit
cleaner.
Bart Coppens
More information about the kimageshop
mailing list