edbee - Qt Editor Library v0.11.1
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
textdocument.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 <QList>
10
12
13namespace edbee {
14
15
16class TextGrammar;
17class Change;
18class ChangeGroup;
20class TextCodec;
25class LineEnding;
26class TextLexer;
27class TextLineData;
29class TextRangeSet;
30class TextUndoStack;
31
41class EDBEE_EXPORT TextDocument : public QObject
42{
43
44Q_OBJECT
45
46public:
47
48 TextDocument( QObject* parent=0);
49 virtual ~TextDocument();
50
53 virtual TextBuffer* buffer() const = 0 ;
54
59 virtual void setLineDataFieldsPerLine( int count );
60
62 virtual TextLineDataManager* lineDataManager() { return textLineDataManager_; }
63 virtual void giveLineDataManager(TextLineDataManager* manager);
64 virtual void giveLineData( int line, int field, TextLineData* dataItem );
65 virtual TextLineData* getLineData( int line, int field );
66// virtual TextLineData* takeLineData( int line, int field ) = 0;
67
69 virtual TextDocumentScopes* scopes() = 0;
70
72 virtual TextCodec* encoding() = 0;
73 virtual void setEncoding( TextCodec* codec ) = 0;
74
76 virtual const LineEnding* lineEnding() = 0 ;
77 virtual void setLineEnding( const LineEnding* lineENding ) = 0;
78
80 virtual TextLexer* textLexer() = 0;
81
84
87 virtual void setLanguageGrammar( TextGrammar* grammar ) = 0;
88
89
92
95 virtual void beginUndoGroup(ChangeGroup* group=0);
96 virtual void endUndoGroup(int coalesceId, bool flatten=false );
97 virtual void endUndoGroupAndDiscard();
98 virtual bool isUndoCollectionEnabled();
99 virtual void setUndoCollectionEnabled( bool enabled );
100 virtual bool isUndoRunning();
101 virtual bool isRedoRunning();
102 virtual bool isUndoOrRedoRunning();
103 virtual bool isPersisted();
104 virtual void setPersisted(bool enabled=true);
105
107 virtual TextEditorConfig* config() const = 0;
108
109 virtual void setDocumentFilter( TextDocumentFilter* filter );
110 virtual void giveDocumentFilter( TextDocumentFilter* filter );
112
113 void beginChanges( TextEditorController* controller );
114 void replaceRangeSet(TextRangeSet& rangeSet, const QString& text, bool stickySelection = false);
115 void replaceRangeSet(TextRangeSet& rangeSet, const QStringList& texts, bool stickySelection = false);
116 void giveSelection( TextEditorController* controller, TextRangeSet* rangeSet);
117 void endChanges( int coalesceId );
118
119
120
121 Change* executeAndGiveChange(Change* change , int coalesceId );
122
123
124// void giveChange( TextChange* change, bool merge );
125 virtual Change* giveChangeWithoutFilter( Change* change, int coalesceId) = 0;
126 void append(const QString& text, int coalesceId=0 );
127 void replace( int offset, int length, const QString& text, int coalesceId=0);
128 void setText( const QString& text );
129
130 // raw access for filling the document
131 void rawAppendBegin();
132 void rawAppendEnd();
133 void rawAppend( QChar c );
134 void rawAppend(const QChar *chars, int length );
135
136public:
137
138 // Methods directly forwarded to the textbuffer
139
140 int length();
141 int lineCount();
142 QChar charAt(int idx);
143 QChar charAtOrNull(int idx);
144 int offsetFromLine( int line );
145 int lineFromOffset( int offset );
146 int columnFromOffsetAndLine( int offset, int line=-1 );
147 int offsetFromLineAndColumn( int line, int column );
148 int lineLength( int line );
150 QString text();
151 QString textPart( int offset, int length );
152 QString lineWithoutNewline( int line );
153 QString line( int line );
154
155signals:
156
158 void textChanged( edbee::TextBufferChange change, QString oldText = QString() );
159
161 void persistedChanged(bool persisted);
162
165
167 void lastScopedOffsetChanged( int previousOffset, int lastScopedOffset );
168
169
170private:
171 TextDocumentFilter* documentFilter_;
172 TextDocumentFilter* documentFilterRef_;
173
174 TextLineDataManager* textLineDataManager_;
175
176};
177
178} // edbee
An undoable-command-group.
Definition change.h:84
A basic change.
Definition change.h:18
A special class to perform line-ending detection.
Definition lineending.h:12
The instance autocomplete provider, managers which autocompleters are available for the given editor.
Definition textautocompleteprovider.h:115
This clas represents a text buffer change and is used to pass around between events This is a sharedd...
Definition textbuffer.h:45
This class represents the textbuffer of the editor.
Definition textbuffer.h:68
This class represents a single text codec The codec has a name and contains methods to create encoder...
Definition textcodec.h:38
Definition textdocumentfilter.h:22
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:180
virtual bool isPersisted()
Checks if the document is in a persited state.
Definition textdocument.cpp:156
void giveSelection(TextEditorController *controller, TextRangeSet *rangeSet)
sets the selectioin for the current rangeset The selection may never be empty
Definition textdocument.cpp:273
void setText(const QString &text)
Changes the compelte document text.
Definition textdocument.cpp:335
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:48
int lineFromOffset(int offset)
returns the line number which contains the given offset
Definition textdocument.cpp:421
void persistedChanged(bool persisted)
This signal is emitted if the persisted state is changed.
Definition moc_textdocument.cpp:296
virtual bool isUndoRunning()
This method should return true if the current change is the cause of an undo operation.
Definition textdocument.cpp:135
virtual void setUndoCollectionEnabled(bool enabled)
Enables or disables the collection of undo commands.
Definition textdocument.cpp:128
int columnFromOffsetAndLine(int offset, int line=-1)
return the column position for the given offset and line
Definition textdocument.cpp:431
int length()
Returns the length of the document in characters default implementation is to forward this call to th...
Definition textdocument.cpp:375
virtual TextAutoCompleteProviderList * autoCompleteProviderList()=0
This method should return the autcompletion provider list.
void replace(int offset, int length, const QString &text, int coalesceId=0)
Appends the given text.
Definition textdocument.cpp:327
virtual TextLexer * textLexer()=0
Should return the current document lexer.
virtual void setLanguageGrammar(TextGrammar *grammar)=0
Changes the language grammar. This method should emit a grammarChanged signal (if the grammar is chan...
int offsetFromLineAndColumn(int line, int column)
Returns the character offset of the given line and column.
Definition textdocument.cpp:441
virtual TextDocumentScopes * scopes()=0
Should return the document-scopes of this document.
void textAboutToBeChanged(edbee::TextBufferChange change)
Definition moc_textdocument.cpp:282
virtual TextLineDataManager * lineDataManager()
this method can be used to give a 'custom' line data item to a given line
Definition textdocument.h:62
void textChanged(edbee::TextBufferChange change, QString oldText=QString())
Definition moc_textdocument.cpp:289
void beginChanges(TextEditorController *controller)
Start the changes.
Definition textdocument.cpp:196
virtual Change * giveChangeWithoutFilter(Change *change, int coalesceId)=0
int lineCount()
Returns the number of lines.
Definition textdocument.cpp:382
void append(const QString &text, int coalesceId=0)
Appends the given text to the document.
Definition textdocument.cpp:318
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:400
void rawAppendEnd()
When then raw appending is done. The events are fired that the document has been changed The undo-col...
Definition textdocument.cpp:352
virtual TextCodec * encoding()=0
This method should return the current encoding.
virtual void setPersisted(bool enabled=true)
Calc this method to mark current state as persisted.
Definition textdocument.cpp:163
virtual TextUndoStack * textUndoStack()=0
this method should return a reference to the undo stack
virtual bool isRedoRunning()
Checks if currently an undo operation is running.
Definition textdocument.cpp:142
virtual TextGrammar * languageGrammar()=0
This method should return the current language grammar.
virtual TextEditorConfig * config() const =0
this method should return the config
QString text()
Returns the document text as a QString.
Definition textdocument.cpp:467
int offsetFromLine(int line)
Retrieves the character-offset of the given line.
Definition textdocument.cpp:412
int lineLengthWithoutNewline(int line)
returns the length of the given lilne without the newline
Definition textdocument.cpp:459
virtual void setEncoding(TextCodec *codec)=0
QString line(int line)
@pparam line the line number to retrieve
Definition textdocument.cpp:495
virtual const LineEnding * lineEnding()=0
This method should return the current line ending.
virtual TextBuffer * buffer() const =0
This method should return the active textbuffer Warning you should NEVER directly modify the textbuff...
virtual bool isUndoCollectionEnabled()
this method return true if the undo stack is enabled
Definition textdocument.cpp:121
virtual void beginUndoGroup(ChangeGroup *group=0)
Starts an undo group.
Definition textdocument.cpp:87
void rawAppend(QChar c)
Appends a single char in raw append mode.
Definition textdocument.cpp:360
virtual void endUndoGroupAndDiscard()
Ends the undo group and discards all recorded information Warning it does NOT undo all made changes!...
Definition textdocument.cpp:114
virtual void endUndoGroup(int coalesceId, bool flatten=false)
Ends the current undo group.
Definition textdocument.cpp:102
QString lineWithoutNewline(int line)
Returns the given line without the trailing character.
Definition textdocument.cpp:486
QChar charAt(int idx)
Returns the character at the given position.
Definition textdocument.cpp:389
void rawAppendBegin()
begins the raw append modes. In raw append mode data is directly streamed to the textdocument-buffer....
Definition textdocument.cpp:343
int lineLength(int line)
Returns the length of the given line.
Definition textdocument.cpp:450
TextDocument(QObject *parent=0)
Constructs the textdocument.
Definition textdocument.cpp:25
virtual TextDocumentFilter * documentFilter()
This method returns the document filter.
Definition textdocument.cpp:189
void endChanges(int coalesceId)
Definition textdocument.cpp:284
void replaceRangeSet(TextRangeSet &rangeSet, const QString &text, bool stickySelection=false)
Replaces the given rangeset.
Definition textdocument.cpp:203
virtual bool isUndoOrRedoRunning()
Is it an undo or redo (which means all commands area already available)
Definition textdocument.cpp:149
virtual void setDocumentFilter(TextDocumentFilter *filter)
Sets the document filter without tranfering the ownership.
Definition textdocument.cpp:170
void languageGrammarChanged()
This signal is emitted if the grammar has been changed.
Definition moc_textdocument.cpp:303
QString textPart(int offset, int length)
Returns the given part of the text.
Definition textdocument.cpp:477
virtual void setLineEnding(const LineEnding *lineENding)=0
void lastScopedOffsetChanged(int previousOffset, int lastScopedOffset)
this signal is emitted if the scoped range has been changed
Definition moc_textdocument.cpp:309
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:298
This class is used to 'contain' all document scope information.
Definition textdocumentscopes.h:322
General configuration settings of the text editor.
Definition texteditorconfig.h:18
The texteditor works via the controller. The controller is the central point/mediator which maps/cont...
Definition texteditorcontroller.h:39
This class defines a single language grammar.
Definition textgrammar.h:124
This is a single lexer.
Definition textlexer.h:17
A text line item reference.
Definition textlinedata.h:30
This manager manages all line definitions.
Definition textlinedata.h:77
The basic textrange class. A simple class of textrange with a simple vector implementation.
Definition textrange.h:202
This is the undo stack for the texteditor. This stack is SHARED by all views of the document The stac...
Definition textundostack.h:51
#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