On Thursday 09 December 2010 08:33:18 Thomas Perl wrote: > 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?
I think it's not a good idea due to the loss of flexibility, sometimes the user need to store the list in a custom data structure and with your suggestion it's impossible. Note that Qt list property is different of QML list property, in terms of C++ Qt list property is a property of type QList<T>, but a QML list property is a property of type QDeclarativeListProperty<T>, and this type is somewhat useless outside the QML itself. > 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 :) No, it's a good idea because most of the time you use a ListProperty you will write the same code for append, at, count, etc.. so this would be a time saver for the programmer and we still with the flexibility to use custom data structures to store our list if we want so. > Thanks, > Thomas -- Hugo Parente Lima INdT - Instituto Nokia de Tecnologia
signature.asc
Description: This is a digitally signed message part.
_______________________________________________ PySide mailing list [email protected] http://lists.openbossa.org/listinfo/pyside
