Hi,

I did implement the support for QML list properties in PySide, but using a 
different syntax than the used by C++[1].

I could mirror the C++ syntax on PySide but in my opinion the QML API to 
export list properties is a bit bizarre, in essence you create a *read-only* 
property that can be *written*, just non-sense to me.

I'll use the example in [1] to show my proposed syntax and a syntax based in 
the C++ API to help you to compare both, the following code represents a 
possible implementation mirroring the C++ syntax:

class PieChart (QDeclarativeItem):

    def __init__(self, parent = None):
        QDeclarativeItem.__init__(self, parent)
        self._slices = []

    def appendSlice(prop, _slice):
        _slice.setParentItem(prop.object)
        prop.object._slices.append(_slice)

    def getSlice(self):
        return QDeclarativeListProperty(PieSlice, self, None, appendSlice)

    slices = Property(QDeclarativeListProperty, getSlice)

Instead of create the getter for the property and return a "mysterious" object 
that turn a read-only property into a writable one I simplified the syntax to 
the following:

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)


This is already implemented, Qt.Declarative.ListProperty is a subclass of 
QtCore.Property, so I would like to know your opinions about this API before 
pushing it to mainline.

[1] http://cakebox.homeunix.net/doc/qt4/html/declarative-tutorials-extending-
chapter5-listproperties.html

-- 
Hugo Parente Lima
INdT - Instituto Nokia de Tecnologia

Attachment: signature.asc
Description: This is a digitally signed message part.

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

Reply via email to