PDA

View Full Version : undo for multiple selected items



mooreaa
13th July 2008, 06:16
Hello,

What is the best way to implement a undo stack for multiple items?

I looked at the undo example, but it only deals with one object.

If I select two objects and move it, What is the best way to group move/unmove those items? Or do I need to move them individually?

wysota
13th July 2008, 11:14
You can begin a macro and then insert undo commands for each item in a group and then end the macro. In such case all the commands will be treated as a single entity and undone or redone at once. Alternatively you can insert an empty undo command on the stack and then insert subsequent commands for each item in the selection passing the earlier inserted empty command as the parent. The effect will be exactly the same.

mooreaa
13th July 2008, 12:09
Thanks for the reply wysota,

I will have to give this a try. Now is there a good way to emit the "objects changed" signal from my Scene or QGraphicsItems? How can I capture a item move event of the QGraphicsScene on multiple selected objects?

wysota
13th July 2008, 15:13
Your command's undo and redo methods will be moving objects around. Each move will cause itemChanged to be executed for a respective item, just like if you moved them manually.