http://en.wikipedia.org/wiki/Command_pattern
Command objects are useful for
implementing:
Multi-level undo
If all user actions in a program are implemented as command objects,
the program can keep a stack of the
most recently executed commands. When
the user wants to undo a command, the
program simply pops the most recent
command object and executes its undo()
method.
Edit: To put in perspective how this could be useful If I was going to solve this what I would do is record each "action" the user does like draw a line etc as a command and store all the assocatied information about completing that action inside that command before applying it to the drawing context.
So every action is pushed onto a stack so you can then pop back off items.
To facilitate speed I would also probably look at something like recording the state of the drawing object for a series of actions. Since it's the context of drawing it would probably be easier to start from a known drawing state and reapply commands to create the current version.
So as an example I would have a running stack of commands and a running stack of drawing objects. Every 5 commands I would push the state of the drawing object onto it's stack, so then when a user would press undo, I would grab the top state of the drawing object and apply the newest commands to the object save for the last one. To undo 10 actions, I would go back 2 states of drawing objects and not need to apply any new commands to it.
You will most likely want to limit the depth of undo/redo states you can do in your program otherwise it will infinitely grow in memory.