Results 1 to 4 of 4

Thread: Ideas about how to implement Undo and Redo actions?

  1. #1
    Join Date
    May 2006
    Location
    Stockholm, Sweden
    Posts
    81
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Ideas about how to implement Undo and Redo actions?

    Hi!

    I am looking for ideas how to implement undo/redo functionality in my program. Maybe there are some tricks...


    My program:
    Is a 3d graphic program where the user can look at 3d objects in a scene and transform them, cut them and do other operations like rotate around it with the camera. Cutting an object means drawing a polygon on the object and delete parts of it and by that creating a new shape ( like in PhotoShop ).

    So i suppose I need some kind of structure that represents some kind of history of actions on the 3d scene as a linked list of nodes containg the actions... but it would be quite slow for operations that need a lot of calculation.

    thanks for reading
    pir

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Ideas about how to implement Undo and Redo actions?

    A common way to implement undo/redo functionality is to encapsulate all undoable/redoable actions into commands and store them into a stack.

    The command interface could look at simplest like this:
    Qt Code:
    1. class Command
    2. {
    3. public:
    4. Command();
    5. virtual ~Command();
    6.  
    7. virtual undo() = 0;
    8. virtual redo() = 0;
    9. };
    To copy to clipboard, switch view to plain text mode 
    Subclass and implement the undo() and redo() methods appropriately.

    Search Google on "command design pattern", and take a look at Qt 4.2's Undo Framework.
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    pir (21st July 2006)

  4. #3
    Join Date
    Jan 2006
    Location
    travelling
    Posts
    1,116
    Thanks
    8
    Thanked 127 Times in 121 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Ideas about how to implement Undo and Redo actions?

    I think Qt 4.2 offers the framework you're looking for : Undo framework

    AFAIUnderstand you'll need to subclass QUndoCommand, to create an undo stack, to connect a few actions and everything will work...
    The hardest part will certainly be implementing the undo() / redo() methods of QUndoCommand... Good luck!
    Current Qt projects : QCodeEdit, RotiDeCode

  5. #4
    Join Date
    May 2006
    Location
    Stockholm, Sweden
    Posts
    81
    Thanks
    12
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Ideas about how to implement Undo and Redo actions?

    Thanks! Found a lot on Command pattern... but it made me think. It's often the case that you want to look for design patterns fitting your problem but do not know what it might be called or where to look. Is there any good websites that list the most common design patterns in a way making it easy to search?

    Another design pattern I would like to find is how to handle transformations on components in a 3d world... at the moment I'm merging the matrices, but it should be better to make each component have some kind of transformation history having different levels of transformations. This would make operations like group/ungroup, chaning pivot points a lot easier.

    thanks for reading
    pir

Similar Threads

  1. Detecting a action ( undo/ redo)
    By ankurjain in forum Qt Programming
    Replies: 2
    Last Post: 5th May 2006, 05:05
  2. Implement Undo Redo
    By ankurjain in forum Qt Programming
    Replies: 5
    Last Post: 28th March 2006, 13:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.