classifierlistitem.cpp
00001 /*************************************************************************** 00002 * * 00003 * This program is free software; you can redistribute it and/or modify * 00004 * it under the terms of the GNU General Public License as published by * 00005 * the Free Software Foundation; either version 2 of the License, or * 00006 * (at your option) any later version. * 00007 * * 00008 * copyright (C) 2003-2007 * 00009 * Umbrello UML Modeller Authors <uml-devel@uml.sf.net> * 00010 ***************************************************************************/ 00011 00012 // own header 00013 #include "classifierlistitem.h" 00014 00015 // qt/kde includes 00016 #include <kdebug.h> 00017 #include <klocale.h> 00018 00019 // local includes 00020 #include "classifier.h" 00021 #include "uml.h" 00022 #include "umldoc.h" 00023 #include "model_utils.h" 00024 #include "object_factory.h" 00025 00026 UMLClassifierListItem::UMLClassifierListItem(const UMLObject *parent, 00027 const QString& name, Uml::IDType id) 00028 : UMLObject(parent, name, id) { 00029 UMLObject *parentObj = const_cast<UMLObject*>(parent); 00030 UMLClassifier *pc = dynamic_cast<UMLClassifier*>(parentObj); 00031 if (pc) 00032 UMLObject::setUMLPackage(pc); 00033 } 00034 00035 UMLClassifierListItem::UMLClassifierListItem(const UMLObject *parent) 00036 : UMLObject(parent) { 00037 UMLObject *parentObj = const_cast<UMLObject*>(parent); 00038 UMLClassifier *pc = dynamic_cast<UMLClassifier*>(parentObj); 00039 if (pc) 00040 UMLObject::setUMLPackage(pc); 00041 } 00042 00043 UMLClassifierListItem::~UMLClassifierListItem() { 00044 } 00045 00046 void UMLClassifierListItem::copyInto(UMLClassifierListItem *rhs) const 00047 { 00048 // Call the parent. 00049 UMLObject::copyInto(rhs); 00050 } 00051 00052 QString UMLClassifierListItem::toString(Uml::Signature_Type /*sig*/) { 00053 return getName(); 00054 } 00055 00056 UMLClassifier * UMLClassifierListItem::getType() { 00057 return static_cast<UMLClassifier*>(m_pSecondary); 00058 } 00059 00060 QString UMLClassifierListItem::getTypeName() { 00061 if (m_pSecondary == NULL) 00062 return m_SecondaryId; 00063 const UMLPackage *typePkg = m_pSecondary->getUMLPackage(); 00064 if (typePkg != NULL && typePkg != m_pUMLPackage) 00065 return m_pSecondary->getFullyQualifiedName(); 00066 return m_pSecondary->getName(); 00067 } 00068 00069 void UMLClassifierListItem::setType(UMLObject *type) { 00070 if (m_pSecondary != type) { 00071 m_pSecondary = type; 00072 UMLObject::emitModified(); 00073 } 00074 } 00075 00076 void UMLClassifierListItem::setTypeName(const QString &type) { 00077 if (type.isEmpty() || type == "void") { 00078 m_pSecondary = NULL; 00079 m_SecondaryId = QString::null; 00080 return; 00081 } 00082 UMLDoc *pDoc = UMLApp::app()->getDocument(); 00083 m_pSecondary = pDoc->findUMLObject(type); 00084 if (m_pSecondary == NULL) { 00085 // Make data type for easily identified cases 00086 if (Model_Utils::isCommonDataType(type) || type.contains('*')) { 00087 m_pSecondary = Object_Factory::createUMLObject(Uml::ot_Datatype, type); 00088 kDebug() << "UMLClassifierListItem::setTypeName: " 00089 << "created datatype for " << type << endl; 00090 } else { 00091 m_SecondaryId = type; 00092 } 00093 } 00094 UMLObject::emitModified(); 00095 } 00096 00097 00098 #include "classifierlistitem.moc"
