summaryrefslogtreecommitdiff
path: root/src/commands.h
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2023-07-07 12:37:21 +0200
committerToni Uhlig <matzeton@googlemail.com>2023-07-07 12:37:21 +0200
commit004b73ed7ef33cb407897f7eccbec5f3861f99d7 (patch)
tree590f4a80bb66fcc74452c9ae0ac824b7d4bc5871 /src/commands.h
Squashed 'qhexedit2/' content from commit 7f22526
git-subtree-dir: qhexedit2 git-subtree-split: 7f22526a86685aec1c5722154b8a7422d5037b77
Diffstat (limited to 'src/commands.h')
-rw-r--r--src/commands.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/commands.h b/src/commands.h
new file mode 100644
index 0000000..51450c5
--- /dev/null
+++ b/src/commands.h
@@ -0,0 +1,47 @@
+#ifndef COMMANDS_H
+#define COMMANDS_H
+
+/** \cond docNever */
+
+#include <QUndoStack>
+
+#include "chunks.h"
+
+/*! CharCommand is a class to provid undo/redo functionality in QHexEdit.
+A QUndoCommand represents a single editing action on a document. CharCommand
+is responsable for manipulations on single chars. It can insert. overwrite and
+remove characters. A manipulation stores allways two actions
+1. redo (or do) action
+2. undo action.
+
+CharCommand also supports command compression via mergeWith(). This enables
+the user to perform an undo command e.g. 3 steps in a single command.
+If you for example insert a new byt "34" this means for the editor doing 3
+steps: insert a "00", overwrite it with "03" and the overwrite it with "34". These
+3 steps are combined into a single step, insert a "34".
+
+The byte array oriented commands are just put into a set of single byte commands,
+which are pooled together with the macroBegin() and macroEnd() functionality of
+Qt's QUndoStack.
+*/
+
+class UndoStack : public QUndoStack
+{
+ Q_OBJECT
+
+public:
+ UndoStack(Chunks *chunks, QObject * parent=0);
+ void insert(qint64 pos, char c);
+ void insert(qint64 pos, const QByteArray &ba);
+ void removeAt(qint64 pos, qint64 len=1);
+ void overwrite(qint64 pos, char c);
+ void overwrite(qint64 pos, int len, const QByteArray &ba);
+
+private:
+ Chunks * _chunks;
+ QObject * _parent;
+};
+
+/** \endcond docNever */
+
+#endif // COMMANDS_H