PDA

View Full Version : Implement Undo Redo



ankurjain
28th March 2006, 11:32
hi all,
i hav to implement undo and redo functionality in my project. The purpose is to cancel (undo) or redo some actions of cut copy paste etc. are there some existing functions for this. or i hav to make my own.

ne ideas ??? :confused:

zlatko
28th March 2006, 11:37
What actually you want do with "Undo", "Redo" buttons?

jpn
28th March 2006, 11:50
Qt Solutions: Undo/Redo Framework (http://www.trolltech.com/products/solutions/catalog/4/Utilities/qtundo/)

And there is a design pattern called Command (http://www.google.fi/search?q=command+design+pattern) which fits for undo/redo purposes.

SkripT
28th March 2006, 11:58
ankurjain, if you wnat to do it manually, I did it in a photo editor. I used a list of "identificators" of the operators that the user has executed.

ankurjain
28th March 2006, 12:05
hi zlatko,

i m having a table. if i cut the contents of the table on undo it must paste back the contents in it. on redo it must again cut. such operations that are generally done on excel file.

hi SkripT,

can u explain a bit by code, how u did it.

SkripT
28th March 2006, 13:17
hi SkripT,

can u explain a bit by code, how u did it.

I think that could be more complex ways to do it, but what I do is everytime that the user executes an action that can be "undoned" I insert its identificator (I have an enum with all the identificator for all the actions) in a QList that I use it like a queue of operators. As you may notice you need also a list for each kind of variables that you enter in each action to execute it. Then when the user wants to undo the last operation, what I do is execute again all the operations in the list till the last operation. How this could be lengthy what I do is clear the list of operations after some operations. I repeat that I use it for a photo editor maybe in your case could differ ;)