PDA

View Full Version : ListView _ TreeView



Binary01
20th February 2017, 19:41
Hello Forum

I want to transform a static structure to a dynamic :

Example:

ListModel {
ListElement {
categoryName: "ABC"
subItems: [
ListElement { itemName: "aaa"},
ListElement { itemName: "bbb"}
]
}
ListElement {
categoryName: "ABC"
subItems: [
ListElement { itemName: "aaa"},
ListElement { itemName: "bbb"}
]
}
ListElement {
categoryName: "ABC"
subItems: [
ListElement { itemName: "aaa"},
ListElement { itemName: "bbb"}
]
}
}

Dynamic :

ListModel {
Component.onCompleted: {
for(var i = 0; i < 2; ++i) {
append({
"categoryName": "ABC",
"subItems": [
{"itemName": "aaa"},
{"itemName": "bbb"}
]
})
}
}
}

Until here everything is good


My Question: How can I transform the below static structure to dynamic


ListModel {
ListElement {
categoryName: "ABC"
subItems: [
ListElement { itemName: "aaa"},
ListElement { itemName: "bbb"}
]
}
ListElement {
categoryName: "DEF"
subItems: [
ListElement { itemName: "ccc"},
ListElement { itemName: "ddd"}
]
}
ListElement {
categoryName: "GHI"
subItems: [
ListElement { itemName: "eee"},
ListElement { itemName: "fff"},
ListElement { itemName: "ggg"}
]
}
}

The problem is I don't know the size of SubItems !!

First : I get the projects (list of project)
Second : I get for each project list of files (list of files)

I want to present this structure :
project0
file1
file2
project1
file3
file4
project2
file5
file6
file7

I try this, not work well !

ListModel {
id: menuModel
Component.onCompleted: {

var listProjects = handledProjets()
for(var k=0; k<listProjects.length; k++)
{
var nameplugin = listProjects[k]
console.log(">>> Projet = "+nameplugin)
//menuModel.append({text:nameplugin})
//append({"categoryName": nameplugin})

var listFiles = handledFiles(nameplugin)
console.log(">>> File("+(l+1)+") = "+listFiles[l])
//mychild.append({text:listFiles[l]})
append({
"categoryName": nameplugin
"subItems": [
{"itemName": listFiles[l]}
]
})
}
}


Cheers;

anda_skoa
21st February 2017, 10:40
This sounds like a use case for a proper custom model, i.e. a custom implementation derived from QAbstractListModel or even QAbstractItemModel.

How do you display this?

Cheers,
_