edbee - Qt Editor Library
texteditorcontroller.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include <QObject>
9 #include <QIcon>
10 
12 
13 class QAction;
14 
15 namespace edbee {
16 
17 class ChangeGroup;
18 class DynamicVariables;
19 class TextBufferChange;
20 class TextCaretCache;
21 class TextCommand;
22 class TextDocument;
23 class TextEditorCommand;
24 class TextEditorKeyMap;
25 class TextEditorCommandMap;
26 class TextEditorComponent;
27 class TextEditorWidget;
28 class TextRenderer;
29 class TextRangeSet;
30 class TextSearcher;
31 class TextSelection;
32 class UndoableTextCommand;
33 
34 
37 class TextEditorController : public QObject
38 {
39  Q_OBJECT
40 public:
41 
46  };
47 
48 
49  explicit TextEditorController( TextEditorWidget* widget=0, QObject *parent = 0);
50  virtual ~TextEditorController();
51 
52 // public method
53  void notifyStateChange();
54 
55  void giveTextDocument( TextDocument* doc );
56  void setTextDocument( TextDocument* doc );
57 
58  void setAutoScrollToCaret( AutoScrollToCaret autoScroll );
59  virtual AutoScrollToCaret autoScrollToCaret() const;
60 
61  bool hasFocus();
62  QAction* createUnconnectedAction(const QString& command, const QString& text, const QIcon& icon=QIcon(), QObject* owner=0 );
63  QAction* createAction(const QString& command, const QString& text , const QIcon& icon=QIcon(), QObject* owner=0 );
64 
65 
66 // getters
67 // TextBuffer* textBuffer() const;
68  TextDocument* textDocument() const;
70  TextRenderer* textRenderer() const;
73  TextEditorKeyMap* keyMap() const;
77  TextEditorWidget* widget() const;
79  void giveTextSearcher( TextSearcher* searcher );
82 
83 signals:
84 
86  void updateStatusTextSignal( const QString& text );
87 
89  void textDocumentChanged( edbee::TextDocument* oldDocument, edbee::TextDocument* newDocument );
90 
94 
95 public slots:
96 
98  void onSelectionChanged( edbee::TextRangeSet *oldRangeSet );
99  void onLineDataChanged( int line, int length, int newLength );
100 
102 
103 public slots:
104 
105  // updates the status text
106  virtual void updateStatusText( const QString& extraText="" );
107 
108  virtual void update();
109 
110  // scrolling
111  virtual void scrollPositionVisible( int xPos, int yPos );
112  virtual void scrollOffsetVisible( int offset );
113  virtual void scrollCaretVisible();
114 
115  virtual void storeSelection( int coalesceId=0 );
116 
117  // replace the given selection
118  virtual void replace( int offset, int length, const QString& text, int coalesceId );
119  virtual void replaceSelection( const QString& text, int coalesceId=0 );
120  virtual void replaceSelection( const QStringList& texts, int coalesceId=0 );
121  virtual void replaceRangeSet(TextRangeSet& rangeSet, const QString& text, int coalesceId=0 );
122  virtual void replaceRangeSet(TextRangeSet& rangeSet, const QStringList& texts, int coalesceId=0 );
123 
124  // caret movements
125  virtual void moveCaretTo( int line, int col, bool keepAnchors );
126  virtual void moveCaretToOffset( int offset, bool keepAnchors );
127  virtual void addCaretAt( int line, int col);
128  virtual void addCaretAtOffset( int offset );
129  virtual void changeAndGiveTextSelection(TextRangeSet* rangeSet , int coalesceId = 0);
130 
131  // perform an undo
132  virtual void undo(bool soft=false);
133  virtual void redo(bool soft=false);
134 
135  // command execution
136  virtual void beginUndoGroup( ChangeGroup* group );
137  virtual void endUndoGroup(int coalesceId, bool flatten);
138 
139  // low level command execution
140  virtual void executeCommand( TextEditorCommand* textCommand );
141  virtual bool executeCommand( const QString& name=QString() );
142 
143 private:
144 
145  TextEditorWidget* widgetRef_;
146  TextDocument* textDocument_;
147  TextDocument* textDocumentRef_;
148 
149  TextSelection* textSelection_;
150  TextEditorKeyMap* keyMap_;
151  TextEditorKeyMap* keyMapRef_;
152  TextEditorCommandMap* commandMap_;
153  TextEditorCommandMap* commandMapRef_;
154  TextRenderer* textRenderer_;
155  TextCaretCache* textCaretCache_;
156 
157  TextSearcher* textSearcher_;
158 
159  AutoScrollToCaret autoScrollToCaret_;
160 };
161 
162 } // edbee
virtual AutoScrollToCaret autoScrollToCaret() const
Returns the autoScrollToCaret setting.
Definition: texteditorcontroller.cpp:176
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 void addCaretAtOffset(int offset)
Adds a carert at the given offset.
Definition: texteditorcontroller.cpp:653
TextCaretCache * textCaretCache() const
Returns the textCaretCache.
Definition: texteditorcontroller.cpp:314
void notifyStateChange()
This method is called to reset the caret timer and update the ui.
Definition: texteditorcontroller.cpp:92
void giveTextSearcher(TextSearcher *searcher)
Gives the text-searcher to this document.
Definition: texteditorcontroller.cpp:322
This clas represents a text buffer change and is used to pass around between events This is a sharedd...
Definition: textbuffer.h:45
A class for rendering the text.
Definition: textrenderer.h:34
An undoable-command-group.
Definition: change.h:84
void commandExecuted(edbee::TextEditorCommand *command)
Definition: moc_texteditorcontroller.cpp:377
TextDocument * textDocument() const
Returns a reference to the textdocument.
Definition: texteditorcontroller.cpp:230
virtual void scrollCaretVisible()
This method makes sure caret 1 is vible.
Definition: texteditorcontroller.cpp:488
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 numbe...
Definition: texteditorcontroller.cpp:610
virtual void changeAndGiveTextSelection(TextRangeSet *rangeSet, int coalesceId=0)
This method changes the text selection.
Definition: texteditorcontroller.cpp:661
void setAutoScrollToCaret(AutoScrollToCaret autoScroll)
Changes the autoScrollToCaret setting.
Definition: texteditorcontroller.cpp:169
void textDocumentChanged(edbee::TextDocument *oldDocument, edbee::TextDocument *newDocument)
This signal is fired if the textdocument changes.
Definition: moc_texteditorcontroller.cpp:363
Definition: texteditorcontroller.h:45
void onLineDataChanged(int line, int length, int newLength)
The line-data is changed, we need to repaint the selected lines.
Definition: texteditorcontroller.cpp:384
This class is used for remembering/managing dynamic variables This are a kind of environment variable...
Definition: dynamicvariables.h:65
virtual void executeCommand(TextEditorCommand *textCommand)
This method executes the command.
Definition: texteditorcontroller.cpp:505
TextEditorWidget * widget() const
Returns the active widget.
Definition: texteditorcontroller.cpp:307
virtual void moveCaretToOffset(int offset, bool keepAnchors)
Moves the caret to the given offset.
Definition: texteditorcontroller.cpp:634
void setCommandMap(TextEditorCommandMap *commandMap)
set a commandmap the ownership is NOT transfered to this object. The old owned command-map is deleted...
Definition: texteditorcontroller.cpp:280
This is the abstract base class for a textcommand.
Definition: texteditorcommand.h:49
void giveTextDocument(TextDocument *doc)
sets the document and tranfers the ownership of the textdocument to this class
Definition: texteditorcontroller.cpp:109
The class textselection is a RangeSet that is used by the view of the document.
Definition: textselection.h:24
virtual ~TextEditorController()
Destroys the controller and associated objects.
Definition: texteditorcontroller.cpp:79
void setKeyMap(TextEditorKeyMap *keyMap)
sets the keymap. It will replace (and if owned, delete) the previous keymap
Definition: texteditorcontroller.cpp:252
AutoScrollToCaret
Definition: texteditorcontroller.h:42
virtual void endUndoGroup(int coalesceId, bool flatten)
Ends the undo-group.
Definition: texteditorcontroller.cpp:700
QAction * createUnconnectedAction(const QString &command, const QString &text, const QIcon &icon=QIcon(), QObject *owner=0)
This method creates an editor action that is.
Definition: texteditorcontroller.cpp:195
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-comma...
Definition: texteditorcontroller.cpp:219
TextEditorKeyMap * keyMap() const
Returns the current keymap.
Definition: texteditorcontroller.cpp:271
virtual void addCaretAt(int line, int col)
Adds a new caret to the selection.
Definition: texteditorcontroller.cpp:645
Copyright 2011-2013 - Reliable Bits Software by Blommers IT.
Definition: commentcommand.cpp:22
Definition: texteditorcontroller.h:43
Definition: texteditorcontroller.h:44
This is a texteditor map. This is used to map Command-Names to commands This class is the owner of th...
Definition: texteditorcommandmap.h:19
void onSelectionChanged(edbee::TextRangeSet *oldRangeSet)
the old selection has been changed
Definition: texteditorcontroller.cpp:369
virtual void redo(bool soft=false)
This method performs an redo operation. By supplying soft only controller based operations are redone...
Definition: texteditorcontroller.cpp:680
void commandToBeExecuted(edbee::TextEditorCommand *command)
this method is executed when a command is going to be executed
Definition: moc_texteditorcontroller.cpp:370
void giveCommandMap(TextEditorCommandMap *commandMap)
gives a commandmap to the editor The old associated command map is deleted
Definition: texteditorcontroller.cpp:291
A text editor key map This key map, maps key-sequences to action-names.
Definition: texteditorkeymap.h:39
A special cache. For remembering the x-coordinates of the carets.
Definition: textcaretcache.h:19
TextSearcher * textSearcher()
Returnst the associated text searcher object.
Definition: texteditorcontroller.cpp:331
virtual void undo(bool soft=false)
This method performs an undo operation. By supplying soft only controller based operations are undone...
Definition: texteditorcontroller.cpp:671
The texteditor works via the controller. The controller is the central point/mediater which maps/cont...
Definition: texteditorcontroller.h:37
virtual void storeSelection(int coalesceId=0)
This method adds a textchange on the stack that simply stores the current text-selection.
Definition: texteditorcontroller.cpp:496
TextSelection * textSelection() const
Returns the textselection.
Definition: texteditorcontroller.cpp:237
void setTextDocument(TextDocument *doc)
Set the text document.
Definition: texteditorcontroller.cpp:120
void onTextChanged(edbee::TextBufferChange change)
This slot is placed if a piece of text is replaced.
Definition: texteditorcontroller.cpp:352
The basic textrange class. A simple class of textrange with a simple vector implementation.
Definition: textrange.h:198
virtual void beginUndoGroup(ChangeGroup *group)
Starts an undo group.
Definition: texteditorcontroller.cpp:689
virtual void scrollPositionVisible(int xPos, int yPos)
Asserts the view shows the given position.
Definition: texteditorcontroller.cpp:471
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&#39;t require an updates, but some do.
Definition: texteditorcontroller.cpp:395
virtual void replaceRangeSet(TextRangeSet &rangeSet, const QString &text, int coalesceId=0)
Replaces the given rangeset with the given text.
Definition: texteditorcontroller.cpp:581
DynamicVariables * dynamicVariables() const
this method returns the dynamic variables object for this controller The current implementation simpl...
Definition: texteditorcontroller.cpp:340
TextEditorCommandMap * commandMap() const
Returns the current commandmap.
Definition: texteditorcontroller.cpp:300
TextEditorController(TextEditorWidget *widget=0, QObject *parent=0)
The constructor.
Definition: texteditorcontroller.cpp:46
This is the general edbee widget This core functionality of this widget is divided in several seperat...
Definition: texteditorwidget.h:32
TextRenderer * textRenderer() const
Returns the current text renderer.
Definition: texteditorcontroller.cpp:244
The text searcher is a class to remember the current search operation It remembers the current search...
Definition: textsearcher.h:23
virtual void scrollOffsetVisible(int offset)
Assets the view shows the given offset.
Definition: texteditorcontroller.cpp:478
virtual void replace(int offset, int length, const QString &text, int coalesceId)
replaces the given text (single ranges)
Definition: texteditorcontroller.cpp:550
virtual void replaceSelection(const QString &text, int coalesceId=0)
This method replaces the selection with the given text.
Definition: texteditorcontroller.cpp:562
bool hasFocus()
This method return true if the text-editor has focus.
Definition: texteditorcontroller.cpp:183
void updateStatusTextSignal(const QString &text)
This signal is fired if the statusbar needs updating.
Definition: moc_texteditorcontroller.cpp:356
virtual void updateStatusText(const QString &extraText="")
This method updates the status text. This is the text as displayed in the lower status bar...
Definition: texteditorcontroller.cpp:410
void giveKeyMap(TextEditorKeyMap *keyMap)
gives a keymap to the editor. The ownership is transfered to this controller
Definition: texteditorcontroller.cpp:262
virtual void update()
updates the main widget
Definition: texteditorcontroller.cpp:462