edbee - Qt Editor Library
textdocument.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <QObject>
9 #include <QList>
10 
12 
13 namespace edbee {
14 
15 
16 class TextGrammar;
17 class Change;
18 class ChangeGroup;
19 class TextCodec;
20 class TextDocumentFilter;
21 class TextDocumentScopes;
22 class TextEditorConfig;
23 class TextEditorController;
24 class LineEnding;
25 class TextLexer;
26 class TextLineData;
27 class TextLineDataManager;
28 class TextRangeSet;
29 class TextUndoStack;
30 
40 class TextDocument : public QObject
41 {
42 
43 Q_OBJECT
44 
45 public:
46 
47  TextDocument( QObject* parent=0);
48  virtual ~TextDocument();
49 
52  virtual TextBuffer* buffer() const = 0 ;
53 
58  virtual void setLineDataFieldsPerLine( int count );
59 
61  virtual TextLineDataManager* lineDataManager() = 0;
62  virtual void giveLineData( int line, int field, TextLineData* dataItem );
63  virtual TextLineData* getLineData( int line, int field );
64 // virtual TextLineData* takeLineData( int line, int field ) = 0;
65 
67  virtual TextDocumentScopes* scopes() = 0;
68 
70  virtual TextCodec* encoding() = 0;
71  virtual void setEncoding( TextCodec* codec ) = 0;
72 
74  virtual const LineEnding* lineEnding() = 0 ;
75  virtual void setLineEnding( const LineEnding* lineENding ) = 0;
76 
78  virtual TextLexer* textLexer() = 0;
79 
81  virtual TextGrammar* languageGrammar() = 0;
82 
85  virtual void setLanguageGrammar( TextGrammar* grammar ) = 0;
86 
88  virtual TextUndoStack* textUndoStack() = 0;
89  virtual void beginUndoGroup(ChangeGroup* group);
90  virtual void endUndoGroup(int coalesceId, bool flatten=false );
91  virtual void endUndoGroupAndDiscard();
92  virtual bool isUndoCollectionEnabled();
93  virtual void setUndoCollectionEnabled( bool enabled );
94  virtual bool isUndoRunning();
95  virtual bool isRedoRunning();
96  virtual bool isUndoOrRedoRunning();
97  virtual bool isPersisted();
98  virtual void setPersisted(bool enabled=true);
99 
101  virtual TextEditorConfig* config() const = 0;
102 
103  virtual void setDocumentFilter( TextDocumentFilter* filter );
104  virtual void giveDocumentFilter( TextDocumentFilter* filter );
106 
107  void beginChanges( TextEditorController* controller );
108  void replaceRangeSet( TextRangeSet& rangeSet, const QString& text );
109  void replaceRangeSet( TextRangeSet& rangeSet, const QStringList& texts );
110  void giveSelection( TextEditorController* controller, TextRangeSet* rangeSet);
111  void endChanges( int coalesceId );
112 
113 
114 
115  Change* executeAndGiveChange(Change* change , int coalesceId );
116 
117 
118 // void giveChange( TextChange* change, bool merge );
119  virtual Change* giveChangeWithoutFilter( Change* change, int coalesceId) = 0;
120  void append(const QString& text, int coalesceId=0 );
121  void replace( int offset, int length, const QString& text, int coalesceId=0);
122  void setText( const QString& text );
123 
124  // raw access for filling the document
125  void rawAppendBegin();
126  void rawAppendEnd();
127  void rawAppend( QChar c );
128  void rawAppend(const QChar *chars, int length );
129 
130 public:
131 
132  // Methods directly forwarded to the textbuffer
133 
134  int length();
135  int lineCount();
136  QChar charAt(int idx);
137  QChar charAtOrNull(int idx);
138  int offsetFromLine( int line );
139  int lineFromOffset( int offset );
140  int columnFromOffsetAndLine( int offset, int line=-1 );
141  int offsetFromLineAndColumn( int line, int column );
142  int lineLength( int line );
143  int lineLengthWithoutNewline( int line );
144  QString text();
145  QString textPart( int offset, int length );
146  QString lineWithoutNewline( int line );
147  QString line( int line );
148 
149 signals:
150 
152  void textChanged( edbee::TextBufferChange change );
153 
155  void persistedChanged(bool persisted);
156 
158  void languageGrammarChanged();
159 
161  void lastScopedOffsetChanged( int previousOffset, int lastScopedOffset );
162 
163 
164 private:
165 
166  TextDocumentFilter* documentFilter_;
167  TextDocumentFilter* documentFilterRef_;
168 };
169 
170 } // edbee
This is the base and abstract class of a text document A TextDocument is the model part of the editor...
Definition: textdocument.h:40
virtual TextEditorConfig * config() const =0
this method should return the config
virtual void setLineEnding(const LineEnding *lineENding)=0
This clas represents a text buffer change and is used to pass around between events This is a sharedd...
Definition: textbuffer.h:45
virtual void giveLineData(int line, int field, TextLineData *dataItem)
This method gives a given data item to a text line.
Definition: textdocument.cpp:56
An undoable-command-group.
Definition: change.h:84
virtual void setDocumentFilter(TextDocumentFilter *filter)
Sets the document filter without tranfering the ownership.
Definition: textdocument.cpp:160
void rawAppendBegin()
begins the raw append modes. In raw append mode data is directly streamed to the textdocument-buffer...
Definition: textdocument.cpp:320
virtual TextCodec * encoding()=0
This method should return the current encoding.
virtual const LineEnding * lineEnding()=0
This method should return the current line ending.
QChar charAtOrNull(int idx)
returns the char at the given index if the index is valid else the null character is returned ...
Definition: textdocument.cpp:377
virtual bool isUndoRunning()
This method should return true if the current change is the cause of an undo operation.
Definition: textdocument.cpp:125
virtual TextLineData * getLineData(int line, int field)
Returns the line specific data at the given line.
Definition: textdocument.cpp:69
virtual void endUndoGroup(int coalesceId, bool flatten=false)
Ends the current undo group.
Definition: textdocument.cpp:92
int lineFromOffset(int offset)
returns the line number which contains the given offset
Definition: textdocument.cpp:398
This manager manages all line definitions.
Definition: textlinedata.h:75
virtual void beginUndoGroup(ChangeGroup *group)
Starts an undo group.
Definition: textdocument.cpp:80
void beginChanges(TextEditorController *controller)
Start the changes.
Definition: textdocument.cpp:186
virtual bool isUndoCollectionEnabled()
this method return true if the undo stack is enabled
Definition: textdocument.cpp:111
virtual void setLanguageGrammar(TextGrammar *grammar)=0
Changes the language grammar. This method should emit a grammarChanged signal (if the grammar is chan...
virtual TextUndoStack * textUndoStack()=0
this method should return a reference to the undo stack
virtual void setLineDataFieldsPerLine(int count)
This method can be used to change the number of reserved fields by the document Increasing the amount...
Definition: textdocument.cpp:47
void languageGrammarChanged()
This signal is emitted if the grammar has been changed.
Definition: moc_textdocument.cpp:214
void rawAppend(QChar c)
Appends a single char in raw append mode.
Definition: textdocument.cpp:337
TextDocument(QObject *parent=0)
Constructs the textdocument.
Definition: textdocument.cpp:27
This class represents a single text codec The codec has a name and contains methods to create encoder...
Definition: textcodec.h:37
void lastScopedOffsetChanged(int previousOffset, int lastScopedOffset)
this signal is emitted if the scoped range has been changed
Definition: moc_textdocument.cpp:220
void textAboutToBeChanged(edbee::TextBufferChange change)
Definition: moc_textdocument.cpp:193
QString textPart(int offset, int length)
Returns the given part of the text.
Definition: textdocument.cpp:454
virtual bool isUndoOrRedoRunning()
Is it an undo or redo (which means all commands area already available)
Definition: textdocument.cpp:139
int length()
Returns the length of the document in characters default implementation is to forward this call to th...
Definition: textdocument.cpp:352
int lineLength(int line)
Returns the length of the given line.
Definition: textdocument.cpp:427
virtual void setUndoCollectionEnabled(bool enabled)
Enables or disables the collection of undo commands.
Definition: textdocument.cpp:118
General configuration settings of the text editor.
Definition: texteditorconfig.h:17
Copyright 2011-2013 - Reliable Bits Software by Blommers IT.
Definition: commentcommand.cpp:22
virtual TextLexer * textLexer()=0
Should return the current document lexer.
virtual void setPersisted(bool enabled=true)
Calc this method to mark current state as persisted.
Definition: textdocument.cpp:153
This class defines a single language grammar.
Definition: textgrammar.h:125
virtual TextGrammar * languageGrammar()=0
This method should return the current language grammar.
virtual bool isPersisted()
Checks if the document is in a persited state.
Definition: textdocument.cpp:146
virtual bool isRedoRunning()
Checks if currently an undo operation is running.
Definition: textdocument.cpp:132
Change * executeAndGiveChange(Change *change, int coalesceId)
call this method to execute a change. The change is first passed to the filter so the documentFilter ...
Definition: textdocument.cpp:281
int offsetFromLine(int line)
Retrieves the character-offset of the given line.
Definition: textdocument.cpp:389
A basic change.
Definition: change.h:18
The texteditor works via the controller. The controller is the central point/mediater which maps/cont...
Definition: texteditorcontroller.h:37
void giveSelection(TextEditorController *controller, TextRangeSet *rangeSet)
sets the selectioin for the current rangeset The selection may never be empty
Definition: textdocument.cpp:256
QString lineWithoutNewline(int line)
Returns the given line without the trailing character.
Definition: textdocument.cpp:463
void textChanged(edbee::TextBufferChange change)
Definition: moc_textdocument.cpp:200
This class represents the textbuffer of the editor.
Definition: textbuffer.h:68
void append(const QString &text, int coalesceId=0)
Appends the given text to the document.
Definition: textdocument.cpp:295
The basic textrange class. A simple class of textrange with a simple vector implementation.
Definition: textrange.h:198
void setText(const QString &text)
Changes the compelte document text.
Definition: textdocument.cpp:312
QChar charAt(int idx)
Returns the character at the given position.
Definition: textdocument.cpp:366
QString text()
Returns the document text as a QString.
Definition: textdocument.cpp:444
int lineCount()
Returns the number of lines.
Definition: textdocument.cpp:359
This class is used to &#39;contain&#39; all document scope information.
Definition: textdocumentscopes.h:325
Definition: textdocumentfilter.h:20
virtual void giveDocumentFilter(TextDocumentFilter *filter)
this method sets the document filter You can give a 0 pointer to delte the old filter! ...
Definition: textdocument.cpp:170
int offsetFromLineAndColumn(int line, int column)
Returns the character offset of the given line and column.
Definition: textdocument.cpp:418
void rawAppendEnd()
When then raw appending is done. The events are fired that the document has been changed The undo-col...
Definition: textdocument.cpp:329
int lineLengthWithoutNewline(int line)
returns the length of the given lilne without the newline
Definition: textdocument.cpp:436
QString line(int line)
line the line number to retrieve
Definition: textdocument.cpp:472
virtual void setEncoding(TextCodec *codec)=0
This is the undo stack for the texteditor. This stack is SHARED by all views of the document The stac...
Definition: textundostack.h:50
virtual TextLineDataManager * lineDataManager()=0
this method can be used to give a &#39;custom&#39; line data item to a given line
virtual TextDocumentScopes * scopes()=0
Should return the document-scopes of this document.
This is a single lexer.
Definition: textlexer.h:17
A special class to perform line-ending detection.
Definition: lineending.h:12
virtual TextDocumentFilter * documentFilter()
This method returns the document filter.
Definition: textdocument.cpp:179
A text line item reference.
Definition: textlinedata.h:28
int columnFromOffsetAndLine(int offset, int line=-1)
return the column position for the given offset and line
Definition: textdocument.cpp:408
virtual ~TextDocument()
Destroys the textdocument.
Definition: textdocument.cpp:36
void persistedChanged(bool persisted)
This signal is emitted if the persisted state is changed.
Definition: moc_textdocument.cpp:207
void endChanges(int coalesceId)
Definition: textdocument.cpp:267
virtual Change * giveChangeWithoutFilter(Change *change, int coalesceId)=0
void replace(int offset, int length, const QString &text, int coalesceId=0)
Appends the given text.
Definition: textdocument.cpp:304
void replaceRangeSet(TextRangeSet &rangeSet, const QString &text)
Replaces the given rangeset.
Definition: textdocument.cpp:193
virtual void endUndoGroupAndDiscard()
Ends the undo group and discards all recorded information Warning it does NOT undo all made changes!!...
Definition: textdocument.cpp:104
virtual TextBuffer * buffer() const =0
This method should return the active textbuffer Warning you should NEVER directly modify the textbuff...