umbrello: umbrello/umlappprivate.h Source File

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

umlappprivate.h
Go to the documentation of this file.
1/*
2 SPDX-License-Identifier: GPL-2.0-or-later
3 SPDX-FileCopyrightText: 2002-2022 Umbrello UML Modeller Authors <umbrello-devel@kde.org>
4*/
5
6#ifndef UMLAPPPRIVATE_H
7#define UMLAPPPRIVATE_H
8
9// app includes
10#include "cmds.h"
11#include "finddialog.h"
12#include "findresults.h"
13#include "uml.h"
14#include "umldoc.h"
15#include "diagramswindow.h"
16#include "objectswindow.h"
17#include "stereotypeswindow.h"
18
19// kde includes
20#include <KActionCollection>
21#if QT_VERSION < 0x050000
22#include <KStandardDirs>
23#endif
24#include <KToggleAction>
25#include <ktexteditor/configinterface.h>
26#include <ktexteditor/document.h>
27#include <ktexteditor/editor.h>
28#if QT_VERSION < 0x050000
29#include <ktexteditor/editorchooser.h>
30#endif
31#include <ktexteditor/view.h>
32
33// qt includes
34#include <QDesktopServices>
35#include <QFile>
36#include <QFileInfo>
37#include <QFont>
38#include <QListWidget>
39#include <QObject>
40#ifdef WEBKIT_WELCOMEPAGE
41#include <QWebView>
42#else
43#include <QTextBrowser>
44#endif
45
46class QWidget;
47
48
55 class UMLAppPrivate : public QObject
56{
57 Q_OBJECT
58public:
59 UMLApp *parent;
60 FindDialog findDialog;
61 FindResults findResults;
62 QListWidget *logWindow;
63 KToggleAction *viewDiagramsWindow;
64 KToggleAction *viewObjectsWindow;
65 KToggleAction *viewStereotypesWindow;
66 KToggleAction *viewWelcomeWindow;
67 DiagramsWindow *diagramsWindow;
68 ObjectsWindow *objectsWindow;
69 StereotypesWindow *stereotypesWindow;
70 QDockWidget *welcomeWindow;
71 QDockWidget *editorWindow;
72
73 KTextEditor::Editor *editor;
74 KTextEditor::View *view;
75 KTextEditor::Document *document;
76
77 explicit UMLAppPrivate(UMLApp *_parent)
78 : parent(_parent),
79 findDialog(_parent),
80 viewDiagramsWindow(0),
81 viewObjectsWindow(0),
82 viewStereotypesWindow(0),
83 viewWelcomeWindow(0),
84 diagramsWindow(0),
85 objectsWindow(0),
86 stereotypesWindow(0),
87 welcomeWindow(0),
88 editorWindow(0),
89 view(0),
90 document(0)
91 {
92#if QT_VERSION >= 0x050000
93 /* TODO: On the call to KTextEditor::Editor::instance() Valgrind reports
94 "Conditional jump or move depends on uninitialised value(s)".
95 */
96 editor = KTextEditor::Editor::instance();
97#else
98 editor = KTextEditor::EditorChooser::editor();
99#endif
100 logWindow = new QListWidget;
101 QFont mono;
102 mono.setFamily(QLatin1String("Monospace"));
103 logWindow->setFont(mono);
104 connect(logWindow, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(slotLogWindowItemDoubleClicked(QListWidgetItem *)));
105 }
106
107 ~UMLAppPrivate()
108 {
109 delete diagramsWindow;
110 delete editorWindow;
111 delete logWindow;
112 delete objectsWindow;
113 delete stereotypesWindow;
114 delete welcomeWindow;
115 }
116
117 bool openFileInEditor(const QUrl &file, int startCursor=0, int endCursor=0);
118
119public slots:
120 void slotLogWindowItemDoubleClicked(QListWidgetItem *item)
121 {
122 QStringList columns = item->text().split(QChar::fromLatin1(':'));
123
124 openFileInEditor(QUrl::fromLocalFile(columns[0]), columns[1].toInt()-1, columns[2].toInt());
125 }
126
127 void createDiagramsWindow()
128 {
129 // create the tree viewer
130 diagramsWindow = new DiagramsWindow(i18n("&Diagrams"), parent);
131 parent->addDockWidget(Qt::LeftDockWidgetArea, diagramsWindow);
132
133 viewDiagramsWindow = parent->actionCollection()->add<KToggleAction>(QLatin1String("view_show_diagrams"));
134 connect(viewDiagramsWindow, SIGNAL(triggered(bool)), diagramsWindow, SLOT(setVisible(bool)));
135 }
136
137 void createObjectsWindow()
138 {
139 // create the object window
140 objectsWindow = new ObjectsWindow(i18n("&UML Objects"), parent);
141 parent->addDockWidget(Qt::LeftDockWidgetArea, objectsWindow);
142
143 viewObjectsWindow = parent->actionCollection()->add<KToggleAction>(QLatin1String("view_show_objects"));
144 connect(viewObjectsWindow, SIGNAL(triggered(bool)), objectsWindow, SLOT(setVisible(bool)));
145 }
146
147 void createStereotypesWindow()
148 {
149 // create the tree viewer
150 stereotypesWindow = new StereotypesWindow(i18n("&Stereotypes"), parent);
151 parent->addDockWidget(Qt::LeftDockWidgetArea, stereotypesWindow);
152
153 viewStereotypesWindow = parent->actionCollection()->add<KToggleAction>(QLatin1String("view_show_stereotypes"));
154 connect(viewStereotypesWindow, SIGNAL(triggered(bool)), stereotypesWindow, SLOT(setVisible(bool)));
155 }
156
157 void createWelcomeWindow()
158 {
159 QString file = findWelcomeFile();
160 if (file.isEmpty())
161 return;
162 QString html = readWelcomeFile(file);
163 if (html.isEmpty())
164 return;
165 // qDebug() << html;
166 welcomeWindow = new QDockWidget(i18n("Welcome"), parent);
167 welcomeWindow->setObjectName(QLatin1String("WelcomeDock"));
168#ifdef WEBKIT_WELCOMEPAGE
169 QWebView *view = new QWebView;
170 view->page()->setLinkDelegationPolicy(QWebPage::DelegateAllLinks);
171 view->setContextMenuPolicy(Qt::NoContextMenu);
172 connect(view, SIGNAL(linkClicked(const QUrl)), this, SLOT(slotWelcomeWindowLinkClicked(const QUrl)));
173 view->setHtml(html);
174 view->show();
175 welcomeWindow->setWidget(view);
176#else
177 QTextBrowser *tb = new QTextBrowser(dynamic_cast<QWidget*>(this));
178 tb->setOpenExternalLinks(true);
179 tb->setOpenLinks(false);
180 tb->setHtml(html);
181 connect(tb, SIGNAL(anchorClicked(const QUrl)), this, SLOT(slotWelcomeWindowLinkClicked(const QUrl)));
182 welcomeWindow->setWidget(tb);
183#endif
184 parent->addDockWidget(Qt::RightDockWidgetArea, welcomeWindow);
185
186 viewWelcomeWindow = parent->actionCollection()->add<KToggleAction>(QLatin1String("view_show_welcome"));
187 connect(viewWelcomeWindow, SIGNAL(triggered(bool)), welcomeWindow, SLOT(setVisible(bool)));
188 }
189
190 void slotWelcomeWindowLinkClicked(const QUrl &url)
191 {
192 //qDebug() << url;
193 if (url.scheme() == QLatin1String("mailto") || url.scheme().startsWith(QLatin1String("http"))) {
194 QDesktopServices::openUrl(url);
195 return;
196 }
197 QStringList list = url.toString().split(QLatin1Char('-'));
198 list.removeLast();
199 QString key;
200 foreach(const QString s, list) {
201 QString a = s;
202 a[0] = a[0].toUpper();
203 key.append(a);
204 }
205 Uml::DiagramType::Enum type = Uml::DiagramType::fromString(key);
206 if (type == Uml::DiagramType::Undefined)
207 return;
208 QString diagramName = UMLApp::app()->document()->createDiagramName(type);
209 if (!diagramName.isEmpty())
210 UMLApp::app()->executeCommand(new Uml::CmdCreateDiagram(UMLApp::app()->document(), type, diagramName));
211 }
212
213private:
214 QString findWelcomeFile();
215 QString readWelcomeFile(const QString &file);
216};
217
218#endif
DiagramsWindow
Definition: diagramswindow.h:15
FindDialog
Definition: finddialog.h:20
FindResults
Definition: findresults.h:25
ObjectsWindow
Definition: objectswindow.h:16
StereotypesWindow
Definition: stereotypeswindow.h:15
UMLAppPrivate
Definition: umlappprivate.h:56
UMLAppPrivate::editor
KTextEditor::Editor * editor
Definition: umlappprivate.h:73
UMLAppPrivate::openFileInEditor
bool openFileInEditor(const QUrl &file, int startCursor=0, int endCursor=0)
Definition: umlappprivate.cpp:142
UMLAppPrivate::createStereotypesWindow
void createStereotypesWindow()
Definition: umlappprivate.h:147
UMLAppPrivate::view
KTextEditor::View * view
Definition: umlappprivate.h:74
UMLAppPrivate::diagramsWindow
DiagramsWindow * diagramsWindow
Definition: umlappprivate.h:67
UMLAppPrivate::createWelcomeWindow
void createWelcomeWindow()
Definition: umlappprivate.h:157
UMLAppPrivate::findWelcomeFile
QString findWelcomeFile()
Definition: umlappprivate.cpp:20
UMLAppPrivate::viewObjectsWindow
KToggleAction * viewObjectsWindow
Definition: umlappprivate.h:64
UMLAppPrivate::~UMLAppPrivate
~UMLAppPrivate()
Definition: umlappprivate.h:107
UMLAppPrivate::parent
UMLApp * parent
Definition: umlappprivate.h:59
UMLAppPrivate::findDialog
FindDialog findDialog
Definition: umlappprivate.h:60
UMLAppPrivate::document
KTextEditor::Document * document
Definition: umlappprivate.h:75
UMLAppPrivate::readWelcomeFile
QString readWelcomeFile(const QString &file)
Definition: umlappprivate.cpp:79
UMLAppPrivate::viewStereotypesWindow
KToggleAction * viewStereotypesWindow
Definition: umlappprivate.h:65
UMLAppPrivate::viewDiagramsWindow
KToggleAction * viewDiagramsWindow
Definition: umlappprivate.h:63
UMLAppPrivate::findResults
FindResults findResults
Definition: umlappprivate.h:61
UMLAppPrivate::stereotypesWindow
StereotypesWindow * stereotypesWindow
Definition: umlappprivate.h:69
UMLAppPrivate::welcomeWindow
QDockWidget * welcomeWindow
Definition: umlappprivate.h:70
UMLAppPrivate::createObjectsWindow
void createObjectsWindow()
Definition: umlappprivate.h:137
UMLAppPrivate::slotWelcomeWindowLinkClicked
void slotWelcomeWindowLinkClicked(const QUrl &url)
Definition: umlappprivate.h:190
UMLAppPrivate::slotLogWindowItemDoubleClicked
void slotLogWindowItemDoubleClicked(QListWidgetItem *item)
Definition: umlappprivate.h:120
UMLAppPrivate::UMLAppPrivate
UMLAppPrivate(UMLApp *_parent)
Definition: umlappprivate.h:77
UMLAppPrivate::logWindow
QListWidget * logWindow
Logging window.
Definition: umlappprivate.h:62
UMLAppPrivate::editorWindow
QDockWidget * editorWindow
Definition: umlappprivate.h:71
UMLAppPrivate::createDiagramsWindow
void createDiagramsWindow()
Definition: umlappprivate.h:127
UMLAppPrivate::objectsWindow
ObjectsWindow * objectsWindow
Definition: umlappprivate.h:68
UMLAppPrivate::viewWelcomeWindow
KToggleAction * viewWelcomeWindow
Definition: umlappprivate.h:66
UMLApp
Definition: uml.h:95
UMLApp::document
UMLDoc * document() const
Definition: uml.cpp:1139
UMLApp::executeCommand
void executeCommand(QUndoCommand *cmd)
Definition: uml.cpp:3623
UMLApp::app
static UMLApp * app()
Definition: uml.cpp:349
UMLDoc::createDiagramName
QString createDiagramName(Uml::DiagramType::Enum type, bool askForName=true)
Definition: umldoc.cpp:1675
Uml::CmdCreateDiagram
Definition: cmdcreatediagram.h:20
cmds.h
diagramswindow.h
finddialog.h
findresults.h
i18n
#define i18n
Definition: main.cpp:35
MyProject\connect
connect()
Definition: namespaces-multiple.php:5
Uml::DiagramType::fromString
Enum fromString(const QString &item)
Definition: basictypes.cpp:224
Uml::DiagramType::Enum
Enum
Definition: basictypes.h:63
Uml::DiagramType::Undefined
@ Undefined
Definition: basictypes.h:66
objectswindow.h
a
QString a
Definition: petalnode.cpp:13
stereotypeswindow.h
uml.h
umldoc.h