umbrello: umbrello/dialogs/codeeditor.h Source File

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

codeeditor.h
Go to the documentation of this file.
1/*
2 SPDX-License-Identifier: GPL-2.0-or-later
3
4 SPDX-FileCopyrightText: 2003 Brian Thomas <brian.thomas@gsfc.nasa.gov>
5 SPDX-FileCopyrightText: 2004-2020 Umbrello UML Modeller Authors <umbrello-devel@kde.org>
6*/
7
8#ifndef CODEEDITOR_H
9#define CODEEDITOR_H
10
11#include "codeviewerstate.h"
12#include "textblocklist.h"
13
14#include <ktextedit.h>
15
16#include <QList>
17#include <QString>
18
19class CodeViewerDialog;
20class CodeComment;
21class CodeDocument;
22class CodeClassFieldDeclarationBlock;
23class CodeMethodBlock;
24class CodeBlockWithComments;
25class HierarchicalCodeBlock;
26class KMenu;
27class QLabel;
28class TextBlock;
29class UMLObject;
30
31 class ParaInfo
32{
33public:
34 int start; // this is a relative offset from the beginning of the tblock
35 int size;
36 int end;
37 QColor fgcolor;
38 QColor bgcolor;
39 bool isEditable;
40
41 ParaInfo ()
42 : start(0),
43 size(0),
44 end(0),
45 isEditable(false) { }
46};
47
48
49 class TextBlockInfo
50{
51public:
52 QList<ParaInfo*> m_paraList;
53 UMLObject * m_parent;
54 QString m_displayName;
55 bool isClickable;
56 bool isCodeAccessorMethod;
57
58 TextBlockInfo () { m_parent = 0; isClickable = false; isCodeAccessorMethod = false; }
59 void setParent(UMLObject *p = 0) { m_parent = p; }
60 UMLObject * parent() { return m_parent; }
61 void setDisplayName(const QString& name) { m_displayName = name; }
62 QString displayName() { return m_displayName; }
63};
64
65
66 class CodeEditor : public KTextEdit
67{
68 Q_OBJECT
69public:
70 explicit CodeEditor(const QString & text, CodeViewerDialog * parent = 0, CodeDocument * doc = 0);
71 explicit CodeEditor(CodeViewerDialog * parent = 0, CodeDocument * doc = 0);
72 ~CodeEditor();
73
74 Settings::CodeViewerState state();
75
76protected:
77 bool close ();
78
79 void appendText(TextBlock * tblock);
80 void appendText(HierarchicalCodeBlock * hblock);
81 void appendText(CodeClassFieldDeclarationBlock * db);
82 void appendText(TextBlockList * items);
83 void appendText(CodeMethodBlock * mb);
84 void appendText(CodeComment * comment, TextBlock * parent, UMLObject * umlObj = 0, const QString & compName = QString());
85 void appendText(CodeBlockWithComments * cb);
86
87 void rebuildView(int startCursorPos);
88
89 void contextMenuEvent(QContextMenuEvent * event);
90 void contentsMouseMoveEvent(QMouseEvent * e);
91 void keyPressEvent(QKeyEvent * e);
92 void mouseDoubleClickEvent(QMouseEvent * e);
93
94 void loadFromDocument();
95
96#if QT_VERSION >= 0x050000
97 QMenu * createPopup();
98#else
99 KMenu * createPopup();
100#endif
101
102private:
103 QString m_parentDocName;
104 CodeDocument * m_parentDoc;
105 CodeViewerDialog * m_parentDialog;
106
107 int m_lastPara;
108 int m_lastPos;
109
110 bool m_newLinePressed;
111 bool m_backspacePressed;
112 bool m_isHighlighted;
113 bool m_showHiddenBlocks;
114
115 TextBlock * m_textBlockToPaste;
116 TextBlock * m_selectedTextBlock;
117 TextBlock * m_lastTextBlockToBeEdited;
118
119 QMap<TextBlock*, TextBlockInfo*> m_tbInfoMap;
120 TextBlockList m_textBlockList;
121
122 void insertText(const QString & text, TextBlock * parent, bool isEditable = false,
123 const QColor & fgcolor = QColor("black"), const QColor & bgcolor = QColor("white"),
124 UMLObject * umlobj = 0, const QString & displayName = QString(), int startLine = -1);
125
126 void editTextBlock(TextBlock * tBlock, int para);
127 void clearText();
128 QLabel * componentLabel();
129 bool paraIsNotSingleLine(int para);
130 void expandSelectedParagraph(int where);
131 void contractSelectedParagraph(int where);
132 void updateTextBlockFromText(TextBlock * block);
133
134 void initText(CodeDocument * doc);
135 void init(CodeViewerDialog * parentDialog, CodeDocument * parentDoc);
136
137 void changeTextBlockHighlighting(TextBlock * tb, bool selected);
138 void setParagraphBackgroundColor(int position, const QColor& color);
139 bool isParaEditable(int para);
140 bool textBlockIsClickable(UMLObject * obj);
141
142 TextBlock* findTextBlockAt(int characterPos);
143
144 void clicked(int para, int pos);
145
146 static bool isNonBlank(const QString &str);
147
148public slots:
149 void insertParagraph(const QString & text, int para);
150 void removeParagraph(int para);
151 void changeHighlighting(int signal);
152 void changeShowHidden(int signal);
153 void slotRedrawText();
154
155protected slots:
156 void slotCursorPositionChanged();
157 void slotCopyTextBlock();
158 void slotCutTextBlock();
159 void slotPasteTextBlock();
160 void slotChangeSelectedBlockView();
161 void slotChangeSelectedBlockCommentView();
162 void slotInsertCodeBlockAfterSelected();
163 void slotInsertCodeBlockBeforeSelected();
164
165signals:
166 // void sigNewLinePressed();
167 // void sigBackspacePressed();
168
169};
170
171#endif // CODEEDITOR_H
CodeBlockWithComments
Definition: codeblockwithcomments.h:20
CodeClassFieldDeclarationBlock
Definition: codeclassfielddeclarationblock.h:26
CodeComment
Definition: codecomment.h:20
CodeDocument
Definition: codedocument.h:30
CodeEditor
Definition: codeeditor.h:67
CodeEditor::updateTextBlockFromText
void updateTextBlockFromText(TextBlock *block)
Definition: codeeditor.cpp:1001
CodeEditor::editTextBlock
void editTextBlock(TextBlock *tBlock, int para)
Definition: codeeditor.cpp:157
CodeEditor::expandSelectedParagraph
void expandSelectedParagraph(int where)
Definition: codeeditor.cpp:1425
CodeEditor::isParaEditable
bool isParaEditable(int para)
Definition: codeeditor.cpp:1250
CodeEditor::slotCutTextBlock
void slotCutTextBlock()
Definition: codeeditor.cpp:903
CodeEditor::insertText
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)
Definition: codeeditor.cpp:250
CodeEditor::slotInsertCodeBlockBeforeSelected
void slotInsertCodeBlockBeforeSelected()
Definition: codeeditor.cpp:687
CodeEditor::close
bool close()
Definition: codeeditor.cpp:143
CodeEditor::clearText
void clearText()
Definition: codeeditor.cpp:83
CodeEditor::loadFromDocument
void loadFromDocument()
Definition: codeeditor.cpp:212
CodeEditor::isNonBlank
static bool isNonBlank(const QString &str)
Definition: codeeditor.cpp:183
CodeEditor::m_newLinePressed
bool m_newLinePressed
Definition: codeeditor.h:110
CodeEditor::m_lastPara
int m_lastPara
Definition: codeeditor.h:107
CodeEditor::~CodeEditor
~CodeEditor()
Definition: codeeditor.cpp:76
CodeEditor::changeShowHidden
void changeShowHidden(int signal)
Definition: codeeditor.cpp:1351
CodeEditor::removeParagraph
void removeParagraph(int para)
Definition: codeeditor.cpp:629
CodeEditor::rebuildView
void rebuildView(int startCursorPos)
Definition: codeeditor.cpp:1523
CodeEditor::paraIsNotSingleLine
bool paraIsNotSingleLine(int para)
Definition: codeeditor.cpp:1202
CodeEditor::m_tbInfoMap
QMap< TextBlock *, TextBlockInfo * > m_tbInfoMap
Definition: codeeditor.h:119
CodeEditor::createPopup
KMenu * createPopup()
Definition: codeeditor.cpp:749
CodeEditor::slotCopyTextBlock
void slotCopyTextBlock()
Definition: codeeditor.cpp:881
CodeEditor::contextMenuEvent
void contextMenuEvent(QContextMenuEvent *event)
Definition: codeeditor.cpp:731
CodeEditor::componentLabel
QLabel * componentLabel()
Definition: codeeditor.cpp:110
CodeEditor::changeHighlighting
void changeHighlighting(int signal)
Definition: codeeditor.cpp:1364
CodeEditor::mouseDoubleClickEvent
void mouseDoubleClickEvent(QMouseEvent *e)
Definition: codeeditor.cpp:1454
CodeEditor::m_isHighlighted
bool m_isHighlighted
Definition: codeeditor.h:112
CodeEditor::textBlockIsClickable
bool textBlockIsClickable(UMLObject *obj)
Definition: codeeditor.cpp:640
CodeEditor::m_selectedTextBlock
TextBlock * m_selectedTextBlock
Definition: codeeditor.h:116
CodeEditor::contentsMouseMoveEvent
void contentsMouseMoveEvent(QMouseEvent *e)
Definition: codeeditor.cpp:1478
CodeEditor::m_parentDoc
CodeDocument * m_parentDoc
Definition: codeeditor.h:104
CodeEditor::CodeEditor
CodeEditor(const QString &text, CodeViewerDialog *parent=0, CodeDocument *doc=0)
Definition: codeeditor.cpp:58
CodeEditor::contractSelectedParagraph
void contractSelectedParagraph(int where)
Definition: codeeditor.cpp:1393
CodeEditor::state
Settings::CodeViewerState state()
Definition: codeeditor.cpp:101
CodeEditor::m_backspacePressed
bool m_backspacePressed
Definition: codeeditor.h:111
CodeEditor::appendText
void appendText(TextBlock *tblock)
Definition: codeeditor.cpp:551
CodeEditor::slotRedrawText
void slotRedrawText()
Definition: codeeditor.cpp:940
CodeEditor::slotChangeSelectedBlockView
void slotChangeSelectedBlockView()
Definition: codeeditor.cpp:658
CodeEditor::keyPressEvent
void keyPressEvent(QKeyEvent *e)
Definition: codeeditor.cpp:195
CodeEditor::m_showHiddenBlocks
bool m_showHiddenBlocks
Definition: codeeditor.h:113
CodeEditor::clicked
void clicked(int para, int pos)
Definition: codeeditor.cpp:120
CodeEditor::init
void init(CodeViewerDialog *parentDialog, CodeDocument *parentDoc)
Definition: codeeditor.cpp:950
CodeEditor::m_lastPos
int m_lastPos
Definition: codeeditor.h:108
CodeEditor::m_textBlockToPaste
TextBlock * m_textBlockToPaste
Definition: codeeditor.h:115
CodeEditor::findTextBlockAt
TextBlock * findTextBlockAt(int characterPos)
Definition: codeeditor.cpp:1223
CodeEditor::slotInsertCodeBlockAfterSelected
void slotInsertCodeBlockAfterSelected()
Definition: codeeditor.cpp:707
CodeEditor::m_parentDocName
QString m_parentDocName
Definition: codeeditor.h:103
CodeEditor::m_textBlockList
TextBlockList m_textBlockList
Definition: codeeditor.h:120
CodeEditor::slotPasteTextBlock
void slotPasteTextBlock()
Definition: codeeditor.cpp:928
CodeEditor::slotChangeSelectedBlockCommentView
void slotChangeSelectedBlockCommentView()
Definition: codeeditor.cpp:671
CodeEditor::initText
void initText(CodeDocument *doc)
CodeEditor::changeTextBlockHighlighting
void changeTextBlockHighlighting(TextBlock *tb, bool selected)
Definition: codeeditor.cpp:1304
CodeEditor::m_lastTextBlockToBeEdited
TextBlock * m_lastTextBlockToBeEdited
Definition: codeeditor.h:117
CodeEditor::m_parentDialog
CodeViewerDialog * m_parentDialog
Definition: codeeditor.h:105
CodeEditor::insertParagraph
void insertParagraph(const QString &text, int para)
Definition: codeeditor.cpp:619
CodeEditor::slotCursorPositionChanged
void slotCursorPositionChanged()
Definition: codeeditor.cpp:1061
CodeEditor::setParagraphBackgroundColor
void setParagraphBackgroundColor(int position, const QColor &color)
Definition: codeeditor.cpp:1340
CodeMethodBlock
Definition: codemethodblock.h:26
CodeViewerDialog
Definition: codeviewerdialog.h:23
HierarchicalCodeBlock
Definition: hierarchicalcodeblock.h:21
ParaInfo
Definition: codeeditor.h:32
ParaInfo::bgcolor
QColor bgcolor
Definition: codeeditor.h:38
ParaInfo::ParaInfo
ParaInfo()
Definition: codeeditor.h:41
ParaInfo::size
int size
number of characters
Definition: codeeditor.h:35
ParaInfo::end
int end
end line number
Definition: codeeditor.h:36
ParaInfo::isEditable
bool isEditable
Definition: codeeditor.h:39
ParaInfo::fgcolor
QColor fgcolor
Definition: codeeditor.h:37
ParaInfo::start
int start
Definition: codeeditor.h:34
Settings::CodeViewerState
configurable params for the code viewer tool
Definition: codeviewerstate.h:15
TextBlockInfo
Definition: codeeditor.h:50
TextBlockInfo::m_displayName
QString m_displayName
Definition: codeeditor.h:54
TextBlockInfo::parent
UMLObject * parent()
Definition: codeeditor.h:60
TextBlockInfo::TextBlockInfo
TextBlockInfo()
Definition: codeeditor.h:58
TextBlockInfo::isClickable
bool isClickable
Definition: codeeditor.h:55
TextBlockInfo::displayName
QString displayName()
Definition: codeeditor.h:62
TextBlockInfo::isCodeAccessorMethod
bool isCodeAccessorMethod
Definition: codeeditor.h:56
TextBlockInfo::m_paraList
QList< ParaInfo * > m_paraList
Definition: codeeditor.h:52
TextBlockInfo::setParent
void setParent(UMLObject *p=0)
Definition: codeeditor.h:59
TextBlockInfo::setDisplayName
void setDisplayName(const QString &name)
Definition: codeeditor.h:61
TextBlockInfo::m_parent
UMLObject * m_parent
Definition: codeeditor.h:53
TextBlock
Definition: textblock.h:23
UMLObject
The base class for UML objects.
Definition: umlobject.h:70
codeviewerstate.h
textblocklist.h
TextBlockList
QList< TextBlock * > TextBlockList
Definition: textblocklist.h:12