|
Krita Source Code Documentation
|
The KUndo2QStack class is a stack of KUndo2Command objects. More...
#include <kundo2stack.h>
Inheritance diagram for KUndo2QStack:Public Slots | |
| void | purgeRedoState () |
| virtual void | redo () |
| void | setActive (bool active=true) |
| void | setClean () |
| virtual void | setIndex (int idx) |
| virtual void | undo () |
Signals | |
| void | canRedoChanged (bool canRedo) |
| void | canUndoChanged (bool canUndo) |
| void | cleanChanged (bool clean) |
| void | indexChanged (int idx) |
| void | redoTextChanged (const QString &redoActionText) |
| void | undoTextChanged (const QString &undoActionText) |
Public Member Functions | |
| QString | actionText (int idx) const |
| void | beginMacro (const KUndo2MagicString &text) |
| bool | canRedo () const |
| bool | canUndo () const |
| int | cleanIndex () const |
| void | clear () |
| const KUndo2Command * | command (int index) const |
| int | count () const |
| QAction * | createRedoAction (QObject *parent) const |
| QAction * | createUndoAction (QObject *parent) const |
| KisCumulativeUndoData | cumulativeUndoData () |
| void | endMacro () |
| int | index () const |
| bool | isActive () const |
| bool | isClean () const |
| KUndo2QStack (QObject *parent=0) | |
| void | push (KUndo2Command *cmd) |
| QString | redoText () const |
| void | setCumulativeUndoData (const KisCumulativeUndoData &data) |
| void | setUndoLimit (int limit) |
| void | setUseCumulativeUndoRedo (bool value) |
| QString | text (int idx) const |
| int | undoLimit () const |
| QString | undoText () const |
| bool | useCumulativeUndoRedo () const |
| ~KUndo2QStack () override | |
Protected Member Functions | |
| virtual void | notifySetIndexChangedOneCommand () |
Properties | |
| bool | active |
| the active status of this stack. | |
| int | undoLimit |
| the maximum number of commands on this stack. | |
Private Member Functions | |
| bool | checkUndoLimit () |
| void | setIndex (int idx, bool clean) |
Private Attributes | |
| int | m_clean_index |
| QList< KUndo2Command * > | m_command_list |
| KisCumulativeUndoData | m_cumulativeUndoData |
| KUndo2Group * | m_group |
| int | m_index |
| QList< KUndo2Command * > | m_macro_stack |
| int | m_undo_limit |
| bool | m_useCumulativeUndoRedo |
Friends | |
| class | KUndo2Group |
The KUndo2QStack class is a stack of KUndo2Command objects.
For an overview of Qt's Undo Framework, see the \l{Overview of Qt's Undo Framework}{overview document}.
An undo stack maintains a stack of commands that have been applied to a document.
New commands are pushed on the stack using push(). Commands can be undone and redone using undo() and redo(), or by triggering the actions returned by createUndoAction() and createRedoAction().
KUndo2QStack keeps track of the current command. This is the command which will be executed by the next call to redo(). The index of this command is returned by index(). The state of the edited object can be rolled forward or back using setIndex(). If the top-most command on the stack has already been redone, index() is equal to count().
KUndo2QStack provides support for undo and redo actions, command compression, command macros, and supports the concept of a {clean state}.
Definition at line 157 of file kundo2stack.h.
|
explicit |
Constructs an empty undo stack with the parent parent. The stack will initially be in the clean state. If parent is a KUndo2Group object, the stack is automatically added to the group.
Definition at line 634 of file kundo2stack.cpp.
|
override |
Destroys the undo stack, deleting any commands that are on it. If the stack is in a KUndo2Group, the stack is automatically removed from the group.
Definition at line 651 of file kundo2stack.cpp.
References clear(), m_group, and KUndo2Group::removeStack().
| QString KUndo2QStack::actionText | ( | int | idx | ) | const |
| void KUndo2QStack::beginMacro | ( | const KUndo2MagicString & | text | ) |
Begins composition of a macro command with the given text description.
An empty command described by the specified text is pushed on the stack. Any subsequent commands pushed on the stack will be appended to the empty command's children until endMacro() is called.
Calls to beginMacro() and endMacro() may be nested, but every call to beginMacro() must have a matching call to endMacro().
While a macro is composed, the stack is disabled. This means that: \list \i indexChanged() and cleanChanged() are not emitted, \i canUndo() and canRedo() return false, \i calling undo() or redo() has no effect, \i the undo/redo actions are disabled. \endlist
The stack becomes enabled and appropriate signals are emitted when endMacro() is called for the outermost macro.
This code is equivalent to:
Definition at line 1214 of file kundo2stack.cpp.
References canRedoChanged(), canUndoChanged(), m_clean_index, m_command_list, m_index, m_macro_stack, redoTextChanged(), KUndo2Command::setText(), text(), and undoTextChanged().
| bool KUndo2QStack::canRedo | ( | ) | const |
Returns true if there is a command available for redo; otherwise returns false.
This function returns false if the stack is empty or if the top command on the stack has already been redone.
Synonymous with index() == count().
Definition at line 1089 of file kundo2stack.cpp.
References m_command_list, m_index, and m_macro_stack.
|
signal |
This signal is emitted whenever the value of canRedo() changes. It is used to enable or disable the redo action returned by createRedoAction(). canRedo specifies the new value.
| bool KUndo2QStack::canUndo | ( | ) | const |
Returns true if there is a command available for undo; otherwise returns false.
This function returns false if the stack is empty, or if the bottom command on the stack has already been undone.
Synonymous with index() == 0.
Definition at line 1071 of file kundo2stack.cpp.
References m_index, and m_macro_stack.
|
signal |
This signal is emitted whenever the value of canUndo() changes. It is used to enable or disable the undo action returned by createUndoAction(). canUndo specifies the new value.
|
private |
Definition at line 606 of file kundo2stack.cpp.
References m_clean_index, m_command_list, m_index, m_macro_stack, and m_undo_limit.
|
signal |
This signal is emitted whenever the stack enters or leaves the clean state. If clean is true, the stack is in a clean state; otherwise this signal indicates that it has left the clean state.
| int KUndo2QStack::cleanIndex | ( | ) | const |
Returns the clean index. This is the index at which setClean() was called.
A stack may not have a clean index. This happens if a document is saved, some commands are undone, then a new command is pushed. Since push() deletes all the undone commands before pushing the new command, the stack can't return to the clean state again. In this case, this function returns -1.
Definition at line 939 of file kundo2stack.cpp.
References m_clean_index.
| void KUndo2QStack::clear | ( | ) |
Clears the command stack by deleting all commands on it, and returns the stack to the clean state.{
}
Commands are not undone or redone; the state of the edited object remains unchanged.
This function is usually used when the contents of the document are abandoned.
Definition at line 675 of file kundo2stack.cpp.
References canRedoChanged(), canUndoChanged(), cleanChanged(), indexChanged(), isClean(), m_clean_index, m_command_list, m_index, m_macro_stack, redoTextChanged(), and undoTextChanged().
| const KUndo2Command * KUndo2QStack::command | ( | int | index | ) | const |
Returns a const pointer to the command at index.
This function returns a const pointer, because modifying a command, once it has been pushed onto the stack and executed, almost always causes corruption of the state of the document, if the command is later undone or redone.
Definition at line 1274 of file kundo2stack.cpp.
References index(), and m_command_list.
| int KUndo2QStack::count | ( | ) | const |
Returns the number of commands on the stack. Macro commands are counted as one command.
Definition at line 1000 of file kundo2stack.cpp.
References m_command_list.
| QAction * KUndo2QStack::createRedoAction | ( | QObject * | parent | ) | const |
Creates an redo QAction object with the given parent.
Triggering this action will cause a call to redo(). The text of this action is the text of the command which will be redone in the next call to redo(), prefixed by the specified prefix. If there is no command available for redo, this action will be disabled.
If prefix is empty, the default prefix "Redo" is used.
Definition at line 1169 of file kundo2stack.cpp.
References canRedo(), canRedoChanged(), connect(), redo(), redoText(), redoTextChanged(), and KUndo2Action::setPrefixedText().
| QAction * KUndo2QStack::createUndoAction | ( | QObject * | parent | ) | const |
Creates an undo QAction object with the given parent.
Triggering this action will cause a call to undo(). The text of this action is the text of the command which will be undone in the next call to undo(), prefixed by the specified prefix. If there is no command available for undo, this action will be disabled.
If prefix is empty, the default prefix "Undo" is used.
Definition at line 1143 of file kundo2stack.cpp.
References canUndo(), canUndoChanged(), connect(), KUndo2Action::setPrefixedText(), undo(), undoText(), and undoTextChanged().
| KisCumulativeUndoData KUndo2QStack::cumulativeUndoData | ( | ) |
Definition at line 1381 of file kundo2stack.cpp.
References m_cumulativeUndoData.
| void KUndo2QStack::endMacro | ( | ) |
Ends composition of a macro command.
If this is the outermost macro in a set nested macros, this function emits indexChanged() once for the entire macro command.
Definition at line 1247 of file kundo2stack.cpp.
References checkUndoLimit(), m_index, m_macro_stack, and setIndex().
| int KUndo2QStack::index | ( | ) | const |
Returns the index of the current command. This is the command that will be executed on the next call to redo(). It is not always the top-most command on the stack, since a number of commands may have been undone.
Definition at line 1013 of file kundo2stack.cpp.
References m_index.
|
signal |
This signal is emitted whenever a command modifies the state of the document. This happens when a command is undone or redone. When a macro command is undone or redone, or setIndex() is called, this signal is emitted only once.
idx specifies the index of the current command, ie. the command which will be executed on the next call to redo().
| bool KUndo2QStack::isActive | ( | ) | const |
Definition at line 1358 of file kundo2stack.cpp.
References KUndo2Group::activeStack(), and m_group.
| bool KUndo2QStack::isClean | ( | ) | const |
If the stack is in the clean state, returns true; otherwise returns false.
Definition at line 921 of file kundo2stack.cpp.
References m_clean_index, m_index, and m_macro_stack.
|
protectedvirtual |
Called by setIndex after every command execution. It is needed by Krita to insert barriers between different kind of commands
Reimplemented in UndoStack.
Definition at line 1056 of file kundo2stack.cpp.
|
slot |
Definition at line 571 of file kundo2stack.cpp.
References canRedo(), canRedoChanged(), cleanChanged(), isClean(), m_clean_index, m_command_list, m_index, m_macro_stack, redoText(), and redoTextChanged().
| void KUndo2QStack::push | ( | KUndo2Command * | cmd | ) |
Pushes cmd on the stack or merges it with the most recently executed command. In either case, executes cmd by calling its redo() function.
If cmd's id is not -1, and if the id is the same as that of the most recently executed command, KUndo2QStack will attempt to merge the two commands by calling KUndo2Command::mergeWith() on the most recently executed command. If KUndo2Command::mergeWith() returns true, cmd is deleted.
In all other cases cmd is simply pushed on the stack.
If commands were undone before cmd was pushed, the current command and all commands above it are deleted. Hence cmd always ends up being the top-most on the stack.
Once a command is pushed, the stack takes ownership of it. There are no getters to return the command, since modifying it after it has been executed will almost always lead to corruption of the document's state.
Here we are going to try to merge several commands together using the QVector field in the commands using 3 parameters.
N : Number of commands that should remain individual at the top of the stack.
T1 : Timeout for the commands to be outdated and merged
T2 : Time separation between two commands to be considered as belonging to the same group
we have a guarantee that std::next(revIt) exists, so we can safely iterate back in the forward order
index and clean_index are one off the real index in the commands list
we have reached the element processed when the previous command was added, now we need to count m_strokesN to make sure that "pinned" jobs are also process
Definition at line 722 of file kundo2stack.cpp.
References KUndo2Command::canAnnihilateWith(), canRedo(), canRedoChanged(), canUndo(), canUndoChanged(), checkUndoLimit(), KUndo2CommandPrivate::child_list, KUndo2Command::d, KUndo2Command::endTime(), KisCumulativeUndoData::excludeFromMerge, KUndo2Command::id(), indexChanged(), KIS_SAFE_ASSERT_RECOVER_BREAK, m_clean_index, m_command_list, m_cumulativeUndoData, m_index, m_macro_stack, m_useCumulativeUndoRedo, KisCumulativeUndoData::maxGroupDuration, KisCumulativeUndoData::maxGroupSeparation, KisCumulativeUndoData::mergeTimeout, KUndo2Command::mergeWith(), KUndo2Command::redoMergedCommands(), redoText(), redoTextChanged(), KUndo2Command::setEndTime(), setIndex(), KUndo2Command::time(), KUndo2Command::timedId(), undoText(), and undoTextChanged().
|
virtualslot |
Redoes the current command by calling KUndo2Command::redo(). Increments the current command index.
If the stack is empty, or if the top command on the stack has already been redone, this function does nothing.
Reimplemented in UndoStack.
Definition at line 979 of file kundo2stack.cpp.
References m_command_list, m_index, m_macro_stack, and setIndex().
| QString KUndo2QStack::redoText | ( | ) | const |
Returns the text of the command which will be redone in the next call to redo().
Definition at line 1119 of file kundo2stack.cpp.
References m_command_list, m_index, and m_macro_stack.
|
signal |
This signal is emitted whenever the value of redoText() changes. It is used to update the text property of the redo action returned by createRedoAction(). redoText specifies the new text.
|
slot |
Definition at line 1344 of file kundo2stack.cpp.
References active, KUndo2Group::activeStack(), m_group, and KUndo2Group::setActiveStack().
|
slot |
Marks the stack as clean and emits cleanChanged() if the stack was not already clean.
Whenever the stack returns to this state through the use of undo/redo commands, it emits the signal cleanChanged(). This signal is also emitted when the stack leaves the clean state.
Definition at line 905 of file kundo2stack.cpp.
References m_index, m_macro_stack, and setIndex().
| void KUndo2QStack::setCumulativeUndoData | ( | const KisCumulativeUndoData & | data | ) |
Definition at line 1376 of file kundo2stack.cpp.
References m_cumulativeUndoData.
|
virtualslot |
Repeatedly calls undo() or redo() until the current command index reaches idx. This function can be used to roll the state of the document forwards of backwards. indexChanged() is emitted only once.
Reimplemented in UndoStack.
Definition at line 1026 of file kundo2stack.cpp.
References m_command_list, m_index, m_macro_stack, notifySetIndexChangedOneCommand(), and setIndex().
|
private |
Definition at line 550 of file kundo2stack.cpp.
References canRedo(), canRedoChanged(), canUndo(), canUndoChanged(), cleanChanged(), indexChanged(), m_clean_index, m_index, redoText(), redoTextChanged(), undoText(), and undoTextChanged().
| void KUndo2QStack::setUndoLimit | ( | int | limit | ) |
Definition at line 1309 of file kundo2stack.cpp.
References checkUndoLimit(), m_command_list, and m_undo_limit.
| void KUndo2QStack::setUseCumulativeUndoRedo | ( | bool | value | ) |
Definition at line 1366 of file kundo2stack.cpp.
References m_useCumulativeUndoRedo, and value().
| QString KUndo2QStack::text | ( | int | idx | ) | const |
Returns the text of the command at index idx.
Definition at line 1287 of file kundo2stack.cpp.
References m_command_list.
|
virtualslot |
Undoes the command below the current command by calling KUndo2Command::undo(). Decrements the current command index.
If the stack is empty, or if the bottom command on the stack has already been undone, this function does nothing.
Reimplemented in UndoStack.
Definition at line 954 of file kundo2stack.cpp.
References m_command_list, m_index, m_macro_stack, and setIndex().
| int KUndo2QStack::undoLimit | ( | ) | const |
Definition at line 1322 of file kundo2stack.cpp.
References m_undo_limit.
| QString KUndo2QStack::undoText | ( | ) | const |
Returns the text of the command which will be undone in the next call to undo().
Definition at line 1102 of file kundo2stack.cpp.
References m_command_list, m_index, and m_macro_stack.
|
signal |
This signal is emitted whenever the value of undoText() changes. It is used to update the text property of the undo action returned by createUndoAction(). undoText specifies the new text.
| bool KUndo2QStack::useCumulativeUndoRedo | ( | ) | const |
Definition at line 1371 of file kundo2stack.cpp.
References m_useCumulativeUndoRedo.
|
friend |
Definition at line 240 of file kundo2stack.h.
|
private |
Definition at line 229 of file kundo2stack.h.
|
private |
Definition at line 226 of file kundo2stack.h.
|
private |
Definition at line 233 of file kundo2stack.h.
|
private |
Definition at line 230 of file kundo2stack.h.
|
private |
Definition at line 228 of file kundo2stack.h.
|
private |
Definition at line 227 of file kundo2stack.h.
|
private |
Definition at line 231 of file kundo2stack.h.
|
private |
Definition at line 232 of file kundo2stack.h.
|
readwrite |
the active status of this stack.
An application often has multiple undo stacks, one for each opened document. The active stack is the one associated with the currently active document. If the stack belongs to a KUndo2Group, calls to KUndo2Group::undo() or KUndo2Group::redo() will be forwarded to this stack when it is active. If the KUndo2Group is watched by a KUndo2View, the view will display the contents of this stack when it is active. If the stack does not belong to a KUndo2Group, making it active has no effect.
It is the programmer's responsibility to specify which stack is active by calling setActive(), usually when the associated document window receives focus.
Definition at line 161 of file kundo2stack.h.
|
readwrite |
the maximum number of commands on this stack.
When the number of commands on a stack exceeds the stack's undoLimit, commands are deleted from the bottom of the stack. Macro commands (commands with child commands) are treated as one command. The default value is 0, which means that there is no limit.
This property may only be set when the undo stack is empty, since setting it on a non-empty stack might delete the command at the current index. Calling setUndoLimit() on a non-empty stack prints a warning and does nothing.
Definition at line 162 of file kundo2stack.h.