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

0001 /*
0002  *  SPDX-FileCopyrightText: 2003 Patrick Julien <freak@codepimps.org>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef KIS_UNDO_STORE_H_
0008 #define KIS_UNDO_STORE_H_
0009 
0010 #include <QObject>
0011 #include <QString>
0012 #include <QVector>
0013 
0014 #include <kritacommand_export.h>
0015 
0016 class KUndo2Command;
0017 class KUndo2MagicString;
0018 
0019 
0020 /**
0021  * See also: https://community.kde.org/Krita/Undo_adapter_vs_Undo_store
0022  *
0023  * Split the functionality of KisUndoAdapter into two classes:
0024  * KisUndoStore and KisUndoAdapter. The former one works as an
0025  * interface to an external storage of the undo information:
0026  * undo stack, KisDocument, /dev/null. The latter one defines the
0027  * behavior of the system when someone wants to add a command. There
0028  * are three variants:
0029  *    1) KisSurrogateUndoAdapter -- saves commands directly to the
0030  *       internal stack. Used for wrapping around legacy code into
0031  *       a single command.
0032  *    2) KisLegacyUndoAdapter -- blocks the strokes and updates queue,
0033  *       and then adds the command to a store
0034  *    3) KisPostExecutionUndoAdapter -- used by the strokes. It doesn't
0035  *       call redo() when you add a command. It is assumed, that you have
0036  *       already executed the command yourself and now just notify
0037  *       the system about it. Warning: it doesn't inherit KisUndoAdapter
0038  *       because it doesn't fit the contract of this class. And, more
0039  *       important, KisTransaction should work differently with this class.
0040  *
0041  * The ownership on the KisUndoStore (that substituted KisUndoAdapter
0042  * in the document's code) now belongs to the image. It means that
0043  * KisDocument::createUndoStore() is just a factory method, the document
0044  * doesn't store the undo store itself.
0045  */
0046 class KRITACOMMAND_EXPORT KisUndoStore : public QObject
0047 {
0048     Q_OBJECT
0049 public:
0050     KisUndoStore();
0051     virtual ~KisUndoStore();
0052 
0053 public:
0054     /**
0055      * WARNING: All these methods are not considered as thread-safe
0056      */
0057 
0058     virtual const KUndo2Command* presentCommand() = 0;
0059     virtual void undoLastCommand() = 0;
0060     virtual void addCommand(KUndo2Command *cmd) = 0;
0061     virtual void beginMacro(const KUndo2MagicString& macroName) = 0;
0062     virtual void endMacro() = 0;
0063     virtual void purgeRedoState() = 0;
0064 
0065 Q_SIGNALS:
0066     void historyStateChanged();
0067 
0068 private:
0069     Q_DISABLE_COPY(KisUndoStore)
0070 };
0071 
0072 
0073 #endif // KIS_UNDO_STORE_H_
0074