Commit d35a9baa authored by Dmitry Kazakov's avatar Dmitry Kazakov
Browse files

Add a barrier between sequentially undone commands with setIndex

Some of the commands are undone asynchronously using strokes and the other
are undone directly by simply executing the code in the loop. To avoid
implicit reordering of the commands which undo/redo we should add barriers
between single commands.

BUG:349819
parent f08f2c33
......@@ -200,6 +200,12 @@ public:
}
}
void notifySetIndexChangedOneCommand() {
KisImageWSP image = this->image();
image->unlock();
image->barrierLock();
}
void undo() {
KisImageWSP image = this->image();
image->requestUndoDuringStroke();
......
......@@ -377,7 +377,7 @@ void KUndo2Command::undoMergedCommands()
QVectorIterator<KUndo2Command*> it(mergeCommandsVector());
it.toFront();
while (it.hasNext()) {
KUndo2Command* cmd = dynamic_cast<KUndo2Command*>(it.next());
KUndo2Command* cmd = it.next();
cmd->undoMergedCommands();
}
}
......@@ -390,7 +390,7 @@ void KUndo2Command::redoMergedCommands()
QVectorIterator<KUndo2Command*> it(mergeCommandsVector());
it.toBack();
while (it.hasPrevious()) {
KUndo2Command* cmd = dynamic_cast<KUndo2Command*>(it.previous());
KUndo2Command* cmd = it.previous();
cmd->redoMergedCommands();
}
}
......@@ -973,14 +973,25 @@ void KUndo2QStack::setIndex(int idx)
int i = m_index;
while (i < idx) {
m_command_list.at(i++)->redoMergedCommands();
notifySetIndexChangedOneCommand();
}
while (i > idx) {
m_command_list.at(--i)->undoMergedCommands();
notifySetIndexChangedOneCommand();
}
setIndex(idx, false);
}
/**
* Called by setIndex after every command execution. It is needed by
* Krita to insert barriers between different kind of commands
*/
void KUndo2QStack::notifySetIndexChangedOneCommand()
{
}
/*!
Returns true if there is a command available for undo; otherwise returns false.
......
......@@ -217,6 +217,9 @@ Q_SIGNALS:
void undoTextChanged(const QString &undoActionText);
void redoTextChanged(const QString &redoActionText);
protected:
virtual void notifySetIndexChangedOneCommand();
private:
// from QUndoStackPrivate
QList<KUndo2Command*> m_command_list;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment