PDA

View Full Version : QStandardItemModel + Undo



NIteLordz
29th January 2015, 01:47
Currently i am displaying a tree using a QStandardItemModel. I wanted to implement Undo/Redo for editing the branch names. I connect to itemChanged(QStandardItem*) and i have created my undo and redo methods. However, when i call undo, i setText on the item, at which point a new itemChanged(QStandardItem*) fires, creating a new QUndoCommand and then things get lost.

I implemented a "hack" where i set a flag in Qt::UserRole+1 when the undoCommand is issued, and i check before issuing the command. This works fine.

My question is, is there a more elegant route to using Undo with the QStandardItemModel, without having to subclass the QStandardItemModel.

wysota
29th January 2015, 06:26
http://www.qtcentre.org/wiki/index.php?title=Using_Undo/Redo_with_Item_Views

NIteLordz
29th January 2015, 12:31
Thank you, i wish i would've found that article before i had started down this path.

neuronet
2nd March 2015, 05:22
Wow just about to embark on this, so glad you asked this recently and our resident Ninja has an article!!!