umbrello: umbrello/dialogs/codeeditor.h Source File

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

- Main Page
- Related Pages
- Topics
- Namespaces
- Classes
- Files

- File List
- File Members

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-2022 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 QMenu;
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() const { 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 QMenu * createPopup();
97
98private:
99 QString m_parentDocName;
100 CodeDocument * m_parentDoc;
101 CodeViewerDialog * m_parentDialog;
102
103 int m_lastPara;
104 int m_lastPos;
105
106 bool m_newLinePressed;
107 bool m_backspacePressed;
108 bool m_isHighlighted;
109 bool m_showHiddenBlocks;
110
111 TextBlock * m_textBlockToPaste;
112 TextBlock * m_selectedTextBlock;
113 TextBlock * m_lastTextBlockToBeEdited;
114
115 QMap<TextBlock*, TextBlockInfo*> m_tbInfoMap;
116 TextBlockList m_textBlockList;
117
118 void insertText(const QString & text, TextBlock * parent, bool isEditable = false,
119 const QColor & fgcolor = QColor("black"), const QColor & bgcolor = QColor("white"),
120 UMLObject * umlobj = 0, const QString & displayName = QString(), int startLine = -1);
121
122 void editTextBlock(TextBlock * tBlock, int para);
123 void clearText();
124 QLabel * componentLabel();
125 bool paraIsNotSingleLine(int para);
126 void expandSelectedParagraph(int where);
127 void contractSelectedParagraph(int where);
128 void updateTextBlockFromText(TextBlock * block);
129
130 void initText(CodeDocument * doc);
131 void init(CodeViewerDialog * parentDialog, CodeDocument * parentDoc);
132
133 void changeTextBlockHighlighting(TextBlock * tb, bool selected);
134 void setParagraphBackgroundColor(int position, const QColor& color);
135 bool isParaEditable(int para);
136 bool textBlockIsClickable(UMLObject * obj);
137
138 TextBlock* findTextBlockAt(int characterPos);
139
140 void clicked(int para, int pos);
141
142 static bool isNonBlank(const QString &str);
143
144public slots:
145 void insertParagraph(const QString & text, int para);
146 void removeParagraph(int para);
147 void changeHighlighting(int signal);
148 void changeShowHidden(int signal);
149 void slotRedrawText();
150
151protected slots:
152 void slotCursorPositionChanged();
153 void slotCopyTextBlock();
154 void slotCutTextBlock();
155 void slotPasteTextBlock();
156 void slotChangeSelectedBlockView();
157 void slotChangeSelectedBlockCommentView();
158 void slotInsertCodeBlockAfterSelected();
159 void slotInsertCodeBlockBeforeSelected();
160
161signals:
162 // void sigNewLinePressed();
163 // void sigBackspacePressed();
164
165};
166
167#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:951
CodeEditor::editTextBlock
void editTextBlock(TextBlock *tBlock, int para)
Definition codeeditor.cpp:154
CodeEditor::expandSelectedParagraph
void expandSelectedParagraph(int where)
Definition codeeditor.cpp:1375
CodeEditor::isParaEditable
bool isParaEditable(int para)
Definition codeeditor.cpp:1200
CodeEditor::slotCutTextBlock
void slotCutTextBlock()
Definition codeeditor.cpp:853
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:248
CodeEditor::slotInsertCodeBlockBeforeSelected
void slotInsertCodeBlockBeforeSelected()
Definition codeeditor.cpp:685
CodeEditor::close
bool close()
Definition codeeditor.cpp:140
CodeEditor::clearText
void clearText()
Definition codeeditor.cpp:80
CodeEditor::loadFromDocument
void loadFromDocument()
Definition codeeditor.cpp:210
CodeEditor::isNonBlank
static bool isNonBlank(const QString &str)
Definition codeeditor.cpp:180
CodeEditor::m_newLinePressed
bool m_newLinePressed
Definition codeeditor.h:106
CodeEditor::m_lastPara
int m_lastPara
Definition codeeditor.h:103
CodeEditor::~CodeEditor
~CodeEditor()
Definition codeeditor.cpp:73
CodeEditor::changeShowHidden
void changeShowHidden(int signal)
Definition codeeditor.cpp:1301
CodeEditor::removeParagraph
void removeParagraph(int para)
Definition codeeditor.cpp:627
CodeEditor::rebuildView
void rebuildView(int startCursorPos)
Definition codeeditor.cpp:1474
CodeEditor::paraIsNotSingleLine
bool paraIsNotSingleLine(int para)
Definition codeeditor.cpp:1152
CodeEditor::m_tbInfoMap
QMap< TextBlock *, TextBlockInfo * > m_tbInfoMap
Definition codeeditor.h:115
CodeEditor::slotCopyTextBlock
void slotCopyTextBlock()
Definition codeeditor.cpp:831
CodeEditor::contextMenuEvent
void contextMenuEvent(QContextMenuEvent *event)
Definition codeeditor.cpp:729
CodeEditor::componentLabel
QLabel * componentLabel()
Definition codeeditor.cpp:107
CodeEditor::changeHighlighting
void changeHighlighting(int signal)
Definition codeeditor.cpp:1314
CodeEditor::mouseDoubleClickEvent
void mouseDoubleClickEvent(QMouseEvent *e)
Definition codeeditor.cpp:1404
CodeEditor::m_isHighlighted
bool m_isHighlighted
Definition codeeditor.h:108
CodeEditor::textBlockIsClickable
bool textBlockIsClickable(UMLObject *obj)
Definition codeeditor.cpp:638
CodeEditor::m_selectedTextBlock
TextBlock * m_selectedTextBlock
Definition codeeditor.h:112
CodeEditor::contentsMouseMoveEvent
void contentsMouseMoveEvent(QMouseEvent *e)
Definition codeeditor.cpp:1429
CodeEditor::m_parentDoc
CodeDocument * m_parentDoc
Definition codeeditor.h:100
CodeEditor::CodeEditor
CodeEditor(const QString &text, CodeViewerDialog *parent=0, CodeDocument *doc=0)
Definition codeeditor.cpp:55
CodeEditor::contractSelectedParagraph
void contractSelectedParagraph(int where)
Definition codeeditor.cpp:1343
CodeEditor::createPopup
QMenu * createPopup()
Definition codeeditor.cpp:740
CodeEditor::state
Settings::CodeViewerState state()
Definition codeeditor.cpp:98
CodeEditor::m_backspacePressed
bool m_backspacePressed
Definition codeeditor.h:107
CodeEditor::appendText
void appendText(TextBlock *tblock)
Definition codeeditor.cpp:549
CodeEditor::slotRedrawText
void slotRedrawText()
Definition codeeditor.cpp:890
CodeEditor::slotChangeSelectedBlockView
void slotChangeSelectedBlockView()
Definition codeeditor.cpp:656
CodeEditor::keyPressEvent
void keyPressEvent(QKeyEvent *e)
Definition codeeditor.cpp:192
CodeEditor::m_showHiddenBlocks
bool m_showHiddenBlocks
Definition codeeditor.h:109
CodeEditor::clicked
void clicked(int para, int pos)
Definition codeeditor.cpp:117
CodeEditor::init
void init(CodeViewerDialog *parentDialog, CodeDocument *parentDoc)
Definition codeeditor.cpp:900
CodeEditor::m_lastPos
int m_lastPos
Definition codeeditor.h:104
CodeEditor::m_textBlockToPaste
TextBlock * m_textBlockToPaste
Definition codeeditor.h:111
CodeEditor::findTextBlockAt
TextBlock * findTextBlockAt(int characterPos)
Definition codeeditor.cpp:1173
CodeEditor::slotInsertCodeBlockAfterSelected
void slotInsertCodeBlockAfterSelected()
Definition codeeditor.cpp:705
CodeEditor::m_parentDocName
QString m_parentDocName
Definition codeeditor.h:99
CodeEditor::m_textBlockList
TextBlockList m_textBlockList
Definition codeeditor.h:116
CodeEditor::slotPasteTextBlock
void slotPasteTextBlock()
Definition codeeditor.cpp:878
CodeEditor::slotChangeSelectedBlockCommentView
void slotChangeSelectedBlockCommentView()
Definition codeeditor.cpp:669
CodeEditor::initText
void initText(CodeDocument *doc)
CodeEditor::changeTextBlockHighlighting
void changeTextBlockHighlighting(TextBlock *tb, bool selected)
Definition codeeditor.cpp:1254
CodeEditor::m_lastTextBlockToBeEdited
TextBlock * m_lastTextBlockToBeEdited
Definition codeeditor.h:113
CodeEditor::m_parentDialog
CodeViewerDialog * m_parentDialog
Definition codeeditor.h:101
CodeEditor::insertParagraph
void insertParagraph(const QString &text, int para)
Definition codeeditor.cpp:617
CodeEditor::slotCursorPositionChanged
void slotCursorPositionChanged()
Definition codeeditor.cpp:1011
CodeEditor::setParagraphBackgroundColor
void setParagraphBackgroundColor(int position, const QColor &color)
Definition codeeditor.cpp:1290
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() const
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:14