File indexing completed on 2024-05-12 15:56:13

0001 /*
0002  *  SPDX-FileCopyrightText: 2011 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include "kis_undo_stores.h"
0008 
0009 #include <kundo2stack.h>
0010 
0011 
0012 /*****************************************************************/
0013 /*                KisSurrogateUndoStore                           */
0014 /*****************************************************************/
0015 
0016 KisSurrogateUndoStore::KisSurrogateUndoStore()
0017     : m_undoStack(new KUndo2Stack)
0018 {
0019     // Use direct connection to avoid queueing the singal forwarding (BUG:447985)
0020     connect(m_undoStack, SIGNAL(indexChanged(int)), this, SIGNAL(historyStateChanged()), Qt::DirectConnection);
0021 }
0022 
0023 KisSurrogateUndoStore::~KisSurrogateUndoStore()
0024 {
0025     // disconnect the signal to avoid the it being emitted on destruction
0026     disconnect(m_undoStack, SIGNAL(indexChanged(int)), this, SIGNAL(historyStateChanged()));
0027     delete m_undoStack;
0028 }
0029 
0030 const KUndo2Command* KisSurrogateUndoStore::presentCommand()
0031 {
0032     return m_undoStack->command(m_undoStack->index() - 1);
0033 }
0034 
0035 void KisSurrogateUndoStore::undoLastCommand()
0036 {
0037     m_undoStack->undo();
0038 }
0039 
0040 void KisSurrogateUndoStore::addCommand(KUndo2Command *command)
0041 {
0042     if(!command) return;
0043     m_undoStack->push(command);
0044 }
0045 
0046 void KisSurrogateUndoStore::beginMacro(const KUndo2MagicString& macroName)
0047 {
0048     m_undoStack->beginMacro(macroName);
0049 }
0050 
0051 void KisSurrogateUndoStore::endMacro()
0052 {
0053     m_undoStack->endMacro();
0054 }
0055 
0056 void KisSurrogateUndoStore::undo()
0057 {
0058     m_undoStack->undo();
0059 }
0060 
0061 void KisSurrogateUndoStore::redo()
0062 {
0063     m_undoStack->redo();
0064 }
0065 
0066 void KisSurrogateUndoStore::purgeRedoState()
0067 {
0068     m_undoStack->purgeRedoState();
0069 }
0070 
0071 void KisSurrogateUndoStore::clear()
0072 {
0073     m_undoStack->clear();
0074 }
0075 
0076 void KisSurrogateUndoStore::undoAll()
0077 {
0078     while(m_undoStack->canUndo()) {
0079         m_undoStack->undo();
0080     }
0081 }
0082 
0083 void KisSurrogateUndoStore::redoAll()
0084 {
0085     while(m_undoStack->canRedo()) {
0086         m_undoStack->redo();
0087     }
0088 }
0089 
0090 
0091 /*****************************************************************/
0092 /*                KisDumbUndoStore                               */
0093 /*****************************************************************/
0094 
0095 const KUndo2Command* KisDumbUndoStore::presentCommand()
0096 {
0097     return 0;
0098 }
0099 
0100 void KisDumbUndoStore::undoLastCommand()
0101 {
0102     /**
0103      * Ermm.. Do we actually have one? We are dumb! ;)
0104      */
0105 
0106     emit historyStateChanged();
0107 }
0108 
0109 void KisDumbUndoStore::addCommand(KUndo2Command *command)
0110 {
0111     /**
0112      * Ermm.. Done with it! :P
0113      */
0114     command->redo();
0115     delete command;
0116 
0117     emit historyStateChanged();
0118 }
0119 
0120 void KisDumbUndoStore::beginMacro(const KUndo2MagicString& macroName)
0121 {
0122     /**
0123      * Yes, sir! >:)
0124      */
0125     Q_UNUSED(macroName);
0126 }
0127 
0128 void KisDumbUndoStore::endMacro()
0129 {
0130     /**
0131      * Roger that! :)
0132      */
0133 
0134     emit historyStateChanged();
0135 }
0136 
0137 void KisDumbUndoStore::purgeRedoState()
0138 {
0139     /**
0140      * Erm... what? %)
0141      */
0142 }