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

This is the basic text change that's the base of the textchanges. More...

#include <textchange.h>

+ Inheritance diagram for edbee::TextChange:
+ Collaboration diagram for edbee::TextChange:

Public Member Functions

 TextChange (int offset, int length, const QString &text)
 Constructs a single textchange. More...
 
virtual ~TextChange ()
 undo's a single textchange More...
 
virtual void execute (TextDocument *document)
 executes the given textchange More...
 
virtual void revert (TextDocument *document)
 Reverts the single textchange. More...
 
virtual bool giveAndMerge (TextDocument *document, Change *textChange)
 This method gives the given change to this textchange. The changes will be merged if possible. This method currently only works with executed changes!!! More...
 
virtual QString toString ()
 converts the change to a string More...
 
int offset () const
 Return the offset. More...
 
void setOffset (int offset)
 set the new offset More...
 
virtual int docLength () const
 This is the length in the document. More...
 
virtual int storedLength () const
 The content length is the length that's currently stored in memory. More...
 
void setDocLength (int len)
 Set the length of the change. More...
 
QString storedText () const
 The text currently stored in this textchange. More...
 
void setStoredText (const QString &text)
 Sets the text of this change. More...
 
void appendStoredText (const QString &text)
 Appends the text to this change. More...
 
const QString docText (TextDocument *doc) const
 This method returns the text currently in the document. More...
 
QString testString ()
 This method returns a string used for testing. More...
 
- Public Member Functions inherited from edbee::AbstractRangedChange
virtual ~AbstractRangedChange ()
 default destructor is empty More...
 
void addOffset (int amount)
 Adds the given amount to the offset. More...
 
bool isOverlappedBy (AbstractRangedChange *secondChange)
 This method checks if this textchange is overlapped by the second text change overlapping is an exclusive overlap, which means the changes are really on top of eachother to test if the changes are touching use isTouchedBy. More...
 
bool isTouchedBy (AbstractRangedChange *secondChange)
 Touched ranges are ranges that are next to eachother Touching means the end offset of one range is the start offset of the other range. More...
 
- Public Member Functions inherited from edbee::Change
virtual ~Change ()
 a virtual empty destructor More...
 
virtual bool canUndo ()
 This method should return true if the change can be reverted. More...
 
virtual bool isPersistenceRequired ()
 This flag is used to mark this stack item as non-persistence requirable The default behaviour is that every textchange requires persistence. It is also possible to have certain changes that do not require persitence but should be placed on the undo stack. More...
 
virtual TextEditorControllercontrollerContext ()
 A text command can belong to a controller/view When it's a view only command. The undo only applies only to this view warning a DOCUMENT change may NEVER return a controllerContext!! More...
 
bool isDocumentChange ()
 this method can be used to check if the given change is a document change More...
 
virtual bool isGroup ()
 This method returns true if this change is a group change. When an object is group change it should be inherited by TextChangeGroup. More...
 

Protected Member Functions

virtual void mergeStoredData (AbstractRangedChange *change)
 This method merges the old data with the new data change the data to merge with. More...
 
void replaceText (TextDocument *document)
 replaces the text and stores the 'old' content More...
 
- Protected Member Functions inherited from edbee::AbstractRangedChange
int getMergedDocLength (AbstractRangedChange *change)
 Calculates the merged length. More...
 
int getMergedStoredLength (AbstractRangedChange *change)
 Calculates the merge data size, that's required for merging the given change. More...
 
void mergeStoredDataViaMemcopy (void *targetData, void *data, void *changeData, AbstractRangedChange *change, int itemSize)
 This method merges the data via a memcopy. I really don't like this way of merging the data. though this is a way which support all kinds of arrays. I cannot use inheritance, because the types like QString don't have a common ancestor. More...
 
bool merge (AbstractRangedChange *change)
 This method merges the change. More...
 

Detailed Description

This is the basic text change that's the base of the textchanges.

This class re-uses the variables offset/length and text. Depending on the undo/redo state these variables contain the new data or the changed data

Constructor & Destructor Documentation

◆ TextChange()

edbee::TextChange::TextChange ( int  offset,
int  length,
const QString &  text 
)

Constructs a single textchange.

Parameters
offset,theoffset of the change
length,thelength of the change
text,thenew text
executed,aboolean (mainly used for testing) to mark this change as exected

◆ ~TextChange()

edbee::TextChange::~TextChange ( )
virtual

undo's a single textchange

Member Function Documentation

◆ appendStoredText()

void edbee::TextChange::appendStoredText ( const QString &  text)

Appends the text to this change.

◆ docLength()

int edbee::TextChange::docLength ( ) const
virtual

This is the length in the document.

Implements edbee::AbstractRangedChange.

◆ docText()

const QString edbee::TextChange::docText ( TextDocument doc) const

This method returns the text currently in the document.

◆ execute()

void edbee::TextChange::execute ( TextDocument document)
virtual

executes the given textchange

Parameters
documentthe document to execute the change on

Implements edbee::Change.

◆ giveAndMerge()

bool edbee::TextChange::giveAndMerge ( TextDocument document,
Change textChange 
)
virtual

This method gives the given change to this textchange. The changes will be merged if possible. This method currently only works with executed changes!!!

Parameters
documentthe document
textChangethe textchange to mege
Returns
true on success else false

Reimplemented from edbee::Change.

◆ mergeStoredData()

void edbee::TextChange::mergeStoredData ( AbstractRangedChange change)
protectedvirtual

This method merges the old data with the new data change the data to merge with.

Implements edbee::AbstractRangedChange.

◆ offset()

int edbee::TextChange::offset ( ) const
virtual

Return the offset.

Returns
the offset of the change

Implements edbee::AbstractRangedChange.

◆ replaceText()

void edbee::TextChange::replaceText ( TextDocument document)
protected

replaces the text and stores the 'old' content

Parameters
documentthe document to change it for

◆ revert()

void edbee::TextChange::revert ( TextDocument document)
virtual

Reverts the single textchange.

Parameters
documentthe document to execute the change on

Reimplemented from edbee::Change.

◆ setDocLength()

void edbee::TextChange::setDocLength ( int  len)
virtual

Set the length of the change.

Parameters
lensets the length of the change

Implements edbee::AbstractRangedChange.

◆ setOffset()

void edbee::TextChange::setOffset ( int  offset)
virtual

set the new offset

Parameters
offsetthe new offset

Implements edbee::AbstractRangedChange.

◆ setStoredText()

void edbee::TextChange::setStoredText ( const QString &  text)

Sets the text of this change.

Parameters
textthe new text

◆ storedLength()

int edbee::TextChange::storedLength ( ) const
virtual

The content length is the length that's currently stored in memory.

Implements edbee::AbstractRangedChange.

◆ storedText()

QString edbee::TextChange::storedText ( ) const

The text currently stored in this textchange.

◆ testString()

QString edbee::TextChange::testString ( )

This method returns a string used for testing.

◆ toString()

QString edbee::TextChange::toString ( )
virtual

converts the change to a string

Implements edbee::Change.


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