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

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>

+ Inheritance diagram for edbee::TextEditorController:
+ Collaboration diagram for edbee::TextEditorController:

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.
 
TextDocumenttextDocument () const
 Returns a reference to the textdocument.
 
TextSelectiontextSelection () const
 Returns the textselection.
 
TextRenderertextRenderer () const
 Returns the current text renderer.
 
TextRangeSetborderedTextRanges () 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
 
TextEditorKeyMapkeyMap () 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
 
TextEditorCommandMapcommandMap () const
 Returns the current commandmap.
 
TextEditorWidgetwidget () const
 Returns the active widget.
 
TextCaretCachetextCaretCache () const
 Returns the textCaretCache.
 
void giveTextSearcher (TextSearcher *searcher)
 Gives the text-searcher to this document.
 
TextSearchertextSearcher ()
 Returns the associated text searcher object.
 
DynamicVariablesdynamicVariables () 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.
 

Detailed Description

The texteditor works via the controller. The controller is the central point/mediator which maps/controls all messages between the different editor components.

Member Enumeration Documentation

◆ AutoScrollToCaret

Enumerator
AutoScrollAlways 
AutoScrollWhenFocus 
AutoScrollNever 

Constructor & Destructor Documentation

◆ TextEditorController() [1/2]

edbee::TextEditorController::TextEditorController ( TextEditorWidget * widget = nullptr,
QObject * parent = nullptr )
explicit

The constructor.

Parameters
widgetthe widget this controller is associated with @paarm parent the QObject parent of the controller

◆ TextEditorController() [2/2]

edbee::TextEditorController::TextEditorController ( TextDocument * document,
TextEditorWidget * widget = nullptr,
QObject * parent = nullptr )
explicit

◆ ~TextEditorController()

edbee::TextEditorController::~TextEditorController ( )
virtual

Destroys the controller and associated objects.

Member Function Documentation

◆ addCaretAt

void edbee::TextEditorController::addCaretAt ( int line,
int col )
virtualslot

Adds a new caret to the selection.

Parameters
linethe line number
colthe column

◆ addCaretAtOffset

void edbee::TextEditorController::addCaretAtOffset ( int offset)
virtualslot

Adds a carert at the given offset.

Parameters
offsetthe character offset to add the caret

◆ autoScrollToCaret()

TextEditorController::AutoScrollToCaret edbee::TextEditorController::autoScrollToCaret ( ) const
virtual

Returns the autoScrollToCaret setting.

◆ backspacePressed

void edbee::TextEditorController::backspacePressed ( )
signal

◆ beginUndoGroup

void edbee::TextEditorController::beginUndoGroup ( edbee::ChangeGroup * group = 0)
virtualslot

Starts an undo group.

Parameters
groupthe undogroup to use (defaults to a MergableChangeGroup)

◆ borderedTextRanges()

TextRangeSet * edbee::TextEditorController::borderedTextRanges ( ) const

returns the bordered textranges These are textranges that are rendered with a border, but aren't truly selected

◆ changeAndGiveTextSelection

void edbee::TextEditorController::changeAndGiveTextSelection ( edbee::TextRangeSet * rangeSet,
int coalesceId = 0 )
virtualslot

This method changes the text selection.

◆ commandExecuted

void edbee::TextEditorController::commandExecuted ( edbee::TextEditorCommand * command)
signal

◆ commandMap()

TextEditorCommandMap * edbee::TextEditorController::commandMap ( ) const

Returns the current commandmap.

◆ commandToBeExecuted

void edbee::TextEditorController::commandToBeExecuted ( edbee::TextEditorCommand * command)
signal

this method is executed when a command is going to be executed

◆ createAction()

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.

Parameters
commandthe command that needs to be executed.
textdescription of the command
iconthe optional icon of the command
ownerthe QObject owner of this action
Returns
the newly created QAction

connect the signal to executeCommand

◆ createUnconnectedAction()

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.

Parameters
commandthe command that needs to be executed.
textdescription of the command
iconthe optional icon of the command
ownerthe QObject owner of this action
Returns
the newly created QAction

◆ dynamicVariables()

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

◆ endUndoGroup

void edbee::TextEditorController::endUndoGroup ( int coalesceId = 0,
bool flatten = false )
virtualslot

Ends the undo-group.

Parameters
coalesceIdis 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
flattenwhen an undogroup is ended and flatten is set to true ALL sub-undo-groups are merged to this group (default=false)

◆ executeCommand [1/2]

void edbee::TextEditorController::executeCommand ( const QString & name = QString())
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

Parameters
nameof the command to execute

◆ executeCommand [2/2]

void edbee::TextEditorController::executeCommand ( edbee::TextEditorCommand * textCommand)
virtualslot

This method executes the command.

Todo
: move this to a nicer place!!

◆ giveCommandMap()

void edbee::TextEditorController::giveCommandMap ( TextEditorCommandMap * commandMap)

gives a commandmap to the editor The old associated command map is deleted

Parameters
commandMapthe new commandMap

◆ giveKeyMap()

void edbee::TextEditorController::giveKeyMap ( TextEditorKeyMap * keyMap)

gives a keymap to the editor. The ownership is transferred to this controller

Parameters
keyMapthe new keymap to give to the controller

◆ giveTextDocument()

void edbee::TextEditorController::giveTextDocument ( TextDocument * doc)

sets the document and transfers the ownership of the textdocument to this class

Parameters
docthe new document for this controller

◆ giveTextSearcher()

void edbee::TextEditorController::giveTextSearcher ( TextSearcher * searcher)

Gives the text-searcher to this document.

Parameters
searcherthe new textsearcher for this document (The old one is deleted)

◆ hasFocus()

bool edbee::TextEditorController::hasFocus ( )

This method return true if the text-editor has focus.

◆ keyMap()

TextEditorKeyMap * edbee::TextEditorController::keyMap ( ) const

Returns the current keymap.

◆ moveCaretAndAnchorToOffset

void edbee::TextEditorController::moveCaretAndAnchorToOffset ( int caret,
int anchor,
int rangeIndex = -1 )
virtualslot

Move the caret and the anchor to the given offset.

Parameters
caretthe caret location
anchorthe anchor location The rangeIndex is used to specify which range to move.. (Defaults to -1 which changes to a single range)

◆ moveCaretTo

void edbee::TextEditorController::moveCaretTo ( int line,
int col,
bool keepAnchors,
int rangeIndex = -1 )
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)

◆ moveCaretToOffset

void edbee::TextEditorController::moveCaretToOffset ( int offset,
bool keepAnchors,
int rangeIndex = -1 )
virtualslot

Moves the caret to the given offset.

Parameters
offsetthe offset to move the caret to
keepAnchorsshould 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)

◆ notifyStateChange()

void edbee::TextEditorController::notifyStateChange ( )

This method is called to reset the caret timer and update the ui.

◆ onLineDataChanged

void edbee::TextEditorController::onLineDataChanged ( int line,
int length,
int newLength )
slot

The line-data is changed, we need to repaint the selected lines.

Parameters
linethe line number that had a data change
lengththe number of lines changed
newLengththe new number of lines

◆ onSelectionChanged

void edbee::TextEditorController::onSelectionChanged ( edbee::TextRangeSet * oldRangeSet)
slot

the old selection has been changed

Parameters
oldRangeSetthe old range set of the change
Todo
: improve this:

◆ onTextChanged

void edbee::TextEditorController::onTextChanged ( edbee::TextBufferChange change,
QString oldText = QString() )
slot

This slot is placed if a piece of text is replaced.

update the selection

Todo
: improve this:

◆ readonly()

bool edbee::TextEditorController::readonly ( ) const
virtual

Return the readonly state.

◆ redo

void edbee::TextEditorController::redo ( bool soft = false)
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.

Parameters
softperform a soft undo?

◆ replace

void edbee::TextEditorController::replace ( int offset,
int length,
const QString & text,
int coalesceId,
bool stickySelection = false )
virtualslot

replaces the given text (single ranges)

Parameters
offsetthe character offset in the document
lengththe number of characters to replace
textthe text to replace
coalesceIdthe identifier for grouping undo operations

◆ replaceRangeSet [1/2]

void edbee::TextEditorController::replaceRangeSet ( edbee::TextRangeSet & rangeSet,
const QString & text,
int coalesceId = 0,
bool stickySelection = false )
virtualslot

Replaces the given rangeset with the given text.

Parameters
rangesetthe ranges to replace
textthe text to replace the selection with
coalesceIdthe identifier for grouping undo operations

◆ replaceRangeSet [2/2]

void edbee::TextEditorController::replaceRangeSet ( edbee::TextRangeSet & rangeSet,
const QStringList & texts,
int coalesceId = 0,
bool stickySelection = false )
virtualslot

Replaces the given ranges with the given texts. Different text per range is possible.

Parameters
rangeSetthe rangeset to fill
textthe texts to fill the given ranges with.
coalesceIdthe identifier for grouping undo operations

◆ replaceSelection [1/2]

void edbee::TextEditorController::replaceSelection ( const QString & text,
int coalesceId = 0,
bool stickySelection = false )
virtualslot

This method replaces the selection with the given text.

Parameters
textthe text to replace the selection with
coalesceIdthe identifier for grouping undo operations

◆ replaceSelection [2/2]

void edbee::TextEditorController::replaceSelection ( const QStringList & texts,
int coalesceId = 0,
bool stickySelection = false )
virtualslot

This method replaces the given selection with the given texts.

Parameters
textsthe list of texts that need to be replaced
coalesceIDthe identifier for grouping undo operation

◆ scrollCaretVisible

void edbee::TextEditorController::scrollCaretVisible ( )
virtualslot

This method makes sure caret 1 is visible.

◆ scrollOffsetVisible

void edbee::TextEditorController::scrollOffsetVisible ( int offset)
virtualslot

Assets the view shows the given offset.

◆ scrollPositionVisible

void edbee::TextEditorController::scrollPositionVisible ( int xPos,
int yPos )
virtualslot

Asserts the view shows the given position.

◆ setAutoScrollToCaret()

void edbee::TextEditorController::setAutoScrollToCaret ( TextEditorController::AutoScrollToCaret autoScroll)

Changes the autoScrollToCaret setting.

Parameters
autoScrollthe new autoscroll to caret setting. This can be one of the following values:
  • AutoScrollAlways => Always scroll the view so the caret is visible

◆ setCommandMap()

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

◆ setKeyMap()

void edbee::TextEditorController::setKeyMap ( TextEditorKeyMap * keyMap)

sets the keymap. It will replace (and if owned, delete) the previous keymap

Parameters
keyMapthe new keyMap to use

◆ setReadonly()

void edbee::TextEditorController::setReadonly ( bool value)
virtual

Sets the readonly state.

◆ setTextDocument()

void edbee::TextEditorController::setTextDocument ( TextDocument * doc)

Set the text document.

Parameters
docthe document for this controller

◆ storeSelection

void edbee::TextEditorController::storeSelection ( int coalesceId = 0)
virtualslot

This method adds a text change on the stack that simply stores the current text-selection.

Parameters
coalsceIdthe coalescing identifier for merging/coalescing undo operations

◆ textCaretCache()

TextCaretCache * edbee::TextEditorController::textCaretCache ( ) const

Returns the textCaretCache.

◆ textDocument()

TextDocument * edbee::TextEditorController::textDocument ( ) const

Returns a reference to the textdocument.

◆ textDocumentChanged

void edbee::TextEditorController::textDocumentChanged ( edbee::TextDocument * oldDocument,
edbee::TextDocument * newDocument )
signal

This signal is fired if the textdocument changes.

◆ textRenderer()

TextRenderer * edbee::TextEditorController::textRenderer ( ) const

Returns the current text renderer.

◆ textSearcher()

TextSearcher * edbee::TextEditorController::textSearcher ( )

Returns the associated text searcher object.

Returns
the textsearcher object

◆ textSelection()

TextSelection * edbee::TextEditorController::textSelection ( ) const

Returns the textselection.

◆ undo

void edbee::TextEditorController::undo ( bool soft = false)
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.

◆ update

void edbee::TextEditorController::update ( )
virtualslot

updates the main widget

◆ updateAfterConfigChange

void edbee::TextEditorController::updateAfterConfigChange ( )
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.

◆ updateStatusText

void edbee::TextEditorController::updateStatusText ( const QString & extraText = QString())
virtualslot

This method updates the status text. This is the text as displayed in the lower status bar.

Parameters
extraTextthe extra text to show in the status bar

◆ updateStatusTextSignal

void edbee::TextEditorController::updateStatusTextSignal ( const QString & text)
signal

This signal is fired if the statusbar needs updating.

◆ widget()

TextEditorWidget * edbee::TextEditorController::widget ( ) const

Returns the active widget.


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