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

- Main Page
- Related Pages
- Modules
- 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 <QTextEdit>
15#include <KTextEditor/Document>
16#include <KTextEditor/Editor>
17#include <KTextEditor/View>
18
19#include <QList>
20#include <QString>
21
22 class CodeViewerDialog;
23 class CodeComment;
24 class CodeDocument;
25 class CodeClassFieldDeclarationBlock;
26 class CodeMethodBlock;
27 class CodeBlockWithComments;
28 class HierarchicalCodeBlock;
29 class QMenu;
30 class QLabel;
31 class TextBlock;
32 class UMLObject;
33
34 struct ParaInfo
35{
36 int start = 0; // this is a relative offset from the beginning of the tblock
37 int size = 0;
38 int end = 0;
39 QColor fgcolor;
40 QColor bgcolor;
41 bool isEditable = false;
42};
43
44
45 class TextBlockInfo
46{
47 public:
48 QList<ParaInfo*> m_paraList;
49 UMLObject * m_parent;
50 QString m_displayName;
51 bool isClickable;
52 bool isCodeAccessorMethod;
53
54 TextBlockInfo () { m_parent = nullptr; isClickable = false; isCodeAccessorMethod = false; }
55 void setParent(UMLObject *p = nullptr) { m_parent = p; }
56 UMLObject * parent() { return m_parent; }
57 void setDisplayName(const QString& name) { m_displayName = name; }
58 QString displayName() const { return m_displayName; }
59};
60
61
62 class CodeEditor : public QTextEdit
63{
64 Q_OBJECT
65 public:
66 explicit CodeEditor(const QString & text, CodeViewerDialog *parent = nullptr, CodeDocument *doc = nullptr);
67 explicit CodeEditor(CodeViewerDialog *parent = nullptr, CodeDocument *doc = nullptr);
68 ~CodeEditor();
69
70 Settings::CodeViewerState state();
71
72 protected:
73 bool close ();
74
75 void appendText(TextBlock * tblock);
76 void appendText(HierarchicalCodeBlock * hblock);
77 void appendText(CodeClassFieldDeclarationBlock * db);
78 void appendText(TextBlockList * items);
79 void appendText(CodeMethodBlock * mb);
80 void appendText(CodeComment *comment, TextBlock * parent, UMLObject *umlObj = nullptr, const QString & compName = QString());
81 void appendText(CodeBlockWithComments * cb);
82
83 void rebuildView(int startCursorPos);
84
85 void contextMenuEvent(QContextMenuEvent * event);
86 void contentsMouseMoveEvent(QMouseEvent * e);
87 void keyPressEvent(QKeyEvent * e);
88 void mouseDoubleClickEvent(QMouseEvent * e);
89
90 void loadFromDocument();
91
92 QMenu * createPopup();
93
94 private:
95 QString m_parentDocName;
96 CodeDocument * m_parentDoc;
97 CodeViewerDialog * m_parentDialog;
98
99 int m_lastPara;
100 int m_lastPos;
101
102 bool m_newLinePressed;
103 bool m_backspacePressed;
104 bool m_isHighlighted;
105 bool m_showHiddenBlocks;
106
107 TextBlock * m_textBlockToPaste;
108 TextBlock * m_selectedTextBlock;
109 TextBlock * m_lastTextBlockToBeEdited;
110
111 QMap<TextBlock*, TextBlockInfo*> m_tbInfoMap;
112 TextBlockList m_textBlockList;
113
114 void insertText(const QString & text, TextBlock * parent, bool isEditable = false,
115 const QColor & fgcolor = QColor("black"), const QColor & bgcolor = QColor("white"),
116 UMLObject *umlobj = nullptr, const QString & displayName = QString(), int startLine = -1);
117
118 void editTextBlock(TextBlock * tBlock, int para);
119 void clearText();
120 QLabel * componentLabel();
121 bool paraIsNotSingleLine(int para);
122 void expandSelectedParagraph(int where);
123 void contractSelectedParagraph(int where);
124 void updateTextBlockFromText(TextBlock * block);
125
126 void initText(CodeDocument * doc);
127 void init(CodeViewerDialog * parentDialog, CodeDocument * parentDoc);
128
129 void changeTextBlockHighlighting(TextBlock * tb, bool selected);
130 void setParagraphBackgroundColor(int position, const QColor& color);
131 bool isParaEditable(int para);
132 bool textBlockIsClickable(UMLObject * obj);
133
134 TextBlock* findTextBlockAt(int characterPos);
135
136 void clicked(int para, int pos);
137
138 static bool isNonBlank(const QString &str);
139
140 public Q_SLOTS:
141 void insertParagraph(const QString & text, int para);
142 void removeParagraph(int para);
143 void changeHighlighting(int signal);
144 void changeShowHidden(int signal);
145 void slotRedrawText();
146
147 protected Q_SLOTS:
148 void slotCursorPositionChanged();
149 void slotCopyTextBlock();
150 void slotCutTextBlock();
151 void slotPasteTextBlock();
152 void slotChangeSelectedBlockView();
153 void slotChangeSelectedBlockCommentView();
154 void slotInsertCodeBlockAfterSelected();
155 void slotInsertCodeBlockBeforeSelected();
156
157Q_SIGNALS:
158 // void sigNewLinePressed();
159 // void sigBackspacePressed();
160
161};
162
163#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:63
CodeEditor::updateTextBlockFromText
void updateTextBlockFromText(TextBlock *block)
Definition: codeeditor.cpp:952
CodeEditor::editTextBlock
void editTextBlock(TextBlock *tBlock, int para)
Definition: codeeditor.cpp:155
CodeEditor::expandSelectedParagraph
void expandSelectedParagraph(int where)
Definition: codeeditor.cpp:1376
CodeEditor::isParaEditable
bool isParaEditable(int para)
Definition: codeeditor.cpp:1201
CodeEditor::slotCutTextBlock
void slotCutTextBlock()
Definition: codeeditor.cpp:854
CodeEditor::slotInsertCodeBlockBeforeSelected
void slotInsertCodeBlockBeforeSelected()
Definition: codeeditor.cpp:686
CodeEditor::close
bool close()
Definition: codeeditor.cpp:141
CodeEditor::clearText
void clearText()
Definition: codeeditor.cpp:81
CodeEditor::loadFromDocument
void loadFromDocument()
Definition: codeeditor.cpp:211
CodeEditor::isNonBlank
static bool isNonBlank(const QString &str)
Definition: codeeditor.cpp:181
CodeEditor::m_newLinePressed
bool m_newLinePressed
Definition: codeeditor.h:102
CodeEditor::m_lastPara
int m_lastPara
Definition: codeeditor.h:99
CodeEditor::~CodeEditor
~CodeEditor()
Definition: codeeditor.cpp:74
CodeEditor::changeShowHidden
void changeShowHidden(int signal)
Definition: codeeditor.cpp:1302
CodeEditor::removeParagraph
void removeParagraph(int para)
Definition: codeeditor.cpp:628
CodeEditor::rebuildView
void rebuildView(int startCursorPos)
Definition: codeeditor.cpp:1475
CodeEditor::paraIsNotSingleLine
bool paraIsNotSingleLine(int para)
Definition: codeeditor.cpp:1153
CodeEditor::m_tbInfoMap
QMap< TextBlock *, TextBlockInfo * > m_tbInfoMap
Definition: codeeditor.h:111
CodeEditor::slotCopyTextBlock
void slotCopyTextBlock()
Definition: codeeditor.cpp:832
CodeEditor::contextMenuEvent
void contextMenuEvent(QContextMenuEvent *event)
Definition: codeeditor.cpp:730
CodeEditor::componentLabel
QLabel * componentLabel()
Definition: codeeditor.cpp:108
CodeEditor::changeHighlighting
void changeHighlighting(int signal)
Definition: codeeditor.cpp:1315
CodeEditor::insertText
void insertText(const QString &text, TextBlock *parent, bool isEditable=false, const QColor &fgcolor=QColor("black"), const QColor &bgcolor=QColor("white"), UMLObject *umlobj=nullptr, const QString &displayName=QString(), int startLine=-1)
Definition: codeeditor.cpp:249
CodeEditor::mouseDoubleClickEvent
void mouseDoubleClickEvent(QMouseEvent *e)
Definition: codeeditor.cpp:1405
CodeEditor::m_isHighlighted
bool m_isHighlighted
Definition: codeeditor.h:104
CodeEditor::textBlockIsClickable
bool textBlockIsClickable(UMLObject *obj)
Definition: codeeditor.cpp:639
CodeEditor::m_selectedTextBlock
TextBlock * m_selectedTextBlock
Definition: codeeditor.h:108
CodeEditor::contentsMouseMoveEvent
void contentsMouseMoveEvent(QMouseEvent *e)
Definition: codeeditor.cpp:1430
CodeEditor::m_parentDoc
CodeDocument * m_parentDoc
Definition: codeeditor.h:96
CodeEditor::contractSelectedParagraph
void contractSelectedParagraph(int where)
Definition: codeeditor.cpp:1344
CodeEditor::createPopup
QMenu * createPopup()
Definition: codeeditor.cpp:741
CodeEditor::state
Settings::CodeViewerState state()
Definition: codeeditor.cpp:99
CodeEditor::m_backspacePressed
bool m_backspacePressed
Definition: codeeditor.h:103
CodeEditor::appendText
void appendText(TextBlock *tblock)
Definition: codeeditor.cpp:550
CodeEditor::slotRedrawText
void slotRedrawText()
Definition: codeeditor.cpp:891
CodeEditor::slotChangeSelectedBlockView
void slotChangeSelectedBlockView()
Definition: codeeditor.cpp:657
CodeEditor::keyPressEvent
void keyPressEvent(QKeyEvent *e)
Definition: codeeditor.cpp:193
CodeEditor::m_showHiddenBlocks
bool m_showHiddenBlocks
Definition: codeeditor.h:105
CodeEditor::clicked
void clicked(int para, int pos)
Definition: codeeditor.cpp:118
CodeEditor::init
void init(CodeViewerDialog *parentDialog, CodeDocument *parentDoc)
Definition: codeeditor.cpp:901
CodeEditor::m_lastPos
int m_lastPos
Definition: codeeditor.h:100
CodeEditor::m_textBlockToPaste
TextBlock * m_textBlockToPaste
Definition: codeeditor.h:107
CodeEditor::findTextBlockAt
TextBlock * findTextBlockAt(int characterPos)
Definition: codeeditor.cpp:1174
CodeEditor::slotInsertCodeBlockAfterSelected
void slotInsertCodeBlockAfterSelected()
Definition: codeeditor.cpp:706
CodeEditor::m_parentDocName
QString m_parentDocName
Definition: codeeditor.h:95
CodeEditor::m_textBlockList
TextBlockList m_textBlockList
Definition: codeeditor.h:112
CodeEditor::slotPasteTextBlock
void slotPasteTextBlock()
Definition: codeeditor.cpp:879
CodeEditor::slotChangeSelectedBlockCommentView
void slotChangeSelectedBlockCommentView()
Definition: codeeditor.cpp:670
CodeEditor::initText
void initText(CodeDocument *doc)
CodeEditor::changeTextBlockHighlighting
void changeTextBlockHighlighting(TextBlock *tb, bool selected)
Definition: codeeditor.cpp:1255
CodeEditor::m_lastTextBlockToBeEdited
TextBlock * m_lastTextBlockToBeEdited
Definition: codeeditor.h:109
CodeEditor::m_parentDialog
CodeViewerDialog * m_parentDialog
Definition: codeeditor.h:97
CodeEditor::insertParagraph
void insertParagraph(const QString &text, int para)
Definition: codeeditor.cpp:618
CodeEditor::slotCursorPositionChanged
void slotCursorPositionChanged()
Definition: codeeditor.cpp:1012
CodeEditor::setParagraphBackgroundColor
void setParagraphBackgroundColor(int position, const QColor &color)
Definition: codeeditor.cpp:1291
CodeMethodBlock
Definition: codemethodblock.h:26
CodeViewerDialog
Definition: codeviewerdialog.h:23
HierarchicalCodeBlock
Definition: hierarchicalcodeblock.h:21
Settings::CodeViewerState
configurable params for the code viewer tool
Definition: codeviewerstate.h:15
TextBlock
Definition: textblock.h:23
TextBlockInfo
Definition: codeeditor.h:46
TextBlockInfo::m_displayName
QString m_displayName
Definition: codeeditor.h:50
TextBlockInfo::parent
UMLObject * parent()
Definition: codeeditor.h:56
TextBlockInfo::TextBlockInfo
TextBlockInfo()
Definition: codeeditor.h:54
TextBlockInfo::isClickable
bool isClickable
Definition: codeeditor.h:51
TextBlockInfo::displayName
QString displayName() const
Definition: codeeditor.h:58
TextBlockInfo::isCodeAccessorMethod
bool isCodeAccessorMethod
Definition: codeeditor.h:52
TextBlockInfo::m_paraList
QList< ParaInfo * > m_paraList
Definition: codeeditor.h:48
TextBlockInfo::setParent
void setParent(UMLObject *p=nullptr)
Definition: codeeditor.h:55
TextBlockInfo::setDisplayName
void setDisplayName(const QString &name)
Definition: codeeditor.h:57
TextBlockInfo::m_parent
UMLObject * m_parent
Definition: codeeditor.h:49
UMLObject
The base class for UML objects.
Definition: umlobject.h:70
codeviewerstate.h
ParaInfo
Definition: codeeditor.h:35
ParaInfo::bgcolor
QColor bgcolor
Definition: codeeditor.h:40
ParaInfo::size
int size
number of characters
Definition: codeeditor.h:37
ParaInfo::end
int end
end line number
Definition: codeeditor.h:38
ParaInfo::isEditable
bool isEditable
Definition: codeeditor.h:41
ParaInfo::fgcolor
QColor fgcolor
Definition: codeeditor.h:39
ParaInfo::start
int start
Definition: codeeditor.h:36
textblocklist.h
TextBlockList
QList< TextBlock * > TextBlockList
Definition: textblocklist.h:14