[Qt-interest] Question about Models, Roles and data
Murphy, Sean M.
sean.murphy at gd-ais.com
Tue Aug 25 21:08:57 CEST 2009
>>> For the table that shows all the data fields of all the bars, you
may
>>> need to build a new model (so, the answer changes to two, sorry!),
as
>>> you would be changing parent/child relationships here.
>>
>> No, a table is actually a tree with only first-level entries:-) In
>> other
> words: A tree-model can have as many columns >as needed, the QTreeView
> or any simpler QTableView (showing only foos or bars) will show the
> columns.
>
> I know, but if I understand the question correctly, the OP wanted to
> show only _second_ level entries. Now that may be a problem... AFAIK a
> QTableView can actually operate on any level, not just the first level
> (just like QListView can).
I guess I probably need to be a little more specific in what I want to
show in each view. First a little better description of the file
structure, at least as it resides in memory. At the top level there the
File class:
classFile
QString fileDescription
<several other file level data fields>
QList<Foo> fooList
For the Foo class I have:
classFoo
QString fooDescription
<several other Foo level data fields>
QList<Bar> barList
For the Bar class:
classBar
QString barDescription
<several other Bar level data fields>
So I need a tree view representation of my classFile object that should
show the classFile::fileDescription string as the root item, all
classFoo::fooDescription strings as the first level items, and all
classBar::barDescription strings as second level items. This tree view
should only have one column. I seem to have this working fine.
In a different part of the application suite we have two list views, one
that shows all classFoo::fooDescription strings, and the second shows
just classBar::barDescription strings. When the user clicks on a
classFoo::fooDescription in the first (Foo only) list view, the second
(Bar only) list view updates to show all the classBar::barDescription
strings that are part of the Foo object clicked on. From Andre's first
post about setting the correct model index as the root index I now seem
to have that working. So these three views are all working from the
same model, and I just play around with the root index. Right now my
model operates on a classFile object and builds up just the description
strings of the Foo's and Bar's and ignores the other data fields that
are part of each class.
The two table views that I want to have which I haven't started on yet
show all the other data fields of the Foo and Bar objects. So these
tables would have multiple columns to show all the data fields of the
respective object. I'm a little stuck on this part so far. My first
gut reaction is that I need to build up two more models, one that
operates on Foo objects, and one that operates on Bar objects, and then
just set my table views to those models.
Or maybe there is a way that my one current model builds up all the
fields of all objects, but I can somehow only show the first column in
my description-only tree view? The only problem I see there is that my
Foo and Bar objects have a different number of data fields, which would
result in a different number of columns - I don't know if that matters
or not.
Thanks for the help so far, I feel like I'm getting closer!
Sean
More information about the Qt-interest-old
mailing list