edbee - Qt Editor Library v0.11.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
textundostack.h
Go to the documentation of this file.
1// edbee - Copyright (c) 2012-2025 by Rick Blommers and contributors
2// SPDX-License-Identifier: MIT
3
4#pragma once
5
6#include "edbee/exports.h"
7
8#include <QObject>
9#include <QMap>
10#include <QStack>
11
12namespace edbee {
13
14class Change;
15class TextDocument;
17class ChangeGroup;
18
19
49
50class EDBEE_EXPORT TextUndoStack : public QObject
51{
52 Q_OBJECT
53
54public:
55
63
64public:
65 explicit TextUndoStack( TextDocument* doc, QObject* parent = 0);
66 virtual ~TextUndoStack();
67 void clear();
68
69 void registerContoller( TextEditorController* controller );
70 void unregisterController( TextEditorController* controller );
71 bool isControllerRegistered( TextEditorController* controller );
72
73 void beginUndoGroup( ChangeGroup* group );
74 ChangeGroup* currentGroup();
75 void endUndoGroup(int coalesceId , bool flatten);
76 void endUndoGroupAndDiscard();
77 int undoGroupLevel();
78
79 int lastCoalesceIdAtCurrentLevel();
80 void setLastCoalesceIdAtCurrentLevel(int id);
81 void resetAllLastCoalesceIds();
82
83 Change* giveChange( Change* change, int coalesceId );
84
85 bool canUndo( TextEditorController* controller=0 );
86 bool canRedo( TextEditorController* controller=0 );
87
88 void undo( TextEditorController* controller=0, bool controllerOnly=false );
89 void redo( TextEditorController* controller=0, bool controllerOnly=false );
90
91 bool isCollectionEnabled() { return collectionEnabled_; }
92 void setCollectionEnabled( bool enabled ) { collectionEnabled_ = enabled; }
93
94 bool isUndoRunning() { return undoRunning_; }
95 bool isRedoRunning() { return redoRunning_; }
96
97 int size();
98 Change* at(int idx);
99 int currentIndex( TextEditorController* controller=0 );
100 int lastIndex( TextEditorController* controller=0 );
101 Change* last(TextEditorController* controller=0 );
102
103 int sizeInDocChanges();
104 int currentIndexInDocChanges();
105
106 Change* findRedoChange( TextEditorController* controller=0);
107 Change* findUndoChange( TextEditorController* controller=0 );
108
109 void setPersisted(bool enabled);
110 bool isPersisted();
111 int persistedIndex();
112
113 TextDocument* document() { return documentRef_; }
114
115 QString dumpStack();
116 void dumpStackInternal();
117
118protected:
119 int findRedoIndex( int index, TextEditorController* controller=0 );
120 int findUndoIndex( int index, TextEditorController* controller=0 );
121 void clearRedo( TextEditorController* controller );
122 bool undoControllerChange( TextEditorController* controller );
123 void undoDocumentChange();
124 bool redoControllerChange( TextEditorController* controller );
125 void redoDocumentChange();
126
127 void setPersistedIndex( int index );
128 void setChangeIndex( int index );
129
130signals:
131
132 void undoGroupStarted( edbee::ChangeGroup* group );
133
136 void undoGroupEnded( int coalesceId, bool merged, int action );
137 void changeAdded( edbee::Change* change );
138// void changeMerged( edbee::TextChange* oldChange, edbee::TextChange* change );
139 void undoExecuted( edbee::Change* change );
140 void redoExecuted( edbee::Change* change );
141
143 void persistedChanged(bool persisted);
144
145
146private:
147 void clearHistoryLists();
148
149
150 TextDocument* documentRef_;
151
152 QList<Change*> changeList_;
153 int changeIndex_;
154 QMap<TextEditorController*,int> controllerIndexMap_;
155 int persistedIndex_;
156
157 QStack<ChangeGroup*> undoGroupStack_;
158 QStack<int> lastCoalesceIdStack_;
159
160// int undoGroupLevel_; ///< The undo group level
161// TextChangeGroup* undoGroup_; ///< The current undo group
162 bool collectionEnabled_;
163
164 bool undoRunning_;
165 bool redoRunning_;
166};
167
168} // edbee
An undoable-command-group.
Definition change.h:84
A basic change.
Definition change.h:18
This is the base and abstract class of a text document A TextDocument is the model part of the editor...
Definition textdocument.h:42
The texteditor works via the controller. The controller is the central point/mediator which maps/cont...
Definition texteditorcontroller.h:39
This is the undo stack for the texteditor. This stack is SHARED by all views of the document The stac...
Definition textundostack.h:51
bool isUndoRunning()
Definition textundostack.h:94
void setCollectionEnabled(bool enabled)
Definition textundostack.h:92
bool isRedoRunning()
Definition textundostack.h:95
EndUndoGroupAction
This enumeration is signaled to the listeners to notify what happend when ending an undo group.
Definition textundostack.h:57
@ ActionFullDiscard
The group contained nothing usefull, nothing is added to the stack.
Definition textundostack.h:59
@ ActionEnd
A normal group end.
Definition textundostack.h:60
@ ActionUngrouped
The group has been ungrouped, the single change has been added to the stack.
Definition textundostack.h:58
bool isCollectionEnabled()
Definition textundostack.h:91
TextDocument * document()
Definition textundostack.h:113
TextUndoStack(TextDocument *doc, QObject *parent=0)
Constructs the main undostack.
Definition textundostack.cpp:18
#define EDBEE_EXPORT
Definition exports.h:15
QT Acessibility has an issue with reporting blank lines between elements lines. defining 'WINDOWS_EMP...
Definition commentcommand.cpp:20