Home

Overview of the Qt Undo/Redo Framework

The Qt Undo/Redo Framework is an undo/redo framework based on the Command design pattern.

This framework allows developers to easily implement multiplatform undo/redo functionality in their applications.

The Command design pattern is based on the idea that all editing in an application is done by creating instances of command objects. Command objects apply changes to the edited object and are then stored on a command stack. Furthermore, each command knows how to undo its changes to bring the edited object back to its previous state. As long as the application only uses command objects to change the state of the edited object, it is possible to undo a sequence of commands by traversing the command stack downwards and calling the "undo" method of each command in turn. It is also possible to redo a sequence of commands by traversing the command stack upwards and calling the "redo" method of each command.

This package consists of four classes:

QtUndoStack supports command compression. This is useful when several commands can be compressed into a single command, which can be undone and redone in one go. For example, in a text editor, when the user types in a character, a new action is created, which inserts that character into the document at the cursor position. However, it is more convenient for the user to be able to undo or redo typing in whole words, sentences, or paragraphs. Command compression allows these single-character commands to be merged into a single command which inserts or deletes sections of text.

QtUndoStack supports command macros. A command macro is a sequence of commands, all of which are undone and redone in one go.

QtUndoManager provides convenient undo and redo QAction objects, which can be inserted into a menu or a toolbar. As the focus moves around the application and commands are redone and undone, QtUndoManager updates the text properties of these QAction objects to reflect what change they will trigger. The QActions are disabled as appropriate when no command is available for undo or redo.


Copyright © 2008 Nokia Corporation and/or its subsidiary(-ies) Trademarks
Qt Solutions