diff options
author | Warwick Allison <warwick.allison@nokia.com> | 2009-09-09 04:12:45 (GMT) |
---|---|---|
committer | Warwick Allison <warwick.allison@nokia.com> | 2009-09-09 04:12:45 (GMT) |
commit | 14e787b7e5abc1d665ba0e0229f60525283b1e38 (patch) | |
tree | 7382a0c9fc282234b2594319d48ac1dfe060770e /examples/declarative/listview | |
parent | 94267bb148fe4c991a10d4aa4c01373821d9216e (diff) | |
download | Qt-14e787b7e5abc1d665ba0e0229f60525283b1e38.zip Qt-14e787b7e5abc1d665ba0e0229f60525283b1e38.tar.gz Qt-14e787b7e5abc1d665ba0e0229f60525283b1e38.tar.bz2 |
Modifying ListModel from JS: work for structured data too.
Diffstat (limited to 'examples/declarative/listview')
-rw-r--r-- | examples/declarative/listview/dynamic.qml | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/examples/declarative/listview/dynamic.qml b/examples/declarative/listview/dynamic.qml index 58ce4b4..5111cec 100644 --- a/examples/declarative/listview/dynamic.qml +++ b/examples/declarative/listview/dynamic.qml @@ -2,42 +2,74 @@ import Qt 4.6 Item { width: 300 - height: 300 + height: 500 ListModel { id: FruitModel ListElement { name: "Apple" cost: 2.45 + attributes: [ + ListElement { description: "Core" }, + ListElement { description: "Deciduous" } + ] } ListElement { name: "Banana" cost: 1.95 + attributes: [ + ListElement { description: "Tropical" }, + ListElement { description: "Seedless" } + ] } ListElement { name: "Cumquat" cost: 3.25 + types: [ "Small", "Smaller" ] + attributes: [ + ListElement { description: "Citrus" } + ] } ListElement { name: "Durian" cost: 9.95 + attributes: [ + ListElement { description: "Tropical" }, + ListElement { description: "Smelly" } + ] } ListElement { name: "Elderberry" cost: 0.05 + attributes: [ + ListElement { description: "Berry" } + ] } ListElement { name: "Fig" cost: 0.25 + attributes: [ + ListElement { description: "Flower" } + ] } } Component { id: FruitDelegate Item { - width: parent.width; height: 35 - Text { font.pixelSize: 24; text: name } + width: parent.width; height: 55 + Text { id: Label; font.pixelSize: 24; text: name } Text { font.pixelSize: 24; text: '$'+Number(cost).toFixed(2); anchors.right: ItemButtons.left } + Row { + anchors.top: Label.bottom + spacing: 5 + Repeater { + model: attributes + Component { + Text { text: description } + } + } + } Row { id: ItemButtons anchors.right: parent.right @@ -79,7 +111,15 @@ Item { anchors.bottom: parent.bottom id: Buttons Image { source: "content/pics/add.png" - MouseRegion { anchors.fill: parent; onClicked: FruitModel.append({"name":"Pizza", "cost":5.95}) } + MouseRegion { anchors.fill: parent; + onClicked: { + FruitModel.append({ + "name":"Pizza", + "cost":5.95, + "attributes":[{"description": "Supreme"},{"description": "Margarita"}] + }) + } + } } Image { source: "content/pics/add.png" MouseRegion { anchors.fill: parent; onClicked: FruitModel.insert(0,{"name":"Pizza", "cost":5.95}) } |