PDA

View Full Version : Proxy model / view update problem



pascal123
23rd February 2010, 20:12
Hi all,

I am experiencing a problem with proxy models, and would greatly appreciate any help. I am not sure if I somehow missed part of the underlying concepts:

What works:

I have a QAbstractTableModel-derived model that is displayed in a QTableView.
This works. I can update the model by calling beginInsertRows(), doing the changes, and then calling endInsertRows(). The view is updated as expected.

What works with the "proxy part":

The same data is displayed, through a QAbstractProxyModel, in another QTableView.

The re-mapping of indexes and selections is implemented and data is displayed correctly.

What does not work:

The view linked to the data via the proxy model is not updated if I change/add data to the model.

The re-mapping of model indexes is relatively complex, and it is not trivial to determine which table fields will change in the "proxy view" when the original model is changed. Therefore, it would be great just to tell the view/proxy model to re-read all (visible) table fields, and to display more/less rows/columns if necessary. However, I unfortunately could not figure out how to do that.

Do I miss an important underlying concept here?

Thanks for your help

Pascal

squidge
23rd February 2010, 20:49
Is your model emitting the dataChanged and other signals correctly?

stefanadelbert
24th February 2010, 04:31
Try using the beginResetModel and endResetModel calls before and after (respectively) modifying data in the model.

pascal123
24th February 2010, 07:00
Re the signals: I think they are emitted correctly, since the view linked directly to the model is updated correctly. (I emit dataChanged() and use beginInsertRows() etc).

What I don't understand is what the proxy model is supposed to handle automatically. I use QAbstractProxyModel, but it is not clear to me what happens with the signals (e.g. dataChanged in the original models). Do I have to somehow translate these by mapping the Indexes to the new layout? What signals need to be connected? If yes, this will probably be very difficult, since data insertion in the original model will change the data in the 2nd view in a non-trivial way. Re-reading the displayed fields would therefore be easiest.

@stefanadelbert: beginResetModel() is only part of qt4.6, and I am using 4.5 for the moment. Is there a way to "emulate" this behaviour in the meanwhile?

stefanadelbert
9th June 2010, 01:02
I'm afraid that I don't know of a way to emulate the begin- and endResetModel signals. I only started using Qt at 4.6.2, so Qt4.6 is all I know! You know have your model emit a custom signal and have a derived QTableView handle the signal and do what it needs to do, which could be explicitely reloading its data somehow. I'm looking at QAssistant now though and there isn't an obvious way yo get a QTableView to reload its data.

Edit: Take a look at the post entitled "How to notify QTableView of a modified CustomModel". There could be a solution for you there.