edbee - Qt Editor Library v0.11.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
edbee::TextDocument Class Referenceabstract

This is the base and abstract class of a text document A TextDocument is the model part of the editor. More...

#include <textdocument.h>

+ Inheritance diagram for edbee::TextDocument:
+ Collaboration diagram for edbee::TextDocument:

Signals

void textAboutToBeChanged (edbee::TextBufferChange change)
 
void textChanged (edbee::TextBufferChange change, QString oldText=QString())
 
void persistedChanged (bool persisted)
 This signal is emitted if the persisted state is changed.
 
void languageGrammarChanged ()
 This signal is emitted if the grammar has been changed.
 
void lastScopedOffsetChanged (int previousOffset, int lastScopedOffset)
 this signal is emitted if the scoped range has been changed
 

Public Member Functions

 TextDocument (QObject *parent=0)
 Constructs the textdocument.
 
virtual ~TextDocument ()
 Destroys the textdocument.
 
virtual TextBufferbuffer () const =0
 This method should return the active textbuffer Warning you should NEVER directly modify the textbuffer unless you're absolutely sure what you're doing!
 
virtual void setLineDataFieldsPerLine (int count)
 This method can be used to change the number of reserved fields by the document Increasing the amount will result in a realoc Decreasting the fieldcount reults in the lost of the 'old' fields At least the 'PredefinedFieldCount' amont of fields are required.
 
virtual TextLineDataManagerlineDataManager ()
 this method can be used to give a 'custom' line data item to a given line
 
virtual void giveLineDataManager (TextLineDataManager *manager)
 
virtual void giveLineData (int line, int field, TextLineData *dataItem)
 This method gives a given data item to a text line.
 
virtual TextLineDatagetLineData (int line, int field)
 Returns the line specific data at the given line.
 
virtual TextDocumentScopesscopes ()=0
 Should return the document-scopes of this document.
 
virtual TextCodecencoding ()=0
 This method should return the current encoding.
 
virtual void setEncoding (TextCodec *codec)=0
 
virtual const LineEndinglineEnding ()=0
 This method should return the current line ending.
 
virtual void setLineEnding (const LineEnding *lineENding)=0
 
virtual TextLexertextLexer ()=0
 Should return the current document lexer.
 
virtual TextGrammarlanguageGrammar ()=0
 This method should return the current language grammar.
 
virtual void setLanguageGrammar (TextGrammar *grammar)=0
 Changes the language grammar. This method should emit a grammarChanged signal (if the grammar is changed)
 
virtual TextAutoCompleteProviderListautoCompleteProviderList ()=0
 This method should return the autcompletion provider list.
 
virtual TextUndoStacktextUndoStack ()=0
 this method should return a reference to the undo stack
 
virtual void beginUndoGroup (ChangeGroup *group=0)
 Starts an undo group.
 
virtual void endUndoGroup (int coalesceId, bool flatten=false)
 Ends the current undo group.
 
virtual void endUndoGroupAndDiscard ()
 Ends the undo group and discards all recorded information Warning it does NOT undo all made changes!!!
 
virtual bool isUndoCollectionEnabled ()
 this method return true if the undo stack is enabled
 
virtual void setUndoCollectionEnabled (bool enabled)
 Enables or disables the collection of undo commands.
 
virtual bool isUndoRunning ()
 This method should return true if the current change is the cause of an undo operation.
 
virtual bool isRedoRunning ()
 Checks if currently an undo operation is running.
 
virtual bool isUndoOrRedoRunning ()
 Is it an undo or redo (which means all commands area already available)
 
virtual bool isPersisted ()
 Checks if the document is in a persited state.
 
virtual void setPersisted (bool enabled=true)
 Calc this method to mark current state as persisted.
 
virtual TextEditorConfigconfig () const =0
 this method should return the config
 
virtual void setDocumentFilter (TextDocumentFilter *filter)
 Sets the document filter without tranfering the ownership.
 
virtual void giveDocumentFilter (TextDocumentFilter *filter)
 this method sets the document filter You can give a 0 pointer to delte the old filter!
 
virtual TextDocumentFilterdocumentFilter ()
 This method returns the document filter.
 
void beginChanges (TextEditorController *controller)
 Start the changes.
 
void replaceRangeSet (TextRangeSet &rangeSet, const QString &text, bool stickySelection=false)
 Replaces the given rangeset.
 
void replaceRangeSet (TextRangeSet &rangeSet, const QStringList &texts, bool stickySelection=false)
 replaces the given rangeset
 
void giveSelection (TextEditorController *controller, TextRangeSet *rangeSet)
 sets the selectioin for the current rangeset The selection may never be empty
 
void endChanges (int coalesceId)
 
ChangeexecuteAndGiveChange (Change *change, int coalesceId)
 call this method to execute a change. The change is first passed to the filter so the documentFilter can handle the processing of the change When not filter is active the 'execute' method is called on the change
 
virtual ChangegiveChangeWithoutFilter (Change *change, int coalesceId)=0
 
void append (const QString &text, int coalesceId=0)
 Appends the given text to the document.
 
void replace (int offset, int length, const QString &text, int coalesceId=0)
 Appends the given text.
 
void setText (const QString &text)
 Changes the compelte document text.
 
void rawAppendBegin ()
 begins the raw append modes. In raw append mode data is directly streamed to the textdocument-buffer. No undo-data is collected and no events are fired
 
void rawAppendEnd ()
 When then raw appending is done. The events are fired that the document has been changed The undo-collection is enabled again.
 
void rawAppend (QChar c)
 Appends a single char in raw append mode.
 
void rawAppend (const QChar *chars, int length)
 Appends an array of characters.
 
int length ()
 Returns the length of the document in characters default implementation is to forward this call to the textbuffer.
 
int lineCount ()
 Returns the number of lines.
 
QChar charAt (int idx)
 Returns the character at the given position.
 
QChar charAtOrNull (int idx)
 returns the char at the given index if the index is valid else the null character is returned
 
int offsetFromLine (int line)
 Retrieves the character-offset of the given line.
 
int lineFromOffset (int offset)
 returns the line number which contains the given offset
 
int columnFromOffsetAndLine (int offset, int line=-1)
 return the column position for the given offset and line
 
int offsetFromLineAndColumn (int line, int column)
 Returns the character offset of the given line and column.
 
int lineLength (int line)
 Returns the length of the given line.
 
int lineLengthWithoutNewline (int line)
 returns the length of the given lilne without the newline
 
QString text ()
 Returns the document text as a QString.
 
QString textPart (int offset, int length)
 Returns the given part of the text.
 
QString lineWithoutNewline (int line)
 Returns the given line without the trailing
character.
 
QString line (int line)
 @pparam line the line number to retrieve
 

Detailed Description

This is the base and abstract class of a text document A TextDocument is the model part of the editor.

It's the main owner of the following objects:

  • A textbuffer, which holds the character data. Currently there's only a CharTextBuffer, a gap-vectored buffer.
  • An undostack, a stack which holds the undo-operations of the editor
  • the textdocument scopes, these are the language-dependent scopes found in the current document
  • A textlexer, which is used for (re-)building the textdocument scopes.

Constructor & Destructor Documentation

◆ TextDocument()

edbee::TextDocument::TextDocument ( QObject * parent = 0)

Constructs the textdocument.

◆ ~TextDocument()

edbee::TextDocument::~TextDocument ( )
virtual

Destroys the textdocument.

Member Function Documentation

◆ append()

void edbee::TextDocument::append ( const QString & text,
int coalesceId = 0 )

Appends the given text to the document.

Parameters
textthe text to append
coalesceId(default 0) the coalesceId to use. Whe using the same number changes could be merged to one change. CoalesceId of 0 means no merging

◆ autoCompleteProviderList()

virtual TextAutoCompleteProviderList * edbee::TextDocument::autoCompleteProviderList ( )
pure virtual

This method should return the autcompletion provider list.

Implemented in edbee::CharTextDocument.

◆ beginChanges()

void edbee::TextDocument::beginChanges ( TextEditorController * controller)

Start the changes.

◆ beginUndoGroup()

void edbee::TextDocument::beginUndoGroup ( ChangeGroup * group = 0)
virtual

Starts an undo group.

Parameters
groupthe textchange group that groups the undo operations

◆ buffer()

virtual TextBuffer * edbee::TextDocument::buffer ( ) const
pure virtual

This method should return the active textbuffer Warning you should NEVER directly modify the textbuffer unless you're absolutely sure what you're doing!

Implemented in edbee::CharTextDocument.

◆ charAt()

QChar edbee::TextDocument::charAt ( int idx)

Returns the character at the given position.

◆ charAtOrNull()

QChar edbee::TextDocument::charAtOrNull ( int idx)

returns the char at the given index if the index is valid else the null character is returned

Parameters
idxthe index to retrieve
Returns
the character at the given index or the null-character

◆ columnFromOffsetAndLine()

int edbee::TextDocument::columnFromOffsetAndLine ( int offset,
int line = -1 )

return the column position for the given offset and line

Parameters
offsetthe offset position
linethe line number which contains this offset. (When -1 the line number is calculated)
Returns
the column position of the given offset

◆ config()

virtual TextEditorConfig * edbee::TextDocument::config ( ) const
pure virtual

this method should return the config

Implemented in edbee::CharTextDocument.

◆ documentFilter()

TextDocumentFilter * edbee::TextDocument::documentFilter ( )
virtual

This method returns the document filter.

◆ encoding()

virtual TextCodec * edbee::TextDocument::encoding ( )
pure virtual

This method should return the current encoding.

Implemented in edbee::CharTextDocument.

◆ endChanges()

void edbee::TextDocument::endChanges ( int coalesceId)

◆ endUndoGroup()

void edbee::TextDocument::endUndoGroup ( int coalesceId,
bool flatten = false )
virtual

Ends the current undo group.

Parameters
coalesceIdthe coalesceId
flattenshould the operation be flatten (flattens undo-group trees)

◆ endUndoGroupAndDiscard()

void edbee::TextDocument::endUndoGroupAndDiscard ( )
virtual

Ends the undo group and discards all recorded information Warning it does NOT undo all made changes!!!

◆ executeAndGiveChange()

Change * edbee::TextDocument::executeAndGiveChange ( Change * change,
int coalesceId )

call this method to execute a change. The change is first passed to the filter so the documentFilter can handle the processing of the change When not filter is active the 'execute' method is called on the change

WARNING, you should never Access the change pointer given to this method It's possible the change gets deleted

This method should return the effective text-change (or 0 if no text-change has been stored)

◆ getLineData()

TextLineData * edbee::TextDocument::getLineData ( int line,
int field )
virtual

Returns the line specific data at the given line.

Parameters
linethe line number to retrieve the line data for
fieldthe field to retrieve the data for
Returns
TextLineData the associated line data
Todo
: disabled, issue with renderer retreiving linedata

◆ giveChangeWithoutFilter()

virtual Change * edbee::TextDocument::giveChangeWithoutFilter ( Change * change,
int coalesceId )
pure virtual

Implemented in edbee::CharTextDocument.

◆ giveDocumentFilter()

void edbee::TextDocument::giveDocumentFilter ( TextDocumentFilter * filter)
virtual

this method sets the document filter You can give a 0 pointer to delte the old filter!

◆ giveLineData()

void edbee::TextDocument::giveLineData ( int line,
int field,
TextLineData * dataItem )
virtual

This method gives a given data item to a text line.

◆ giveLineDataManager()

void edbee::TextDocument::giveLineDataManager ( TextLineDataManager * manager)
virtual

◆ giveSelection()

void edbee::TextDocument::giveSelection ( TextEditorController * controller,
TextRangeSet * rangeSet )

sets the selectioin for the current rangeset The selection may never be empty

Parameters
controllerthe controller to given the selection for
rangeSetthe rangeset with the new selection

◆ isPersisted()

bool edbee::TextDocument::isPersisted ( )
virtual

Checks if the document is in a persited state.

◆ isRedoRunning()

bool edbee::TextDocument::isRedoRunning ( )
virtual

Checks if currently an undo operation is running.

◆ isUndoCollectionEnabled()

bool edbee::TextDocument::isUndoCollectionEnabled ( )
virtual

this method return true if the undo stack is enabled

◆ isUndoOrRedoRunning()

bool edbee::TextDocument::isUndoOrRedoRunning ( )
virtual

Is it an undo or redo (which means all commands area already available)

◆ isUndoRunning()

bool edbee::TextDocument::isUndoRunning ( )
virtual

This method should return true if the current change is the cause of an undo operation.

◆ languageGrammar()

virtual TextGrammar * edbee::TextDocument::languageGrammar ( )
pure virtual

This method should return the current language grammar.

Implemented in edbee::CharTextDocument.

◆ languageGrammarChanged

void edbee::TextDocument::languageGrammarChanged ( )
signal

This signal is emitted if the grammar has been changed.

◆ lastScopedOffsetChanged

void edbee::TextDocument::lastScopedOffsetChanged ( int previousOffset,
int lastScopedOffset )
signal

this signal is emitted if the scoped range has been changed

◆ length()

int edbee::TextDocument::length ( )

Returns the length of the document in characters default implementation is to forward this call to the textbuffer.

◆ line()

QString edbee::TextDocument::line ( int line)

@pparam line the line number to retrieve

Returns
the line at the given position

◆ lineCount()

int edbee::TextDocument::lineCount ( )

Returns the number of lines.

◆ lineDataManager()

virtual TextLineDataManager * edbee::TextDocument::lineDataManager ( )
inlinevirtual

this method can be used to give a 'custom' line data item to a given line

◆ lineEnding()

virtual const LineEnding * edbee::TextDocument::lineEnding ( )
pure virtual

This method should return the current line ending.

Implemented in edbee::CharTextDocument.

◆ lineFromOffset()

int edbee::TextDocument::lineFromOffset ( int offset)

returns the line number which contains the given offset

Parameters
offsetthe character offset
Returns
the line number (0 is the first line )

◆ lineLength()

int edbee::TextDocument::lineLength ( int line)

Returns the length of the given line.

Parameters
linethe line number
Returns
the line length

◆ lineLengthWithoutNewline()

int edbee::TextDocument::lineLengthWithoutNewline ( int line)

returns the length of the given lilne without the newline

Parameters
linethe line number
Returns
the length of the line excluding the newline character

◆ lineWithoutNewline()

QString edbee::TextDocument::lineWithoutNewline ( int line)

Returns the given line without the trailing
character.

Parameters
linethe line number to retrieve the data for
Returns
the content at the given line

◆ offsetFromLine()

int edbee::TextDocument::offsetFromLine ( int line)

Retrieves the character-offset of the given line.

Parameters
linethe line number (0-based) to retrieve the offset for
Returns
the character offset

◆ offsetFromLineAndColumn()

int edbee::TextDocument::offsetFromLineAndColumn ( int line,
int column )

Returns the character offset of the given line and column.

Parameters
linethe line number
columnthe column position
Returns
the character offset in the document

◆ persistedChanged

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

This signal is emitted if the persisted state is changed.

◆ rawAppend() [1/2]

void edbee::TextDocument::rawAppend ( const QChar * chars,
int length )

Appends an array of characters.

◆ rawAppend() [2/2]

void edbee::TextDocument::rawAppend ( QChar c)

Appends a single char in raw append mode.

◆ rawAppendBegin()

void edbee::TextDocument::rawAppendBegin ( )

begins the raw append modes. In raw append mode data is directly streamed to the textdocument-buffer. No undo-data is collected and no events are fired

◆ rawAppendEnd()

void edbee::TextDocument::rawAppendEnd ( )

When then raw appending is done. The events are fired that the document has been changed The undo-collection is enabled again.

◆ replace()

void edbee::TextDocument::replace ( int offset,
int length,
const QString & text,
int coalesceId = 0 )

Appends the given text.

Parameters
textthe text to append
coalesceId(default 0) the coalesceId to use. Whe using the same number changes could be merged to one change. CoalesceId of 0 means no merging

◆ replaceRangeSet() [1/2]

void edbee::TextDocument::replaceRangeSet ( TextRangeSet & rangeSet,
const QString & text,
bool stickySelection = false )

Replaces the given rangeset.

◆ replaceRangeSet() [2/2]

void edbee::TextDocument::replaceRangeSet ( TextRangeSet & rangeSet,
const QStringList & texts,
bool stickySelection = false )

replaces the given rangeset

◆ scopes()

virtual TextDocumentScopes * edbee::TextDocument::scopes ( )
pure virtual

Should return the document-scopes of this document.

Implemented in edbee::CharTextDocument.

◆ setDocumentFilter()

void edbee::TextDocument::setDocumentFilter ( TextDocumentFilter * filter)
virtual

Sets the document filter without tranfering the ownership.

◆ setEncoding()

virtual void edbee::TextDocument::setEncoding ( TextCodec * codec)
pure virtual

Implemented in edbee::CharTextDocument.

◆ setLanguageGrammar()

virtual void edbee::TextDocument::setLanguageGrammar ( TextGrammar * grammar)
pure virtual

Changes the language grammar. This method should emit a grammarChanged signal (if the grammar is changed)

Implemented in edbee::CharTextDocument.

◆ setLineDataFieldsPerLine()

void edbee::TextDocument::setLineDataFieldsPerLine ( int count)
virtual

This method can be used to change the number of reserved fields by the document Increasing the amount will result in a realoc Decreasting the fieldcount reults in the lost of the 'old' fields At least the 'PredefinedFieldCount' amont of fields are required.

This method can be used to change the number of reserved fields by the document Increasing the amount will result in a realoc Decreasting the fieldcount reults in the lost of the 'old' fields At least the 'PredefinedFieldCount' amont of fields are required This method EMPTIES the undo-stack. So after this call all undo history is gone!

◆ setLineEnding()

virtual void edbee::TextDocument::setLineEnding ( const LineEnding * lineENding)
pure virtual

Implemented in edbee::CharTextDocument.

◆ setPersisted()

void edbee::TextDocument::setPersisted ( bool enabled = true)
virtual

Calc this method to mark current state as persisted.

◆ setText()

void edbee::TextDocument::setText ( const QString & text)

Changes the compelte document text.

Parameters
textthe new document text

◆ setUndoCollectionEnabled()

void edbee::TextDocument::setUndoCollectionEnabled ( bool enabled)
virtual

Enables or disables the collection of undo commands.

◆ text()

QString edbee::TextDocument::text ( )

Returns the document text as a QString.

Returns
the complete document context

◆ textAboutToBeChanged

void edbee::TextDocument::textAboutToBeChanged ( edbee::TextBufferChange change)
signal

◆ textChanged

void edbee::TextDocument::textChanged ( edbee::TextBufferChange change,
QString oldText = QString() )
signal

◆ textLexer()

virtual TextLexer * edbee::TextDocument::textLexer ( )
pure virtual

Should return the current document lexer.

Implemented in edbee::CharTextDocument.

◆ textPart()

QString edbee::TextDocument::textPart ( int offset,
int length )

Returns the given part of the text.

Parameters
offsetthe character offset in the document
lengththe length of the part in characters
Returns
the text at the given positions

◆ textUndoStack()

virtual TextUndoStack * edbee::TextDocument::textUndoStack ( )
pure virtual

this method should return a reference to the undo stack

Implemented in edbee::CharTextDocument.


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