Krita Source Code Documentation
Loading...
Searching...
No Matches
KUndo2QStack Class Reference

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 KUndo2Commandcommand (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
 
KUndo2Groupm_group
 
int m_index
 
QList< KUndo2Command * > m_macro_stack
 
int m_undo_limit
 
bool m_useCumulativeUndoRedo
 

Friends

class KUndo2Group
 

Detailed Description

The KUndo2QStack class is a stack of KUndo2Command objects.

Since
4.2

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.

Constructor & Destructor Documentation

◆ KUndo2QStack()

KUndo2QStack::KUndo2QStack ( QObject * parent = 0)
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.

See also
push()

Definition at line 634 of file kundo2stack.cpp.

635 : QObject(parent), m_index(0), m_clean_index(0), m_group(0), m_undo_limit(0)
637{
638#ifndef QT_NO_UNDOGROUP
639 if (KUndo2Group *group = qobject_cast<KUndo2Group*>(parent))
640 group->addStack(this);
641#endif
642}
The KUndo2Group class is a group of KUndo2QStack objects.
Definition kundo2group.h:57
void addStack(KUndo2QStack *stack)
bool m_useCumulativeUndoRedo
KUndo2Group * m_group

◆ ~KUndo2QStack()

KUndo2QStack::~KUndo2QStack ( )
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.

See also
KUndo2QStack()The number of last strokes which Krita should store separately

Definition at line 651 of file kundo2stack.cpp.

652{
653#ifndef QT_NO_UNDOGROUP
654 if (m_group != 0)
655 m_group->removeStack(this);
656#endif
657 clear();
658}
void removeStack(KUndo2QStack *stack)

References clear(), m_group, and KUndo2Group::removeStack().

Member Function Documentation

◆ actionText()

QString KUndo2QStack::actionText ( int idx) const

◆ beginMacro()

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:

See also
endMacro()

Definition at line 1214 of file kundo2stack.cpp.

1215{
1216 KUndo2Command *cmd = new KUndo2Command();
1217 cmd->setText(text);
1218
1219 if (m_macro_stack.isEmpty()) {
1220 while (m_index < m_command_list.size())
1221 delete m_command_list.takeLast();
1222 if (m_clean_index > m_index)
1223 m_clean_index = -1; // we've deleted the clean state
1224 m_command_list.append(cmd);
1225 } else {
1226 m_macro_stack.last()->d->child_list.append(cmd);
1227 }
1228 m_macro_stack.append(cmd);
1229
1230 if (m_macro_stack.count() == 1) {
1231 Q_EMIT canUndoChanged(false);
1232 Q_EMIT undoTextChanged(QString());
1233 Q_EMIT canRedoChanged(false);
1234 Q_EMIT redoTextChanged(QString());
1235 }
1236}
void setText(const KUndo2MagicString &text)
QList< KUndo2Command * > m_command_list
QList< KUndo2Command * > m_macro_stack
void redoTextChanged(const QString &redoActionText)
void canUndoChanged(bool canUndo)
QString text(int idx) const
void canRedoChanged(bool canRedo)
void undoTextChanged(const QString &undoActionText)

References canRedoChanged(), canUndoChanged(), m_clean_index, m_command_list, m_index, m_macro_stack, redoTextChanged(), KUndo2Command::setText(), text(), and undoTextChanged().

◆ canRedo()

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().

See also
index() canUndo()

Definition at line 1089 of file kundo2stack.cpp.

1090{
1091 if (!m_macro_stack.isEmpty())
1092 return false;
1093 return m_index < m_command_list.size();
1094}

References m_command_list, m_index, and m_macro_stack.

◆ canRedoChanged

void KUndo2QStack::canRedoChanged ( bool canRedo)
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.

◆ canUndo()

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.

See also
index() canRedo()

Definition at line 1071 of file kundo2stack.cpp.

1072{
1073 if (!m_macro_stack.isEmpty())
1074 return false;
1075 return m_index > 0;
1076}

References m_index, and m_macro_stack.

◆ canUndoChanged

void KUndo2QStack::canUndoChanged ( bool canUndo)
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.

◆ checkUndoLimit()

bool KUndo2QStack::checkUndoLimit ( )
private

Definition at line 606 of file kundo2stack.cpp.

607{
608 if (m_undo_limit <= 0 || !m_macro_stack.isEmpty() || m_undo_limit >= m_command_list.count())
609 return false;
610
611 int del_count = m_command_list.count() - m_undo_limit;
612
613 for (int i = 0; i < del_count; ++i)
614 delete m_command_list.takeFirst();
615
616 m_index -= del_count;
617 if (m_clean_index != -1) {
618 if (m_clean_index < del_count)
619 m_clean_index = -1; // we've deleted the clean command
620 else
621 m_clean_index -= del_count;
622 }
623 return true;
624}

References m_clean_index, m_command_list, m_index, m_macro_stack, and m_undo_limit.

◆ cleanChanged

void KUndo2QStack::cleanChanged ( bool clean)
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.

See also
isClean() setClean()

◆ cleanIndex()

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.

See also
isClean() setClean()

Definition at line 939 of file kundo2stack.cpp.

940{
941 return m_clean_index;
942}

References m_clean_index.

◆ clear()

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.

See also
KUndo2QStack()

Definition at line 675 of file kundo2stack.cpp.

676{
677 if (m_command_list.isEmpty())
678 return;
679
680 bool was_clean = isClean();
681
682 m_macro_stack.clear();
683 qDeleteAll(m_command_list);
684 m_command_list.clear();
685
686 m_index = 0;
687 m_clean_index = 0;
688
689 Q_EMIT indexChanged(0);
690 Q_EMIT canUndoChanged(false);
691 Q_EMIT undoTextChanged(QString());
692 Q_EMIT canRedoChanged(false);
693 Q_EMIT redoTextChanged(QString());
694
695 if (!was_clean)
696 Q_EMIT cleanChanged(true);
697}
void cleanChanged(bool clean)
void indexChanged(int idx)
bool isClean() const

References canRedoChanged(), canUndoChanged(), cleanChanged(), indexChanged(), isClean(), m_clean_index, m_command_list, m_index, m_macro_stack, redoTextChanged(), and undoTextChanged().

◆ command()

const KUndo2Command * KUndo2QStack::command ( int index) const
Since
4.4

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.

See also
KUndo2Command::child()

Definition at line 1274 of file kundo2stack.cpp.

1275{
1276 if (index < 0 || index >= m_command_list.count())
1277 return 0;
1278 return m_command_list.at(index);
1279}
int index() const

References index(), and m_command_list.

◆ count()

int KUndo2QStack::count ( ) const

Returns the number of commands on the stack. Macro commands are counted as one command.

See also
index() setIndex() command()

Definition at line 1000 of file kundo2stack.cpp.

1001{
1002 return m_command_list.size();
1003}

References m_command_list.

◆ createRedoAction()

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.

See also
createUndoAction(), canRedo(), KUndo2Command::text()

Definition at line 1169 of file kundo2stack.cpp.

1170{
1171 KUndo2Action *result = new KUndo2Action(i18n("Redo %1"), i18nc("Default text for redo action", "Redo"), parent);
1172 result->setEnabled(canRedo());
1173 result->setPrefixedText(redoText());
1174 connect(this, SIGNAL(canRedoChanged(bool)),
1175 result, SLOT(setEnabled(bool)));
1176 connect(this, SIGNAL(redoTextChanged(QString)),
1177 result, SLOT(setPrefixedText(QString)));
1178 connect(result, SIGNAL(triggered()), this, SLOT(redo()));
1179 return result;
1180}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
void setPrefixedText(const QString &text)
QString redoText() const
bool canRedo() const
virtual void redo()

References canRedo(), canRedoChanged(), connect(), redo(), redoText(), redoTextChanged(), and KUndo2Action::setPrefixedText().

◆ createUndoAction()

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.

See also
createRedoAction(), canUndo(), KUndo2Command::text()

Definition at line 1143 of file kundo2stack.cpp.

1144{
1145 KUndo2Action *result = new KUndo2Action(i18n("Undo %1"), i18nc("Default text for undo action", "Undo"), parent);
1146 result->setEnabled(canUndo());
1147 result->setPrefixedText(undoText());
1148 connect(this, SIGNAL(canUndoChanged(bool)),
1149 result, SLOT(setEnabled(bool)));
1150 connect(this, SIGNAL(undoTextChanged(QString)),
1151 result, SLOT(setPrefixedText(QString)));
1152 connect(result, SIGNAL(triggered()), this, SLOT(undo()));
1153 return result;
1154}
QString undoText() const
virtual void undo()
bool canUndo() const

References canUndo(), canUndoChanged(), connect(), KUndo2Action::setPrefixedText(), undo(), undoText(), and undoTextChanged().

◆ cumulativeUndoData()

KisCumulativeUndoData KUndo2QStack::cumulativeUndoData ( )

Definition at line 1381 of file kundo2stack.cpp.

1382{
1383 return m_cumulativeUndoData;
1384}
KisCumulativeUndoData m_cumulativeUndoData

References m_cumulativeUndoData.

◆ endMacro()

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.

See also
beginMacro()

Definition at line 1247 of file kundo2stack.cpp.

1248{
1249 if (m_macro_stack.isEmpty()) {
1250 qWarning("KUndo2QStack::endMacro(): no matching beginMacro()");
1251 return;
1252 }
1253
1254 m_macro_stack.removeLast();
1255
1256 if (m_macro_stack.isEmpty()) {
1258 setIndex(m_index + 1, false);
1259 }
1260}
virtual void setIndex(int idx)
bool checkUndoLimit()

References checkUndoLimit(), m_index, m_macro_stack, and setIndex().

◆ index()

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.

See also
undo() redo() count()

Definition at line 1013 of file kundo2stack.cpp.

1014{
1015 return m_index;
1016}

References m_index.

◆ indexChanged

void KUndo2QStack::indexChanged ( int idx)
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().

See also
index() setIndex()

◆ isActive()

bool KUndo2QStack::isActive ( ) const

Definition at line 1358 of file kundo2stack.cpp.

1359{
1360#ifdef QT_NO_UNDOGROUP
1361 return true;
1362#else
1363 return m_group == 0 || m_group->activeStack() == this;
1364#endif
1365}
KUndo2QStack * activeStack() const

References KUndo2Group::activeStack(), and m_group.

◆ isClean()

bool KUndo2QStack::isClean ( ) const

If the stack is in the clean state, returns true; otherwise returns false.

See also
setClean() cleanIndex()

Definition at line 921 of file kundo2stack.cpp.

922{
923 if (!m_macro_stack.isEmpty())
924 return false;
925 return m_clean_index == m_index;
926}

References m_clean_index, m_index, and m_macro_stack.

◆ notifySetIndexChangedOneCommand()

void KUndo2QStack::notifySetIndexChangedOneCommand ( )
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.

1057{
1058}

◆ purgeRedoState

void KUndo2QStack::purgeRedoState ( )
slot

Definition at line 571 of file kundo2stack.cpp.

572{
573 bool macro = !m_macro_stack.isEmpty();
574 if (macro) return;
575
576 bool redoStateChanged = false;
577 bool cleanStateChanged = false;
578
579 while (m_index < m_command_list.size()) {
580 delete m_command_list.takeLast();
581 redoStateChanged = true;
582 }
583
584 if (m_clean_index > m_index) {
585 m_clean_index = -1; // we've deleted the clean state
586 cleanStateChanged = true;
587 }
588
589 if (redoStateChanged) {
590 Q_EMIT canRedoChanged(canRedo());
591 Q_EMIT redoTextChanged(redoText());
592 }
593
594 if (cleanStateChanged) {
595 Q_EMIT cleanChanged(isClean());
596 }
597}

References canRedo(), canRedoChanged(), cleanChanged(), isClean(), m_clean_index, m_command_list, m_index, m_macro_stack, redoText(), and redoTextChanged().

◆ push()

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.

See also
KUndo2Command::id() KUndo2Command::mergeWith()

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.

723{
724 cmd->redoMergedCommands();
725
726 if (cmd->endTime().isNull()) {
727 cmd->setEndTime();
728 }
729
730 bool macro = !m_macro_stack.isEmpty();
731
732 KUndo2Command *cur = 0;
733 if (macro) {
734 KUndo2Command *macro_cmd = m_macro_stack.last();
735 if (!macro_cmd->d->child_list.isEmpty())
736 cur = macro_cmd->d->child_list.last();
737 } else {
738 if (m_index > 0)
739 cur = m_command_list.at(m_index - 1);
740 while (m_index < m_command_list.size())
741 delete m_command_list.takeLast();
743 m_clean_index = -1; // we've deleted the clean state
744 }
745
746 bool try_merge = cur != 0
747 && cur->id() != -1
748 && cur->id() == cmd->id()
749 && (macro || m_index != m_clean_index);
750
765 if (!macro && m_command_list.size() > 1 && cmd->timedId() != -1 && m_useCumulativeUndoRedo) {
766 KUndo2Command* lastcmd = m_command_list.last();
767
768 auto tryMergeBack =
769 [this] (auto revIt, bool *isMerged) {
772 auto dst = std::prev(revIt.base());
773 auto src = std::prev(dst);
774
775 if ((*dst)->timedId() != -1 &&
776 (*dst)->timedId() == (*src)->timedId() &&
777 (*src)->time().msecsTo((*dst)->endTime()) <= m_cumulativeUndoData.maxGroupDuration &&
778 (*src)->endTime().msecsTo((*dst)->time()) <= m_cumulativeUndoData.maxGroupSeparation &&
779 (*dst)->timedMergeWith(*src)) {
780
781 const int removedIndex = std::distance(m_command_list.begin(), src);
782
785 if (m_clean_index - 1 == removedIndex) {
786 m_clean_index = -1;
787 } else if (m_clean_index - 1 > removedIndex) {
789 }
790 m_index--;
791
792 dst = m_command_list.erase(src);
793 *isMerged = true;
794 } else {
795 *isMerged = false;
796 }
797
798 return std::make_reverse_iterator(std::next(dst));
799 };
800
801 int extraCheckDepth = 0;
802 int newDepth = 1; // `cmd` will be added soon and will increase the total depth!
803 QTime oldTimeBase = lastcmd->time(); // needed to calculate already processed items
804 QTime newTimeBase = cmd->time();
805
806 auto it = std::make_reverse_iterator(m_command_list.end());
807 auto next = std::next(it);
808
809 while (next != std::make_reverse_iterator(m_command_list.begin())) {
810
811 if (newDepth < m_cumulativeUndoData.excludeFromMerge) {
812 ++it;
813 ++newDepth;
814 next = std::next(it);
815 continue;
816 }
817
818 int oldTime = (*it)->endTime().msecsTo(oldTimeBase);
819 int newTime = (*it)->endTime().msecsTo(newTimeBase);
820
825 if (oldTime > m_cumulativeUndoData.mergeTimeout &&
826 extraCheckDepth++ >= m_cumulativeUndoData.excludeFromMerge) break;
827
828 if (newTime >= m_cumulativeUndoData.mergeTimeout) {
829 bool merged = true;
830
831 KUndo2Command *debugOldCmd = *it;
832
833 it = tryMergeBack(it, &merged);
834
835 KUndo2Command *debugNewCmd = *it;
836
837 KIS_SAFE_ASSERT_RECOVER_BREAK(it != std::make_reverse_iterator(m_command_list.begin()));
838 KIS_SAFE_ASSERT_RECOVER_BREAK(debugOldCmd == debugNewCmd);
839
840 if (!merged) {
841 ++it;
842 ++newDepth;
843 }
844
845 } else {
846 ++it;
847 ++newDepth;
848 }
849
850 next = std::next(it);
851 }
852 }
853
854 if (try_merge && !macro && cur->canAnnihilateWith(cmd)) {
855 delete cmd;
856 if (!macro) {
857 // this condition must be ruled out by try_merge check
858 // otherwise we would have to do cleanup for the clean state
859 Q_ASSERT(m_clean_index != m_index);
860
861 delete m_command_list.takeLast();
862 m_index--;
863
864 Q_EMIT indexChanged(m_index);
865 Q_EMIT canUndoChanged(canUndo());
866 Q_EMIT undoTextChanged(undoText());
867 Q_EMIT canRedoChanged(canRedo());
868 Q_EMIT redoTextChanged(redoText());
869 } else {
870 delete m_macro_stack.takeLast();
871 }
872
873 } else if (try_merge && cur->mergeWith(cmd)) {
874 delete cmd;
875 if (!macro) {
876 Q_EMIT indexChanged(m_index);
877 Q_EMIT canUndoChanged(canUndo());
878 Q_EMIT undoTextChanged(undoText());
879 Q_EMIT canRedoChanged(canRedo());
880 Q_EMIT redoTextChanged(redoText());
881 }
882 } else {
883 if (macro) {
884 m_macro_stack.last()->d->child_list.append(cmd);
885 } else {
886 m_command_list.append(cmd);
887
889 setIndex(m_index + 1, false);
890 }
891 }
892}
QList< KUndo2Command * > child_list
virtual bool mergeWith(const KUndo2Command *other)
virtual void redoMergedCommands()
KUndo2CommandPrivate * d
Definition kundo2stack.h:88
virtual QTime time() const
virtual QTime endTime() const
virtual bool canAnnihilateWith(const KUndo2Command *other) const
virtual int id() const
virtual int timedId() const
#define KIS_SAFE_ASSERT_RECOVER_BREAK(cond)
Definition kis_assert.h:127
QAction * next(const QObject *recvr, const char *slot, QObject *parent)

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().

◆ redo

void KUndo2QStack::redo ( )
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.

See also
undo() index()

Reimplemented in UndoStack.

Definition at line 979 of file kundo2stack.cpp.

980{
981 if (m_index == m_command_list.size())
982 return;
983
984 if (!m_macro_stack.isEmpty()) {
985 qWarning("KUndo2QStack::redo(): cannot redo in the middle of a macro");
986 return;
987 }
988
989 m_command_list.at(m_index)->redoMergedCommands();
990 setIndex(m_index + 1, false);
991}

References m_command_list, m_index, m_macro_stack, and setIndex().

◆ redoText()

QString KUndo2QStack::redoText ( ) const

Returns the text of the command which will be redone in the next call to redo().

See also
KUndo2Command::text() undoActionText() redoItemText()

Definition at line 1119 of file kundo2stack.cpp.

1120{
1121 if (!m_macro_stack.isEmpty())
1122 return QString();
1123 if (m_index < m_command_list.size())
1124 return m_command_list.at(m_index)->actionText();
1125 return QString();
1126}

References m_command_list, m_index, and m_macro_stack.

◆ redoTextChanged

void KUndo2QStack::redoTextChanged ( const QString & redoText)
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.

◆ setActive

void KUndo2QStack::setActive ( bool active = true)
slot

Definition at line 1344 of file kundo2stack.cpp.

1345{
1346#ifdef QT_NO_UNDOGROUP
1347 Q_UNUSED(active);
1348#else
1349 if (m_group != 0) {
1350 if (active)
1351 m_group->setActiveStack(this);
1352 else if (m_group->activeStack() == this)
1354 }
1355#endif
1356}
void setActiveStack(KUndo2QStack *stack)
bool active
the active status of this stack.

References active, KUndo2Group::activeStack(), m_group, and KUndo2Group::setActiveStack().

◆ setClean

void KUndo2QStack::setClean ( )
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.

See also
isClean(), cleanIndex()

Definition at line 905 of file kundo2stack.cpp.

906{
907 if (!m_macro_stack.isEmpty()) {
908 qWarning("KUndo2QStack::setClean(): cannot set clean in the middle of a macro");
909 return;
910 }
911
912 setIndex(m_index, true);
913}

References m_index, m_macro_stack, and setIndex().

◆ setCumulativeUndoData()

void KUndo2QStack::setCumulativeUndoData ( const KisCumulativeUndoData & data)

Definition at line 1376 of file kundo2stack.cpp.

1377{
1378 m_cumulativeUndoData = data;
1379}

References m_cumulativeUndoData.

◆ setIndex [1/2]

void KUndo2QStack::setIndex ( int idx)
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.

See also
index() count() undo() redo()

Reimplemented in UndoStack.

Definition at line 1026 of file kundo2stack.cpp.

1027{
1028 if (!m_macro_stack.isEmpty()) {
1029 qWarning("KUndo2QStack::setIndex(): cannot set index in the middle of a macro");
1030 return;
1031 }
1032
1033 if (idx < 0)
1034 idx = 0;
1035 else if (idx > m_command_list.size())
1036 idx = m_command_list.size();
1037
1038 int i = m_index;
1039 while (i < idx) {
1040 m_command_list.at(i++)->redoMergedCommands();
1042 }
1043 while (i > idx) {
1044 m_command_list.at(--i)->undoMergedCommands();
1046 }
1047
1048 setIndex(idx, false);
1049}
virtual void notifySetIndexChangedOneCommand()

References m_command_list, m_index, m_macro_stack, notifySetIndexChangedOneCommand(), and setIndex().

◆ setIndex() [2/2]

void KUndo2QStack::setIndex ( int idx,
bool clean )
private

Definition at line 550 of file kundo2stack.cpp.

551{
552 bool was_clean = m_index == m_clean_index;
553
554 if (idx != m_index) {
555 m_index = idx;
556 Q_EMIT indexChanged(m_index);
557 Q_EMIT canUndoChanged(canUndo());
558 Q_EMIT undoTextChanged(undoText());
559 Q_EMIT canRedoChanged(canRedo());
560 Q_EMIT redoTextChanged(redoText());
561 }
562
563 if (clean)
565
566 bool is_clean = m_index == m_clean_index;
567 if (is_clean != was_clean)
568 Q_EMIT cleanChanged(is_clean);
569}

References canRedo(), canRedoChanged(), canUndo(), canUndoChanged(), cleanChanged(), indexChanged(), m_clean_index, m_index, redoText(), redoTextChanged(), undoText(), and undoTextChanged().

◆ setUndoLimit()

void KUndo2QStack::setUndoLimit ( int limit)

Definition at line 1309 of file kundo2stack.cpp.

1310{
1311 if (!m_command_list.isEmpty()) {
1312 qWarning("KUndo2QStack::setUndoLimit(): an undo limit can only be set when the stack is empty");
1313 return;
1314 }
1315
1316 if (limit == m_undo_limit)
1317 return;
1318 m_undo_limit = limit;
1320}

References checkUndoLimit(), m_command_list, and m_undo_limit.

◆ setUseCumulativeUndoRedo()

void KUndo2QStack::setUseCumulativeUndoRedo ( bool value)

Definition at line 1366 of file kundo2stack.cpp.

1367{
1369}
float value(const T *src, size_t ch)

References m_useCumulativeUndoRedo, and value().

◆ text()

QString KUndo2QStack::text ( int idx) const

Returns the text of the command at index idx.

See also
beginMacro()

Definition at line 1287 of file kundo2stack.cpp.

1288{
1289 if (idx < 0 || idx >= m_command_list.size())
1290 return QString();
1291 return m_command_list.at(idx)->text().toString();
1292}

References m_command_list.

◆ undo

void KUndo2QStack::undo ( )
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.

See also
redo() index()

Reimplemented in UndoStack.

Definition at line 954 of file kundo2stack.cpp.

955{
956 if (m_index == 0)
957 return;
958
959 if (!m_macro_stack.isEmpty()) {
960 qWarning("KUndo2QStack::undo(): cannot undo in the middle of a macro");
961 return;
962 }
963
964 int idx = m_index - 1;
965 m_command_list.at(idx)->undoMergedCommands();
966 setIndex(idx, false);
967}

References m_command_list, m_index, m_macro_stack, and setIndex().

◆ undoLimit()

int KUndo2QStack::undoLimit ( ) const

Definition at line 1322 of file kundo2stack.cpp.

1323{
1324 return m_undo_limit;
1325}

References m_undo_limit.

◆ undoText()

QString KUndo2QStack::undoText ( ) const

Returns the text of the command which will be undone in the next call to undo().

See also
KUndo2Command::text() redoActionText() undoItemText()

Definition at line 1102 of file kundo2stack.cpp.

1103{
1104 if (!m_macro_stack.isEmpty()) {
1105 return QString();
1106 }
1107 if (m_index > 0 && m_command_list.count() >= m_index -1 && m_command_list.at(m_index - 1) != 0) {
1108 return m_command_list.at(m_index - 1)->actionText();
1109 }
1110 return QString();
1111}

References m_command_list, m_index, and m_macro_stack.

◆ undoTextChanged

void KUndo2QStack::undoTextChanged ( const QString & undoText)
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.

◆ useCumulativeUndoRedo()

bool KUndo2QStack::useCumulativeUndoRedo ( ) const

Definition at line 1371 of file kundo2stack.cpp.

1372{
1374}

References m_useCumulativeUndoRedo.

Friends And Related Symbol Documentation

◆ KUndo2Group

friend class KUndo2Group
friend

Definition at line 240 of file kundo2stack.h.

Member Data Documentation

◆ m_clean_index

int KUndo2QStack::m_clean_index
private

Definition at line 229 of file kundo2stack.h.

◆ m_command_list

QList<KUndo2Command*> KUndo2QStack::m_command_list
private

Definition at line 226 of file kundo2stack.h.

◆ m_cumulativeUndoData

KisCumulativeUndoData KUndo2QStack::m_cumulativeUndoData
private

Definition at line 233 of file kundo2stack.h.

◆ m_group

KUndo2Group* KUndo2QStack::m_group
private

Definition at line 230 of file kundo2stack.h.

◆ m_index

int KUndo2QStack::m_index
private

Definition at line 228 of file kundo2stack.h.

◆ m_macro_stack

QList<KUndo2Command*> KUndo2QStack::m_macro_stack
private

Definition at line 227 of file kundo2stack.h.

◆ m_undo_limit

int KUndo2QStack::m_undo_limit
private

Definition at line 231 of file kundo2stack.h.

◆ m_useCumulativeUndoRedo

bool KUndo2QStack::m_useCumulativeUndoRedo
private

Definition at line 232 of file kundo2stack.h.

Property Documentation

◆ active

KUndo2QStack::active
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.

See also
KUndo2Group

Definition at line 161 of file kundo2stack.h.

◆ undoLimit

KUndo2QStack::undoLimit
readwrite

the maximum number of commands on this stack.

Since
4.3

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.


The documentation for this class was generated from the following files: