enum.cpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #include "enum.h"
00014
00015 #include <kdebug.h>
00016 #include <klocale.h>
00017 #include <kmessagebox.h>
00018
00019 #include "enumliteral.h"
00020 #include "umldoc.h"
00021 #include "uml.h"
00022 #include "clipboard/idchangelog.h"
00023
00024 UMLEnum::UMLEnum(const QString& name, Uml::IDType id) : UMLClassifier(name, id) {
00025 init();
00026 }
00027
00028 UMLEnum::~UMLEnum() {
00029 m_List.clear();
00030 }
00031
00032 bool UMLEnum::operator==( UMLEnum & rhs ) {
00033 return UMLClassifier::operator==(rhs);
00034 }
00035
00036 void UMLEnum::copyInto(UMLEnum *rhs) const
00037 {
00038 UMLClassifier::copyInto(rhs);
00039 }
00040
00041 UMLObject* UMLEnum::clone() const
00042 {
00043 UMLEnum *clone = new UMLEnum();
00044 copyInto(clone);
00045
00046 return clone;
00047 }
00048
00049 void UMLEnum::init() {
00050 m_BaseType = Uml::ot_Enum;
00051 setStereotype( "enum" );
00052 }
00053
00054 UMLObject* UMLEnum::createEnumLiteral() {
00055 QString currentName = uniqChildName(Uml::ot_EnumLiteral);
00056 UMLEnumLiteral* newEnumLiteral = new UMLEnumLiteral(this, currentName);
00057
00058 bool ok = true;
00059 bool goodName = false;
00060
00061 while (ok && !goodName) {
00062 ok = newEnumLiteral->showPropertiesDialog( UMLApp::app() );
00063 QString name = newEnumLiteral->getName();
00064
00065 if(name.length() == 0) {
00066 KMessageBox::error(0, i18n("That is an invalid name."), i18n("Invalid Name"));
00067 } else {
00068 goodName = true;
00069 }
00070 }
00071
00072 if (!ok) {
00073 return NULL;
00074 }
00075
00076 addEnumLiteral(newEnumLiteral);
00077
00078 UMLDoc *umldoc = UMLApp::app()->getDocument();
00079 umldoc->signalUMLObjectCreated(newEnumLiteral);
00080 return newEnumLiteral;
00081 }
00082
00083 UMLObject* UMLEnum::addEnumLiteral(const QString &name, Uml::IDType id) {
00084 UMLObject *el = UMLCanvasObject::findChildObject(name);
00085 if (el != NULL) {
00086 kDebug() << "UMLEnum::addEnumLiteral: " << name
00087 << " is already present" << endl;
00088 return el;
00089 }
00090 UMLEnumLiteral* literal = new UMLEnumLiteral(this, name, id);
00091 m_List.append(literal);
00092 UMLObject::emitModified();
00093 emit enumLiteralAdded(literal);
00094 connect(literal,SIGNAL(modified()),this,SIGNAL(modified()));
00095 return literal;
00096 }
00097
00098 bool UMLEnum::addEnumLiteral(UMLEnumLiteral* literal, IDChangeLog* Log ) {
00099 QString name = (QString)literal->getName();
00100 if (findChildObject(name) == NULL) {
00101 literal->parent()->removeChild(literal);
00102 this->insertChild(literal);
00103 m_List.append(literal);
00104 UMLObject::emitModified();
00105 emit enumLiteralAdded(literal);
00106 connect(literal,SIGNAL(modified()),this,SIGNAL(modified()));
00107 return true;
00108 } else if (Log) {
00109 Log->removeChangeByNewID( literal->getID() );
00110 delete literal;
00111 }
00112 return false;
00113 }
00114
00115 bool UMLEnum::addEnumLiteral(UMLEnumLiteral* literal, int position) {
00116 QString name = (QString)literal->getName();
00117 if (findChildObject(name) == NULL) {
00118 literal->parent()->removeChild(literal);
00119 this->insertChild(literal);
00120 if ( position >= 0 && position <= (int)m_List.count() ) {
00121 m_List.insert(position,literal);
00122 } else {
00123 m_List.append(literal);
00124 }
00125 UMLObject::emitModified();
00126 emit enumLiteralAdded(literal);
00127 connect(literal,SIGNAL(modified()),this,SIGNAL(modified()));
00128 return true;
00129 }
00130 return false;
00131 }
00132
00133 int UMLEnum::removeEnumLiteral(UMLEnumLiteral* literal) {
00134 if (!m_List.remove(literal)) {
00135 kDebug() << "can't find att given in list" << endl;
00136 return -1;
00137 }
00138 emit enumLiteralRemoved(literal);
00139 UMLObject::emitModified();
00140
00141
00142
00143 delete literal;
00144 return m_List.count();
00145 }
00146
00147 int UMLEnum::enumLiterals() {
00148 return m_List.count();
00149 }
00150
00151 void UMLEnum::signalEnumLiteralRemoved(UMLClassifierListItem *elit) {
00152 emit enumLiteralRemoved(elit);
00153 }
00154
00155 void UMLEnum::saveToXMI(QDomDocument& qDoc, QDomElement& qElement) {
00156 QDomElement enumElement = UMLObject::save("UML:Enumeration", qDoc);
00157
00158 UMLClassifierListItemList enumLiterals = getFilteredList(Uml::ot_EnumLiteral);
00159 UMLClassifierListItem* pEnumLiteral = 0;
00160 for (UMLClassifierListItemListIt it(enumLiterals);
00161 (pEnumLiteral = it.current()) != NULL; ++it) {
00162 pEnumLiteral->saveToXMI(qDoc, enumElement);
00163 }
00164 qElement.appendChild(enumElement);
00165 }
00166
00167 bool UMLEnum::load(QDomElement& element) {
00168 QDomNode node = element.firstChild();
00169 while( !node.isNull() ) {
00170 if (node.isComment()) {
00171 node = node.nextSibling();
00172 continue;
00173 }
00174 QDomElement tempElement = node.toElement();
00175 QString tag = tempElement.tagName();
00176 if (Uml::tagEq(tag, "EnumerationLiteral") ||
00177 Uml::tagEq(tag, "EnumLiteral")) {
00178 UMLEnumLiteral* pEnumLiteral = new UMLEnumLiteral(this);
00179 if( !pEnumLiteral->loadFromXMI(tempElement) ) {
00180 return false;
00181 }
00182 m_List.append(pEnumLiteral);
00183 } else if (tag == "stereotype") {
00184 kDebug() << "UMLEnum::load(" << m_Name
00185 << "): losing old-format stereotype." << endl;
00186 } else {
00187 kWarning() << "unknown child type in UMLEnum::load" << endl;
00188 }
00189 node = node.nextSibling();
00190 }
00191 return true;
00192 }
00193
00194
00195 #include "enum.moc"
This file is part of the documentation for umbrello Version 3.1.0.