View Full Version : Using internal data structure with model/view architecture

1st March 2006, 10:10
Just to get the concept right and before starting to implement anything..
I'm thinking of writing a model for a quite complex data object structure.

The internal data structure would consist of several different types of
objects laid in a hierachical tree.

Now the question is, if I wanna connect signals to (and modify) the objects
in the internal data structure, how is the model/view architecture supposed
to detect the changes?

Do I need to make a connection between the model and each object in
the internal data structure to explicitly inform about changes?
Or is there any more elegant way to achieve this kind of behaviour?

1st March 2006, 12:43
As long as you reimplement and use methods from QAbstractItemModel, all things related to the view will be updated correctly. Now, if you want to change objects of the model without using standard model calls (mainly setData(), beingInsert/RemoveRows(), etc.), you have to make sure the model is aware of those changes and signals that some things have changed (signals layoutChanged() and dataChanged() handle this). But in general you should incorporate methods changing those objects into the model, so that you can emit proper signals. If you feel like doing otherwise, you just need a way to emit those signals from the model, meaning that those objects have to call some method defined in the model, which knows how to distinguish between objects and knows how to check what exactly changed (the layout or the data) and emits proper signals in either case.