• 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
enum.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) 2003-2013 *
8  * Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
9  ***************************************************************************/
10 
11 // own header
12 #include "enum.h"
13 
14 // app includes
15 #include "debug_utils.h"
16 #include "enumliteral.h"
17 #include "umldoc.h"
18 #include "uml.h"
19 #include "uniqueid.h"
20 #include "idchangelog.h"
21 
22 // kde includes
23 #include <klocale.h>
24 #include <kmessagebox.h>
25 
31 UMLEnum::UMLEnum(const QString& name, Uml::ID::Type id) : UMLClassifier(name, id)
32 {
33  init();
34 }
35 
39 UMLEnum::~UMLEnum()
40 {
41  m_List.clear();
42 }
43 
47 bool UMLEnum::operator==(const UMLEnum & rhs) const
48 {
49  return UMLClassifier::operator==(rhs);
50 }
51 
56 void UMLEnum::copyInto(UMLObject *lhs) const
57 {
58  UMLClassifier::copyInto(lhs);
59 }
60 
64 UMLObject* UMLEnum::clone() const
65 {
66  UMLEnum *clone = new UMLEnum();
67  copyInto(clone);
68 
69  return clone;
70 }
71 
75 void UMLEnum::init()
76 {
77  m_BaseType = UMLObject::ot_Enum;
78  setStereotype("enum");
79 }
80 
85 UMLObject* UMLEnum::createEnumLiteral(const QString& name)
86 {
87  Uml::ID::Type id = UniqueID::gen();
88  QString currentName;
89  if (name.isNull()) {
90  currentName = uniqChildName(UMLObject::ot_EnumLiteral);
91  } else {
92  currentName = name;
93  }
94 
95  UMLEnumLiteral* newEnumLiteral = new UMLEnumLiteral(this, currentName);
96 
97  bool ok = true;
98  bool goodName = false;
99 
100  //check for name.isNull() stops dialog being shown
101  //when creating enum literal via list view
102  while (ok && !goodName && name.isNull()) {
103  ok = newEnumLiteral->showPropertiesDialog(UMLApp::app());
104  QString name = newEnumLiteral->name();
105 
106  if(name.length() == 0) {
107  KMessageBox::error(0, i18n("That is an invalid name."), i18n("Invalid Name"));
108  } else {
109  goodName = true;
110  }
111  }
112 
113  if (!ok) {
114  delete newEnumLiteral;
115  return NULL;
116  }
117 
118  addEnumLiteral(newEnumLiteral);
119 
120  UMLDoc *umldoc = UMLApp::app()->document();
121  umldoc->signalUMLObjectCreated(newEnumLiteral);
122  return newEnumLiteral;
123 }
124 
132 UMLObject* UMLEnum::addEnumLiteral(const QString &name, Uml::ID::Type id)
133 {
134  UMLObject *el = UMLCanvasObject::findChildObject(name);
135  if (el != NULL) {
136  uDebug() << name << " is already present";
137  return el;
138  }
139  UMLEnumLiteral* literal = new UMLEnumLiteral(this, name, id);
140  m_List.append(literal);
141  UMLObject::emitModified();
142  emit enumLiteralAdded(literal);
143  connect(literal, SIGNAL(modified()), this, SIGNAL(modified()));
144  return literal;
145 }
146 
154 bool UMLEnum::addEnumLiteral(UMLEnumLiteral* literal, IDChangeLog* Log /* = 0*/)
155 {
156  QString name = (QString)literal->name();
157  if (findChildObject(name) == NULL) {
158  literal->setParent(this);
159  m_List.append(literal);
160  UMLObject::emitModified();
161  emit enumLiteralAdded(literal);
162  connect(literal, SIGNAL(modified()), this, SIGNAL(modified()));
163  return true;
164  } else if (Log) {
165  Log->removeChangeByNewID(literal->id());
166  delete literal;
167  }
168  return false;
169 }
170 
180 bool UMLEnum::addEnumLiteral(UMLEnumLiteral* literal, int position)
181 {
182  QString name = (QString)literal->name();
183  if (findChildObject(name) == NULL) {
184  literal->setParent(this);
185  if (position >= 0 && position <= (int)m_List.count()) {
186  m_List.insert(position, literal);
187  } else {
188  m_List.append(literal);
189  }
190  UMLObject::emitModified();
191  emit enumLiteralAdded(literal);
192  connect(literal, SIGNAL(modified()), this, SIGNAL(modified()));
193  return true;
194  }
195  return false;
196 }
197 
204 int UMLEnum::removeEnumLiteral(UMLEnumLiteral* literal)
205 {
206  if (!m_List.removeAll(literal)) {
207  uDebug() << "can not find att given in list";
208  return -1;
209  }
210  emit enumLiteralRemoved(literal);
211  UMLObject::emitModified();
212  // If we are deleting the object, then we don't need to disconnect..this is done auto-magically
213  // for us by QObject. -b.t.
214  // disconnect(a, SIGNAL(modified()), this, SIGNAL(modified()));
215  delete literal;
216  return m_List.count();
217 }
218 
223 int UMLEnum::enumLiterals()
224 {
225  return m_List.count();
226 }
227 
231 void UMLEnum::signalEnumLiteralRemoved(UMLClassifierListItem *elit)
232 {
233  emit enumLiteralRemoved(elit);
234 }
235 
239 void UMLEnum::saveToXMI(QDomDocument& qDoc, QDomElement& qElement)
240 {
241  QDomElement enumElement = UMLObject::save("UML:Enumeration", qDoc);
242  // save enum literals
243  UMLClassifierListItemList enumLiterals = getFilteredList(UMLObject::ot_EnumLiteral);
244  foreach (UMLClassifierListItem* pEnumLiteral, enumLiterals) {
245  pEnumLiteral->saveToXMI(qDoc, enumElement);
246  }
247  qElement.appendChild(enumElement);
248 }
249 
253 bool UMLEnum::load(QDomElement& element)
254 {
255  QDomNode node = element.firstChild();
256  while(!node.isNull()) {
257  if (node.isComment()) {
258  node = node.nextSibling();
259  continue;
260  }
261  QDomElement tempElement = node.toElement();
262  QString tag = tempElement.tagName();
263  if (UMLDoc::tagEq(tag, "EnumerationLiteral") ||
264  UMLDoc::tagEq(tag, "EnumLiteral")) { // for backward compatibility
265  UMLEnumLiteral* pEnumLiteral = new UMLEnumLiteral(this);
266  if(!pEnumLiteral->loadFromXMI(tempElement)) {
267  return false;
268  }
269  m_List.append(pEnumLiteral);
270  } else if (tag == "stereotype") {
271  uDebug() << name() << ": losing old-format stereotype.";
272  } else {
273  uWarning() << "unknown child type in UMLEnum::load";
274  }
275  node = node.nextSibling();
276  }//end while
277  return true;
278 }
279 
288 UMLClassifierListItem* UMLEnum::makeChildObject(const QString& xmiTag)
289 {
290  UMLClassifierListItem* pObject = NULL;
291  if (UMLDoc::tagEq(xmiTag, "EnumerationLiteral") || UMLDoc::tagEq(xmiTag, "EnumLiteral")) {
292  pObject = new UMLEnumLiteral(this);
293  }
294  return pObject;
295 }
296 
297 #include "enum.moc"
UMLEnum::addEnumLiteral
UMLObject * addEnumLiteral(const QString &name, Uml::ID::Type id=Uml::ID::None)
Adds an enumliteral to the enum.
Definition: enum.cpp:132
UMLObject::ot_EnumLiteral
Definition: umlobject.h:60
UMLEnum::copyInto
virtual void copyInto(UMLObject *lhs) const
Copy the internal presentation of this object into the new object.
Definition: enum.cpp:56
UMLClassifierListItemList
This sub-class adds copyInto and clone to the QPtrList base class...
Definition: umlclassifierlistitemlist.h:26
UMLClassifier
This class defines the non-graphical information required for a UML Classifier (ie a class or interfa...
Definition: classifier.h:39
UniqueID::gen
Uml::ID::Type gen()
MAIN FUNCTION: Return a new unique ID.
Definition: uniqueid.cpp:26
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
UMLClassifierListItem
Classifiers (classes, interfaces) have lists of operations, attributes, templates and others...
Definition: classifierlistitem.h:29
idchangelog.h
UMLClassifier::getFilteredList
virtual UMLClassifierListItemList getFilteredList(UMLObject::ObjectType ot) const
Returns the entries in m_List that are of the requested type.
Definition: classifier.cpp:1019
UMLObject::ot_Enum
Definition: umlobject.h:55
UMLDoc::tagEq
static bool tagEq(const QString &tag, const QString &pattern)
Function for comparing tags in XMI files.
Definition: umldoc.cpp:3030
UMLEnum::removeEnumLiteral
int removeEnumLiteral(UMLEnumLiteral *literal)
Removes an enumliteral from the class.
Definition: enum.cpp:204
IDChangeLog
This class contains all the ID translations done for each UMLObject pasted.
Definition: idchangelog.h:26
UMLEnum::~UMLEnum
virtual ~UMLEnum()
Standard destructor.
Definition: enum.cpp:39
UMLApp::app
static UMLApp * app()
Get the last created instance of this class.
Definition: uml.cpp:206
uWarning
#define uWarning()
Definition: debug_utils.h:97
UMLEnum::operator==
bool operator==(const UMLEnum &rhs) const
Overloaded '==' operator.
Definition: enum.cpp:47
UMLApp::document
UMLDoc * document() const
Returns a pointer to the current document connected to the KMainWindow instance.
Definition: uml.cpp:872
IDChangeLog::removeChangeByNewID
void removeChangeByNewID(Uml::ID::Type OldID)
Definition: idchangelog.cpp:124
debug_utils.h
UMLObject
This class is the non-graphical version of UMLWidget.
Definition: umlobject.h:41
UMLEnum::signalEnumLiteralRemoved
void signalEnumLiteralRemoved(UMLClassifierListItem *elit)
Emit the enumLiteralRemoved signal.
Definition: enum.cpp:231
enum.h
UMLEnum::enumLiteralRemoved
void enumLiteralRemoved(UMLClassifierListItem *)
UMLEnum::makeChildObject
virtual UMLClassifierListItem * makeChildObject(const QString &xmiTag)
Create a new ClassifierListObject (enumLiteral) according to the given XMI tag.
Definition: enum.cpp:288
UMLCanvasObject::findChildObject
virtual UMLObject * findChildObject(const QString &n, UMLObject::ObjectType t=UMLObject::ot_UMLObject)
Find a child object with the given name.
Definition: umlcanvasobject.cpp:240
uDebug
#define uDebug()
Definition: debug_utils.h:95
UMLObject::emitModified
void emitModified()
Forces the emission of the modified signal.
Definition: umlobject.cpp:354
UMLEnumLiteral
This class is used to set up information for an enum literal.
Definition: enumliteral.h:25
UMLClassifier::copyInto
virtual void copyInto(UMLObject *lhs) const
Copy the internal presentation of this object into the new object.
Definition: classifier.cpp:665
UMLCanvasObject::m_List
UMLObjectList m_List
List of all the associations in this object.
Definition: umlcanvasobject.h:99
UMLEnum::enumLiteralAdded
void enumLiteralAdded(UMLClassifierListItem *)
enumliteral.h
Uml::ID::Type
std::string Type
Definition: basictypes.h:317
UMLObject::m_BaseType
ObjectType m_BaseType
objects type
Definition: umlobject.h:176
UMLEnum
This class contains the non-graphical information required for a UML Enum.
Definition: enum.h:28
UMLObject::save
QDomElement save(const QString &tag, QDomDocument &qDoc)
Auxiliary to saveToXMI.
Definition: umlobject.cpp:808
umldoc.h
UMLEnum::enumLiterals
int enumLiterals()
Returns the number of enumliterals for the class.
Definition: enum.cpp:223
UMLObject::saveToXMI
virtual void saveToXMI(QDomDocument &qDoc, QDomElement &qElement)=0
UMLEnum::clone
virtual UMLObject * clone() const
Make a clone of this object.
Definition: enum.cpp:64
UMLEnumLiteral::showPropertiesDialog
bool showPropertiesDialog(QWidget *parent)
Display the properties configuration dialog for the enum literal.
Definition: enumliteral.cpp:101
UMLObject::name
QString name() const
Returns a copy of m_name.
Definition: umlobject.cpp:185
uniqueid.h
UMLCanvasObject::uniqChildName
virtual QString uniqChildName(const UMLObject::ObjectType type, const QString &prefix=QString())
Returns a name for the new association, operation, template or attribute appended with a number if th...
Definition: umlcanvasobject.cpp:185
UMLEnum::UMLEnum
UMLEnum(const QString &name=QString(), Uml::ID::Type id=Uml::ID::None)
Sets up an enum.
Definition: enum.cpp:31
UMLEnum::createEnumLiteral
UMLObject * createEnumLiteral(const QString &name=QString())
Creates a literal for the enum.
Definition: enum.cpp:85
UMLEnum::load
bool load(QDomElement &element)
Loads the element including its enumliterals.
Definition: enum.cpp:253
UMLObject::modified
void modified()
UMLClassifier::operator==
bool operator==(const UMLClassifier &rhs) const
Overloaded '==' operator.
Definition: classifier.cpp:648
UMLObject::setStereotype
void setStereotype(const QString &_name)
Sets the classes stereotype name.
Definition: umlobject.cpp:494
UMLEnum::saveToXMI
virtual void saveToXMI(QDomDocument &qDoc, QDomElement &qElement)
Creates the element including its enumliterals.
Definition: enum.cpp:239
uml.h
UMLDoc::signalUMLObjectCreated
void signalUMLObjectCreated(UMLObject *o)
Signal that a UMLObject has been created.
Definition: umldoc.cpp:1619
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: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