edbee - Qt Editor Library
Public Types | Public Slots | Signals | Public Member Functions | List of all members
edbee::TextEditorController Class Reference

The texteditor works via the controller. The controller is the central point/mediater which maps/controls all messages between the different editor componenents. 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)
 This slot is placed if a piece of text is replaced. More...
 
void onSelectionChanged (edbee::TextRangeSet *oldRangeSet)
 the old selection has been changed More...
 
void onLineDataChanged (int line, int length, int newLength)
 The line-data is changed, we need to repaint the selected lines. More...
 
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. More...
 
virtual void updateStatusText (const QString &extraText="")
 This method updates the status text. This is the text as displayed in the lower status bar. More...
 
virtual void update ()
 updates the main widget More...
 
virtual void scrollPositionVisible (int xPos, int yPos)
 Asserts the view shows the given position. More...
 
virtual void scrollOffsetVisible (int offset)
 Assets the view shows the given offset. More...
 
virtual void scrollCaretVisible ()
 This method makes sure caret 1 is vible. More...
 
virtual void storeSelection (int coalesceId=0)
 This method adds a textchange on the stack that simply stores the current text-selection. More...
 
virtual void replace (int offset, int length, const QString &text, int coalesceId)
 replaces the given text (single ranges) More...
 
virtual void replaceSelection (const QString &text, int coalesceId=0)
 This method replaces the selection with the given text. More...
 
virtual void replaceSelection (const QStringList &texts, int coalesceId=0)
 This method replaces the given selection with the given texts. More...
 
virtual void replaceRangeSet (TextRangeSet &rangeSet, const QString &text, int coalesceId=0)
 Replaces the given rangeset with the given text. More...
 
virtual void replaceRangeSet (TextRangeSet &rangeSet, const QStringList &texts, int coalesceId=0)
 Replaces the given ranges with the given texts. Different text per range is possible. More...
 
virtual void moveCaretTo (int line, int col, bool keepAnchors)
 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! More...
 
virtual void moveCaretToOffset (int offset, bool keepAnchors)
 Moves the caret to the given offset. More...
 
virtual void addCaretAt (int line, int col)
 Adds a new caret to the selection. More...
 
virtual void addCaretAtOffset (int offset)
 Adds a carert at the given offset. More...
 
virtual void changeAndGiveTextSelection (TextRangeSet *rangeSet, int coalesceId=0)
 This method changes the text selection. More...
 
virtual void undo (bool soft=false)
 This method performs an undo operation. By supplying soft only controller based operations are undone. When suppplying false a Document operation is being undone. More...
 
virtual void redo (bool soft=false)
 This method performs an redo operation. By supplying soft only controller based operations are redone. When suppplying false a Document operation is being redone. More...
 
virtual void beginUndoGroup (ChangeGroup *group)
 Starts an undo group. More...
 
virtual void endUndoGroup (int coalesceId, bool flatten)
 Ends the undo-group. More...
 
virtual void executeCommand (TextEditorCommand *textCommand)
 This method executes the command. More...
 
virtual bool executeCommand (const QString &name=QString())
 Executes a command with the given name. More...
 

Signals

void updateStatusTextSignal (const QString &text)
 This signal is fired if the statusbar needs updating. More...
 
void textDocumentChanged (edbee::TextDocument *oldDocument, edbee::TextDocument *newDocument)
 This signal is fired if the textdocument changes. More...
 
void commandToBeExecuted (edbee::TextEditorCommand *command)
 this method is executed when a command is going to be executed More...
 
void commandExecuted (edbee::TextEditorCommand *command)
 

Public Member Functions

 TextEditorController (TextEditorWidget *widget=0, QObject *parent=0)
 The constructor. More...
 
virtual ~TextEditorController ()
 Destroys the controller and associated objects. More...
 
void notifyStateChange ()
 This method is called to reset the caret timer and update the ui. More...
 
void giveTextDocument (TextDocument *doc)
 sets the document and tranfers the ownership of the textdocument to this class More...
 
void setTextDocument (TextDocument *doc)
 Set the text document. More...
 
void setAutoScrollToCaret (AutoScrollToCaret autoScroll)
 Changes the autoScrollToCaret setting. More...
 
virtual AutoScrollToCaret autoScrollToCaret () const
 Returns the autoScrollToCaret setting. More...
 
bool hasFocus ()
 This method return true if the text-editor has focus. More...
 
QAction * createUnconnectedAction (const QString &command, const QString &text, const QIcon &icon=QIcon(), QObject *owner=0)
 This method creates an editor action that is. More...
 
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. More...
 
TextDocumenttextDocument () const
 Returns a reference to the textdocument. More...
 
TextSelectiontextSelection () const
 Returns the textselection. More...
 
TextRenderertextRenderer () const
 Returns the current text renderer. More...
 
void setKeyMap (TextEditorKeyMap *keyMap)
 sets the keymap. It will replace (and if owned, delete) the previous keymap More...
 
void giveKeyMap (TextEditorKeyMap *keyMap)
 gives a keymap to the editor. The ownership is transfered to this controller More...
 
TextEditorKeyMapkeyMap () const
 Returns the current keymap. More...
 
void setCommandMap (TextEditorCommandMap *commandMap)
 set a commandmap the ownership is NOT transfered to this object. The old owned command-map is deleted commandMap the new commandMap of this object More...
 
void giveCommandMap (TextEditorCommandMap *commandMap)
 gives a commandmap to the editor The old associated command map is deleted More...
 
TextEditorCommandMapcommandMap () const
 Returns the current commandmap. More...
 
TextEditorWidgetwidget () const
 Returns the active widget. More...
 
TextCaretCachetextCaretCache () const
 Returns the textCaretCache. More...
 
void giveTextSearcher (TextSearcher *searcher)
 Gives the text-searcher to this document. More...
 
TextSearchertextSearcher ()
 Returnst the associated text searcher object. More...
 
DynamicVariablesdynamicVariables () const
 this method returns the dynamic variables object for this controller The current implementation simply returns the application-wide environment variables More...
 

Detailed Description

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

Member Enumeration Documentation

◆ AutoScrollToCaret

Enumerator
AutoScrollAlways 
AutoScrollWhenFocus 
AutoScrollNever 

Constructor & Destructor Documentation

◆ TextEditorController()

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

The constructor.

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

◆ ~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.

◆ beginUndoGroup

void edbee::TextEditorController::beginUndoGroup ( ChangeGroup group)
virtualslot

Starts an undo group.

Parameters
groupthe undogroup to use

◆ changeAndGiveTextSelection

void edbee::TextEditorController::changeAndGiveTextSelection ( 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,
bool  flatten 
)
virtualslot

Ends the undo-group.

Parameters
coalesceIdis used to decide if merging of groups is required. a value of 0 means NO merging 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

◆ executeCommand [1/2]

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

This method executes the command.

Todo:
: move this to a nicer place!!

◆ executeCommand [2/2]

bool edbee::TextEditorController::executeCommand ( const QString &  name = QString())
virtualslot

Executes a command with the given name.

When the name hasn't been supplied. This functiona 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
Returns
true if the command exists

◆ 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 transfered to this controller

Parameters
keyMapthe new keymap to give to the controller

◆ giveTextDocument()

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

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

Parameters
docthe new document for this controlelr

◆ 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.

◆ moveCaretTo

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

◆ moveCaretToOffset

void edbee::TextEditorController::moveCaretToOffset ( int  offset,
bool  keepAnchors 
)
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)

◆ 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)
slot

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

update the selection

Todo:
: improve this:

◆ 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 suppplying 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 
)
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 ( TextRangeSet rangeSet,
const QString &  text,
int  coalesceId = 0 
)
virtualslot

Replaces the given rangeset with the given text.

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

◆ replaceRangeSet [2/2]

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

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

Parameters
rangeSetthe rangeset to fille
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 
)
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 
)
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 vible.

◆ 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 transfered to this object. The old owned command-map is deleted 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

◆ 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 textchange 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 ( )

Returnst 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 suppplying 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 = "")
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: