PDA

View Full Version : Aggregating a model's data



caduel
19th July 2008, 21:31
I have a model that supplies a list of items.
Each of the items has some properties.
(So the model is a tree of depth 2. Like the widgets in designer...)

When I select an item, in a separate view this item's properties are displayed for editing. Works like a charm.

What I want to do now is:
* when multiple items are selected, show the properties common to all of the selected items
* if the a property has the same value for each item, show that value,
* otherwise show something like "<different values>"
(I.e. a property value is not mapped to a single item, but to a list of items!)

So far, I have implemented a second model (on the underlying data). Works, but I am not happy with it: it is not connected to the first model and does not update itself when the underlying data is changed via the first model.
(I can work around that. But the solution does not get more elegant from it...)

Question:
Is it possible (sensible) to implement that with a proxy model? I.e. can proxy models aggregate their source model's data?
Do methods like QAbstractProxyModel::mapToSource() need to implement a 1:1 mapping? (Obviously impossible here...)

Thank you for thinking about that problem!
Christoph

wysota
20th July 2008, 15:59
Yes, the proxy can aggregate data provided you can map items both ways. multiple->one mapping is easy, the other way it is harder as mapToSource can't be used in a regular way, so you'll have to reimplement all virtual methods that might be using it.