umbrello: umbrello/dialogs/codeeditor.h Source File

umbrello 2.31.1 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 * This program is free software; you can redistribute it and/or modify *
3 * it under the terms of the GNU General Public License as published by *
4 * the Free Software Foundation; either version 2 of the License, or *
5 * (at your option) any later version. *
6 * *
7 * copyright (C) 2003 Brian Thomas <brian.thomas@gsfc.nasa.gov> *
8 * copyright (C) 2004-2020 *
9 * Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
10 ***************************************************************************/
11
12 #ifndef CODEEDITOR_H
13 #define CODEEDITOR_H
14
15 #include "codeviewerstate.h"
16 #include "textblocklist.h"
17
18 #include <ktextedit.h>
19
20 #include <QList>
21 #include <QString>
22
23 class CodeViewerDialog;
24 class CodeComment;
25 class CodeDocument;
26 class CodeClassFieldDeclarationBlock;
27 class CodeMethodBlock;
28 class CodeBlockWithComments;
29 class HierarchicalCodeBlock;
30 class KMenu;
31 class QLabel;
32 class TextBlock;
33 class UMLObject;
34
35 class ParaInfo
36 {
37 public:
38 int start; // this is a relative offset from the beginning of the tblock
39 int size;
40 int end;
41 QColor fgcolor;
42 QColor bgcolor;
43 bool isEditable;
44
45 ParaInfo ()
46 : start(0),
47 size(0),
48 end(0),
49 isEditable(false) { }
50 };
51
52
53 class TextBlockInfo
54 {
55 public:
56 QList<ParaInfo*> m_paraList;
57 UMLObject * m_parent;
58 QString m_displayName;
59 bool isClickable;
60 bool isCodeAccessorMethod;
61
62 TextBlockInfo () { m_parent = 0; isClickable = false; isCodeAccessorMethod = false; }
63 void setParent(UMLObject *p = 0) { m_parent = p; }
64 UMLObject * parent() { return m_parent; }
65 void setDisplayName(const QString& name) { m_displayName = name; }
66 QString displayName() { return m_displayName; }
67 };
68
69
70 class CodeEditor : public KTextEdit
71 {
72 Q_OBJECT
73 public:
74 explicit CodeEditor(const QString & text, CodeViewerDialog * parent = 0, CodeDocument * doc = 0);
75 explicit CodeEditor(CodeViewerDialog * parent = 0, CodeDocument * doc = 0);
76 ~CodeEditor();
77
78 Settings::CodeViewerState state();
79
80 protected:
81 bool close ();
82
83 void appendText(TextBlock * tblock);
84 void appendText(HierarchicalCodeBlock * hblock);
85 void appendText(CodeClassFieldDeclarationBlock * db);
86 void appendText(TextBlockList * items);
87 void appendText(CodeMethodBlock * mb);
88 void appendText(CodeComment * comment, TextBlock * parent, UMLObject * umlObj = 0, const QString & compName = QString());
89 void appendText(CodeBlockWithComments * cb);
90
91 void rebuildView(int startCursorPos);
92
93 void contextMenuEvent(QContextMenuEvent * event);
94 void contentsMouseMoveEvent(QMouseEvent * e);
95 void keyPressEvent(QKeyEvent * e);
96 void mouseDoubleClickEvent(QMouseEvent * e);
97
98 void loadFromDocument();
99
100 #if QT_VERSION >= 0x050000
101 QMenu * createPopup();
102 #else
103 KMenu * createPopup();
104 #endif
105
106 private:
107 QString m_parentDocName;
108 CodeDocument * m_parentDoc;
109 CodeViewerDialog * m_parentDialog;
110
111 int m_lastPara;
112 int m_lastPos;
113
114 bool m_newLinePressed;
115 bool m_backspacePressed;
116 bool m_isHighlighted;
117 bool m_showHiddenBlocks;
118
119 TextBlock * m_textBlockToPaste;
120 TextBlock * m_selectedTextBlock;
121 TextBlock * m_lastTextBlockToBeEdited;
122
123 QMap<TextBlock*, TextBlockInfo*> m_tbInfoMap;
124 TextBlockList m_textBlockList;
125
126 void insertText(const QString & text, TextBlock * parent, bool isEditable = false,
127 const QColor & fgcolor = QColor("black"), const QColor & bgcolor = QColor("white"),
128 UMLObject * umlobj = 0, const QString & displayName = QString(), int startLine = -1);
129
130 void editTextBlock(TextBlock * tBlock, int para);
131 void clearText();
132 QLabel * componentLabel();
133 bool paraIsNotSingleLine(int para);
134 void expandSelectedParagraph(int where);
135 void contractSelectedParagraph(int where);
136 void updateTextBlockFromText(TextBlock * block);
137
138 void initText(CodeDocument * doc);
139 void init(CodeViewerDialog * parentDialog, CodeDocument * parentDoc);
140
141 void changeTextBlockHighlighting(TextBlock * tb, bool selected);
142 void setParagraphBackgroundColor(int position, const QColor& color);
143 bool isParaEditable(int para);
144 bool textBlockIsClickable(UMLObject * obj);
145
146 TextBlock* findTextBlockAt(int characterPos);
147
148 void clicked(int para, int pos);
149
150 static bool isNonBlank(const QString &str);
151
152 public slots:
153 void insertParagraph(const QString & text, int para);
154 void removeParagraph(int para);
155 void changeHighlighting(int signal);
156 void changeShowHidden(int signal);
157 void slotRedrawText();
158
159 protected slots:
160 void slotCursorPositionChanged();
161 void slotCopyTextBlock();
162 void slotCutTextBlock();
163 void slotPasteTextBlock();
164 void slotChangeSelectedBlockView();
165 void slotChangeSelectedBlockCommentView();
166 void slotInsertCodeBlockAfterSelected();
167 void slotInsertCodeBlockBeforeSelected();
168
169 signals:
170 // void sigNewLinePressed();
171 // void sigBackspacePressed();
172
173 };
174
175 #endif // CODEEDITOR_H
umlrole.h
codeclassfield.h
CodeEditor::slotCutTextBlock
void slotCutTextBlock()
Definition: codeeditor.cpp:907
UMLObject::asUMLClassifier
UMLClassifier * asUMLClassifier()
Definition: umlobject.cpp:1308
DEBUG_REGISTER
#define DEBUG_REGISTER(src)
Definition: debug_utils.h:131
CodeEditor::setParagraphBackgroundColor
void setParagraphBackgroundColor(int position, const QColor &color)
Definition: codeeditor.cpp:1344
TextBlock::getWriteOutText
bool getWriteOutText() const
Definition: textblock.cpp:141
CodeEditor::updateTextBlockFromText
void updateTextBlockFromText(TextBlock *block)
Definition: codeeditor.cpp:1005
CodeEditor::expandSelectedParagraph
void expandSelectedParagraph(int where)
Definition: codeeditor.cpp:1429
textblocklist.h
TextBlockInfo::displayName
QString displayName()
Definition: codeeditor.h:66
OwnedCodeBlock
Definition: ownedcodeblock.h:27
CodeDocument::newHierarchicalCodeBlock
virtual HierarchicalCodeBlock * newHierarchicalCodeBlock()
Definition: codedocument.cpp:478
codegenfactory.h
CodeEditor::m_isHighlighted
bool m_isHighlighted
Definition: codeeditor.h:116
UMLClassifier::isInterface
bool isInterface() const
Definition: classifier.cpp:118
CodeMethodBlock::getStartMethodText
QString getStartMethodText() const
Definition: codemethodblock.cpp:42
CodeClassFieldDeclarationBlock
Definition: codeclassfielddeclarationblock.h:30
TextBlock::toString
virtual QString toString() const
Definition: textblock.cpp:407
UMLObject::asUMLOperation
UMLOperation * asUMLOperation()
Definition: umlobject.cpp:1323
UMLObject::name
QString name() const
Definition: umlobject.cpp:211
CodeEditor::editTextBlock
void editTextBlock(TextBlock *tBlock, int para)
Definition: codeeditor.cpp:161
umlattributedialog.h
TextBlockInfo::m_paraList
QList< ParaInfo * > m_paraList
Definition: codeeditor.h:56
CodeClassField::parentIsAttribute
bool parentIsAttribute() const
Definition: codeclassfield.cpp:127
CodeEditor::m_lastPara
int m_lastPara
Definition: codeeditor.h:111
CodeGenObjectWithTextBlocks::removeTextBlock
virtual bool removeTextBlock(TextBlock *remove_object)
Definition: codegenobjectwithtextblocks.cpp:92
ParaInfo::bgcolor
QColor bgcolor
Definition: codeeditor.h:42
TextBlock::setAttributesFromObject
virtual void setAttributesFromObject(TextBlock *obj)
Definition: textblock.cpp:347
UMLObject::asUMLAttribute
UMLAttribute * asUMLAttribute()
Definition: umlobject.cpp:1304
ParaInfo::end
int end
end line number
Definition: codeeditor.h:40
ParaInfo::size
int size
number of characters
Definition: codeeditor.h:39
CodeEditor::m_newLinePressed
bool m_newLinePressed
Definition: codeeditor.h:114
namespace_enum_literal::test
test
Definition: namespace-enum-literal.h:3
Settings::CodeViewerState::showHiddenBlocks
bool showHiddenBlocks
Definition: codeviewerstate.h:43
TextBlockInfo::setParent
void setParent(UMLObject *p=0)
Definition: codeeditor.h:63
CodeComment
Definition: codecomment.h:24
codeviewerdialog.h
TextBlock::setWriteOutText
void setWriteOutText(bool write)
Definition: textblock.cpp:131
UMLObject::showPropertiesDialog
virtual bool showPropertiesDialog(QWidget *parent=0)
Definition: umlobject.cpp:145
CodeEditor::slotCopyTextBlock
void slotCopyTextBlock()
Definition: codeeditor.cpp:885
CodeEditor::m_backspacePressed
bool m_backspacePressed
Definition: codeeditor.h:115
umloperationdialog.h
CodeMethodBlock::syncToParent
virtual void syncToParent()
Definition: codemethodblock.cpp:169
CodeEditor::slotCursorPositionChanged
void slotCursorPositionChanged()
Definition: codeeditor.cpp:1065
UniqueID::init
void init()
Definition: uniqueid.cpp:45
CodeEditor::loadFromDocument
void loadFromDocument()
Definition: codeeditor.cpp:216
CodeAccessorMethod::getParentClassField
CodeClassField * getParentClassField()
Definition: codeaccessormethod.cpp:40
TextBlock::getIndentationString
QString getIndentationString(int level=0) const
Definition: textblock.cpp:193
ownedhierarchicalcodeblock.h
CodeEditor::~CodeEditor
~CodeEditor()
Definition: codeeditor.cpp:80
CodeEditor::slotChangeSelectedBlockCommentView
void slotChangeSelectedBlockCommentView()
Definition: codeeditor.cpp:675
CodeAccessorMethod
Definition: codeaccessormethod.h:21
ParaInfo::start
int start
Definition: codeeditor.h:38
CodeEditor::slotRedrawText
void slotRedrawText()
Definition: codeeditor.cpp:944
CodeBlockWithComments::getComment
CodeComment * getComment() const
Definition: codeblockwithcomments.cpp:47
Settings::CodeViewerState::hiddenColor
QColor hiddenColor
Definition: codeviewerstate.h:52
CodeEditor::m_parentDoc
CodeDocument * m_parentDoc
Definition: codeeditor.h:108
CodeEditor::close
bool close()
Definition: codeeditor.cpp:147
CodeEditor::clicked
void clicked(int para, int pos)
Definition: codeeditor.cpp:124
CodeDocument::getFileExtension
QString getFileExtension() const
Definition: codedocument.cpp:82
CodeDocument
Definition: codedocument.h:33
CodeEditor::changeShowHidden
void changeShowHidden(int signal)
Definition: codeeditor.cpp:1355
TextBlockInfo::isCodeAccessorMethod
bool isCodeAccessorMethod
Definition: codeeditor.h:60
CodeEditor::removeParagraph
void removeParagraph(int para)
Definition: codeeditor.cpp:633
CodeBlock::UserGenerated
@ UserGenerated
the content was entered by the user
Definition: codeblock.h:47
UMLObject
The base class for UML objects.
Definition: umlobject.h:74
CodeMethodBlock::getEndMethodText
QString getEndMethodText() const
Definition: codemethodblock.cpp:50
ParaInfo::isEditable
bool isEditable
Definition: codeeditor.h:43
TextBlockInfo::m_parent
UMLObject * m_parent
Definition: codeeditor.h:57
UMLRole
Definition: umlrole.h:25
TextBlock::lastEditableLine
virtual int lastEditableLine()
Definition: textblock.cpp:223
CodeGenObjectWithTextBlocks::getTextBlockList
TextBlockList * getTextBlockList() const
Definition: codegenobjectwithtextblocks.cpp:46
CodeEditor::clearText
void clearText()
Definition: codeeditor.cpp:87
codeoperation.h
CodeBlock
Definition: codeblock.h:21
Settings::CodeViewerState::editBlockColor
QColor editBlockColor
Definition: codeviewerstate.h:49
ClassifierCodeDocument
Definition: classifiercodedocument.h:33
OwnedCodeBlock::getParentObject
UMLObject * getParentObject()
Definition: ownedcodeblock.cpp:64
CodeEditor::CodeEditor
CodeEditor(const QString &text, CodeViewerDialog *parent=0, CodeDocument *doc=0)
Definition: codeeditor.cpp:62
CodeEditor::textBlockIsClickable
bool textBlockIsClickable(UMLObject *obj)
Definition: codeeditor.cpp:644
CodeEditor::contractSelectedParagraph
void contractSelectedParagraph(int where)
Definition: codeeditor.cpp:1397
TextBlockInfo::isClickable
bool isClickable
Definition: codeeditor.h:59
CodeEditor::slotInsertCodeBlockAfterSelected
void slotInsertCodeBlockAfterSelected()
Definition: codeeditor.cpp:711
CodeEditor::paraIsNotSingleLine
bool paraIsNotSingleLine(int para)
Definition: codeeditor.cpp:1206
Settings::CodeViewerState::nonEditBlockColor
QColor nonEditBlockColor
Definition: codeviewerstate.h:50
CodeEditor::changeTextBlockHighlighting
void changeTextBlockHighlighting(TextBlock *tb, bool selected)
Definition: codeeditor.cpp:1308
CodeGenFactory::newCodeComment
CodeComment * newCodeComment(CodeDocument *cd)
Definition: codegenfactory.cpp:412
attribute.h
CodeEditor::contextMenuEvent
void contextMenuEvent(QContextMenuEvent *event)
Definition: codeeditor.cpp:735
TextBlockInfo::parent
UMLObject * parent()
Definition: codeeditor.h:64
TextBlockInfo::TextBlockInfo
TextBlockInfo()
Definition: codeeditor.h:62
uWarning
#define uWarning()
Definition: debug_utils.h:124
TextBlock::canDelete
bool canDelete() const
Definition: textblock.cpp:61
HierarchicalCodeBlock::getStartText
QString getStartText() const
Definition: hierarchicalcodeblock.cpp:207
UMLObject::asUMLRole
UMLRole * asUMLRole()
Definition: umlobject.cpp:1326
OwnedHierarchicalCodeBlock
Definition: ownedhierarchicalcodeblock.h:27
TextBlockInfo::m_displayName
QString m_displayName
Definition: codeeditor.h:58
i18n
#define i18n
Definition: main.cpp:39
CodeEditor::findTextBlockAt
TextBlock * findTextBlockAt(int characterPos)
Definition: codeeditor.cpp:1227
classifiercodedocument.h
CodeEditor::m_selectedTextBlock
TextBlock * m_selectedTextBlock
Definition: codeeditor.h:120
codeclassfielddeclarationblock.h
ParaInfo
Definition: codeeditor.h:36
CodeEditor::init
void init(CodeViewerDialog *parentDialog, CodeDocument *parentDoc)
Definition: codeeditor.cpp:954
CodeEditor::isParaEditable
bool isParaEditable(int para)
Definition: codeeditor.cpp:1254
uDebug
#define uDebug()
Definition: debug_utils.h:122
CodeEditor::state
Settings::CodeViewerState state()
Definition: codeeditor.cpp:105
CodeBlock::setContentType
void setContentType(ContentType new_var)
Definition: codeblock.cpp:43
CodeEditor::slotChangeSelectedBlockView
void slotChangeSelectedBlockView()
Definition: codeeditor.cpp:662
CodeEditor::m_tbInfoMap
QMap< TextBlock *, TextBlockInfo * > m_tbInfoMap
Definition: codeeditor.h:123
CodeEditor::initText
void initText(CodeDocument *doc)
TextBlock::getNewEditorLine
virtual QString getNewEditorLine(int amount=0)
Definition: textblock.cpp:240
CodeEditor::m_lastTextBlockToBeEdited
TextBlock * m_lastTextBlockToBeEdited
Definition: codeeditor.h:121
MyProject\connect
connect()
Definition: namespaces-multiple.php:5
CodeEditor::m_textBlockToPaste
TextBlock * m_textBlockToPaste
Definition: codeeditor.h:119
CodeBlockWithComments
Definition: codeblockwithcomments.h:24
CodeDocument::synchronize
virtual void synchronize()
Definition: codedocument.cpp:329
CodeEditor::m_parentDialog
CodeViewerDialog * m_parentDialog
Definition: codeeditor.h:109
CodeEditor::insertParagraph
void insertParagraph(const QString &text, int para)
Definition: codeeditor.cpp:623
Settings::CodeViewerState::blocksAreHighlighted
bool blocksAreHighlighted
Definition: codeviewerstate.h:44
TextBlock::unformatText
virtual QString unformatText(const QString &text, const QString &indent=QString())
Definition: textblock.cpp:253
CodeDocument::insertTextBlock
bool insertTextBlock(TextBlock *newBlock, TextBlock *existingBlock, bool after=true)
Definition: codedocument.cpp:216
codeeditor.h
CodeEditor::m_parentDocName
QString m_parentDocName
Definition: codeeditor.h:107
CodeViewerDialog
Definition: codeviewerdialog.h:28
CodeDocument::newCodeBlock
virtual CodeBlock * newCodeBlock()
Definition: codedocument.cpp:460
CodeBlock::AutoGenerated
@ AutoGenerated
the content was generated by code generation itself
Definition: codeblock.h:46
TextBlock::firstEditableLine
virtual int firstEditableLine()
Definition: textblock.cpp:215
codedocument.h
TextBlock::formatMultiLineText
static QString formatMultiLineText(const QString &work, const QString &linePrefix, const QString &breakStr, bool addBreak=true, bool lastLineHasBreak=true)
Definition: textblock.cpp:288
CodeEditor::isNonBlank
static bool isNonBlank(const QString &str)
Definition: codeeditor.cpp:187
UMLObject::setDoc
void setDoc(const QString &d)
Definition: umlobject.cpp:455
CodeEditor::m_lastPos
int m_lastPos
Definition: codeeditor.h:112
pi
int * pi
Definition: cxx11-null-pointer-constant.h:5
ClassifierCodeDocument::getParentClassifier
UMLClassifier * getParentClassifier()
Definition: classifiercodedocument.cpp:275
HierarchicalCodeBlock
Definition: hierarchicalcodeblock.h:23
CodeEditor::appendText
void appendText(TextBlock *tblock)
Definition: codeeditor.cpp:555
DEBUG
#define DEBUG(src)
Definition: debug_utils.h:129
classifier.h
CodeOperation::getParentOperation
UMLOperation * getParentOperation()
Definition: codeoperation.cpp:64
HierarchicalCodeBlock::getEndText
QString getEndText() const
Definition: hierarchicalcodeblock.cpp:52
CodeEditor
Definition: codeeditor.h:71
uError
#define uError()
Definition: debug_utils.h:123
umlroledialog.h
UMLOperation
Definition: operation.h:25
CodeOperation
Definition: codeoperation.h:24
CodeViewerDialog::state
Settings::CodeViewerState state()
Definition: codeviewerdialog.cpp:73
CodeDocument::getFileName
QString getFileName() const
Definition: codedocument.cpp:63
CodeEditor::changeHighlighting
void changeHighlighting(int signal)
Definition: codeeditor.cpp:1368
UMLClassifier
Information for a non-graphical Concept/Class.
Definition: classifier.h:40
debug_utils.h
codeviewerstate.h
CodeDocument::newCodeBlockWithComments
virtual CodeBlockWithComments * newCodeBlockWithComments()
Definition: codedocument.cpp:469
TextBlockList
QList< TextBlock * > TextBlockList
Definition: textblocklist.h:17
DBG_SRC
#define DBG_SRC
Definition: import_utils.cpp:43
CodeEditor::mouseDoubleClickEvent
void mouseDoubleClickEvent(QMouseEvent *e)
Definition: codeeditor.cpp:1458
codeaccessormethod.h
CodeEditor::contentsMouseMoveEvent
void contentsMouseMoveEvent(QMouseEvent *e)
Definition: codeeditor.cpp:1482
CodeEditor::m_showHiddenBlocks
bool m_showHiddenBlocks
Definition: codeeditor.h:117
ParaInfo::ParaInfo
ParaInfo()
Definition: codeeditor.h:45
classpropertiesdialog.h
CodeEditor::slotInsertCodeBlockBeforeSelected
void slotInsertCodeBlockBeforeSelected()
Definition: codeeditor.cpp:691
codemethodblock.h
CodeEditor::createPopup
KMenu * createPopup()
Definition: codeeditor.cpp:753
TextBlock
Definition: textblock.h:25
TextBlock::setText
void setText(const QString &text)
Definition: textblock.cpp:80
TextBlock::getIndentationLevel
int getIndentationLevel() const
Definition: textblock.cpp:163
CodeDocument::getHeader
CodeComment * getHeader()
Definition: codedocument.cpp:183
CodeEditor::m_textBlockList
TextBlockList m_textBlockList
Definition: codeeditor.h:124
Settings::CodeViewerState
configurable params for the code viewer tool
Definition: codeviewerstate.h:28
CodeEditor::slotPasteTextBlock
void slotPasteTextBlock()
Definition: codeeditor.cpp:932
CodeEditor::keyPressEvent
void keyPressEvent(QKeyEvent *e)
Definition: codeeditor.cpp:199
TextBlock::getText
QString getText() const
Definition: textblock.cpp:99
CodeClassFieldDeclarationBlock::getParentClassField
CodeClassField * getParentClassField()
Definition: codeclassfielddeclarationblock.cpp:40
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:254
CodeParameter::getParentObject
UMLObject * getParentObject()
Definition: codeparameter.cpp:141
CodeEditor::rebuildView
void rebuildView(int startCursorPos)
Definition: codeeditor.cpp:1527
umldoc.h
TextBlockInfo
Definition: codeeditor.h:54
CodeEditor::componentLabel
QLabel * componentLabel()
Definition: codeeditor.cpp:114
ParaInfo::fgcolor
QColor fgcolor
Definition: codeeditor.h:41
Settings::CodeViewerState::umlObjectColor
QColor umlObjectColor
Definition: codeviewerstate.h:51
CodeMethodBlock
Definition: codemethodblock.h:29
TextBlockInfo::setDisplayName
void setDisplayName(const QString &name)
Definition: codeeditor.h:65