[Interest] Problem understanding QAbstractProxyModel::mapFromSource and displaying summary data from a model
Tony Rietwyk
tony at rightsoft.com.au
Wed Jul 18 07:53:54 CEST 2012
> Sent: Wednesday, 18 July 2012 2:28 PM
>
> 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
Hi,
I think QAbstractProxyModel only applies when there IS a direct mapping
between the elements of each model, that maintains their identity.
You need a model with an element for each group (or grouping level), that
listens for the changes in the source model and adjusts the group's summary,
then signals the change for that one group.
The QML VisualDataModel component looks like it has grouping capabilities.
Maybe you can get some ideas from its implementation?
Hope that helps,
Tony.
More information about the Interest
mailing list