edbee - Qt Editor Library
Public Types | Signals | Public Member Functions | Protected Member Functions | List of all members
edbee::TextUndoStack Class Reference

This is the undo stack for the texteditor. This stack is SHARED by all views of the document The stack also stores view-specific commands of all views. More...

#include <textundostack.h>

+ Inheritance diagram for edbee::TextUndoStack:
+ Collaboration diagram for edbee::TextUndoStack:

Public Types

enum  EndUndoGroupAction { ActionUngrouped, ActionFullDiscard, ActionEnd }
 This enumeration is signaled to the listeners to notify what happend when ending an undo group. More...
 

Signals

void undoGroupStarted (edbee::ChangeGroup *group)
 
void undoGroupEnded (int coalesceId, bool merged, int action)
 This signal is fired when the group is ended. Warning, when the group is merged the group pointer will be 0!! More...
 
void changeAdded (edbee::Change *change)
 
void undoExecuted (edbee::Change *change)
 
void redoExecuted (edbee::Change *change)
 
void persistedChanged (bool persisted)
 This signal is emitted if the persisted state is changed. More...
 

Public Member Functions

 TextUndoStack (TextDocument *doc, QObject *parent=0)
 Constructs the main undostack. More...
 
virtual ~TextUndoStack ()
 the undo stack items More...
 
void clear ()
 clears both stacks More...
 
void registerContoller (TextEditorController *controller)
 Registers acontroller for it's own view pointer. More...
 
void unregisterController (TextEditorController *controller)
 Unregisters the given controller. More...
 
bool isControllerRegistered (TextEditorController *controller)
 Checks if the given controller is registered. More...
 
void beginUndoGroup (ChangeGroup *group)
 Starts an undo group (or increase nest-level-counter) More...
 
ChangeGroupcurrentGroup ()
 This method returns the current active group. More...
 
void endUndoGroup (int coalesceId, bool flatten)
 Ends the undogroup. More...
 
void endUndoGroupAndDiscard ()
 Ends the undo-group and discards all content. More...
 
int undoGroupLevel ()
 returns the number of stacked undo-groups More...
 
int lastCoalesceIdAtCurrentLevel ()
 returns the last coalesceId at the given level More...
 
void setLastCoalesceIdAtCurrentLevel (int id)
 Sets the last coalesceId at the current level. More...
 
void resetAllLastCoalesceIds ()
 Resets all coalsceIds. More...
 
ChangegiveChange (Change *change, int coalesceId)
 This method gives the command and tries to coalesce the command if possible Warning when a change is MERGED, the original change is deleted!!! And the original pointer is invalid!!!! More...
 
bool canUndo (TextEditorController *controller=0)
 Should check if a undo operation can be performed. When no controller is given a document-undo is checkd else a view specific soft undo is tested. More...
 
bool canRedo (TextEditorController *controller=0)
 Should check if a redo operation can be performed. When no controller is given a document-redo is checkd else a view specific soft redo is tested. More...
 
void undo (TextEditorController *controller=0, bool controllerOnly=false)
 performs an undo operation More...
 
void redo (TextEditorController *controller=0, bool controllerOnly=false)
 performs the redo operation for the given controller More...
 
bool isCollectionEnabled ()
 
void setCollectionEnabled (bool enabled)
 
bool isUndoRunning ()
 
bool isRedoRunning ()
 
int size ()
 returns the number of changes on the stack More...
 
Changeat (int idx)
 returns the change at the given index More...
 
int currentIndex (TextEditorController *controller=0)
 This method return the index that's active for the given controller The currentIndex points directly AFTER the last placed item on the stack. More...
 
int lastIndex (TextEditorController *controller=0)
 This method returns the last index for a given controller The lastIndex points to the index on the stack. More...
 
Changelast (TextEditorController *controller=0)
 Returns last textchange on the undo stack. More...
 
int sizeInDocChanges ()
 The number of doc-'undo' items on the stack. More...
 
int currentIndexInDocChanges ()
 This method returns the current doc change index. More...
 
ChangefindRedoChange (TextEditorController *controller=0)
 This method returns the current redo change. This maybe the change for the given context or the document change depending on what comes first. More...
 
ChangefindUndoChange (TextEditorController *controller=0)
 This method returns the last change (TOS) for the given controller. More...
 
void setPersisted (bool enabled)
 Marks the current documentIndex as persisted. More...
 
bool isPersisted ()
 returns true if the undo-stack is on a persisted index More...
 
int persistedIndex ()
 This method returns the current persisted index. More...
 
TextDocumentdocument ()
 
QString dumpStack ()
 makes a dump of the current stack More...
 
void dumpStackInternal ()
 Dumps the internal stack. More...
 

Protected Member Functions

int findRedoIndex (int index, TextEditorController *controller=0)
 This method finds the next redo-item. More...
 
int findUndoIndex (int index, TextEditorController *controller=0)
 This method finds the index of the given stackitem from the given index. More...
 
void clearRedo (TextEditorController *controller)
 Clears all redo's for the given controller. More...
 
bool undoControllerChange (TextEditorController *controller)
 This method undos the given controller change. This method does NOT undo document changes. More...
 
void undoDocumentChange ()
 Performs an document-change undo. More...
 
bool redoControllerChange (TextEditorController *controller)
 undo's the given controller change More...
 
void redoDocumentChange ()
 redo a document change More...
 
void setPersistedIndex (int index)
 Sets the persisted in dex and fires a signal. More...
 
void setChangeIndex (int index)
 When setting the change-index we sometimes must emit a persisted change. More...
 

Detailed Description

This is the undo stack for the texteditor. This stack is SHARED by all views of the document The stack also stores view-specific commands of all views.

Every view has got it's own pointer on the stack. This pointer points at the index AFTER the last item on the stack that's used for this view.

When a view-performs a view-specific undo (soft-undo) it's own pointer is stepped back. Only view-specific commands are undone When a view performs a document undo. ALL view-pointers a are undone to the point of the document undo.

7 | | <= controllerIndexMap_(v1)
+-------+
6 | v1 | <= controllerIndexMap_(v2)
+-------+
5 | v2 |
+-------+
4 | v1 | <= changeIndex_
+-------+
3 | DOC |
+-------+
2 | v1 |
+-------+
1 | DOC |
+-------+
0 | v2 |
+-------+

Member Enumeration Documentation

◆ EndUndoGroupAction

This enumeration is signaled to the listeners to notify what happend when ending an undo group.

Enumerator
ActionUngrouped 

The group has been ungrouped, the single change has been added to the stack.

ActionFullDiscard 

The group contained nothing usefull, nothing is added to the stack.

ActionEnd 

A normal group end.

Constructor & Destructor Documentation

◆ TextUndoStack()

edbee::TextUndoStack::TextUndoStack ( TextDocument doc,
QObject *  parent = 0 
)
explicit

Constructs the main undostack.

◆ ~TextUndoStack()

edbee::TextUndoStack::~TextUndoStack ( )
virtual

the undo stack items

Member Function Documentation

◆ at()

Change * edbee::TextUndoStack::at ( int  idx)

returns the change at the given index

◆ beginUndoGroup()

void edbee::TextUndoStack::beginUndoGroup ( ChangeGroup group)

Starts an undo group (or increase nest-level-counter)

◆ canRedo()

bool edbee::TextUndoStack::canRedo ( TextEditorController controller = 0)

Should check if a redo operation can be performed. When no controller is given a document-redo is checkd else a view specific soft redo is tested.

◆ canUndo()

bool edbee::TextUndoStack::canUndo ( TextEditorController controller = 0)

Should check if a undo operation can be performed. When no controller is given a document-undo is checkd else a view specific soft undo is tested.

◆ changeAdded

void edbee::TextUndoStack::changeAdded ( edbee::Change change)
signal

◆ clear()

void edbee::TextUndoStack::clear ( )

clears both stacks

◆ clearRedo()

void edbee::TextUndoStack::clearRedo ( TextEditorController controller)
protected

Clears all redo's for the given controller.

◆ currentGroup()

ChangeGroup * edbee::TextUndoStack::currentGroup ( )

This method returns the current active group.

Returns
the current undo stack item or 0

◆ currentIndex()

int edbee::TextUndoStack::currentIndex ( TextEditorController controller = 0)

This method return the index that's active for the given controller The currentIndex points directly AFTER the last placed item on the stack.

◆ currentIndexInDocChanges()

int edbee::TextUndoStack::currentIndexInDocChanges ( )

This method returns the current doc change index.

◆ document()

TextDocument* edbee::TextUndoStack::document ( )
inline

◆ dumpStack()

QString edbee::TextUndoStack::dumpStack ( )

makes a dump of the current stack

build the stack overview

◆ dumpStackInternal()

void edbee::TextUndoStack::dumpStackInternal ( )

Dumps the internal stack.

◆ endUndoGroup()

void edbee::TextUndoStack::endUndoGroup ( int  coalesceId,
bool  flatten 
)

Ends the undogroup.

Parameters
coalesceIdthe coalesceId to use
flattenshould the textchange groups be flattened

◆ endUndoGroupAndDiscard()

void edbee::TextUndoStack::endUndoGroupAndDiscard ( )

Ends the undo-group and discards all content.

◆ findRedoChange()

Change * edbee::TextUndoStack::findRedoChange ( TextEditorController controller = 0)

This method returns the current redo change. This maybe the change for the given context or the document change depending on what comes first.

Parameters
controllerthe controller this change is for
Returns
the new text change (0 if there aren't any redo items availabe for the given context). When a controller is given the document change is ALSO returned

◆ findRedoIndex()

int edbee::TextUndoStack::findRedoIndex ( int  index,
TextEditorController controller = 0 
)
protected

This method finds the next redo-item.

Parameters
indexthe index to search it from
controllerthe controller context
Returns
the next change index. Or changeList_.size() if there's no next change

◆ findUndoChange()

Change * edbee::TextUndoStack::findUndoChange ( TextEditorController controller = 0)

This method returns the last change (TOS) for the given controller.

◆ findUndoIndex()

int edbee::TextUndoStack::findUndoIndex ( int  index,
TextEditorController controller = 0 
)
protected

This method finds the index of the given stackitem from the given index.

Parameters
indexthe previous index
controllerthe controller context
Returns
the previous index -1, if there's no previous index

◆ giveChange()

Change * edbee::TextUndoStack::giveChange ( Change change,
int  coalesceId 
)

This method gives the command and tries to coalesce the command if possible Warning when a change is MERGED, the original change is deleted!!! And the original pointer is invalid!!!!

Parameters
changethe change that's added
coalesceIdthe coalseceId to use for this text change. /
Returns
the merged Change The return value is 0, if the change was discared The return value == change if the change was appended to the stack The return value != change if the change was merged (previous stack item is returned)
Todo:
: giveChange to a group can also merge a change. This can have implications

◆ isCollectionEnabled()

bool edbee::TextUndoStack::isCollectionEnabled ( )
inline

◆ isControllerRegistered()

bool edbee::TextUndoStack::isControllerRegistered ( TextEditorController controller)

Checks if the given controller is registered.

◆ isPersisted()

bool edbee::TextUndoStack::isPersisted ( )

returns true if the undo-stack is on a persisted index

◆ isRedoRunning()

bool edbee::TextUndoStack::isRedoRunning ( )
inline

◆ isUndoRunning()

bool edbee::TextUndoStack::isUndoRunning ( )
inline

◆ last()

Change * edbee::TextUndoStack::last ( TextEditorController controller = 0)

Returns last textchange on the undo stack.

Parameters
controllerthe controller
Returns
the last change (with optional the controller context) 0 if no last change

◆ lastCoalesceIdAtCurrentLevel()

int edbee::TextUndoStack::lastCoalesceIdAtCurrentLevel ( )

returns the last coalesceId at the given level

◆ lastIndex()

int edbee::TextUndoStack::lastIndex ( TextEditorController controller = 0)

This method returns the last index for a given controller The lastIndex points to the index on the stack.

Returns
the index on the stack or -1 if the item isn't on the undo-stack

◆ persistedChanged

void edbee::TextUndoStack::persistedChanged ( bool  persisted)
signal

This signal is emitted if the persisted state is changed.

◆ persistedIndex()

int edbee::TextUndoStack::persistedIndex ( )

This method returns the current persisted index.

◆ redo()

void edbee::TextUndoStack::redo ( TextEditorController controller = 0,
bool  controllerOnly = false 
)

performs the redo operation for the given controller

Parameters
controllerthe controller to execute the redo for
controllerOnlyundo controller undo's only?

◆ redoControllerChange()

bool edbee::TextUndoStack::redoControllerChange ( TextEditorController controller)
protected

undo's the given controller change

◆ redoDocumentChange()

void edbee::TextUndoStack::redoDocumentChange ( )
protected

redo a document change

◆ redoExecuted

void edbee::TextUndoStack::redoExecuted ( edbee::Change change)
signal

◆ registerContoller()

void edbee::TextUndoStack::registerContoller ( TextEditorController controller)

Registers acontroller for it's own view pointer.

◆ resetAllLastCoalesceIds()

void edbee::TextUndoStack::resetAllLastCoalesceIds ( )

Resets all coalsceIds.

◆ setChangeIndex()

void edbee::TextUndoStack::setChangeIndex ( int  index)
protected

When setting the change-index we sometimes must emit a persisted change.

◆ setCollectionEnabled()

void edbee::TextUndoStack::setCollectionEnabled ( bool  enabled)
inline

◆ setLastCoalesceIdAtCurrentLevel()

void edbee::TextUndoStack::setLastCoalesceIdAtCurrentLevel ( int  id)

Sets the last coalesceId at the current level.

◆ setPersisted()

void edbee::TextUndoStack::setPersisted ( bool  enabled)

Marks the current documentIndex as persisted.

◆ setPersistedIndex()

void edbee::TextUndoStack::setPersistedIndex ( int  index)
protected

Sets the persisted in dex and fires a signal.

◆ size()

int edbee::TextUndoStack::size ( )

returns the number of changes on the stack

◆ sizeInDocChanges()

int edbee::TextUndoStack::sizeInDocChanges ( )

The number of doc-'undo' items on the stack.

◆ undo()

void edbee::TextUndoStack::undo ( TextEditorController controller = 0,
bool  controllerOnly = false 
)

performs an undo operation

Parameters
controllerthis method is called

◆ undoControllerChange()

bool edbee::TextUndoStack::undoControllerChange ( TextEditorController controller)
protected

This method undos the given controller change. This method does NOT undo document changes.

Parameters
controllerthe controller to undo the change form
Returns
true if a change has been undone.

◆ undoDocumentChange()

void edbee::TextUndoStack::undoDocumentChange ( )
protected

Performs an document-change undo.

◆ undoExecuted

void edbee::TextUndoStack::undoExecuted ( edbee::Change change)
signal

◆ undoGroupEnded

void edbee::TextUndoStack::undoGroupEnded ( int  coalesceId,
bool  merged,
int  action 
)
signal

This signal is fired when the group is ended. Warning, when the group is merged the group pointer will be 0!!

◆ undoGroupLevel()

int edbee::TextUndoStack::undoGroupLevel ( )

returns the number of stacked undo-groups

◆ undoGroupStarted

void edbee::TextUndoStack::undoGroupStarted ( edbee::ChangeGroup group)
signal

◆ unregisterController()

void edbee::TextUndoStack::unregisterController ( TextEditorController controller)

Unregisters the given controller.


The documentation for this class was generated from the following files: