Hi Hugo,

2010/12/8 Hugo Parente Lima <[email protected]>:
> class PieChart (QDeclarativeItem):
>
>    def __init__(self, parent = None):
>        QDeclarativeItem.__init__(self, parent)
>        self._slices = []
>
>    def appendSlice(self, _slice):
>        _slice.setParentItem(self)
>        self._slices.append(_slice)
>
>    slices = ListProperty(PieSlice, appendSlice)

Definitely looks cleaner than the other example. Just one question:
The "_slices" attribute is only used for keeping a reference to each
slice? You don't specify the "_slices" attribute when creating the
ListProperty, and I hope it's not implicit (i.e. slices uses _slices
for storage because of the name). If it is needed only because of
keeping a reference, why not move the reference-keeping into
ListProperty? Or does ListProperty not store anything at all, and is
just an interface for QML to access the list? If so, isn't there a
need to also provide a "getter" function to the ListProperty
constructor that accesses the "_slices" property of PieChart?

Also, what about a "convenience" ListProperty subclass for the generic
case where a simply Python list is used to store items (so the
ListProperty creates a Python list "inside" itself, and provides
implementations of things like append, count, at, clear, ...)? I
haven't thought about a specific use case, so maybe this convenience
subclass idea totally misses the point and is not useful at all :)

Thanks,
Thomas
_______________________________________________
PySide mailing list
[email protected]
http://lists.openbossa.org/listinfo/pyside

Reply via email to