Commit dd847f15 authored by Ralf Habacker's avatar Ralf Habacker

Replace usage of UMLObject::m_pUMLPackage by QObject member 'parent' through...

Replace usage of UMLObject::m_pUMLPackage by QObject member 'parent' through new method umlParent().

In the past UMLObject::m_pUMLPackage has been used in some classes,
while other uses the QObject class member 'parent'. This commit unify
both approaches by using QObject class member 'parent' in all classes.

class UMLObject now has two new functions setUMLParent() and umlParent()
to provides a UMLObject based interface to the parent uml object;
method umlPackage() is now a shortcut of umlParent()->asUMLPackage().

CCBUG:368282
Reviewed-by: aaron.nottbeck at sag.eu
parent fa3f51e7
......@@ -458,7 +458,7 @@ void AdaWriter::writeOperation(UMLOperation *op, QTextStream &ada, bool is_comme
ada << cleanName(op->name()) << " ";
if (! (op->isStatic() && atl.count() == 0))
ada << "(";
UMLClassifier *parentClassifier = static_cast<UMLClassifier*>(op->umlPackage());
UMLClassifier *parentClassifier = op->umlParent()->asUMLClassifier();
if (! op->isStatic()) {
ada << "Self : access " << className(parentClassifier);
if (atl.count())
......
......@@ -510,7 +510,7 @@ UMLAttribute* addMethodParameter(UMLOperation *method,
const QString& type,
const QString& name)
{
UMLClassifier *owner = static_cast<UMLClassifier*>(method->parent());
UMLClassifier *owner = method->umlParent()->asUMLClassifier();
UMLObject *typeObj = owner->findTemplate(type);
if (typeObj == NULL) {
bPutAtGlobalScope = true;
......
......@@ -441,7 +441,7 @@ void UMLForeignKeyConstraintDialog::refillLocalAttributeCB()
m_pLocalAttributeList.clear();
m_ColumnWidgets.localColumnCB->clear();
// fill the combo boxes
UMLEntity* ue = static_cast<UMLEntity*>(m_pForeignKeyConstraint->parent());
UMLEntity* ue = m_pForeignKeyConstraint->umlParent()->asUMLEntity();
if (ue) {
UMLClassifierListItemList ual = ue->getFilteredList(UMLObject::ot_EntityAttribute);
......
......@@ -401,7 +401,7 @@ bool UMLOperationDialog::apply()
return false;
}
UMLClassifier *classifier = dynamic_cast<UMLClassifier*>(m_operation->parent());
UMLClassifier *classifier = m_operation->umlParent()->asUMLClassifier();
if(classifier != 0 &&
classifier->checkOperationSignature(name, m_operation->getParmList(), m_operation))
{
......
......@@ -127,7 +127,7 @@ void UMLUniqueConstraintDialog::setupDialog()
comboButtonHBoxLayout->addWidget(buttonBox);
// We first insert all attributes to the combo box
UMLEntity* ue = static_cast<UMLEntity*>(m_pUniqueConstraint->parent());
UMLEntity* ue = m_pUniqueConstraint->umlParent()->asUMLEntity();
uDebug() << ue;
if (ue) {
UMLClassifierListItemList ual = ue->getFilteredList(UMLObject::ot_EntityAttribute);
......
......@@ -39,7 +39,7 @@ UMLDatatypeWidget::UMLDatatypeWidget(UMLAttribute *attribute, QWidget *parent)
m_template(0)
{
init();
m_parent = dynamic_cast<UMLClassifier*>(m_attribute->parent()->parent());
m_parent = m_attribute->umlParent()->umlParent()->asUMLClassifier();
insertTypesSortedParameter(m_attribute->getTypeName());
}
......@@ -52,7 +52,7 @@ UMLDatatypeWidget::UMLDatatypeWidget(UMLClassifierListItem *datatype, QWidget *p
m_template(0)
{
init();
m_parent = dynamic_cast<UMLClassifier *>(m_datatype->parent());
m_parent = m_datatype->umlParent()->asUMLClassifier();
insertTypesSortedAttribute(m_datatype->getTypeName());
}
......@@ -78,7 +78,7 @@ UMLDatatypeWidget::UMLDatatypeWidget(UMLOperation *operation, QWidget *parent)
m_template(0)
{
init();
m_parent = dynamic_cast<UMLClassifier*>(m_operation->parent());
m_parent = m_operation->umlParent()->asUMLClassifier();
insertTypesSortedOperation(m_operation->getTypeName());
}
......
......@@ -174,7 +174,7 @@ UMLObject* findUMLObject(const UMLObjectList& inList,
if (currentObj) {
UMLPackage *pkg = NULL;
if (currentObj->asUMLClassifierListItem()) {
currentObj = static_cast<UMLObject*>(currentObj->parent());
currentObj = currentObj->umlParent();
}
pkg = currentObj->asUMLPackage();
if (pkg == NULL || pkg->baseType() == UMLObject::ot_Association)
......@@ -1429,7 +1429,7 @@ UMLListViewItem::ListViewType convert_OT_LVT(UMLObject *o)
break;
case UMLObject::ot_UniqueConstraint: {
UMLEntity* ent = static_cast<UMLEntity*>(o->parent());
UMLEntity* ent = o->umlParent()->asUMLEntity();
UMLUniqueConstraint* uc = o->asUMLUniqueConstraint();
if (ent->isPrimaryKey(uc)) {
type = UMLListViewItem::lvt_PrimaryKeyConstraint;
......
......@@ -219,7 +219,7 @@ void RefactoringAssistant::operationAdded(UMLClassifierListItem *listItem)
{
UMLOperation *op = listItem->asUMLOperation();
DEBUG(DBG_SRC) << "operation = " << op->name(); //:TODO:
UMLClassifier *parent = dynamic_cast<UMLClassifier*>(op->parent());
UMLClassifier *parent = op->umlParent()->asUMLClassifier();
if (!parent) {
uWarning() << op->name() << " - Parent of operation is not a classifier!";
return;
......@@ -265,7 +265,7 @@ void RefactoringAssistant::attributeAdded(UMLClassifierListItem *listItem)
{
UMLAttribute *att = listItem->asUMLAttribute();
DEBUG(DBG_SRC) << "attribute = " << att->name(); //:TODO:
UMLClassifier *parent = dynamic_cast<UMLClassifier*>(att->parent());
UMLClassifier *parent = att->umlParent()->asUMLClassifier();
if (!parent) {
uWarning() << att->name() << " - Parent of attribute is not a classifier!";
return;
......@@ -831,7 +831,7 @@ DEBUG(DBG_SRC) << "acceptProposedAction"; //:TODO:fischer
}
UMLOperation* newOp = op->clone()->asUMLOperation();
UMLClassifier *oldClassifier = dynamic_cast<UMLClassifier*>(op->parent());
UMLClassifier *oldClassifier = op->umlParent()->asUMLClassifier();
if (oldClassifier) {
oldClassifier->removeOperation(op);
DEBUG(DBG_SRC) << "oldClassifier=" << oldClassifier->name() << " / newClassifier=" << newClassifier->name(); //:TODO:fischer
......@@ -852,7 +852,7 @@ DEBUG(DBG_SRC) << "acceptProposedAction"; //:TODO:fischer
}
UMLAttribute* newAtt = att->clone()->asUMLAttribute();
UMLClassifier *oldClassifier = dynamic_cast<UMLClassifier*>(att->parent());
UMLClassifier *oldClassifier = att->umlParent()->asUMLClassifier();
if (oldClassifier) {
oldClassifier->removeAttribute(att);
DEBUG(DBG_SRC) << "oldClassifier=" << oldClassifier->name() << " / newClassifier=" << newClassifier->name(); //:TODO:fischer
......
......@@ -1678,7 +1678,7 @@ void UMLDoc::renameUMLObject(UMLObject *o)
void UMLDoc::renameChildUMLObject(UMLObject *o)
{
bool ok = false;
UMLClassifier* p = dynamic_cast<UMLClassifier *>(o->parent());
UMLClassifier* p = o->umlParent()->asUMLClassifier();
if (!p) {
DEBUG(DBG_SRC) << "Cannot create object, no parent found.";
return;
......@@ -1807,7 +1807,7 @@ UMLFolder *UMLDoc::currentRoot()
}
UMLFolder *f = currentView->umlScene()->folder();
while (f->umlPackage()) {
f = static_cast<UMLFolder*>(f->umlPackage());
f = f->umlParent()->asUMLFolder();
}
return f;
}
......@@ -1843,7 +1843,7 @@ void UMLDoc::removeUMLObject(UMLObject* umlobject, bool deleteObject)
umlobject->setUMLStereotype(0); // triggers possible cleanup of UMLStereotype
if (umlobject->asUMLClassifierListItem()) {
UMLClassifier* parent = dynamic_cast<UMLClassifier*>(umlobject->parent());
UMLClassifier* parent = umlobject->umlParent()->asUMLClassifier();
if (parent == 0) {
uError() << "parent of umlobject is NULL";
return;
......
......@@ -1816,7 +1816,7 @@ UMLListViewItem * UMLListView::moveObject(Uml::ID::Type srcId, UMLListViewItem::
break;
}
UMLClassifier *oldParentClassifier = dynamic_cast<UMLClassifier*>(srcObj->parent());
UMLClassifier *oldParentClassifier = srcObj->umlParent()->asUMLClassifier();
UMLClassifier *newParentClassifier = newParentObj->asUMLClassifier();
if (srcType == UMLListViewItem::lvt_Attribute) {
UMLAttribute *att = srcObj->asUMLAttribute();
......@@ -2240,7 +2240,7 @@ void UMLListView::addNewItem(UMLListViewItem *parentItem, UMLListViewItem::ListV
// the parent entity)
if (type == UMLListViewItem::lvt_PrimaryKeyConstraint) {
UMLUniqueConstraint* uuc = object->asUMLUniqueConstraint();
UMLEntity* ent = static_cast<UMLEntity*>(uuc->parent());
UMLEntity* ent = uuc->umlParent()->asUMLEntity();
if (ent) {
ent->setAsPrimaryKey(uuc);
}
......
......@@ -510,7 +510,7 @@ void UMLListViewItem::slotEditFinished(const QString &newText)
return;
}
UMLOperation *op = m_object->asUMLOperation();
UMLClassifier *parent = static_cast<UMLClassifier *>(op->parent());
UMLClassifier *parent = op->umlParent()->asUMLClassifier();
Model_Utils::OpDescriptor od;
Model_Utils::Parse_Status st = Model_Utils::parseOperation(newText, od, parent);
if (st == Model_Utils::PS_OK) {
......@@ -560,7 +560,7 @@ void UMLListViewItem::slotEditFinished(const QString &newText)
cancelRenameWithMsg();
return;
}
UMLClassifier *parent = static_cast<UMLClassifier*>(m_object->parent());
UMLClassifier *parent = m_object->umlParent()->asUMLClassifier();
Model_Utils::NameAndType nt;
Uml::Visibility::Enum vis;
Model_Utils::Parse_Status st;
......@@ -595,7 +595,7 @@ void UMLListViewItem::slotEditFinished(const QString &newText)
cancelRenameWithMsg();
return;
}
UMLEntity *parent = static_cast<UMLEntity*>(m_object->parent());
UMLEntity *parent = m_object->umlParent()->asUMLEntity();
QString name;
Model_Utils::Parse_Status st;
st = Model_Utils::parseConstraint(newText, name, parent);
......@@ -623,7 +623,7 @@ void UMLListViewItem::slotEditFinished(const QString &newText)
cancelRenameWithMsg();
return;
}
UMLClassifier *parent = static_cast<UMLClassifier*>(m_object->parent());
UMLClassifier *parent = m_object->umlParent()->asUMLClassifier();
Model_Utils::NameAndType nt;
Model_Utils::Parse_Status st = Model_Utils::parseTemplate(newText, nt, parent);
if (st == Model_Utils::PS_OK) {
......@@ -731,8 +731,8 @@ int UMLListViewItem::compare(QTreeWidgetItem *other, int col, bool ascending) co
#endif
return retval;
}
UMLClassifier *ourParent = dynamic_cast<UMLClassifier*>(m_object->parent());
UMLClassifier *otherParent = dynamic_cast<UMLClassifier*>(otherObj->parent());
UMLClassifier *ourParent = m_object->umlParent()->asUMLClassifier();
UMLClassifier *otherParent = otherObj->umlParent()->asUMLClassifier();
if (ourParent == 0) {
retval = (subItem ? 1 : alphaOrder);
#ifdef DEBUG_LVITEM_INSERTION_ORDER
......
......@@ -151,7 +151,7 @@ bool UMLAssociation::resolveRef()
if (isRealization(objA, objB)) {
m_AssocType = Uml::AssociationType::Realization;
}
m_pUMLPackage->addAssocToConcepts(this);
umlPackage()->addAssocToConcepts(this);
return true;
}
return false;
......@@ -238,7 +238,7 @@ bool UMLAssociation::load(QDomElement & element)
m_AssocType == Uml::AssociationType::Category2Parent) {
QString general = element.attribute(QLatin1String("general"));
if (!general.isEmpty()) {
UMLClassifier *owningClassifier = m_pUMLPackage->asUMLClassifier();
UMLClassifier *owningClassifier = umlParent()->asUMLClassifier();
if (owningClassifier == NULL){
uWarning() << "Cannot load UML2 generalization: m_pUMLPackage is expected "
<< "to be the owning classifier (=client)";
......@@ -247,8 +247,8 @@ bool UMLAssociation::load(QDomElement & element)
m_pRole[RoleType::A]->setObject(owningClassifier);
m_pRole[RoleType::B]->setSecondaryId(general); // defer resolution to resolveRef()
owningClassifier->addAssociationEnd(this);
m_pUMLPackage = m_pUMLPackage->umlPackage(); // reparent
m_pUMLPackage->addObject(this);
setUMLPackage(umlPackage()->umlPackage()); // reparent
umlPackage()->addObject(this);
return true;
}
for (unsigned r = RoleType::A; r <= RoleType::B; ++r) {
......@@ -268,9 +268,9 @@ bool UMLAssociation::load(QDomElement & element)
m_pRole[role]->setSecondaryId(roleIdStr); // defer to resolveRef()
} else {
m_pRole[role]->setObject(obj[r]);
if (m_pUMLPackage == NULL) {
if (umlPackage() == NULL) {
Uml::ModelType::Enum mt = Model_Utils::convert_OT_MT(obj[r]->baseType());
m_pUMLPackage = doc->rootFolder(mt);
setUMLPackage(doc->rootFolder(mt));
DEBUG(DBG_SRC) << "assoctype " << m_AssocType
<< ": setting model type " << Uml::ModelType::toString(mt);
}
......@@ -378,9 +378,9 @@ bool UMLAssociation::load(QDomElement & element)
if (! getUMLRole(RoleType::B)->loadFromXMI(tempElement))
return false;
if (m_pUMLPackage == NULL) {
if (umlPackage() == NULL) {
Uml::ModelType::Enum mt = Model_Utils::convert_OT_MT(getObject(RoleType::B)->baseType());
m_pUMLPackage = doc->rootFolder(mt);
setUMLPackage(doc->rootFolder(mt));
DEBUG(DBG_SRC) << "setting model type " << Uml::ModelType::toString(mt);
}
......@@ -738,7 +738,7 @@ void UMLAssociation::init(Uml::AssociationType::Enum type, UMLObject *roleAObj,
m_bOldLoadMode = false;
nrof_parent_widgets = -1;
if (!UMLApp::app()->document()->loading()) {
m_pUMLPackage = UMLApp::app()->document()->currentRoot();
setUMLPackage(UMLApp::app()->document()->currentRoot());
}
m_pRole[RoleType::A] = new UMLRole (this, roleAObj, RoleType::A);
m_pRole[RoleType::B] = new UMLRole (this, roleBObj, RoleType::B);
......
......@@ -140,11 +140,11 @@ QString UMLAttribute::toString(Uml::SignatureType::Enum sig)
if (sig == Uml::SignatureType::ShowSig || sig == Uml::SignatureType::SigNoVis) {
// Determine whether the type name needs to be scoped.
UMLObject *owningObject = parent()->asUMLObject();
UMLObject *owningObject = umlParent();
if (owningObject->baseType() == UMLObject::ot_Operation) {
// The immediate parent() is the UMLOperation but we want
// The immediate parent is the UMLOperation but we want
// the UMLClassifier:
owningObject = static_cast<UMLObject*>(owningObject->parent());
owningObject = owningObject->umlParent();
}
UMLClassifier *ownParent = owningObject->asUMLClassifier();
if (ownParent == NULL) {
......@@ -184,10 +184,10 @@ QString UMLAttribute::getFullyQualifiedName(const QString& separator,
bool includeRoot /* = false */) const
{
UMLOperation *op = NULL;
UMLObject *owningObject = parent()->asUMLObject();
UMLObject *owningObject = umlParent();
if (owningObject->baseType() == UMLObject::ot_Operation) {
op = owningObject->asUMLOperation();
owningObject = static_cast<UMLObject*>(owningObject->parent());
owningObject = owningObject->umlParent();
}
UMLClassifier *ownParent = owningObject->asUMLClassifier();
if (ownParent == NULL) {
......@@ -247,7 +247,7 @@ void UMLAttribute::copyInto(UMLObject *lhs) const
UMLObject* UMLAttribute::clone() const
{
//FIXME: The new attribute should be slaved to the NEW parent not the old.
UMLAttribute *clone = new UMLAttribute(parent()->asUMLObject());
UMLAttribute *clone = new UMLAttribute(umlParent());
copyInto(clone);
return clone;
......
......@@ -82,7 +82,7 @@ void UMLCheckConstraint::copyInto(UMLObject *lhs) const
UMLObject* UMLCheckConstraint::clone() const
{
//FIXME: The new attribute should be slaved to the NEW parent not the old.
UMLCheckConstraint *clone = new UMLCheckConstraint(parent()->asUMLObject());
UMLCheckConstraint *clone = new UMLCheckConstraint(umlParent());
copyInto(clone);
return clone;
}
......
......@@ -38,8 +38,7 @@ UMLClassifierListItem::UMLClassifierListItem(UMLObject *parent,
const QString& name, Uml::ID::Type id)
: UMLObject(parent, name, id)
{
UMLObject *parentObj = const_cast<UMLObject*>(parent);
UMLClassifier *pc = parentObj->asUMLClassifier();
UMLClassifier *pc = parent->asUMLClassifier();
if (pc)
UMLObject::setUMLPackage(pc);
}
......@@ -57,8 +56,7 @@ UMLClassifierListItem::UMLClassifierListItem(UMLObject *parent,
UMLClassifierListItem::UMLClassifierListItem(UMLObject *parent)
: UMLObject(parent)
{
UMLObject *parentObj = const_cast<UMLObject*>(parent);
UMLClassifier *pc = parentObj->asUMLClassifier();
UMLClassifier *pc = parent->asUMLClassifier();
if (pc)
UMLObject::setUMLPackage(pc);
}
......@@ -112,7 +110,7 @@ QString UMLClassifierListItem::getTypeName() const
if (m_pSecondary == NULL)
return m_SecondaryId;
const UMLPackage *typePkg = m_pSecondary->umlPackage();
if (typePkg != NULL && typePkg != m_pUMLPackage)
if (typePkg != NULL && typePkg != umlPackage())
return m_pSecondary->fullyQualifiedName();
return m_pSecondary->name();
}
......
......@@ -516,7 +516,7 @@ bool UMLEntity::setAsPrimaryKey(UMLUniqueConstraint* uconstr)
return false;
}
if (static_cast<UMLEntity*>(uconstr->parent()) != this) {
if (uconstr->umlParent()->asUMLEntity() != this) {
uDebug() << "Parent of " << uconstr->name()
<< " does not match with current entity";
......@@ -524,7 +524,7 @@ bool UMLEntity::setAsPrimaryKey(UMLUniqueConstraint* uconstr)
}
// check if this constraint already exists as a unique constraint for this entity
UMLUniqueConstraint* uuc = static_cast<UMLUniqueConstraint*>(findChildObjectById(uconstr->id()));
UMLUniqueConstraint* uuc = findChildObjectById(uconstr->id())->asUMLUniqueConstraint();
if (uuc == NULL) {
addConstraint(uconstr);
uuc = uconstr;
......
......@@ -226,7 +226,7 @@ void UMLEntityAttribute::copyInto(UMLObject *lhs) const
*/
UMLObject* UMLEntityAttribute::clone() const
{
UMLEntityAttribute* clone = new UMLEntityAttribute((UMLEntityAttribute*)parent());
UMLEntityAttribute* clone = new UMLEntityAttribute(umlParent()->asUMLEntityAttribute());
copyInto(clone);
return clone;
......
......@@ -126,7 +126,7 @@ void UMLEnumLiteral::copyInto(UMLObject *lhs) const
*/
UMLObject* UMLEnumLiteral::clone() const
{
UMLEnumLiteral *clone = new UMLEnumLiteral((UMLObject *) parent());
UMLEnumLiteral *clone = new UMLEnumLiteral(umlParent());
copyInto(clone);
return clone;
......
......@@ -362,8 +362,8 @@ void UMLFolder::saveToXMI(QDomDocument& qDoc, QDomElement& qElement)
folderRoot.setAttribute(QLatin1String("name"), name());
folderRoot.setAttribute(QLatin1String("filename"), m_folderFile);
folderRoot.setAttribute(QLatin1String("mainModel"), umldoc->url().fileName());
folderRoot.setAttribute(QLatin1String("parentId"), Uml::ID::toString(m_pUMLPackage->id()));
folderRoot.setAttribute(QLatin1String("parent"), m_pUMLPackage->fullyQualifiedName(QLatin1String("::"), true));
folderRoot.setAttribute(QLatin1String("parentId"), Uml::ID::toString(umlPackage()->id()));
folderRoot.setAttribute(QLatin1String("parent"), umlPackage()->fullyQualifiedName(QLatin1String("::"), true));
saveContents(folderDoc, folderRoot);
folderDoc.appendChild(folderRoot);
QTextStream stream(&file);
......
......@@ -54,7 +54,7 @@ void UMLForeignKeyConstraint::init()
// should be NULL actually
// self referencing assigned to protect default behaviour
m_ReferencedEntity = parent()->asUMLEntity();
m_ReferencedEntity = umlParent()->asUMLEntity();
m_UpdateAction = uda_NoAction;
m_DeleteAction = uda_NoAction;
......@@ -108,7 +108,7 @@ void UMLForeignKeyConstraint::copyInto(UMLObject *lhs) const
UMLObject* UMLForeignKeyConstraint::clone() const
{
//FIXME: The new attribute should be slaved to the NEW parent not the old.
UMLForeignKeyConstraint *clone = new UMLForeignKeyConstraint(parent()->asUMLObject());
UMLForeignKeyConstraint *clone = new UMLForeignKeyConstraint(umlParent());
copyInto(clone);
return clone;
}
......@@ -183,7 +183,7 @@ bool UMLForeignKeyConstraint::showPropertiesDialog(QWidget* parent)
*/
bool UMLForeignKeyConstraint::addEntityAttributePair(UMLEntityAttribute* pAttr, UMLEntityAttribute* rAttr)
{
UMLEntity *owningParent = dynamic_cast<UMLEntity*>(parent());
UMLEntity *owningParent = umlParent()->asUMLEntity();
if (pAttr == NULL || rAttr == NULL) {
uError() << "null values passed to function";
......@@ -299,7 +299,7 @@ bool UMLForeignKeyConstraint::load(QDomElement & element)
Uml::ID::Type keyId = Uml::ID::fromString(xmiKey);
Uml::ID::Type valueId = Uml::ID::fromString(xmiValue);
UMLEntity* parentEntity = parent()->asUMLEntity();
UMLEntity* parentEntity = umlParent()->asUMLEntity();
UMLObject* keyObj = parentEntity->findChildObjectById(keyId);
UMLEntityAttribute* key = keyObj->asUMLEntityAttribute();
......
......@@ -227,7 +227,7 @@ QString UMLOperation::toString(Uml::SignatureType::Enum sig)
} else if (parameterlessOpNeedsParentheses) {
s.append(QLatin1String("()"));
}
UMLClassifier *ownParent = parent()->asUMLClassifier();
UMLClassifier *ownParent = umlParent()->asUMLClassifier();
QString returnType;
UMLClassifier *retType = UMLClassifierListItem::getType();
if (retType) {
......@@ -322,7 +322,7 @@ void UMLOperation::copyInto(UMLObject *lhs) const
UMLObject* UMLOperation::clone() const
{
//FIXME: The new operation should be slaved to the NEW parent not the old.
UMLOperation *clone = new UMLOperation(parent()->asUMLClassifier());
UMLOperation *clone = new UMLOperation(umlParent()->asUMLClassifier());
copyInto(clone);
return clone;
......@@ -357,7 +357,7 @@ bool UMLOperation::isConstructorOperation()
if (stereotype() == QLatin1String("constructor"))
return true;
UMLClassifier * c = static_cast<UMLClassifier*>(this->parent());
UMLClassifier * c = umlParent()->asUMLClassifier();
QString cName = c->name();
QString opName = name();
// It's a constructor operation if the operation name
......@@ -374,7 +374,7 @@ bool UMLOperation::isDestructorOperation()
{
if (stereotype() == QLatin1String("destructor"))
return true;
UMLClassifier * c = static_cast<UMLClassifier*>(this->parent());
UMLClassifier * c = umlParent()->asUMLClassifier();
QString cName = c->name();
QString opName = name();
......
......@@ -107,7 +107,7 @@ void UMLTemplate::copyInto(UMLObject *lhs) const
*/
UMLObject* UMLTemplate::clone() const
{
UMLTemplate *clone = new UMLTemplate((UMLTemplate*) parent());
UMLTemplate *clone = new UMLTemplate(umlParent()->asUMLTemplate());
copyInto(clone);
return clone;
......
......@@ -44,7 +44,7 @@ DEBUG_REGISTER_DISABLED(UMLObject)
* @param other object to created from
*/
UMLObject::UMLObject(const UMLObject &other)
: QObject(other.parent())
: QObject(other.umlParent())
{
other.copyInto(this);
}
......@@ -73,7 +73,7 @@ UMLObject::UMLObject(UMLObject* parent, const QString& name, ID::Type id)
* then a new ID will be assigned internally.
*/
UMLObject::UMLObject(const QString& name, ID::Type id)
: QObject(UMLApp::app()->document()),
: QObject(0),
m_nId(id),
m_name(name)
{
......@@ -115,7 +115,6 @@ void UMLObject::init()
{
setObjectName(QLatin1String("UMLObject"));
m_BaseType = ot_UMLObject;
m_pUMLPackage = 0;
m_visibility = Uml::Visibility::Public;
m_pStereotype = 0;
m_Doc.clear();
......@@ -217,19 +216,19 @@ QString UMLObject::fullyQualifiedName(const QString& separator,
bool includeRoot /* = false */) const
{
QString fqn;
if (m_pUMLPackage && m_pUMLPackage != this) {
if (umlPackage() && umlPackage() != this) {
bool skipPackage = false;
if (!includeRoot) {
UMLDoc *umldoc = UMLApp::app()->document();
if (umldoc->rootFolderType(m_pUMLPackage) != Uml::ModelType::N_MODELTYPES ||
m_pUMLPackage == umldoc->datatypeFolder())
if (umldoc->rootFolderType(umlPackage()) != Uml::ModelType::N_MODELTYPES ||
(umlPackage() == umldoc->datatypeFolder()));
skipPackage = true;
}
if (!skipPackage) {
QString tempSeparator = separator;
if (tempSeparator.isEmpty())
tempSeparator = UMLApp::app()->activeLanguageScopeSeparator();
fqn = m_pUMLPackage->fullyQualifiedName(tempSeparator, includeRoot);
fqn = umlParent()->asUMLPackage()->fullyQualifiedName(tempSeparator, includeRoot);
fqn.append(tempSeparator);
}
}
......@@ -256,7 +255,7 @@ bool UMLObject::operator==(const UMLObject & rhs) const
// Packages create different namespaces, therefore they should be
// part of the equality test.
if (m_pUMLPackage != rhs.m_pUMLPackage)
if (umlPackage() != rhs.umlPackage())
return false;
// Making the type part of an object's identity has its problems:
......@@ -310,16 +309,16 @@ void UMLObject::copyInto(UMLObject *lhs) const
lhs->m_bStatic = m_bStatic;
lhs->m_BaseType = m_BaseType;
lhs->m_visibility = m_visibility;
lhs->m_pUMLPackage = m_pUMLPackage;
lhs->setUMLPackage(umlPackage());
// We don't want the same name existing twice.
lhs->m_name = Model_Utils::uniqObjectName(m_BaseType, m_pUMLPackage, m_name);
lhs->m_name = Model_Utils::uniqObjectName(m_BaseType, umlPackage(), m_name);
// Create a new ID.
lhs->m_nId = UniqueID::gen();
// Hope that the parent from QObject is okay.
if (lhs->parent() != parent())
if (lhs->umlPackage() != umlPackage())
uDebug() << "copyInto has a wrong parent";
}
......@@ -585,7 +584,7 @@ QString UMLObject::package(const QString& separator, bool includeRoot)
UMLPackageList UMLObject::packages(bool includeRoot) const
{
UMLPackageList pkgList;
UMLPackage* pkg = m_pUMLPackage;
UMLPackage* pkg = umlPackage();
while (pkg != NULL) {
pkgList.prepend(pkg);
pkg = pkg->umlPackage();
......@@ -613,7 +612,7 @@ bool UMLObject::setUMLPackage(UMLPackage *pPkg)
return true;
}
if (pPkg->umlParent()->asUMLPackage() == this) {
if (pPkg->umlPackage() == this) {
uDebug() << "setting parent to an object of which I'm already the parent is not allowed";
return false;
}
......@@ -626,11 +625,38 @@ bool UMLObject::setUMLPackage(UMLPackage *pPkg)
/**
* Returns the UMLPackage that this class is located in.
*
* This method is a shortcut for calling umlParent()->asUMLPackage().
*
* @return Pointer to the UMLPackage of this class.
*/
UMLPackage* UMLObject::umlPackage()
UMLPackage* UMLObject::umlPackage() const
{
return dynamic_cast<UMLPackage *>(parent());
}
/**
* Set UML model parent.
*
* @param parent object to set as parent
*
* @TODO prevent setting parent to myself
*/
void UMLObject::setUMLParent(UMLObject *parent)
{
setParent(parent);
}
/**
* Return UML model parent.
*
* Model classes of type UMLClassifierListItem and below
* uses QObject::parent to hold the model parent
*