PDA

View Full Version : Undo/Redo Functionality



Gurjot
10th October 2014, 07:42
I have a Qt Graphics Application that can draw QGraphicsItems like line, circle, ellipse, etc.

My entities are implemented using QGraphicsItemGroup. The particular groups are being added to the QList<QGraphicsItemGroup *>.

Now I want to implement undo/redo functionality to it. I have read that I can use Undo Framework(QUndoCommand, QUndoStack, etc.) for that but then I'd have to make use of command objects, which restricts my implementation to commands only.

Is there any other approach something like returning to previous state of the graphicsScene? Do I have to make custom functionality for undo/redo?

wysota
10th October 2014, 09:43
No, there is no alternative which is built into graphics view. In theory you could be cloning all items in the scene but that's probably more work than implementing commands for all your operations.

anda_skoa
10th October 2014, 09:45
Now I want to implement undo/redo functionality to it. I have read that I can use Undo Framework(QUndoCommand, QUndoStack, etc.) for that but then I'd have to make use of command objects, which restricts my implementation to commands only.


What do you mean with "restricts my implementation to commands only"?

A command in the context of undo/redo is just an interface for a state change that can be applied and reverted.

What kind of operation that does not change the state of the application would you want to undo?

Cheers,
_