• 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
umlobject.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 <[email protected]> *
9  ***************************************************************************/
10 
11 // own header
12 #include "umlobject.h"
13 
14 // app includes
15 #include "debug_utils.h"
16 #include "uniqueid.h"
17 #include "uml.h"
18 #include "umldoc.h"
19 #include "umllistview.h"
20 #include "package.h"
21 #include "folder.h"
22 #include "stereotype.h"
23 #include "object_factory.h"
24 #include "model_utils.h"
25 #include "import_utils.h"
26 #include "docwindow.h"
27 #include "classpropdlg.h"
28 #include "cmds.h"
29 
30 // kde includes
31 #include <klocale.h>
32 
33 // qt includes
34 #include <QApplication>
35 #include <QPointer>
36 
37 using namespace Uml;
38 
39 DEBUG_REGISTER_DISABLED(UMLObject)
40 
41 
48 UMLObject::UMLObject(UMLObject* parent, const QString& name, ID::Type id)
49  : QObject(parent),
50  m_nId(id),
51  m_name(name)
52 {
53  init();
54  if (id == Uml::ID::None)
55  m_nId = UniqueID::gen();
56 }
57 
64 UMLObject::UMLObject(const QString& name, ID::Type id)
65  : QObject(UMLApp::app()->document()),
66  m_nId(id),
67  m_name(name)
68 {
69  init();
70  if (id == Uml::ID::None)
71  m_nId = UniqueID::gen();
72 }
73 
78 UMLObject::UMLObject(UMLObject * parent)
79  : QObject(parent),
80  m_nId(Uml::ID::None),
81  m_name(QString())
82 {
83  init();
84 }
85 
89 UMLObject::~UMLObject()
90 {
91 }
92 
96 void UMLObject::init()
97 {
98  setObjectName("UMLObject");
99  m_BaseType = ot_UMLObject;
100  m_pUMLPackage = 0;
101  m_visibility = Uml::Visibility::Public;
102  m_pStereotype = 0;
103  m_Doc.clear();
104  m_bAbstract = false;
105  m_bStatic = false;
106  m_bInPaste = false;
107  m_bCreationWasSignalled = false;
108  m_pSecondary = 0;
109 }
110 
120 bool UMLObject::showPropertiesPagedDialog(int page, bool assoc)
121 {
122  Q_UNUSED(page);
123  DocWindow *docwindow = UMLApp::app()->docWindow();
124  docwindow->updateDocumentation(false);
125  QPointer<ClassPropDlg> dlg = new ClassPropDlg((QWidget*)UMLApp::app(), this, assoc);
126  bool modified = false;
127  if (dlg->exec()) {
128  docwindow->showDocumentation(this, true);
129  UMLApp::app()->document()->setModified(true);
130  modified = true;
131  }
132  dlg->close();
133  delete dlg;
134  return modified;
135 }
136 
149 bool UMLObject::acceptAssociationType(Uml::AssociationType::Enum type)
150 {
151  Q_UNUSED(type);
152  // A UMLObject accepts nothing. This should be reimplemented by the subclasses
153  return false;
154 }
155 
159 void UMLObject::setID(ID::Type NewID)
160 {
161  m_nId = NewID;
162  emitModified();
163 }
164 
168 void UMLObject::setName(const QString &strName)
169 {
170  UMLApp::app()->executeCommand(new Uml::CmdRenameUMLObject(this, strName));
171 }
172 
176 void UMLObject::setNameCmd(const QString &strName)
177 {
178  m_name = strName;
179  emitModified();
180 }
181 
185 QString UMLObject::name() const
186 {
187  return m_name;
188 }
189 
201 QString UMLObject::fullyQualifiedName(const QString& separator,
202  bool includeRoot /* = false */) const
203 {
204  QString fqn;
205  if (m_pUMLPackage && m_pUMLPackage != this) {
206  bool skipPackage = false;
207  if (!includeRoot) {
208  UMLDoc *umldoc = UMLApp::app()->document();
209  if (umldoc->rootFolderType(m_pUMLPackage) != Uml::ModelType::N_MODELTYPES ||
210  m_pUMLPackage == umldoc->datatypeFolder())
211  skipPackage = true;
212  }
213  if (!skipPackage) {
214  QString tempSeparator = separator;
215  if (tempSeparator.isEmpty())
216  tempSeparator = UMLApp::app()->activeLanguageScopeSeparator();
217  fqn = m_pUMLPackage->fullyQualifiedName(tempSeparator, includeRoot);
218  fqn.append(tempSeparator);
219  }
220  }
221  fqn.append(m_name);
222  return fqn;
223 }
224 
228 bool UMLObject::operator==(const UMLObject & rhs) const
229 {
230  if (this == &rhs)
231  return true;
232 
233  //don't compare IDs, these are program specific and
234  //don't mean the objects are the same
235  //***** CHECK: Who put in this comment? What was the reason?
236  //***** Currently some operator== in umbrello compare the IDs
237  //***** while others don't.
238 
239  if (m_name != rhs.m_name)
240  return false;
241 
242  // Packages create different namespaces, therefore they should be
243  // part of the equality test.
244  if (m_pUMLPackage != rhs.m_pUMLPackage)
245  return false;
246 
247  // Making the type part of an object's identity has its problems:
248  // Not all programming languages support declarations of the same
249  // name but different type.
250  // In such cases, the code generator is responsible for generating
251  // the appropriate error message.
252  if (m_BaseType != rhs.m_BaseType)
253  return false;
254 
255  // The documentation should not be part of the equality test.
256  // If two objects are the same but differ only in their documentation,
257  // what does that mean?
258  //if(m_Doc != rhs.m_Doc)
259  // return false;
260 
261  // The visibility should not be part of the equality test.
262  // What does it mean if two objects are the same but differ in their
263  // visibility? - I'm not aware of any programming language that would
264  // support that.
265  //if(m_visibility != rhs.m_visibility)
266  // return false;
267 
268  // See comments above
269  //if(m_pStereotype != rhs.m_pStereotype)
270  // return false;
271 
272  // See comments above
273  //if(m_bAbstract != rhs.m_bAbstract)
274  // return false;
275 
276  // See comments above
277  //if(m_bStatic != rhs.m_bStatic)
278  // return false;
279 
280  return true;
281 }
282 
287 void UMLObject::copyInto(UMLObject *lhs) const
288 {
289  // Data members with copy constructor
290  lhs->m_Doc = m_Doc;
291  lhs->m_pStereotype = m_pStereotype;
292  lhs->m_bAbstract = m_bAbstract;
293  lhs->m_bStatic = m_bStatic;
294  lhs->m_BaseType = m_BaseType;
295  lhs->m_visibility = m_visibility;
296  lhs->m_pUMLPackage = m_pUMLPackage;
297 
298  // We don't want the same name existing twice.
299  lhs->m_name = Model_Utils::uniqObjectName(m_BaseType, m_pUMLPackage, m_name);
300 
301  // Create a new ID.
302  lhs->m_nId = UniqueID::gen();
303 
304  // Hope that the parent from QObject is okay.
305  if (lhs->parent() != parent())
306  uDebug() << "copyInto has a wrong parent";
307 }
308 
312 bool UMLObject::isAbstract() const
313 {
314  return m_bAbstract;
315 }
316 
320 void UMLObject::setAbstract(bool bAbstract)
321 {
322  m_bAbstract = bAbstract;
323  emitModified();
324 }
325 
326 void UMLObject::setInPaste(bool bInPaste /* =true */)
327 {
328  m_bInPaste = bInPaste;
329 }
330 
335 bool UMLObject::isStatic() const
336 {
337  return m_bStatic;
338 }
339 
343 void UMLObject::setStatic(bool bStatic)
344 {
345  m_bStatic = bStatic;
346  emitModified();
347 }
348 
354 void UMLObject::emitModified()
355 {
356  UMLDoc *umldoc = UMLApp::app()->document();
357  if (!umldoc->loading() && !umldoc->closing())
358  emit modified();
359 }
360 
366 UMLObject::ObjectType UMLObject::baseType() const
367 {
368  return m_BaseType;
369 }
370 
374 QLatin1String UMLObject::baseTypeStr() const
375 {
376  return QLatin1String(ENUM_NAME(UMLObject, ObjectType, m_BaseType));
377 }
378 
384 void UMLObject::setBaseType(ObjectType ot)
385 {
386  m_BaseType = ot;
387 }
388 
394 ID::Type UMLObject::id() const
395 {
396  return m_nId;
397 }
398 
404 QString UMLObject::doc() const
405 {
406  return m_Doc;
407 }
408 
414 bool UMLObject::hasDoc() const
415 {
416  return !m_Doc.isEmpty();
417 }
418 
424 void UMLObject::setDoc(const QString &d)
425 {
426  m_Doc = d;
427  //emit modified(); No, this is done centrally at DocWindow::updateDocumentation()
428 }
429 
435 Visibility::Enum UMLObject::visibility() const
436 {
437  return m_visibility;
438 }
439 
445 void UMLObject::setVisibility(Visibility::Enum visibility)
446 {
447  UMLApp::app()->executeCommand(new CmdSetVisibility(this, visibility));
448 }
449 
453 void UMLObject::setVisibilityCmd(Visibility::Enum visibility)
454 {
455  m_visibility = visibility;
456  emitModified();
457 }
458 
468 void UMLObject::setUMLStereotype(UMLStereotype *stereo)
469 {
470  if (stereo == m_pStereotype)
471  return;
472  if (stereo) {
473  stereo->incrRefCount();
474  }
475  if (m_pStereotype) {
476  m_pStereotype->decrRefCount();
477  if (m_pStereotype->refCount() == 0) {
478  UMLDoc *pDoc = UMLApp::app()->document();
479  pDoc->removeStereotype(m_pStereotype);
480  delete m_pStereotype;
481  }
482  }
483  m_pStereotype = stereo;
484  // TODO: don't emit modified() if predefined folder
485  emitModified();
486 }
487 
494 void UMLObject::setStereotype(const QString &_name)
495 {
496  // UMLDoc* pDoc = UMLApp::app()->document();
497  // pDoc->executeCommand(new cmdSetStereotype(this, _name));
498  if (_name.isEmpty()) {
499  setUMLStereotype(NULL);
500  return;
501  }
502  UMLDoc *pDoc = UMLApp::app()->document();
503  UMLStereotype *s = pDoc->findOrCreateStereotype(_name);
504  setUMLStereotype(s);
505 }
506 
507 void UMLObject::setStereotypeCmd(const QString& /*_name*/)
508 {
509 //TODO: put SetStereotype into QundoStack
510 }
511 
518 void UMLObject::setPackage(const QString &_name)
519 {
520  UMLObject *pkgObj = NULL;
521  if (!_name.isEmpty()) {
522  UMLDoc* umldoc = UMLApp::app()->document();
523  pkgObj = umldoc->findUMLObject(_name);
524  if (pkgObj == NULL) {
525  uDebug() << "creating UMLPackage " << _name << " for " << m_name;
526  pkgObj = Import_Utils::createUMLObject(ot_Package, _name);
527  } else {
528  const ObjectType ot = pkgObj->baseType();
529  if (ot != ot_Package && ot != ot_Folder && ot != ot_Component) {
530  uError() << m_name << ": " << "existing " << _name << " is not a container";
531  // This should not happen - if it does, there may be further problems.
532  // A container name should not overlap with another name in the same scope.
533  pkgObj = Import_Utils::createUMLObject(ot_Package, _name);
534  }
535  }
536  }
537  setUMLPackage(static_cast<UMLPackage *>(pkgObj));
538 }
539 
545 bool UMLObject::setUMLPackage(UMLPackage* pPkg)
546 {
547  if (pPkg == this) {
548  uDebug() << "setting parent to myself is not allowed";
549  return false;
550  }
551 
552  if (pPkg == NULL) {
553  // Allow setting to NULL for stereotypes
554  m_pUMLPackage = pPkg;
555  return true;
556  }
557 
558  if (pPkg->umlPackage() == this) {
559  uDebug() << "setting parent to an object of which I'm already the parent is not allowed";
560  return false;
561  }
562 
563  m_pUMLPackage = pPkg;
564  emitModified();
565  return true;
566 }
567 
573 const UMLStereotype * UMLObject::umlStereotype()
574 {
575  return m_pStereotype;
576 }
577 
581 QString UMLObject::stereotype(bool includeAdornments /* = false */) const
582 {
583  if (m_pStereotype == NULL)
584  return "";
585  QString name = m_pStereotype->name();
586  if (includeAdornments)
587  name = QString::fromUtf8("«") + name + QString::fromUtf8("»");
588  return name;
589 }
590 
603 QString UMLObject::package(const QString& separator, bool includeRoot)
604 {
605  QString tempSeparator = separator;
606  if (tempSeparator.isEmpty())
607  tempSeparator = UMLApp::app()->activeLanguageScopeSeparator();
608  QString fqn = fullyQualifiedName(tempSeparator, includeRoot);
609  if (!fqn.contains(tempSeparator))
610  return "";
611  QString scope = fqn.left(fqn.length() - tempSeparator.length() - m_name.length());
612  return scope;
613 }
614 
623 UMLPackageList UMLObject::packages(bool includeRoot) const
624 {
625  UMLPackageList pkgList;
626  UMLPackage* pkg = m_pUMLPackage;
627  while (pkg != NULL) {
628  pkgList.prepend(pkg);
629  pkg = pkg->umlPackage();
630  }
631  if (!includeRoot)
632  pkgList.removeFirst();
633  return pkgList;
634 }
635 
641 UMLPackage* UMLObject::umlPackage()
642 {
643  return m_pUMLPackage;
644 }
645 
649 QString UMLObject::secondaryId() const
650 {
651  return m_SecondaryId;
652 }
653 
659 void UMLObject::setSecondaryId(const QString& id)
660 {
661  m_SecondaryId = id;
662 }
663 
668 QString UMLObject::secondaryFallback() const
669 {
670  return m_SecondaryFallback;
671 }
672 
677 void UMLObject::setSecondaryFallback(const QString& id)
678 {
679  m_SecondaryFallback = id;
680 }
681 
686 void UMLObject::maybeSignalObjectCreated()
687 {
688  if (!m_bCreationWasSignalled &&
689  m_BaseType != ot_Stereotype &&
690  m_BaseType != ot_Association &&
691  m_BaseType != ot_Role) {
692  m_bCreationWasSignalled = true;
693  UMLDoc* umldoc = UMLApp::app()->document();
694  umldoc->signalUMLObjectCreated(this);
695  }
696 }
697 
709 bool UMLObject::resolveRef()
710 {
711  if (m_pSecondary || (m_SecondaryId.isEmpty() && m_SecondaryFallback.isEmpty())) {
712  maybeSignalObjectCreated();
713  return true;
714  }
715 #ifdef VERBOSE_DEBUGGING
716  uDebug() << m_name << ": m_SecondaryId is " << m_SecondaryId;
717 #endif
718  UMLDoc *pDoc = UMLApp::app()->document();
719  // In the new, XMI standard compliant save format,
720  // the type is the xmi.id of a UMLClassifier.
721  if (! m_SecondaryId.isEmpty()) {
722  m_pSecondary = pDoc->findObjectById(Uml::ID::fromString(m_SecondaryId));
723  if (m_pSecondary != NULL) {
724  if (m_pSecondary->baseType() == ot_Stereotype) {
725  m_pStereotype = static_cast<UMLStereotype*>(m_pSecondary);
726  m_pStereotype->incrRefCount();
727  m_pSecondary = NULL;
728  }
729  m_SecondaryId = "";
730  maybeSignalObjectCreated();
731  return true;
732  }
733  if (m_SecondaryFallback.isEmpty()) {
734  uDebug() << "object with xmi.id=" << m_SecondaryId << " not found, setting to undef";
735  UMLFolder *datatypes = pDoc->datatypeFolder();
736  m_pSecondary = Object_Factory::createUMLObject(ot_Datatype, "undef", datatypes, false);
737  return true;
738  }
739  }
740  if (m_SecondaryFallback.isEmpty()) {
741  uError() << m_name << ": cannot find type with id " << m_SecondaryId;
742  return false;
743  }
744 #ifdef VERBOSE_DEBUGGING
745  uDebug() << m_name << ": could not resolve secondary ID " << m_SecondaryId
746  << ", using secondary fallback " << m_SecondaryFallback;
747 #endif
748  m_SecondaryId = m_SecondaryFallback;
749  // Assume we're dealing with the older Umbrello format where
750  // the type name was saved in the "type" attribute rather
751  // than the xmi.id of the model object of the attribute type.
752  m_pSecondary = pDoc->findUMLObject(m_SecondaryId, ot_UMLObject, this);
753  if (m_pSecondary) {
754  m_SecondaryId = "";
755  maybeSignalObjectCreated();
756  return true;
757  }
758  // Work around Object_Factory::createUMLObject()'s incapability
759  // of on-the-fly scope creation:
760  if (m_SecondaryId.contains("::")) {
761  // TODO: Merge Import_Utils::createUMLObject() into Object_Factory::createUMLObject()
762  m_pSecondary = Import_Utils::createUMLObject(ot_UMLObject, m_SecondaryId, m_pUMLPackage);
763  if (m_pSecondary) {
764  if (Import_Utils::newUMLObjectWasCreated()) {
765  maybeSignalObjectCreated();
766  qApp->processEvents();
767  uDebug() << "Import_Utils::createUMLObject() created a new type for "
768  << m_SecondaryId;
769  } else {
770  uDebug() << "Import_Utils::createUMLObject() returned an existing type for "
771  << m_SecondaryId;
772  }
773  m_SecondaryId = "";
774  return true;
775  }
776  uError() << "Import_Utils::createUMLObject() failed to create a new type for "
777  << m_SecondaryId;
778  return false;
779  }
780  uDebug() << "Creating new type for " << m_SecondaryId;
781  // This is very C++ specific - we rely on some '*' or
782  // '&' to decide it's a ref type. Plus, we don't recognize
783  // typedefs of ref types.
784  bool isReferenceType = (m_SecondaryId.contains('*') ||
785  m_SecondaryId.contains('&'));
786  ObjectType ot = ot_Class;
787  if (isReferenceType) {
788  ot = ot_Datatype;
789  } else {
790  if (Model_Utils::isCommonDataType(m_SecondaryId))
791  ot = ot_Datatype;
792  }
793  m_pSecondary = Object_Factory::createUMLObject(ot, m_SecondaryId, NULL);
794  if (m_pSecondary == NULL)
795  return false;
796  m_SecondaryId = "";
797  maybeSignalObjectCreated();
798  //qApp->processEvents();
799  return true;
800 }
801 
808 QDomElement UMLObject::save(const QString &tag, QDomDocument & qDoc)
809 {
810  /*
811  Call as the first action of saveToXMI() in child class:
812  This creates the QDomElement with which to work.
813  */
814  QDomElement qElement = qDoc.createElement(tag);
815  qElement.setAttribute("isSpecification", "false");
816  if (m_BaseType != ot_Association &&
817  m_BaseType != ot_Role &&
818  m_BaseType != ot_Attribute) {
819  qElement.setAttribute("isLeaf", "false");
820  qElement.setAttribute("isRoot", "false");
821  if (m_bAbstract)
822  qElement.setAttribute("isAbstract", "true");
823  else
824  qElement.setAttribute("isAbstract", "false");
825  }
826  qElement.setAttribute("xmi.id", Uml::ID::toString(m_nId));
827  qElement.setAttribute("name", m_name);
828  if (m_BaseType != ot_Operation &&
829  m_BaseType != ot_Role &&
830  m_BaseType != ot_Attribute) {
831  Uml::ID::Type nmSpc;
832  if (m_pUMLPackage)
833  nmSpc = m_pUMLPackage->id();
834  else
835  nmSpc = UMLApp::app()->document()->modelID();
836  qElement.setAttribute("namespace", Uml::ID::toString(nmSpc));
837  }
838  if (! m_Doc.isEmpty())
839  qElement.setAttribute("comment", m_Doc); //CHECK: uml13.dtd compliance
840 #ifdef XMI_FLAT_PACKAGES
841  if (m_pUMLPackage) //FIXME: uml13.dtd compliance
842  qElement.setAttribute("package", m_pUMLPackage->ID());
843 #endif
844  QString visibility = Uml::Visibility::toString(m_visibility, false);
845  qElement.setAttribute("visibility", visibility);
846  if (m_pStereotype != NULL)
847  qElement.setAttribute("stereotype", Uml::ID::toString(m_pStereotype->id()));
848  if (m_bStatic)
849  qElement.setAttribute("ownerScope", "classifier");
850  /* else
851  qElement.setAttribute("ownerScope", "instance");
852  *** ownerScope defaults to instance if not set **********/
853  return qElement;
854 }
855 
862 bool UMLObject::load(QDomElement&)
863 {
864  // This body is not usually executed because child classes
865  // overwrite the load method.
866  return true;
867 }
868 
875 bool UMLObject::loadStereotype(QDomElement & element)
876 {
877  QString tag = element.tagName();
878  if (!UMLDoc::tagEq(tag, "stereotype"))
879  return false;
880  QString stereo = element.attribute("xmi.value", "");
881  if (stereo.isEmpty() && element.hasChildNodes()) {
882  /* like so:
883  <UML:ModelElement.stereotype>
884  <UML:Stereotype xmi.idref = '07CD'/>
885  </UML:ModelElement.stereotype>
886  */
887  QDomNode stereoNode = element.firstChild();
888  QDomElement stereoElem = stereoNode.toElement();
889  tag = stereoElem.tagName();
890  if (UMLDoc::tagEq(tag, "Stereotype")) {
891  stereo = stereoElem.attribute("xmi.idref", "");
892  }
893  }
894  if (stereo.isEmpty())
895  return false;
896  Uml::ID::Type stereoID = Uml::ID::fromString(stereo);
897  UMLDoc *pDoc = UMLApp::app()->document();
898  m_pStereotype = pDoc->findStereotypeById(stereoID);
899  if (m_pStereotype)
900  m_pStereotype->incrRefCount();
901  else
902  m_SecondaryId = stereo; // leave it to resolveRef()
903  return true;
904 }
905 
914 bool UMLObject::loadFromXMI(QDomElement & element)
915 {
916  UMLDoc* umldoc = UMLApp::app()->document();
917  if (umldoc == 0) {
918  uError() << "umldoc is NULL";
919  return false;
920  }
921  // Read the name first so that if we encounter a problem, the error
922  // message can say the name.
923  m_name = element.attribute("name", "");
924  QString id = element.attribute("xmi.id", "");
925  if (id.isEmpty() || id == "-1") {
926  if (m_BaseType == ot_Role) {
927  // Before version 1.4, Umbrello did not save the xmi.id
928  // of UMLRole objects.
929  m_nId = UniqueID::gen();
930  } else {
931  uError() << m_name << ": nonexistent or illegal xmi.id";
932  return false;
933  }
934  } else {
935  Uml::ID::Type nId = Uml::ID::fromString(id);
936  if (m_BaseType == ot_Role) {
937  // Some older Umbrello versions had a problem with xmi.id's
938  // of other objects being reused for the UMLRole, see e.g.
939  // attachment 21179 at http://bugs.kde.org/147988 .
940  // If the xmi.id is already being used then we generate a new one.
941  UMLObject *o = umldoc->findObjectById(nId);
942  if (o) {
943  uError() << "loadFromXMI(UMLRole): id " << id
944  << " is already in use!!! Please fix your XMI file.";
945  }
946  }
947  m_nId = nId;
948  }
949 
950  if (element.hasAttribute("documentation")) // for bkwd compat.
951  m_Doc = element.attribute("documentation", "");
952  else
953  m_Doc = element.attribute("comment", ""); //CHECK: need a UML:Comment?
954 
955  m_visibility = Uml::Visibility::Public;
956  if (element.hasAttribute("scope")) { // for bkwd compat.
957  QString scope = element.attribute("scope", "");
958  if (scope == "instance_level") // nsuml compat.
959  m_bStatic = false;
960  else if (scope == "classifier_level") // nsuml compat.
961  m_bStatic = true;
962  else {
963  int nScope = scope.toInt();
964  switch (nScope) {
965  case 200:
966  m_visibility = Uml::Visibility::Public;
967  break;
968  case 201:
969  m_visibility = Uml::Visibility::Private;
970  break;
971  case 202:
972  m_visibility = Uml::Visibility::Protected;
973  break;
974  default:
975  uError() << m_name << ": illegal scope " << nScope;
976  }
977  }
978  } else {
979  QString visibility = element.attribute("visibility", "public");
980  if (visibility == "private"
981  || visibility == "private_vis") // for compatibility with other programs
982  m_visibility = Uml::Visibility::Private;
983  else if (visibility == "protected"
984  || visibility == "protected_vis") // for compatibility with other programs
985  m_visibility = Uml::Visibility::Protected;
986  else if (visibility == "implementation")
987  m_visibility = Uml::Visibility::Implementation;
988  }
989 
990  QString stereo = element.attribute("stereotype", "");
991  if (!stereo.isEmpty()) {
992  Uml::ID::Type stereoID = Uml::ID::fromString(stereo);
993  m_pStereotype = umldoc->findStereotypeById(stereoID);
994  if (m_pStereotype) {
995  m_pStereotype->incrRefCount();
996  } else {
997  uDebug() << m_name << ": UMLStereotype " << Uml::ID::toString(stereoID)
998  << " not found, creating now.";
999  setStereotype(stereo);
1000  }
1001  }
1002 
1003  if (element.hasAttribute("abstract")) { // for bkwd compat.
1004  QString abstract = element.attribute("abstract", "0");
1005  m_bAbstract = (bool)abstract.toInt();
1006  } else {
1007  QString isAbstract = element.attribute("isAbstract", "false");
1008  m_bAbstract = (isAbstract == "true");
1009  }
1010 
1011  if (element.hasAttribute("static")) { // for bkwd compat.
1012  QString staticScope = element.attribute("static", "0");
1013  m_bStatic = (bool)staticScope.toInt();
1014  } else {
1015  QString ownerScope = element.attribute("ownerScope", "instance");
1016  m_bStatic = (ownerScope == "classifier");
1017  }
1018 
1019  // If the node has child nodes, check whether attributes can be
1020  // extracted from them.
1021  if (element.hasChildNodes()) {
1022  QDomNode node = element.firstChild();
1023  if (node.isComment())
1024  node = node.nextSibling();
1025  QDomElement elem = node.toElement();
1026  while (!elem.isNull()) {
1027  QString tag = elem.tagName();
1028  if (UMLDoc::tagEq(tag, "name")) {
1029  m_name = elem.attribute("xmi.value", "");
1030  if (m_name.isEmpty())
1031  m_name = elem.text();
1032  } else if (UMLDoc::tagEq(tag, "visibility")) {
1033  QString vis = elem.attribute("xmi.value", "");
1034  if (vis.isEmpty())
1035  vis = elem.text();
1036  if (vis == "private" || vis == "private_vis")
1037  m_visibility = Uml::Visibility::Private;
1038  else if (vis == "protected" || vis == "protected_vis")
1039  m_visibility = Uml::Visibility::Protected;
1040  else if (vis == "implementation")
1041  m_visibility = Uml::Visibility::Implementation;
1042  } else if (UMLDoc::tagEq(tag, "isAbstract")) {
1043  QString isAbstract = elem.attribute("xmi.value", "");
1044  if (isAbstract.isEmpty())
1045  isAbstract = elem.text();
1046  m_bAbstract = (isAbstract == "true");
1047  } else if (UMLDoc::tagEq(tag, "ownerScope")) {
1048  QString ownerScope = elem.attribute("xmi.value", "");
1049  if (ownerScope.isEmpty())
1050  ownerScope = elem.text();
1051  m_bStatic = (ownerScope == "classifier");
1052  } else {
1053  loadStereotype(elem);
1054  }
1055  node = node.nextSibling();
1056  if (node.isComment())
1057  node = node.nextSibling();
1058  elem = node.toElement();
1059  }
1060  }
1061 
1062  // Operations, attributes, enum literals, templates, stereotypes,
1063  // and association role objects get added and signaled elsewhere.
1064  if (m_BaseType != ot_Operation && m_BaseType != ot_Attribute &&
1065  m_BaseType != ot_EnumLiteral && m_BaseType != ot_EntityAttribute &&
1066  m_BaseType != ot_Template && m_BaseType != ot_Stereotype &&
1067  m_BaseType != ot_Role && m_BaseType != ot_UniqueConstraint &&
1068  m_BaseType != ot_ForeignKeyConstraint) {
1069  // Todo: refactor outside of loadFromXmi()
1070  //
1071  // Determine parent of new object:
1072  // * if m_bInPaste=true, object was pasted in the tree view -> get package from current
1073  // * if there's no package and we're not loading a XMI file, object was
1074  // pasted from another instance of umbrello -> get package from current
1075  if (m_bInPaste || (!m_pUMLPackage && !umldoc->loading())) {
1076  m_pUMLPackage = Model_Utils::treeViewGetPackageFromCurrent();
1077  }
1078  if (m_pUMLPackage) {
1079  m_pUMLPackage->addObject(this);
1080  } else if (umldoc->rootFolderType(this) == Uml::ModelType::N_MODELTYPES) {
1081  // m_pUMLPackage is not set on the root folders.
1082  uDebug() << m_name << ": m_pUMLPackage is not set";
1083  }
1084  }
1085  return load(element);
1086 }
1087 
1094 QString UMLObject::toString(ObjectType ot)
1095 {
1096  return QLatin1String(ENUM_NAME(UMLObject, ObjectType, ot));
1097 }
1098 
1103 QDebug operator<<(QDebug out, const UMLObject& obj)
1104 {
1105  out.nospace() << "UMLObject: name= " << obj.name()
1106  << ", type= " << UMLObject::toString(obj.m_BaseType);
1107  return out.space();
1108 }
1109 
1110 #include "umlobject.moc"
object_factory.h
UMLDoc::rootFolderType
Uml::ModelType::Enum rootFolderType(UMLObject *obj)
Return the corresponding Model_Type if the given object is one of the root folders.
Definition: umldoc.cpp:2691
UMLObject::packages
UMLPackageList packages(bool includeRoot=false) const
Return a list of the packages in which this class is embedded.
Definition: umlobject.cpp:623
UMLObject::m_Doc
QString m_Doc
object's documentation
Definition: umlobject.h:172
UMLObject::copyInto
virtual void copyInto(UMLObject *lhs) const
Copy the internal presentation of this object into the new object.
Definition: umlobject.cpp:287
UMLObject::ot_EnumLiteral
Definition: umlobject.h:60
UMLObject::setName
virtual void setName(const QString &strName)
Set the UMLObject's name.
Definition: umlobject.cpp:168
umlobject.h
UMLPackage
This class contains the non-graphical information required for a UML Package.
Definition: package.h:32
UMLObject::ot_Component
Definition: umlobject.h:62
UniqueID::init
void init()
Reinitialize the unique ID counter.
Definition: uniqueid.cpp:37
UMLObject::m_bStatic
bool m_bStatic
flag for instance scope
Definition: umlobject.h:179
UMLObject::showPropertiesPagedDialog
virtual bool showPropertiesPagedDialog(int page=0, bool assoc=false)
This method is called if you wish to see the properties of a UMLObject.
Definition: umlobject.cpp:120
UniqueID::gen
Uml::ID::Type gen()
MAIN FUNCTION: Return a new unique ID.
Definition: uniqueid.cpp:26
UMLObject::setUMLStereotype
void setUMLStereotype(UMLStereotype *stereo)
Sets the class' UMLStereotype.
Definition: umlobject.cpp:468
Import_Utils::newUMLObjectWasCreated
bool newUMLObjectWasCreated()
Returns whether the last createUMLObject() actually created a new object or just returned an existing...
Definition: import_utils.cpp:112
UMLObject::loadFromXMI
virtual bool loadFromXMI(QDomElement &element)
This method loads the generic parts of the XMI common to most model classes.
Definition: umlobject.cpp:914
UMLStereotype::incrRefCount
void incrRefCount()
Increments the reference count for this stereotype.
Definition: stereotype.cpp:122
UMLObject::operator==
bool operator==(const UMLObject &rhs) const
Overloaded '==' operator.
Definition: umlobject.cpp:228
Uml::Visibility::Enum
Enum
Definition: basictypes.h:56
UMLObject::ot_Role
Definition: umlobject.h:66
UMLObject::visibility
Uml::Visibility::Enum visibility() const
Returns the visibility of the object.
Definition: umlobject.cpp:435
UMLObject::secondaryFallback
QString secondaryFallback() const
Return secondary ID fallback.
Definition: umlobject.cpp:668
UMLStereotype::decrRefCount
void decrRefCount()
Decrements the reference count for this stereotype.
Definition: stereotype.cpp:130
UMLDoc::tagEq
static bool tagEq(const QString &tag, const QString &pattern)
Function for comparing tags in XMI files.
Definition: umldoc.cpp:3030
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
UMLObject::setVisibility
void setVisibility(Uml::Visibility::Enum visibility)
Sets the visibility of the object.
Definition: umlobject.cpp:445
UMLObject::setNameCmd
void setNameCmd(const QString &strName)
Method used by setName: it is called by cmdSetName, Don't use it!
Definition: umlobject.cpp:176
Uml::CmdRenameUMLObject
Definition: cmd_renameUMLObject.h:20
QWidget
UMLApp::app
static UMLApp * app()
Get the last created instance of this class.
Definition: uml.cpp:206
UMLObject::setStereotypeCmd
void setStereotypeCmd(const QString &_name)
Definition: umlobject.cpp:507
UMLObject::init
void init()
Initializes key variables of the class.
Definition: umlobject.cpp:96
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
UMLObject::loadStereotype
bool loadStereotype(QDomElement &element)
Analyzes the given QDomElement for a reference to a stereotype.
Definition: umlobject.cpp:875
UMLObject::ot_UniqueConstraint
Definition: umlobject.h:71
UMLStereotype
This class is used to set up information for a stereotype.
Definition: stereotype.h:40
UMLObject::ot_Operation
Definition: umlobject.h:59
UMLObject::ot_Template
Definition: umlobject.h:61
UMLObject::setPackage
void setPackage(const QString &_name)
Sets the classes Package.
Definition: umlobject.cpp:518
ClassPropDlg
Definition: classpropdlg.h:34
QObject
UMLApp::document
UMLDoc * document() const
Returns a pointer to the current document connected to the KMainWindow instance.
Definition: uml.cpp:872
UMLDoc::findStereotypeById
UMLStereotype * findStereotypeById(Uml::ID::Type id)
Find a UMLStereotype by its unique ID.
Definition: umldoc.cpp:787
DEBUG_REGISTER_DISABLED
#define DEBUG_REGISTER_DISABLED(src)
Definition: debug_utils.h:103
model_utils.h
debug_utils.h
UMLListViewItem::ID
Uml::ID::Type ID() const
Returns the id this class represents.
Definition: umllistviewitem.cpp:268
Uml::Visibility::Private
Definition: basictypes.h:58
UMLObject
This class is the non-graphical version of UMLWidget.
Definition: umlobject.h:41
UMLDoc::loading
bool loading() const
Returns true when loading a document file.
Definition: umldoc.cpp:1241
ENUM_NAME
#define ENUM_NAME(o, e, v)
In a Q_OBJECT class define any enum as Q_ENUMS.
Definition: debug_utils.h:114
UMLObject::~UMLObject
virtual ~UMLObject()
Standard destructor.
Definition: umlobject.cpp:89
UMLDoc::datatypeFolder
UMLFolder * datatypeFolder() const
Returns the datatype folder.
Definition: umldoc.cpp:2451
UMLDoc::removeStereotype
void removeStereotype(UMLStereotype *s)
Remove a UMLStereotype from the application.
Definition: umldoc.cpp:935
docwindow.h
UMLObject::m_bCreationWasSignalled
bool m_bCreationWasSignalled
auxiliary to maybeSignalObjectCreated()
Definition: umlobject.h:181
UMLObject::m_pStereotype
UMLStereotype * m_pStereotype
stereotype of the object if applicable
Definition: umlobject.h:174
Object_Factory::createUMLObject
UMLObject * createUMLObject(UMLObject::ObjectType type, const QString &n, UMLPackage *parentPkg, bool solicitNewName)
Creates a UMLObject of the given type.
Definition: object_factory.cpp:162
UMLObject::acceptAssociationType
virtual bool acceptAssociationType(Uml::AssociationType::Enum)
This should be reimplemented by subclasses if they wish to accept certain types of associations...
Definition: umlobject.cpp:149
DocWindow
Definition: docwindow.h:28
UMLObject::toString
static QString toString(ObjectType ot)
Helper function for debug output.
Definition: umlobject.cpp:1094
UMLListViewItem::type
ListViewType type() const
Returns the type this instance represents.
Definition: umllistviewitem.cpp:231
UMLObject::resolveRef
virtual bool resolveRef()
Resolve referenced objects (if any.) Needs to be called after all UML objects are loaded from file...
Definition: umlobject.cpp:709
UMLApp::docWindow
DocWindow * docWindow() const
Returns the doc window used.
Definition: uml.cpp:1673
Model_Utils::uniqObjectName
QString uniqObjectName(UMLObject::ObjectType type, UMLPackage *parentPkg, QString prefix)
Returns a name for the new object, appended with a number if the default name is taken e...
Definition: model_utils.cpp:452
Import_Utils::createUMLObject
UMLObject * createUMLObject(UMLObject::ObjectType type, const QString &inName, UMLPackage *parentPkg, const QString &comment, const QString &stereotype)
Find or create a document object.
Definition: import_utils.cpp:169
UMLApp::executeCommand
void executeCommand(QUndoCommand *cmd)
Execute a command and pushit in the stack.
Definition: uml.cpp:3077
UMLObject::setUMLPackage
bool setUMLPackage(UMLPackage *pPkg)
Sets the UMLPackage in which this class is located.
Definition: umlobject.cpp:545
Model_Utils::isCommonDataType
bool isCommonDataType(QString type)
Return true if the given type is common among the majority of programming languages, such as "bool" or "boolean".
Definition: model_utils.cpp:528
UMLObject::ot_Folder
Definition: umlobject.h:69
UMLObject::setDoc
void setDoc(const QString &d)
Sets the documentation for the object.
Definition: umlobject.cpp:424
Uml::Visibility::Implementation
Definition: basictypes.h:60
Type
Type
Definition: preprocesslexer.h:59
UMLObject::UMLObject
UMLObject(UMLObject *parent, const QString &name, Uml::ID::Type id=Uml::ID::None)
Creates a UMLObject.
Definition: umlobject.cpp:48
UMLObject::setVisibilityCmd
void setVisibilityCmd(Uml::Visibility::Enum visibility)
Method used by setVisibility: it is called by cmdSetVisibility, Don't use it!
Definition: umlobject.cpp:453
UMLApp::activeLanguageScopeSeparator
QString activeLanguageScopeSeparator()
Return the target language depedent scope separator.
Definition: uml.cpp:2373
Uml::AssociationType::Enum
Enum
Definition: basictypes.h:99
UMLObject::m_SecondaryFallback
QString m_SecondaryFallback
Last-chance backup for when m_SecondaryId is not found.
Definition: umlobject.h:189
UMLApp
The base class for UML application windows.
Definition: uml.h:81
UMLObject::maybeSignalObjectCreated
void maybeSignalObjectCreated()
Calls UMLDoc::signalUMLObjectCreated() if m_BaseType affords doing so.
Definition: umlobject.cpp:686
stereotype.h
UMLFolder
This class manages the UMLObjects and UMLViews of a Folder.
Definition: folder.h:34
uDebug
#define uDebug()
Definition: debug_utils.h:95
UMLPackageList
QList< UMLPackage * > UMLPackageList
Definition: umlpackagelist.h:17
Uml::Visibility::toString
QString toString(Enum item, bool mnemonic)
Convert Visibility item into QString representation.
Definition: basictypes.cpp:99
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
UMLObject::emitModified
void emitModified()
Forces the emission of the modified signal.
Definition: umlobject.cpp:354
UMLObject::ot_ForeignKeyConstraint
Definition: umlobject.h:72
UMLObject::baseTypeStr
QLatin1String baseTypeStr() const
Definition: umlobject.cpp:374
operator<<
QDebug operator<<(QDebug out, const UMLObject &obj)
Print UML Object to debug output stream, so it can be used like uDebug() << "This object shouldn't be...
Definition: umlobject.cpp:1103
UMLObject::stereotype
QString stereotype(bool includeAdornments=false) const
Returns the stereotype.
Definition: umlobject.cpp:581
Uml::ID::Type
std::string Type
Definition: basictypes.h:317
UMLDoc::closing
bool closing() const
Returns the m_bClosing flag.
Definition: umldoc.cpp:1259
Uml::Visibility::Public
Definition: basictypes.h:57
folder.h
UMLObject::ot_Attribute
Definition: umlobject.h:58
UMLObject::baseType
ObjectType baseType() const
Returns the type of the object.
Definition: umlobject.cpp:366
UMLObject::m_BaseType
ObjectType m_BaseType
objects type
Definition: umlobject.h:176
Uml::ID::toString
QString toString(const ID::Type &id)
Definition: basictypes.cpp:1048
UMLDoc::findObjectById
UMLObject * findObjectById(Uml::ID::Type id)
Used to find a reference to a UMLObject by its ID.
Definition: umldoc.cpp:766
UMLObject::m_name
QString m_name
objects name
Definition: umlobject.h:175
UMLPackage::addObject
bool addObject(UMLObject *pObject)
Adds an object in this package.
Definition: package.cpp:130
UMLObject::isStatic
bool isStatic() const
Returns true if this UMLObject has classifier scope, otherwise false (the default).
Definition: umlobject.cpp:335
UMLObject::ot_Association
Definition: umlobject.h:57
UMLObject::m_pUMLPackage
UMLPackage * m_pUMLPackage
package the object belongs to if applicable
Definition: umlobject.h:173
UMLObject::save
QDomElement save(const QString &tag, QDomDocument &qDoc)
Auxiliary to saveToXMI.
Definition: umlobject.cpp:808
cmds.h
umldoc.h
UMLObject::load
virtual bool load(QDomElement &element)
Auxiliary to loadFromXMI.
Definition: umlobject.cpp:862
UMLObject::umlPackage
UMLPackage * umlPackage()
Returns the UMLPackage that this class is located in.
Definition: umlobject.cpp:641
UMLDoc::findOrCreateStereotype
UMLStereotype * findOrCreateStereotype(const QString &name)
Finds or creates a stereotype for the parent object.
Definition: umldoc.cpp:1054
UMLObject::m_bInPaste
bool m_bInPaste
caller sets this true when in paste operation
Definition: umlobject.h:180
UMLObject::ObjectType
ObjectType
Definition: umlobject.h:47
UMLObject::setSecondaryFallback
void setSecondaryFallback(const QString &id)
Set the secondary ID fallback.
Definition: umlobject.cpp:677
Uml::ModelType::N_MODELTYPES
Definition: basictypes.h:44
UMLObject::ot_Class
Definition: umlobject.h:56
package.h
UMLObject::setInPaste
void setInPaste(bool bInPaste=true)
Definition: umlobject.cpp:326
Model_Utils::treeViewGetPackageFromCurrent
UMLPackage * treeViewGetPackageFromCurrent()
Return the UMLPackage if the current item in the tree view is a package.
Definition: model_utils.cpp:391
UMLObject::package
QString package(const QString &separator=QString(), bool includeRoot=false)
Return the package(s) in which this UMLObject is contained as a text.
Definition: umlobject.cpp:603
import_utils.h
UMLObject::ot_UMLObject
Definition: umlobject.h:49
UMLObject::secondaryId
QString secondaryId() const
Return secondary ID.
Definition: umlobject.cpp:649
umllistview.h
uError
#define uError()
Definition: debug_utils.h:96
classpropdlg.h
UMLObject::m_bAbstract
bool m_bAbstract
state of whether the object is abstract or not
Definition: umlobject.h:178
UMLDoc::modelID
Uml::ID::Type modelID() const
Return the m_modelID (currently this a fixed value: Umbrello supports only a single document...
Definition: umldoc.cpp:1650
UMLObject::name
QString name() const
Returns a copy of m_name.
Definition: umlobject.cpp:185
UMLObject::setSecondaryId
void setSecondaryId(const QString &id)
Set the secondary ID.
Definition: umlobject.cpp:659
uniqueid.h
UMLObject::ot_Stereotype
Definition: umlobject.h:65
UMLStereotype::refCount
int refCount() const
Returns the reference count for this stereotype.
Definition: stereotype.cpp:138
UMLObject::ot_Package
Definition: umlobject.h:52
UMLObject::setID
virtual void setID(Uml::ID::Type NewID)
Assigns a new Id to the object.
Definition: umlobject.cpp:159
UMLObject::setAbstract
void setAbstract(bool bAbstract)
Sets the paste state of the object.
Definition: umlobject.cpp:320
UMLObject::isAbstract
bool isAbstract() const
Returns the abstract state of the object.
Definition: umlobject.cpp:312
UMLObject::m_SecondaryId
QString m_SecondaryId
xmi.id of the secondary object for intermediate use during loading.
Definition: umlobject.h:186
Uml::ID::fromString
ID::Type fromString(const QString &id)
Definition: basictypes.cpp:1053
Uml::CmdSetVisibility
Definition: cmd_setVisibility.h:22
UMLObject::setBaseType
virtual void setBaseType(ObjectType ot)
Set the type of the object.
Definition: umlobject.cpp:384
UMLObject::setStatic
void setStatic(bool bStatic)
Sets the value for m_bStatic.
Definition: umlobject.cpp:343
UMLObject::fullyQualifiedName
virtual QString fullyQualifiedName(const QString &separator=QString(), bool includeRoot=false) const
Returns the fully qualified name, i.e.
Definition: umlobject.cpp:201
UMLObject::m_visibility
Uml::Visibility::Enum m_visibility
objects visibility
Definition: umlobject.h:177
Uml::ID::None
const Type None
special value for uninitialized ID
Definition: basictypes.h:319
UMLDoc::findUMLObject
UMLObject * findUMLObject(const QString &name, UMLObject::ObjectType type=UMLObject::ot_UMLObject, UMLObject *currentObj=0)
Used to find a UMLObject by its type and name.
Definition: umldoc.cpp:809
UMLObject::modified
void modified()
Uml::Visibility::Protected
Definition: basictypes.h:59
UMLObject::setStereotype
void setStereotype(const QString &_name)
Sets the classes stereotype name.
Definition: umlobject.cpp:494
UMLObject::ot_Datatype
Definition: umlobject.h:54
UMLObject::umlStereotype
const UMLStereotype * umlStereotype()
Returns the classes UMLStereotype object.
Definition: umlobject.cpp:573
UMLObject::m_nId
Uml::ID::Type m_nId
object's id
Definition: umlobject.h:171
UMLObject::ot_EntityAttribute
Definition: umlobject.h:68
UMLObject::m_pSecondary
UMLObject * m_pSecondary
pointer to an associated object Only a few of the classes inheriting from UMLObject use this...
Definition: umlobject.h:182
uml.h
UMLDoc::signalUMLObjectCreated
void signalUMLObjectCreated(UMLObject *o)
Signal that a UMLObject has been created.
Definition: umldoc.cpp:1619
UMLObject::doc
QString doc() const
Returns the documentation for the object.
Definition: umlobject.cpp:404
UMLObject::hasDoc
bool hasDoc() const
Returns state of documentation for the object.
Definition: umlobject.cpp:414
UMLDoc
UMLDoc provides a document object for a document-view model.
Definition: umldoc.h:63
UMLObject::id
virtual Uml::ID::Type id() const
Returns the ID of the object.
Definition: umlobject.cpp:394
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:06:00 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