Nested data model
Michał "rysiek" Woźniak
rysiek at fwioo.pl
Sun Nov 10 22:47:35 UTC 2013
Hi there,
I am trying to create a nested, tree-view like structure. I am trying to base
on:
http://www.codeproject.com/Articles/632795/QML-TreeModel-and-TreeView
However, I do not have QtQuick 2.0 (and the components that go with it).
Anyway, I have created the following code that... crashes both PlasMate and
plasmoidviewer with the message:
"QDeclarativeComponent: Cannot create new component instance before completing
the previous"
As soon as I comment-out the line:
model: subitems
in the Repeater element, the plasmoid "works", but obviously does not display
the sub-items.
Any suggestions?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
import QtQuick 1.1
import org.kde.plasma.components 0.1 as PlasmaComponents
Item {
width: 200
height: 300
function makeList(list, data){
// as suggested on StackOverflow
// http://stackoverflow.com/questions/5818334/qml-listview-filled-by-
// javascript
for (var t in data) {
list.append(data[t]);
console.log('+-- handling: ' + data[t].text)
}
}
ListModel {
id: theModel
}
Component {
id: recursiveToDoItem
Rectangle {
id: todoContainer
property alias text: todoText.text
property bool running: model.running
property bool done: model.done
property int index: model.index
Component.onCompleted: {
console.log('+-- handled: ' + todoContainer.text +
' as index: ' + todoContainer.index)
}
color: (todoContainer.done) ? "grey" : "white"
border {
width:1
color: (todoContainer.running) ? "green" : "red"
}
anchors {
left: parent.left
right: parent.right
}
height: todoRow.implicitHeight
Row {
id: todoRow
Text {
id: todoText
text: model.text
color: "black"
height:28
}
Repeater {
id: todoSubitems
delegate: recursiveToDoItem
model: subitems
}
}
}
}
ListView {
id: itemContainer
anchors.fill: parent
delegate: recursiveToDoItem
}
Component.onCompleted: {
makeList(
theModel,
[{
"text":"Test 1",
"elapsed":4,
"running":false,
"done":false,
"expanded":true,
"subitems":[]
},{
"text":"Test 2",
"elapsed":26398,
"running":false,
"done":false,
"expanded":false,
"subitems":[{
"text":"Test 2.1",
"elapsed":0,
"running":false,
"done":false,
"expanded":true,
"subitems":[]
},{
"text":"Test 2.2",
"elapsed":0,
"running":false,
"done":false,
"expanded":true,
"subitems":[]
}]
},{
"text":"Test 3",
"elapsed":26398,
"running":false,
"done":false,
"expanded":false,
"subitems":[]
},{
"text":"Test 4",
"elapsed":26398,
"running":false,
"done":false,
"expanded":false,
"subitems":[{
"text":"Test 4.1",
"elapsed":0,
"running":false,
"done":false,
"expanded":true,
"subitems":[]
},{
"text":"Test 4.2",
"elapsed":0,
"running":false,
"done":false,
"expanded":true,
"subitems":[]
},{
"text":"Test 4.2",
"elapsed":0,
"running":false,
"done":false,
"expanded":true,
"subitems":[{
"text":"Test 4.2.1",
"elapsed":0,
"running":false,
"done":false,
"expanded":true,
"subitems":[]
}]
}]
}]
)
itemContainer.model = theModel
}
}
--
Pozdrawiam
Michał "rysiek" Woźniak
Fundacja Wolnego i Otwartego Oprogramowania
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 316 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/plasma-devel/attachments/20131110/141b540a/attachment.sig>
More information about the Plasma-devel
mailing list