I want to display hierarchical Data with a QML-Listview. This means that I have different Cpp datamodels, that have the following structure:
- Section 1
- Subsection 1
- Item
- Item
- Subsection 2
- Item
- Section 2
The number of subsections is different in every model, so that I'm looking for a general solution to display that data in a flat list like that:
- Section 1
- Subsection 1
- Item
- Item ...
I'm using Qt 4.8.2 with Qt Quick 1.1.
What I figured out till now:
- The QML ListView cannot display hierarchical listmodels
- There are different solutions to display tree-structured extendable lists with multiple Listviews, but that's too complex for my models
- I can make my model flat by using a Abstract-Class insert different Object types in a flat list, but that would be a lot of work, cause I had to insert lots of loops
Till now I found one solution provided by blackberry cascades, but I can't use it because I have to run my application on Embedded Linux:
Cascades Vegetables Data Model
At this moment I'm thinking about to write my own ListView with Cpp, but I would really like to avoid that because It will be a lot of work to implement that.
I'm new here at stackoverflow, so please let me know if I have to give you more informations.
Thank's in advance.
Quperman
EDIT 05.08.2014:
Temporary Solution:
Since It seems to be hard work for me to implement my own Cpp TreeView, I found another easier solution:
I created an abstract class AbstractItem with an attribute ItemType (enum), that has the following values:
- Item
- Section
- Subsection
- ...
What I now do is the following: I inherit my Section and Item classes from my new class AbstractItem. Now I put QList into my QAbstractListModel and appended the items, sections, subsections... I can now provide different data in header and item by implementing the data() function with a switch over ItemType. depending on the ItemType I can do a reinterpret_cast to access the data.
Now I have a flat hierarchy that works for me. Sadly I can't use the class hierarchy, but at this moment it seems to be the fastest solution.