digiKam
undomanager.h
Go to the documentation of this file.
1 /* ============================================================
2  *
3  * This file is a part of digiKam project
4  * https://www.digikam.org
5  *
6  * Date : 2005-02-06
7  * Description : an image editor actions undo/redo manager
8  *
9  * Copyright (C) 2005-2006 by Renchi Raju <renchi dot raju at gmail dot com>
10  * Copyright (C) 2005-2006 by Joern Ahrens <joern dot ahrens at kdemail dot net>
11  * Copyright (C) 2006-2022 by Gilles Caulier <caulier dot gilles at gmail dot com>
12  *
13  * This program is free software; you can redistribute it
14  * and/or modify it under the terms of the GNU General
15  * Public License as published by the Free Software Foundation;
16  * either version 2, or (at your option)
17  * any later version.
18  *
19  * This program is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22  * GNU General Public License for more details.
23  *
24  * ============================================================ */
25 
26 #ifndef DIGIKAM_UNDO_MANAGER_H
27 #define DIGIKAM_UNDO_MANAGER_H
28 
29 // Qt includes
30 
31 #include <QStringList>
32 
33 // Local includes
34 
35 #include "digikam_export.h"
36 
37 namespace Digikam
38 {
39 
40 class DImageHistory;
41 class DImg;
42 class EditorCore;
43 class UndoAction;
44 class UndoMetadataContainer;
45 
46 class DIGIKAM_EXPORT UndoManager
47 {
48 
49 public:
50 
51  explicit UndoManager(EditorCore* const core);
52  ~UndoManager();
53 
54  void addAction(UndoAction* const action);
55  void undo();
56  void redo();
57  void rollbackToOrigin();
58  bool putImageDataAndHistory(DImg* const img, int stepsBack) const;
59 
60  void clear(bool clearCache = true);
61 
62  bool anyMoreUndo() const;
63  bool anyMoreRedo() const;
64  int availableUndoSteps() const;
65  int availableRedoSteps() const;
66  QStringList getUndoHistory() const;
67  QStringList getRedoHistory() const;
68  bool isAtOrigin() const;
69  void setOrigin() const;
70  bool hasChanges() const;
71 
73  DImageHistory getImageHistoryOfFullRedo() const;
74 
75  void clearPreviousOriginData();
76 
77 private:
78 
79  void clearUndoActions();
80  void clearRedoActions();
81  void undoStep(bool saveRedo, bool execute, bool flyingRollback);
82  void redoStep(bool execute, bool flyingRollback);
83  void makeSnapshot(int index);
84  void restoreSnapshot(int index, const UndoMetadataContainer& c);
85  void getSnapshot(int index, DImg* const img) const;
86 
87 private:
88 
89  // Disable
90  UndoManager(const UndoManager&) = delete;
91  UndoManager& operator=(const UndoManager&) = delete;
92 
93 private:
94 
95  class Private;
96  Private* const d;
97 };
98 
99 } // namespace Digikam
100 
101 #endif // DIGIKAM_UNDO_MANAGER_H
Definition: dimagehistory.h:49
Definition: dimg.h:62
Definition: editorcore.h:58
Definition: undoaction.h:66
Definition: undomanager.h:47
Definition: undoaction.h:42
Definition: datefolderview.cpp:43