| Home | ![]() |
The QtUndoStack class is a stack of QtCommand objects. More...
#include <qtundo.h>
The QtUndoStack class is a stack of QtCommand objects.
For an overview of the Qt Undo/Redo framework, see the overview.
New commands are added with push(). When a command is pushed on to the stack, QtUndoStack takes ownership of the command and applies it by calling QtCommand::redo(). Undo and redo are invoked with undo() and redo(). These functions may be called directly, or through the QtUndoManager::undoAction() and QtUndoManager::redoAction() QAction objects. In the latter case, QtUndoManager will choose a stack based on which object has the focus, and call the relevant undo() or redo() function.
FaceEdit::FaceEdit(QWidget *parent, const char *name)
: QWidget(parent, name, Qt::WDestructiveClose)
{
...
m_undo_stack = new QtUndoStack(this);
...
}
void FaceEdit::setImage(const QString &image_name)
{
Face *face = focusedFace();
...
m_undo_stack->push(new CmdChangeImage(face, image_name));
...
}
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, and paragraphs. Command compression allows these single-character commands to be merged into a single command which inserts or deletes chunks of text. See push() for more information on command compression.
QtUndoStack supports command macros. A command macro is a sequence of commands which are undone and redone in one go. The sequence starts with a QtCommand object whose type() is MacroBegin. The description() of this command is taken to describe the effect of the entire macro. The sequence ends with a QtCommand object whose type() is MacroEnd. See undo() and redo() for more information on command macros.
void FaceEdit::clearFaces()
{
...
m_undo_stack->push(new QtCommand(QtCommand::MacroBegin, "Clear faces"));
for (; *child_it != 0; ++child_it) {
Face *face = (Face*) *child_it;
m_undo_stack->push(new CmdChangeImage(face, "none"));
m_undo_stack->push(new CmdChangeColor(face, "green"));
}
m_undo_stack->push(new QtCommand(QtCommand::MacroEnd));
...
}
A certain state of the edited object may be marked as "clean", using setClean(). This function is usually called whenever the edited object is saved. QtUndoStack emits the cleanChanged() signal whenever the edited object enters or leaves the clean state.
See also QtCommand and QtUndoManager.
Returns true if a command is available for redo; otherwise returns false. Redo is not possible if the stack is empty or if the top command on the stack has already been redone.
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().
Returns true if a command is available for undo; otherwise returns false. Undo is not possible if the stack is empty or if the bottom command on the stack has already been undone.
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().
This signal is emitted whenever the edited object enters or leaves the clean state. If clean is true, the edited object is currently clean; otherwise it is currently not clean.
See also isClean() and setClean().
Example: faceedit.cpp.
See also push().
Example: faceedit.cpp.
This signal is emitted whenever a QtCommand on the stack is undone or redone. When macro commands are undone or redone, this signal is emitted only once, even though the macro may contain more than one command.
Example: faceedit.cpp.
Unlike QtUndoManager::createRedoAction(), the returned QAction is connected directly to this stack's redo() slot. This is useful if you want each of your target windows to have it's own redo button.
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().
Example: faceedit.cpp.
Unlike QtUndoManager::createUndoAction(), the returned QAction is connected directly to this stack's undo() slot. This is useful if you want each of your target windows to have it's own undo button.
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().
Example: faceedit.cpp.
More precisely, the edited object is in a clean state if the current QtUndoStack command is the same one as it was at the time of the last call to setClean().
See also setClean() and cleanChanged().
Example: faceedit.cpp.
If the current command is not topmost on the stack, all commands above it are deleted.
This function will attempt to merge a new command with the command on top of the stack only if they are both instances of the same class (ascertained using QObject::className()) and if the new command's merge flag is true.
If there is no current command on this stack, or command and the current command are of different types, or command's merge flag is false, or QtCommand::mergeMeWith() returns false, push() will push command onto the stack.
See also undo(), redo(), and clear().
Example: faceedit.cpp.
If the current command's type() is MacroBegin, traverses the stack upwards calling each command's redo(), until a command of type MacroEnd is found. The current position remains at this command.
This process is repeated count times. count defaults to 1.
See also push(), undo(), and canRedo().
See also QtUndoManager::redoDescription(), QtCommand::description(), and undoDescription().
This signal is emitted whenever the redo description for this QtUndoStack changes. newDescription is the new redo description. It is useful when you want to trigger undo using a custom widget, rather than using the QAction returned by createRedoAction().
See also redoDescription(), canRedoChanged(), and undoDescriptionChanged().
See also undoList().
See also isClean() and cleanChanged().
Example: faceedit.cpp.
If the current command's type() is MacroEnd, traverses the stack downwards calling each command's undo(), until a command of type MacroBegin is found. The current position is then set to one command below the macro begin marker.
This process is repeated count times. count defaults to 1.
See also push(), redo(), and canUndo().
See also QtUndoManager::undoDescription(), QtCommand::description(), and redoDescription().
This signal is emitted whenever the undo description for this QtUndoStack 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 redoList().
This file is part of the Qt Solutions.
Copyright © 2003-2006
Trolltech. All Rights Reserved.
| Copyright © 2003-2006 Trolltech | Trademarks | Qt Solutions
|