PDA

View Full Version : how to disable views from a model



zeeeend
8th September 2008, 20:39
I use a QSqlTableModel with several views. When processing large amounts of data - using insertRecord(), insertRow() or setData() - the automatic updating of the views costs much processor time. I am looking for a proper way to disable the views before processing data and (re)enabling them afterwards.

I tried subclassing QSqlTableModel and the Views by adding a signal/slot enableView(bool). At enableView(false) the views remove the model by calling setModel(0) and they restore to the original model at enableView(true). This works fine and gains lots of time. The drawback is, that it limits the reusabiltiy of the views, and makes it impossible or difficult to use proxymodels.

Any suggestions?

jacek
8th September 2008, 23:45
Maybe you could implement a "batch update proxy model" and put it between the views and troublesome model? You could say to the proxy "from now on don't propagate the updates", do your updates and then say "pass all changes accumulated changes to the view".

Of course easier said than done. It's easy to implement it for setData(), but there might be a problem with insertRow(). If you don't have much data, but a lot of changes, you can simply use modelReset() signal.

zeeeend
9th September 2008, 20:01
Thanks,

found a simple way to stop the views from updating.

myModel->blockSignals(true);

...process data ...

myModel->blockSignals(false);
myModel->reset();

wysota
9th September 2008, 21:14
Avoid resetting the model as it invalidates all selections and other things related to the views. If you have to block the signals, track what you change and emit proper signals after you update the model. It would be wiser to do it the way Jacek suggests, though.