The texteditor works via the controller. The controller is the central point/mediator which maps/controls all messages between the different editor components. More...
#include <texteditorcontroller.h>
Public Types | |
enum | AutoScrollToCaret { AutoScrollAlways , AutoScrollWhenFocus , AutoScrollNever } |
Public Slots | |
void | onTextChanged (edbee::TextBufferChange change, QString oldText=QString()) |
This slot is placed if a piece of text is replaced. | |
void | onSelectionChanged (edbee::TextRangeSet *oldRangeSet) |
the old selection has been changed | |
void | onLineDataChanged (int line, int length, int newLength) |
The line-data is changed, we need to repaint the selected lines. | |
void | updateAfterConfigChange () |
This method is used to update the component when the configuration has been changed. This is a temporary solution, perhaps we should make TextConfig signal changes A lot of changes don't require an updates, but some do. | |
virtual void | updateStatusText (const QString &extraText=QString()) |
This method updates the status text. This is the text as displayed in the lower status bar. | |
virtual void | update () |
updates the main widget | |
virtual void | scrollPositionVisible (int xPos, int yPos) |
Asserts the view shows the given position. | |
virtual void | scrollOffsetVisible (int offset) |
Assets the view shows the given offset. | |
virtual void | scrollCaretVisible () |
This method makes sure caret 1 is visible. | |
virtual void | storeSelection (int coalesceId=0) |
This method adds a text change on the stack that simply stores the current text-selection. | |
virtual void | replace (int offset, int length, const QString &text, int coalesceId, bool stickySelection=false) |
replaces the given text (single ranges) | |
virtual void | replaceSelection (const QString &text, int coalesceId=0, bool stickySelection=false) |
This method replaces the selection with the given text. | |
virtual void | replaceSelection (const QStringList &texts, int coalesceId=0, bool stickySelection=false) |
This method replaces the given selection with the given texts. | |
virtual void | replaceRangeSet (edbee::TextRangeSet &rangeSet, const QString &text, int coalesceId=0, bool stickySelection=false) |
Replaces the given rangeset with the given text. | |
virtual void | replaceRangeSet (edbee::TextRangeSet &rangeSet, const QStringList &texts, int coalesceId=0, bool stickySelection=false) |
Replaces the given ranges with the given texts. Different text per range is possible. | |
virtual void | moveCaretTo (int line, int col, bool keepAnchors, int rangeIndex=-1) |
This method creates a command that moves the caret to the given line/column position A negative number means that we're counting from the end This method assumes line 0 is the first line! | |
virtual void | moveCaretToOffset (int offset, bool keepAnchors, int rangeIndex=-1) |
Moves the caret to the given offset. | |
virtual void | moveCaretAndAnchorToOffset (int caret, int anchor, int rangeIndex=-1) |
Move the caret and the anchor to the given offset. | |
virtual void | addCaretAt (int line, int col) |
Adds a new caret to the selection. | |
virtual void | addCaretAtOffset (int offset) |
Adds a carert at the given offset. | |
virtual void | changeAndGiveTextSelection (edbee::TextRangeSet *rangeSet, int coalesceId=0) |
This method changes the text selection. | |
virtual void | undo (bool soft=false) |
This method performs an undo operation. By supplying soft only controller based operations are undone. When supplying false a Document operation is being undone. | |
virtual void | redo (bool soft=false) |
This method performs an redo operation. By supplying soft only controller based operations are redone. When supplying false a Document operation is being redone. | |
virtual void | beginUndoGroup (edbee::ChangeGroup *group=0) |
Starts an undo group. | |
virtual void | endUndoGroup (int coalesceId=0, bool flatten=false) |
Ends the undo-group. | |
virtual void | executeCommand (edbee::TextEditorCommand *textCommand) |
This method executes the command. | |
virtual void | executeCommand (const QString &name=QString()) |
Executes a command with the given name. | |
Signals | |
void | updateStatusTextSignal (const QString &text) |
This signal is fired if the statusbar needs updating. | |
void | textDocumentChanged (edbee::TextDocument *oldDocument, edbee::TextDocument *newDocument) |
This signal is fired if the textdocument changes. | |
void | commandToBeExecuted (edbee::TextEditorCommand *command) |
this method is executed when a command is going to be executed | |
void | commandExecuted (edbee::TextEditorCommand *command) |
void | backspacePressed () |
Public Member Functions | |
TextEditorController (TextEditorWidget *widget=nullptr, QObject *parent=nullptr) | |
The constructor. | |
TextEditorController (TextDocument *document, TextEditorWidget *widget=nullptr, QObject *parent=nullptr) | |
virtual | ~TextEditorController () |
Destroys the controller and associated objects. | |
void | notifyStateChange () |
This method is called to reset the caret timer and update the ui. | |
void | giveTextDocument (TextDocument *doc) |
sets the document and transfers the ownership of the textdocument to this class | |
void | setTextDocument (TextDocument *doc) |
Set the text document. | |
void | setAutoScrollToCaret (AutoScrollToCaret autoScroll) |
Changes the autoScrollToCaret setting. | |
virtual AutoScrollToCaret | autoScrollToCaret () const |
Returns the autoScrollToCaret setting. | |
bool | hasFocus () |
This method return true if the text-editor has focus. | |
QAction * | createUnconnectedAction (const QString &command, const QString &text, const QIcon &icon=QIcon(), QObject *owner=0) |
This method creates an editor action that is. | |
QAction * | createAction (const QString &command, const QString &text, const QIcon &icon=QIcon(), QObject *owner=0) |
Creates a QAction object that performs the given editor action The shortcut of the given editor-command is retrieved from the keymap. | |
TextDocument * | textDocument () const |
Returns a reference to the textdocument. | |
TextSelection * | textSelection () const |
Returns the textselection. | |
TextRenderer * | textRenderer () const |
Returns the current text renderer. | |
TextRangeSet * | borderedTextRanges () const |
returns the bordered textranges These are textranges that are rendered with a border, but aren't truly selected | |
void | setKeyMap (TextEditorKeyMap *keyMap) |
sets the keymap. It will replace (and if owned, delete) the previous keymap | |
void | giveKeyMap (TextEditorKeyMap *keyMap) |
gives a keymap to the editor. The ownership is transferred to this controller | |
TextEditorKeyMap * | keyMap () const |
Returns the current keymap. | |
void | setCommandMap (TextEditorCommandMap *commandMap) |
set a commandmap the ownership is NOT transferred to this object. The old owned command-map is deleted @parm commandMap the new commandMap of this object | |
void | giveCommandMap (TextEditorCommandMap *commandMap) |
gives a commandmap to the editor The old associated command map is deleted | |
TextEditorCommandMap * | commandMap () const |
Returns the current commandmap. | |
TextEditorWidget * | widget () const |
Returns the active widget. | |
TextCaretCache * | textCaretCache () const |
Returns the textCaretCache. | |
void | giveTextSearcher (TextSearcher *searcher) |
Gives the text-searcher to this document. | |
TextSearcher * | textSearcher () |
Returns the associated text searcher object. | |
DynamicVariables * | dynamicVariables () const |
this method returns the dynamic variables object for this controller The current implementation simply returns the application-wide environment variables | |
virtual bool | readonly () const |
Return the readonly state. | |
virtual void | setReadonly (bool value) |
Sets the readonly state. | |
The texteditor works via the controller. The controller is the central point/mediator which maps/controls all messages between the different editor components.
|
explicit |
The constructor.
widget | the widget this controller is associated with @paarm parent the QObject parent of the controller |
|
explicit |
|
virtual |
Destroys the controller and associated objects.
|
virtualslot |
Adds a new caret to the selection.
line | the line number |
col | the column |
|
virtualslot |
Adds a carert at the given offset.
offset | the character offset to add the caret |
|
virtual |
Returns the autoScrollToCaret setting.
|
signal |
|
virtualslot |
Starts an undo group.
group | the undogroup to use (defaults to a MergableChangeGroup) |
TextRangeSet * edbee::TextEditorController::borderedTextRanges | ( | ) | const |
returns the bordered textranges These are textranges that are rendered with a border, but aren't truly selected
|
virtualslot |
This method changes the text selection.
|
signal |
TextEditorCommandMap * edbee::TextEditorController::commandMap | ( | ) | const |
Returns the current commandmap.
|
signal |
this method is executed when a command is going to be executed
QAction * edbee::TextEditorController::createAction | ( | const QString & | command, |
const QString & | text, | ||
const QIcon & | icon = QIcon(), | ||
QObject * | owner = 0 ) |
Creates a QAction object that performs the given editor action The shortcut of the given editor-command is retrieved from the keymap.
command | the command that needs to be executed. |
text | description of the command |
icon | the optional icon of the command |
owner | the QObject owner of this action |
connect the signal to executeCommand
QAction * edbee::TextEditorController::createUnconnectedAction | ( | const QString & | command, |
const QString & | text, | ||
const QIcon & | icon = QIcon(), | ||
QObject * | owner = 0 ) |
This method creates an editor action that is.
command | the command that needs to be executed. |
text | description of the command |
icon | the optional icon of the command |
owner | the QObject owner of this action |
DynamicVariables * edbee::TextEditorController::dynamicVariables | ( | ) | const |
this method returns the dynamic variables object for this controller The current implementation simply returns the application-wide environment variables
|
virtualslot |
Ends the undo-group.
coalesceId | is used to decide if merging of groups is required. a value of 0 means NO merging (default) and id > 0 means if the previous command had the same id, the command is merged |
flatten | when an undogroup is ended and flatten is set to true ALL sub-undo-groups are merged to this group (default=false) |
|
virtualslot |
Executes a command with the given name.
When the name hasn't been supplied. This function assumes the command is triggered by a QAction and it will retrieve the command-name from the QAction data method
name | of the command to execute |
|
virtualslot |
This method executes the command.
void edbee::TextEditorController::giveCommandMap | ( | TextEditorCommandMap * | commandMap | ) |
gives a commandmap to the editor The old associated command map is deleted
commandMap | the new commandMap |
void edbee::TextEditorController::giveKeyMap | ( | TextEditorKeyMap * | keyMap | ) |
gives a keymap to the editor. The ownership is transferred to this controller
keyMap | the new keymap to give to the controller |
void edbee::TextEditorController::giveTextDocument | ( | TextDocument * | doc | ) |
sets the document and transfers the ownership of the textdocument to this class
doc | the new document for this controller |
void edbee::TextEditorController::giveTextSearcher | ( | TextSearcher * | searcher | ) |
Gives the text-searcher to this document.
searcher | the new textsearcher for this document (The old one is deleted) |
bool edbee::TextEditorController::hasFocus | ( | ) |
This method return true if the text-editor has focus.
TextEditorKeyMap * edbee::TextEditorController::keyMap | ( | ) | const |
Returns the current keymap.
|
virtualslot |
Move the caret and the anchor to the given offset.
caret | the caret location |
anchor | the anchor location The rangeIndex is used to specify which range to move.. (Defaults to -1 which changes to a single range) |
|
virtualslot |
This method creates a command that moves the caret to the given line/column position A negative number means that we're counting from the end This method assumes line 0 is the first line!
For example: moveCaretTo( 2, 1 ) => Moves the caret to the 3rd line and 2nd column moveCaretTo( -1, -2 ) => Moves the caret to the character before the last character
The rangeIndex is used to specify which range to move.. (Defaults to -1 which changes to a single range)
|
virtualslot |
Moves the caret to the given offset.
offset | the offset to move the caret to |
keepAnchors | should the anchors stay at the current position (extending the selection range) The rangeIndex is used to specify which range to move.. (Defaults to -1 which changes to a single range) |
void edbee::TextEditorController::notifyStateChange | ( | ) |
This method is called to reset the caret timer and update the ui.
|
slot |
The line-data is changed, we need to repaint the selected lines.
line | the line number that had a data change |
length | the number of lines changed |
newLength | the new number of lines |
|
slot |
the old selection has been changed
oldRangeSet | the old range set of the change |
|
slot |
|
virtual |
Return the readonly state.
|
virtualslot |
This method performs an redo operation. By supplying soft only controller based operations are redone. When supplying false a Document operation is being redone.
soft | perform a soft undo? |
|
virtualslot |
replaces the given text (single ranges)
offset | the character offset in the document |
length | the number of characters to replace |
text | the text to replace |
coalesceId | the identifier for grouping undo operations |
|
virtualslot |
Replaces the given rangeset with the given text.
rangeset | the ranges to replace |
text | the text to replace the selection with |
coalesceId | the identifier for grouping undo operations |
|
virtualslot |
Replaces the given ranges with the given texts. Different text per range is possible.
rangeSet | the rangeset to fill |
text | the texts to fill the given ranges with. |
coalesceId | the identifier for grouping undo operations |
|
virtualslot |
This method replaces the selection with the given text.
text | the text to replace the selection with |
coalesceId | the identifier for grouping undo operations |
|
virtualslot |
This method replaces the given selection with the given texts.
texts | the list of texts that need to be replaced |
coalesceID | the identifier for grouping undo operation |
|
virtualslot |
This method makes sure caret 1 is visible.
|
virtualslot |
Assets the view shows the given offset.
|
virtualslot |
Asserts the view shows the given position.
void edbee::TextEditorController::setAutoScrollToCaret | ( | TextEditorController::AutoScrollToCaret | autoScroll | ) |
Changes the autoScrollToCaret setting.
autoScroll | the new autoscroll to caret setting. This can be one of the following values:
|
void edbee::TextEditorController::setCommandMap | ( | TextEditorCommandMap * | commandMap | ) |
set a commandmap the ownership is NOT transferred to this object. The old owned command-map is deleted @parm commandMap the new commandMap of this object
void edbee::TextEditorController::setKeyMap | ( | TextEditorKeyMap * | keyMap | ) |
sets the keymap. It will replace (and if owned, delete) the previous keymap
keyMap | the new keyMap to use |
|
virtual |
Sets the readonly state.
void edbee::TextEditorController::setTextDocument | ( | TextDocument * | doc | ) |
Set the text document.
doc | the document for this controller |
|
virtualslot |
This method adds a text change on the stack that simply stores the current text-selection.
coalsceId | the coalescing identifier for merging/coalescing undo operations |
TextCaretCache * edbee::TextEditorController::textCaretCache | ( | ) | const |
Returns the textCaretCache.
TextDocument * edbee::TextEditorController::textDocument | ( | ) | const |
Returns a reference to the textdocument.
|
signal |
This signal is fired if the textdocument changes.
TextRenderer * edbee::TextEditorController::textRenderer | ( | ) | const |
Returns the current text renderer.
TextSearcher * edbee::TextEditorController::textSearcher | ( | ) |
Returns the associated text searcher object.
TextSelection * edbee::TextEditorController::textSelection | ( | ) | const |
Returns the textselection.
|
virtualslot |
This method performs an undo operation. By supplying soft only controller based operations are undone. When supplying false a Document operation is being undone.
|
virtualslot |
updates the main widget
|
slot |
This method is used to update the component when the configuration has been changed. This is a temporary solution, perhaps we should make TextConfig signal changes A lot of changes don't require an updates, but some do.
|
virtualslot |
This method updates the status text. This is the text as displayed in the lower status bar.
extraText | the extra text to show in the status bar |
|
signal |
This signal is fired if the statusbar needs updating.
TextEditorWidget * edbee::TextEditorController::widget | ( | ) | const |
Returns the active widget.