umbrello: CodeEditor Class Reference

umbrello 2.32.1 Umbrello UML Modeller is a Unified Modelling Language (UML) diagram program based on KDE Technology

Public Slots | Public Member Functions | Protected Slots | Protected Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
CodeEditor Class Reference

`#include <codeeditor.h>`

Inheritance diagram for CodeEditor:

## Public Slots
void | insertParagraph (const QString &text, int para)
void | removeParagraph (int para)
void | changeHighlighting (int signal)
void | changeShowHidden (int signal)
void | slotRedrawText ()

## Public Member Functions
| CodeEditor (const QString &text, CodeViewerDialog *parent=0, CodeDocument *doc=0)
| CodeEditor (CodeViewerDialog *parent=0, CodeDocument *doc=0)
| ~CodeEditor ()
Settings::CodeViewerState | state ()

## Protected Slots
void | slotCursorPositionChanged ()
void | slotCopyTextBlock ()
void | slotCutTextBlock ()
void | slotPasteTextBlock ()
void | slotChangeSelectedBlockView ()
void | slotChangeSelectedBlockCommentView ()
void | slotInsertCodeBlockAfterSelected ()
void | slotInsertCodeBlockBeforeSelected ()

## Protected Member Functions
bool | close ()
void | appendText (TextBlock *tblock)
void | appendText (HierarchicalCodeBlock *hblock)
void | appendText (CodeClassFieldDeclarationBlock *db)
void | appendText (TextBlockList *items)
void | appendText (CodeMethodBlock *mb)
void | appendText (CodeComment *comment, TextBlock *parent, UMLObject *umlObj=0, const QString &compName=QString())
void | appendText (CodeBlockWithComments *cb)
void | rebuildView (int startCursorPos)
void | contextMenuEvent (QContextMenuEvent *event)
void | contentsMouseMoveEvent (QMouseEvent *e)
void | keyPressEvent (QKeyEvent *e)
void | mouseDoubleClickEvent (QMouseEvent *e)
void | loadFromDocument ()
KMenu * | createPopup ()

## Private Member Functions
void | insertText (const QString &text, TextBlock *parent, bool isEditable=false, const QColor &fgcolor=QColor("black"), const QColor &bgcolor=QColor("white"), UMLObject *umlobj=0, const QString &displayName=QString(), int startLine=-1)
void | editTextBlock (TextBlock *tBlock, int para)
void | clearText ()
QLabel * | componentLabel ()
bool | paraIsNotSingleLine (int para)
void | expandSelectedParagraph (int where)
void | contractSelectedParagraph (int where)
void | updateTextBlockFromText (TextBlock *block)
void | initText (CodeDocument *doc)
void | init (CodeViewerDialog *parentDialog, CodeDocument *parentDoc)
void | changeTextBlockHighlighting (TextBlock *tb, bool selected)
void | setParagraphBackgroundColor (int position, const QColor &color)
bool | isParaEditable (int para)
bool | textBlockIsClickable (UMLObject *obj)
TextBlock * | findTextBlockAt (int characterPos)
void | clicked (int para, int pos)

## Static Private Member Functions
static bool | isNonBlank (const QString &str)

## Private Attributes
QString | m_parentDocName
CodeDocument * | m_parentDoc
CodeViewerDialog * | m_parentDialog
int | m_lastPara
int | m_lastPos
bool | m_newLinePressed
bool | m_backspacePressed
bool | m_isHighlighted
bool | m_showHiddenBlocks
TextBlock * | m_textBlockToPaste
TextBlock * | m_selectedTextBlock
TextBlock * | m_lastTextBlockToBeEdited
QMap< TextBlock *, TextBlockInfo * > | m_tbInfoMap
TextBlockList | m_textBlockList

## Constructor & Destructor Documentation

## ◆ CodeEditor() [1/2]

CodeEditor::CodeEditor | ( | const QString & | text,
|  | CodeViewerDialog * | parent = `0`,
|  | CodeDocument * | doc = `0`
| ) |  |
| explicit

Constructor.

## ◆ CodeEditor() [2/2]

CodeEditor::CodeEditor | ( | CodeViewerDialog * | parent = `0`,
|  | CodeDocument * | doc = `0`
| ) |  |
| explicit

Constructor.

## ◆ ~CodeEditor()

CodeEditor::~CodeEditor | ( |  | ) |

Destructor.

## Member Function Documentation

## ◆ appendText() [1/7]

void CodeEditor::appendText | ( | CodeBlockWithComments * | cb | ) |
| protected

Appends a CodeBlockWithComments to the widget.

Parameters

  cb | the code block to add

## ◆ appendText() [2/7]

void CodeEditor::appendText | ( | CodeClassFieldDeclarationBlock * | db | ) |
| protected

Appends a CodeClassFieldDeclarationBlock to the widget.

Parameters

  db | the code class field declaration block to add

## ◆ appendText() [3/7]

void CodeEditor::appendText | ( | CodeComment * | comment,
|  | TextBlock * | parent,
|  | UMLObject * | umlObj = `0`,
|  | const QString & | componentName = `QString()`
| ) |  |
| protected

Appends a CodeComment to the widget.

Parameters

  comment | the code comment to add
  parent | the parent text block
  umlObj | the UML object
  componentName | the name of the component

## ◆ appendText() [4/7]

void CodeEditor::appendText | ( | CodeMethodBlock * | mb | ) |
| protected

Appends a CodeMethodBlock to the widget.

Parameters

  mb | the code method block to add

## ◆ appendText() [5/7]

void CodeEditor::appendText | ( | HierarchicalCodeBlock * | hblock | ) |
| protected

Appends a HierarchicalCodeBlock to the widget.

Parameters

  hblock | the hierarchical code block to add

## ◆ appendText() [6/7]

void CodeEditor::appendText | ( | TextBlock * | tb | ) |
| protected

Appends a TextBlock to the widget.

Parameters

  tb | the text block to add

## ◆ appendText() [7/7]

void CodeEditor::appendText | ( | TextBlockList * | items | ) |
| protected

Appends a TextBlockList to the widget.

Parameters

  items | list of TextBlock items

## ◆ changeHighlighting

void CodeEditor::changeHighlighting | ( | int | signal | ) |
| slot

Colorizes/uncolorizes type for ALL paragraphs.

## ◆ changeShowHidden

void CodeEditor::changeShowHidden | ( | int | signal | ) |
| slot

:TODO:

## ◆ changeTextBlockHighlighting()

void CodeEditor::changeTextBlockHighlighting | ( | TextBlock * | tBlock,
|  | bool | selected
| ) |  |
| private

:TODO:

## ◆ clearText()

void CodeEditor::clearText | ( |  | ) |
| private

Clear the display of all text.

## ◆ clicked()

void CodeEditor::clicked | ( | int | para,
|  | int | pos
| ) |  |
| private

TODO: Used only for debugging right now. int para = tc.position(); –> is the character in the editor int pos = tc.blockNumber(); –> is the row in the editor

## ◆ close()

bool CodeEditor::close | ( |  | ) |
| protected

Slot which closes this widget. Returns true if the widget was closed; otherwise returns false. Reimplemented from QWidget.

Returns
  state of close action

## ◆ componentLabel()

QLabel * CodeEditor::componentLabel | ( |  | ) |
| private

Return the label on the dialog window. Some info can be shown.

Returns
  label widget of dialog

## ◆ contentsMouseMoveEvent()

void CodeEditor::contentsMouseMoveEvent | ( | QMouseEvent * | e | ) |
| protected

Override the QT event so we can do appropriate things.

## ◆ contextMenuEvent()

void CodeEditor::contextMenuEvent | ( | QContextMenuEvent * | event | ) |
| protected

Shows the context menu. Reimplemented from QWidget::contextMenuEvent().

## ◆ contractSelectedParagraph()

void CodeEditor::contractSelectedParagraph | ( | int | paraToRemove | ) |
| private

:TODO:

## ◆ createPopup()

KMenu * CodeEditor::createPopup | ( |  | ) |
| protected

Create the popup menu.

Returns
  the popup menu

## ◆ editTextBlock()

void CodeEditor::editTextBlock | ( | TextBlock * | tBlock,
|  | int | para
| ) |  |
| private

Allow us to edit, as appropriate, the parent UMLObject of the given text block.

## ◆ expandSelectedParagraph()

void CodeEditor::expandSelectedParagraph | ( | int | priorPara | ) |
| private

:TODO:

## ◆ findTextBlockAt()

TextBlock * CodeEditor::findTextBlockAt | ( | int | characterPos | ) |
| private

Find the text block in which the character position is located.

Parameters

  characterPos | the given character position

Returns
  the text block in which the character position is found

## ◆ init()

void CodeEditor::init | ( | CodeViewerDialog * | parentDialog,
|  | CodeDocument * | parentDoc
| ) |  |
| private

Initialization routine which is used in the constructors.

Parameters

  parentDialog | the parent CodeViewerDialog
  parentDoc | the parent CodeDocument

## ◆ initText()

void CodeEditor::initText | ( | CodeDocument * | doc | ) |
| private

## ◆ insertParagraph

void CodeEditor::insertParagraph | ( | const QString & | text,
|  | int | para
| ) |  |
| slot

Insert a paragraph at a given position.

Parameters

  text | the paragraph text
  para | the position where to add the text

## ◆ insertText()

void CodeEditor::insertText | ( | const QString & | text,
|  | TextBlock * | parent,
|  | bool | editable = `false`,
|  | const QColor & | fgcolor = `QColor("black")`,
|  | const QColor & | bgcolor = `QColor("white")`,
|  | UMLObject * | umlobj = `0`,
|  | const QString & | displayName = `QString()`,
|  | int | startLine = `-1`
| ) |  |
| private

Main insert routine. Will append if startLine is not supplied or -1.

Parameters

  text | the text which has to be inserted
  parent | the parent TextBlock
  editable | flag if editable
  fgcolor | foreground color
  bgcolor | background color
  umlobj | the UML object
  displayName | the name which can be displayed
  startLine | the starting line

## ◆ isNonBlank()

bool CodeEditor::isNonBlank | ( | const QString & | str | ) |
| staticprivate

Return whether or not the passed string is empty or contains nothing but whitespace. Note: The logic is the other way round. In this way we do not need all the "!" in if statements.

## ◆ isParaEditable()

bool CodeEditor::isParaEditable | ( | int | para | ) |
| private

Checks if paragraph is editable or not. Method is used only in slotCursorPositionChanged.

Parameters

  para | the desired paragraph (character number)

Returns
  flag if paragraph is editable or not

## ◆ keyPressEvent()

void CodeEditor::keyPressEvent | ( | QKeyEvent * | e | ) |
| protected

Implemented so we may capture certain key presses, namely backspace and 'return' events.

## ◆ loadFromDocument()

void CodeEditor::loadFromDocument | ( |  | ) |
| protected

(Re) Load the parent code document into the editor.

## ◆ mouseDoubleClickEvent()

void CodeEditor::mouseDoubleClickEvent | ( | QMouseEvent * | e | ) |
| protected

Override the QT event so we can do appropriate things.

## ◆ paraIsNotSingleLine()

bool CodeEditor::paraIsNotSingleLine | ( | int | para | ) |
| private

Check whether a block at a given position is on a single line.

Parameters

  para | the index of the block in the list

Returns
  flag whether block is on a single line

## ◆ rebuildView()

void CodeEditor::rebuildView | ( | int | startCursorPos | ) |
| protected

Rebuild our view of the document. Happens whenever we change some field/aspect of an underlying UML object used to create the view. If connections are right, then the UMLObject will send out the modified() signal which will trigger a call to re-generate the appropriate code within the code document. Our burden is to appropriately prepare the tool: we clear out ALL the textblocks in the KTextEdit widget and then re-show them after the dialog disappears.

## ◆ removeParagraph

void CodeEditor::removeParagraph | ( | int | para | ) |
| slot

Remove a paragraph from a given position.

Parameters

  para | the position from where to remove the text

## ◆ setParagraphBackgroundColor()

void CodeEditor::setParagraphBackgroundColor | ( | int | position,
|  | const QColor & | color
| ) |  |
| private

Set the background color at the cursor position.

Parameters

  position | the character position
  color | the desired color

## ◆ slotChangeSelectedBlockCommentView

void CodeEditor::slotChangeSelectedBlockCommentView | ( |  | ) |
| protectedslot

Change the status of the comment writeOutText value to opposite of current value.

## ◆ slotChangeSelectedBlockView

void CodeEditor::slotChangeSelectedBlockView | ( |  | ) |
| protectedslot

Slot to change the view of the selected block. This is called from a popup menu item.

## ◆ slotCopyTextBlock

void CodeEditor::slotCopyTextBlock | ( |  | ) |
| protectedslot

Slot to copy a text block.

## ◆ slotCursorPositionChanged

void CodeEditor::slotCursorPositionChanged | ( |  | ) |
| protectedslot

Slot for cursor position changed signal.

## ◆ slotCutTextBlock

void CodeEditor::slotCutTextBlock | ( |  | ) |
| protectedslot

Slot to cut a text block.

## ◆ slotInsertCodeBlockAfterSelected

void CodeEditor::slotInsertCodeBlockAfterSelected | ( |  | ) |
| protectedslot

Slot to insert a code block after the selection.

## ◆ slotInsertCodeBlockBeforeSelected

void CodeEditor::slotInsertCodeBlockBeforeSelected | ( |  | ) |
| protectedslot

Slot to insert a code block before the selection.

## ◆ slotPasteTextBlock

void CodeEditor::slotPasteTextBlock | ( |  | ) |
| protectedslot

Slot to paste a text block.

## ◆ slotRedrawText

void CodeEditor::slotRedrawText | ( |  | ) |
| slot

Slot to redraw the text.

## ◆ state()

Settings::CodeViewerState CodeEditor::state | ( |  | ) |

Return code viewer state.

Returns
  state of the code viewer

## ◆ textBlockIsClickable()

bool CodeEditor::textBlockIsClickable | ( | UMLObject * | obj | ) |
| private

All umlobjects which may have pop-up boxes should return true here. Yes, a CRAPPY way of doing this. Im not proud. =b.t.

## ◆ updateTextBlockFromText()

void CodeEditor::updateTextBlockFromText | ( | TextBlock * | block | ) |
| private

Read the text under the cursor and add it to the text block.

Parameters

  block | the text block to which the text is added

## Member Data Documentation

## ◆ m_backspacePressed

bool CodeEditor::m_backspacePressed
| private

## ◆ m_isHighlighted

bool CodeEditor::m_isHighlighted
| private

## ◆ m_lastPara

int CodeEditor::m_lastPara
| private

## ◆ m_lastPos

int CodeEditor::m_lastPos
| private

## ◆ m_lastTextBlockToBeEdited

TextBlock* CodeEditor::m_lastTextBlockToBeEdited
| private

## ◆ m_newLinePressed

bool CodeEditor::m_newLinePressed
| private

## ◆ m_parentDialog

CodeViewerDialog* CodeEditor::m_parentDialog
| private

## ◆ m_parentDoc

CodeDocument* CodeEditor::m_parentDoc
| private

## ◆ m_parentDocName

QString CodeEditor::m_parentDocName
| private

## ◆ m_selectedTextBlock

TextBlock* CodeEditor::m_selectedTextBlock
| private

## ◆ m_showHiddenBlocks

bool CodeEditor::m_showHiddenBlocks
| private

## ◆ m_tbInfoMap

QMap<TextBlock*, TextBlockInfo*> CodeEditor::m_tbInfoMap
| private

## ◆ m_textBlockList

TextBlockList CodeEditor::m_textBlockList
| private

## ◆ m_textBlockToPaste

TextBlock* CodeEditor::m_textBlockToPaste
| private

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

- umbrello/dialogs/codeeditor.h
- umbrello/dialogs/codeeditor.cpp