QAbstractItemModel modification via QUndoCommand issue
-
Hello,
I am trying to move all my tree view modification code into appropriate undo commands. Identical code that works as part of my tree model does not work when implemented in (or just invoked from) the undo command. By not working, I mean that the view does not get updated, although the model is updated, and saving the current data reflects the fact that the model was updated.
The window class code is at http://kenai.com/projects/mongoviewer/sources/svn/content/desktop/trunk/src/view/DocumentWindow.cpp?rev=89 (lines 173-4). Intention is to have only line 174, and get rid of line 173. The undo command redo method is currently a copy of the add method in the model, but there was no difference when the add method was invoked from redo instead.
The model class is at http://kenai.com/projects/mongoviewer/sources/svn/content/desktop/trunk/src/model/tree/BSONDocumentModel.cpp?rev=89 (method is from line 197). The undo command is at http://kenai.com/projects/mongoviewer/sources/svn/content/desktop/trunk/src/model/command/ElementAdd.cpp?rev=89. The parent class invokes doUndo and doRedo in its undo/redo implementation.
If I enable line 174 as well, then the view is updated and as expected shows two identical entries. Flipping 173 and 174 also produces two identical entries in the view. I am at a loss to figure out why the dataChanged signal and beginInsertRows/endInsertRows etc. have no effect when they are executed as part of the command. Directly invoking the redo method instead of pushing into the stack also has no effect on the view.
Thanks in advance for all help and suggestions.
Rakesh -
The difference in behaviour is only when the QModelIndex is invalid (usually when I am starting with a new document). Not sure why the logic in lines 89-92 (see link to source below) behaves differently when invoked through the undo command, and directly through the model without going through command.
Adding a reset() as line 93 fixes the issue, but still no idea why the original logic does not work.