[Interest] Problem understanding QAbstractProxyModel::mapFromSource and displaying summary data from a model

h hdixon at bigpond.net.au
Wed Jul 18 06:28:14 CEST 2012


Hi,
 I am writing an app in which I am wanting to display my data in a number of 
different ways.  (Currently QT4.8 on linux, but will also run it on windows, 
if this is relevant!)

As an example what I have is a set of tuples with two field, say 
Name and Hours

I have this working with table view and am able to access and edit the data.

What I want is a not editable view of the data which shows the total of all 
the Hours for each Name. 

I have used the QAbstractProxyModel class to do this.

My problem is I do not know how to implement the mapTosource and mapFromSource 
functions as there is not a direct 1 to 1 correlation between indexes in the 
proxy model and indexes in the source model.  The function definitions appear 
to assume that this is the case.

I have done a basic implementation of these functions which returns a default 
QModelIndex.
The part I have found which is not working is that that the summary  or total 
view does not update when I change values in the other view.    I have changed 
the emit in the setData function to cover the whole model.

The summary view does update when it gets focus.

Can someone please tell me if there is something better  than the 
QAbstractProxyModel for me to use for this purpose and

How is the mapFromSource function suppose to work when there is not a 1:1 
mapping between the abstract model and the source model?

Are there any samples of QAbstractProxyMode available?


With thanks,
Hugh



More information about the Interest mailing list