| Home | ![]() |
The QtUndoManager class manages command stacks in an undo/redo framework based on the Command design pattern. More...
#include <qtundo.h>
The QtUndoManager class manages command stacks in an undo/redo framework based on the Command design pattern.
For an overview of the Qt Undo/Redo framework, see the overview.
QtUndoManager keeps a list of QtUndoStack objects. Each is a list of QtCommand objects and a pointer to the last executed command (the undo stack's current command). Undo is invoked by calling the current command's QtCommand::undo() function and making the previous command in the stack the current command. Redo is invoked by making the next command in the stack the current command and calling its QtCommand::redo() function.
An application has one global QtUndoManager, accessed through the static function QtUndoManager::manager() (which creates the QtUndoManager when it is called for the first time).
Undo and redo are requested through the undo() and redo() slots. QtUndoManager also provides the functions createUndoAction() and createRedoAction() for creating QAction objects that trigger undo and redo. These QActions have the additional benefit of keeping their text properties in sync with undoDescription() and redoDescription(), as well as disabling themselves whenever no commands are available for undo or redo.
MainWindow::MainWindow(QWidget *parent, const char *name)
: QMainWindow(parent, name)
{
...
QtUndoManager *manager = QtUndoManager::manager();
QAction *undo_action = manager->createUndoAction(this);
QAction *redo_action = manager->createRedoAction(this);
undo_action->setAccel(QKeySequence("Ctrl+Z"));
redo_action->setAccel(QKeySequence("Shift+Ctrl+Z"));
QToolBar *toolbar = new QToolBar(this);
undo_action->addTo(toolbar);
redo_action->addTo(toolbar);
QPopupMenu *editmenu = new QPopupMenu(this);
undo_action->addTo(editmenu);
redo_action->addTo(editmenu);
...
}
A single application can have multiple undo stacks, typically one for each editor window in an MDI application. Each stack is associated with a widget, called the stack's target. undo() and redo() requests are directed to a stack whenever its target, or a child of its target, has the keyboard focus. A target is associated with a stack in QtUndoStack's constructor. Additional targets may be associated with a stack using associateView(). This is useful when two or more editor windows edit the same underlying object. An SDI aplication typically has a single stack associated with the application's main window.
Whenever the widget with the keyboard focus has no targets in its parent chain, the QAction objects created using createUndoAction() and createRedoAction() are disabled.


See also QtCommand and QtUndoStack.
See also disassociateView().
A QAction returned by createRedoAction() disables itself whenever canRedo() is false.
See also redo() and canUndo().
This signal is emitted whenever the state reported by canRedo() changes. enabled is the new state.
This function is useful if you want to trigger redo with a custom widget, rather than the QAction returned by createRedoAction().
See also canRedo(), redoDescriptionChanged(), and canUndoChanged().
The QAction returned by createUndoAction() disables itself whenever canUndo() is false.
See also undo() and canRedo().
This signal is emitted whenever the state reported by canUndo() changes. enabled is the new state.
This function is useful if you want to trigger undo with a custom widget, rather than the QAction returned by createUndoAction().
See also canUndo(), undoDescriptionChanged(), and canRedoChanged().
The returned QAction will keep its text property in sync with redoDescription() and disable itself whenever no commands are available for redo.
If the application's default QMimeSourceFactory contains a pixmap called "redo" or "redo.png", this pixmap is assigned to the QAction.
See also redo(), redoDescription(), and createUndoAction().
The returned QAction will keep its text property in sync with undoDescription() and disable itself whenever no commands are available for undo.
If the application's default QMimeSourceFactory contains a pixmap called "undo" or "undo.png", this pixmap is assigned to the QAction.
See also undo(), undoDescription(), and createRedoAction().
See also associateView().
count is the number of commands that should be redone. It defaults to 1.
See also undo() and canRedo().
The redo description is a string that describes what effects calling QtUndoManager::redo() will have on the edited object.
It contains the text returned by QtCommand::description() for the command preceding the current command on the QtUndoStack associated with the target widget that contains the keyboard focus.
The QAction returned by createRedoAction() keeps its text property in sync with the redo description. This function is useful if you want to trigger redo with a custom widget, rather than with this QAction.
See also redoDescriptionChanged(), createRedoAction(), QtCommand::description(), and QtUndoStack::redoDescription().
This signal is emitted whenever the redo description for the QtUndoStack associated with the target widget that contains the keyboard focus changes. newDescription is the new redo description. It is useful when you want to trigger redo using a custom widget, rather than using the QAction returned by createRedoAction().
See also redoDescription(), canRedoChanged(), and undoDescriptionChanged().
See also undoList().
See also undoLimit().
count is the number of commands that should be undone. It defaults to 1.
See also redo() and canUndo().
The undo description is a string that describes what effects calling QtUndoManager::undo() will have on the edited object.
It contains the text returned by QtCommand::description() for the current command on the QtUndoStack associated with the target widget that contains the keyboard focus.
The QAction returned by createUndoAction() keeps its text property in sync with the undo description. This function is useful if you want to trigger undo with a custom widget, rather than with this QAction.
See also undoDescriptionChanged(), createUndoAction(), QtCommand::description(), and QtUndoStack::undoDescription().
This signal is emitted whenever the undo description for the QtUndoStack associated with the target widget that contains the keyboard focus changes. newDescription is the new undo description. It is useful when you want to trigger undo using a custom widget, rather than using the QAction returned by createUndoAction().
See also undoDescription(), canUndoChanged(), and redoDescriptionChanged().
See also setUndoLimit().
See also redoList().
This file is part of the Qt Solutions.
Copyright © 2003-2006
Trolltech. All Rights Reserved.
| Copyright © 2003-2006 Trolltech | Trademarks | Qt Solutions
|