• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

umbrello/umbrello

  • sources
  • kde-4.12
  • kdesdk
  • umbrello
  • umbrello
docwindow.cpp
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) 2002-2013 *
8  * Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
9  ***************************************************************************/
10 
11 // own header
12 #include "docwindow.h"
13 
14 // local includes
15 #include "associationwidget.h"
16 #include "debug_utils.h"
17 #include "icon_utils.h"
18 #include "umldoc.h"
19 #include "umlobject.h"
20 #include "umlscene.h"
21 #include "umlwidget.h"
22 
23 // kde includes
24 #include <ktextedit.h>
25 #include <klocale.h>
26 
27 // qt includes
28 #include <QLabel>
29 #include <QGridLayout>
30 #include <QVBoxLayout>
31 
35 DocWindow::DocWindow(UMLDoc * doc, QWidget *parent)
36  : QWidget(parent),
37  m_pUMLObject(0),
38  m_pUMLScene(0),
39  m_pUMLDoc(doc),
40  m_pUMLWidget(0),
41  m_pAssocWidget(0),
42  m_Showing(st_Project)
43 {
44  //setup visual display
45  QGridLayout* statusLayout = new QGridLayout();
46  m_typeLabel = createPixmapLabel();
47  m_typeLabel->setToolTip(i18n("Documentation type"));
48  statusLayout->addWidget(m_typeLabel, 0, 0, 1, 1);
49  m_nameLabel = new QLabel(this);
50  m_nameLabel->setFrameStyle(QFrame::Panel | QFrame::Raised);
51  m_nameLabel->setAlignment(Qt::AlignHCenter);
52  statusLayout->addWidget(m_nameLabel, 0, 1, 1, 4);
53  m_modifiedLabel = createPixmapLabel();
54  m_modifiedLabel->setToolTip(i18n("Flag whether documentation was modified"));
55  statusLayout->addWidget(m_modifiedLabel, 0, 5, 1, 1);
56  m_docTE = new KTextEdit(this);
57  m_docTE->setText("");
58  //m_docTE->setWordWrapMode(QTextEdit::WidgetWidth);
59  QVBoxLayout* docLayout = new QVBoxLayout(this);
60  docLayout->addLayout(statusLayout);
61  docLayout->addWidget(m_docTE);
62  docLayout->setMargin(0);
63 
64  connect(m_docTE, SIGNAL(textChanged()), this, SLOT(slotTextChanged()));
65 }
66 
70 DocWindow::~DocWindow()
71 {
72 }
73 
87 void DocWindow::showDocumentation(UMLObject * object, bool overwrite)
88 {
89  if (!object) {
90  reset();
91  return;
92  }
93  if (object == m_pUMLObject) {
94  if (overwrite) {
95  updateDocumentation(true);
96  }
97  else {
98  return;
99  }
100  }
101  else {
102  updateDocumentation(true);
103  }
104  m_Showing = st_UMLObject;
105  m_pUMLObject = object;
106  m_docTE->setText(m_pUMLObject->doc());
107  updateLabel(m_pUMLObject->name());
108 }
109 
114 void DocWindow::showDocumentation(UMLScene * scene, bool overwrite)
115 {
116  if (!scene) {
117  reset();
118  return;
119  }
120  if (scene == m_pUMLScene) {
121  if (overwrite) {
122  updateDocumentation(true);
123  }
124  else {
125  return;
126  }
127  }
128  else {
129  updateDocumentation(true);
130  }
131  m_Showing = st_UMLScene;
132  m_pUMLScene = scene;
133  m_docTE->setText(m_pUMLScene->documentation());
134  updateLabel(m_pUMLScene->name());
135 }
136 
142 void DocWindow::showDocumentation(UMLWidget * widget, bool overwrite)
143 {
144  if (!widget) {
145  reset();
146  return;
147  }
148  if (widget == m_pUMLWidget) {
149  if (overwrite) {
150  updateDocumentation(true);
151  }
152  else {
153  return;
154  }
155  }
156  else {
157  updateDocumentation(true);
158  }
159  m_Showing = st_UMLWidget;
160  m_pUMLWidget = widget;
161  m_docTE->setText(m_pUMLWidget->documentation());
162  updateLabel(m_pUMLWidget->name());
163 }
164 
170 void DocWindow::showDocumentation(AssociationWidget * widget, bool overwrite)
171 {
172  if (!widget) {
173  reset();
174  return;
175  }
176  if (widget == m_pAssocWidget) {
177  if (overwrite) {
178  updateDocumentation(true);
179  }
180  else {
181  return;
182  }
183  }
184  else {
185  updateDocumentation(true);
186  }
187  m_Showing = st_Association;
188  m_pAssocWidget = widget;
189  m_docTE->setText(m_pAssocWidget->documentation());
190  updateLabel(m_pAssocWidget->name());
191 }
192 
205 void DocWindow::updateDocumentation(bool clear, bool startup)
206 {
207  // the file is marked modified, if the documentation differs
208  // we don't do this on startup/load of a xmi file, because every time
209  // modified is set, we get another undo/redo backup point
210  if (isModified()) {
211  if (m_pUMLObject) {
212  m_pUMLObject->setDoc(m_docTE->toPlainText());
213  } else if(m_pUMLScene) {
214  m_pUMLScene->setDocumentation(m_docTE->toPlainText());
215  } else if (m_pUMLWidget) {
216  m_pUMLWidget->setDocumentation(m_docTE->toPlainText());
217  } else if (m_pAssocWidget) {
218  m_pAssocWidget->setDocumentation(m_docTE->toPlainText());
219  } else {
220  m_pUMLDoc->setDocumentation(m_docTE->toPlainText());
221  }
222 
223  // now do the setModified call
224  if (startup == false) {
225  m_pUMLDoc->setModified(true);
226  }
227  }
228 
229  // we should show the documentation of the whole project
230  if (clear) {
231  reset();
232  }
233 }
234 
238 void DocWindow::reset()
239 {
240  m_pUMLScene = 0;
241  m_pUMLObject = 0;
242  m_pUMLWidget = 0;
243  m_pAssocWidget = 0;
244  m_Showing = st_Project;
245  m_docTE->setText(m_pUMLDoc->documentation());
246  updateLabel(m_pUMLDoc->name());
247 }
248 
252 bool DocWindow::isTyping()
253 {
254  if (m_docTE->hasFocus())
255  return true;
256  else
257  return false;
258 }
259 
263 bool DocWindow::isModified()
264 {
265  bool modified = false;
266  const QString currentText = m_docTE->toPlainText();
267  QString originalText;
268  switch (m_Showing) {
269  case st_UMLObject:
270  if (m_pUMLObject) {
271  originalText = m_pUMLObject->doc();
272  }
273  break;
274  case st_UMLScene:
275  if (m_pUMLScene) {
276  originalText = m_pUMLScene->documentation();
277  }
278  break;
279  case st_UMLWidget:
280  if (m_pUMLWidget) {
281  originalText = m_pUMLWidget->documentation();
282  }
283  break;
284  case st_Association:
285  if (m_pAssocWidget) {
286  originalText = m_pAssocWidget->documentation();
287  }
288  break;
289  case st_Project:
290  if (m_pUMLDoc) {
291  originalText = m_pUMLDoc->documentation();
292  }
293  break;
294  default:
295  break;
296  }
297  if (QString::compare(originalText, currentText) != 0) {
298  modified = true;
299  }
300  return modified;
301 }
302 
308 void DocWindow::slotAssociationRemoved(AssociationWidget* association)
309 {
310  if (association == m_pAssocWidget || association->umlObject() == m_pUMLObject) {
311  // In old code, the below line crashed (bugs.kde.org/89860)
312  // A hotfix was made and detailed analysis was To Be Done:
313  // reset()
314  // However, it seems to have been fixed and the below line seems to work fine
315  updateDocumentation(true);
316  }
317 }
318 
324 void DocWindow::slotWidgetRemoved(UMLWidget* widget)
325 {
326  if (widget == m_pUMLWidget || widget->umlObject() == m_pUMLObject) {
327  updateDocumentation(true);
328  }
329 }
330 
334 void DocWindow::slotTextChanged()
335 {
336  updateLabel();
337 }
338 
343 void DocWindow::updateLabel(const QString& name)
344 {
345  if (!name.isEmpty()) {
346  Icon_Utils::IconType icon = Icon_Utils::it_Home;
347  switch (m_Showing) {
348  case st_Project:
349  icon = Icon_Utils::it_Code_Gen_Wizard;
350  break;
351  case st_UMLScene:
352  icon = Icon_Utils::it_Diagram_Class;
353  break;
354  case st_UMLObject:
355  icon = Icon_Utils::it_Object;
356  break;
357  case st_UMLWidget:
358  icon = Icon_Utils::it_Class;
359  break;
360  case st_Association:
361  icon = Icon_Utils::it_Association;
362  break;
363  }
364  m_typeLabel->setPixmap(Icon_Utils::SmallIcon(icon));
365  m_nameLabel->setText(name);
366  }
367  if (isModified()) {
368  m_modifiedLabel->setPixmap(Icon_Utils::SmallIcon(Icon_Utils::it_Document_Edit));
369  }
370  else {
371  m_modifiedLabel->setPixmap(QPixmap());
372  }
373 }
374 
379 QLabel* DocWindow::createPixmapLabel()
380 {
381  QLabel* label = new QLabel(this);
382  label->setAlignment(Qt::AlignCenter);
383  return label;
384 }
385 
386 #include "docwindow.moc"
Icon_Utils::it_Code_Gen_Wizard
Definition: icon_utils.h:216
umlobject.h
Icon_Utils::it_Diagram_Class
Definition: icon_utils.h:113
WidgetBase::umlObject
UMLObject * umlObject() const
Returns the UMLObject set to represent.
Definition: widgetbase.cpp:113
DocWindow::~DocWindow
~DocWindow()
Destructor.
Definition: docwindow.cpp:70
UMLScene::name
QString name() const
Return the name of the diagram.
Definition: umlscene.cpp:240
DocWindow::showDocumentation
void showDocumentation(UMLObject *object, bool overwrite=false)
Called when a widget wishes to display its documentation in the doc window.
Definition: docwindow.cpp:87
umlscene.h
QWidget
UMLScene::documentation
QString documentation() const
Return the documentation of the diagram.
Definition: umlscene.cpp:201
DocWindow::updateDocumentation
void updateDocumentation(bool clear=false, bool startup=false)
Call when you wish move changes in the doc window back into the members documentation.
Definition: docwindow.cpp:205
Icon_Utils::it_Home
Definition: icon_utils.h:40
WidgetBase::name
QString name() const
Gets the name from the corresponding UMLObject if this widget has an underlying UMLObject; if it does...
Definition: widgetbase.cpp:197
DocWindow::reset
void reset()
Re-initializes the class for a new document.
Definition: docwindow.cpp:238
debug_utils.h
WidgetBase::documentation
QString documentation() const
Used by some child classes to get documentation.
Definition: widgetbase.cpp:157
UMLObject
This class is the non-graphical version of UMLWidget.
Definition: umlobject.h:41
AssociationWidget
This class represents an association inside a diagram.
Definition: associationwidget.h:50
DocWindow::slotWidgetRemoved
void slotWidgetRemoved(UMLWidget *widget)
A widget was removed from the UMLScene.
Definition: docwindow.cpp:324
UMLDoc::documentation
QString documentation() const
Returns the documentation for the project.
Definition: umldoc.cpp:2757
docwindow.h
DocWindow::DocWindow
DocWindow(UMLDoc *doc, QWidget *parent=0)
Constructor.
Definition: docwindow.cpp:35
Icon_Utils::it_Association
Definition: icon_utils.h:93
umlwidget.h
Icon_Utils::it_Class
Definition: icon_utils.h:76
UMLScene::setDocumentation
void setDocumentation(const QString &doc)
Set the documentation of the diagram.
Definition: umlscene.cpp:209
UMLObject::setDoc
void setDoc(const QString &d)
Sets the documentation for the object.
Definition: umlobject.cpp:424
WidgetBase::setDocumentation
void setDocumentation(const QString &doc)
Used by some child classes to set documentation.
Definition: widgetbase.cpp:182
Icon_Utils::SmallIcon
QPixmap SmallIcon(IconType type)
Returns the pixmap for the given type as small icon.
Definition: icon_utils.cpp:36
AssociationWidget::name
QString name() const
Returns the m_nameWidget's text.
Definition: associationwidget.cpp:901
UMLDoc::setModified
void setModified(bool modified=true)
Sets the modified flag for the document after a modifying action on the view connected to the documen...
Definition: umldoc.cpp:2607
DocWindow::slotAssociationRemoved
void slotAssociationRemoved(AssociationWidget *association)
An association was removed from the UMLScene.
Definition: docwindow.cpp:308
Icon_Utils::it_Object
Definition: icon_utils.h:77
associationwidget.h
umldoc.h
icon_utils.h
UMLDoc::setDocumentation
void setDocumentation(const QString &doc)
Sets the documentation for the project.
Definition: umldoc.cpp:2767
UMLObject::name
QString name() const
Returns a copy of m_name.
Definition: umlobject.cpp:185
Icon_Utils::it_Document_Edit
Definition: icon_utils.h:218
Icon_Utils::IconType
IconType
Definition: icon_utils.h:38
UMLDoc::name
QString name() const
Return the name of this model.
Definition: umldoc.cpp:1641
UMLScene
UMLScene instances represent diagrams.
Definition: umlscene.h:70
KTextEdit
UMLObject::doc
QString doc() const
Returns the documentation for the object.
Definition: umlobject.cpp:404
DocWindow::isTyping
bool isTyping()
Checks if the user is typing in the documentation edit window.
Definition: docwindow.cpp:252
UMLDoc
UMLDoc provides a document object for a document-view model.
Definition: umldoc.h:63
UMLWidget
This is the base class for nearly all graphical widgets.
Definition: umlwidget.h:40
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:05:59 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

umbrello/umbrello

Skip menu "umbrello/umbrello"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal