[Qt-interest] Question about Models, Roles and data

Murphy, Sean M. sean.murphy at gd-ais.com
Tue Aug 25 17:41:23 CEST 2009


I'm slowly working my way into writing models for an existing data file
structure that we use for a bunch of internal applications and have a
couple of general questions.

First the file structure:  Our data file (or document) is built up of
two types of classes, foo and bar, where bar classes are children of foo
classes.  The file has 0-N foo objects, each foo object has 0-N bar
objects as children.

Since the file has this hierarchal structure, it makes sense to look at
the file in a tree view, so I've built a custom model from
QAbstractItemModel that works on the *file object* and shows the
relationships of all the foo's and bar's; it seems to be working well.  

I'm realizing however that it may be handy to have all sort of different
ways to look into these different classes, like a list view that just
shows all the foo's, and a separate list view that just shows the bar's
for a given foo.  Also a table view that shows all the data fields of
all the bar's would be nice too.

So my question is, how many models do I create to get all the different
slices into my data?  Is the general rule of thumb that I need one model
per data class per view type?  Or can I play around with custom roles to
reduce the number of model classes I need?

I realize that I'm being general enough that I can't get specific
answers, but I'm just looking for general comments of how you go about
maintaining all the models for your data.

Sean





More information about the Qt-interest-old mailing list