summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRalf Habacker <ralf.habacker@freenet.de>2016-09-06 14:57:20 (GMT)
committerRalf Habacker <ralf.habacker@freenet.de>2016-09-06 15:00:01 (GMT)
commitdd847f1576b37f9da31df51084fa3dda243ccc3c (patch)
treee2a35e56bed4f646f339b4a19ab9fbef4c830c56
parentfa3f51e764c4296c81454f25b340d00241f172d3 (diff)
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
-rw-r--r--umbrello/codegenerators/ada/adawriter.cpp2
-rw-r--r--umbrello/codeimport/import_utils.cpp2
-rw-r--r--umbrello/dialogs/umlforeignkeyconstraintdialog.cpp2
-rw-r--r--umbrello/dialogs/umloperationdialog.cpp2
-rw-r--r--umbrello/dialogs/umluniqueconstraintdialog.cpp2
-rw-r--r--umbrello/dialogs/widgets/umldatatypewidget.cpp6
-rw-r--r--umbrello/model_utils.cpp4
-rw-r--r--umbrello/refactoring/refactoringassistant.cpp8
-rw-r--r--umbrello/umldoc.cpp6
-rw-r--r--umbrello/umllistview.cpp4
-rw-r--r--umbrello/umllistviewitem.cpp12
-rw-r--r--umbrello/umlmodel/association.cpp18
-rw-r--r--umbrello/umlmodel/attribute.cpp12
-rw-r--r--umbrello/umlmodel/checkconstraint.cpp2
-rw-r--r--umbrello/umlmodel/classifierlistitem.cpp8
-rw-r--r--umbrello/umlmodel/entity.cpp4
-rw-r--r--umbrello/umlmodel/entityattribute.cpp2
-rw-r--r--umbrello/umlmodel/enumliteral.cpp2
-rw-r--r--umbrello/umlmodel/folder.cpp4
-rw-r--r--umbrello/umlmodel/foreignkeyconstraint.cpp8
-rw-r--r--umbrello/umlmodel/operation.cpp8
-rw-r--r--umbrello/umlmodel/template.cpp2
-rw-r--r--umbrello/umlmodel/umlobject.cpp74
-rw-r--r--umbrello/umlmodel/umlobject.h6
-rw-r--r--umbrello/umlmodel/uniqueconstraint.cpp15
-rw-r--r--umbrello/umlwidgets/associationwidget.cpp6
-rw-r--r--umbrello/umlwidgets/linkwidget.cpp2
27 files changed, 125 insertions, 98 deletions
diff --git a/umbrello/codegenerators/ada/adawriter.cpp b/umbrello/codegenerators/ada/adawriter.cpp
index 28e6355..8b981cf 100644
--- a/umbrello/codegenerators/ada/adawriter.cpp
+++ b/umbrello/codegenerators/ada/adawriter.cpp
@@ -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())
diff --git a/umbrello/codeimport/import_utils.cpp b/umbrello/codeimport/import_utils.cpp
index 558adf1..1a6b28b 100644
--- a/umbrello/codeimport/import_utils.cpp
+++ b/umbrello/codeimport/import_utils.cpp
@@ -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;
diff --git a/umbrello/dialogs/umlforeignkeyconstraintdialog.cpp b/umbrello/dialogs/umlforeignkeyconstraintdialog.cpp
index d0e5b5c..3191106 100644
--- a/umbrello/dialogs/umlforeignkeyconstraintdialog.cpp
+++ b/umbrello/dialogs/umlforeignkeyconstraintdialog.cpp
@@ -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);
diff --git a/umbrello/dialogs/umloperationdialog.cpp b/umbrello/dialogs/umloperationdialog.cpp
index e953cfa..bbd8310 100644
--- a/umbrello/dialogs/umloperationdialog.cpp
+++ b/umbrello/dialogs/umloperationdialog.cpp
@@ -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))
{
diff --git a/umbrello/dialogs/umluniqueconstraintdialog.cpp b/umbrello/dialogs/umluniqueconstraintdialog.cpp
index 2a4addc..0a7828b 100644
--- a/umbrello/dialogs/umluniqueconstraintdialog.cpp
+++ b/umbrello/dialogs/umluniqueconstraintdialog.cpp
@@ -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);
diff --git a/umbrello/dialogs/widgets/umldatatypewidget.cpp b/umbrello/dialogs/widgets/umldatatypewidget.cpp
index 3fcf32d..db97e37 100644
--- a/umbrello/dialogs/widgets/umldatatypewidget.cpp
+++ b/umbrello/dialogs/widgets/umldatatypewidget.cpp
@@ -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());
}
diff --git a/umbrello/model_utils.cpp b/umbrello/model_utils.cpp
index 3a1f396..dd3496a 100644
--- a/umbrello/model_utils.cpp
+++ b/umbrello/model_utils.cpp
@@ -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;
diff --git a/umbrello/refactoring/refactoringassistant.cpp b/umbrello/refactoring/refactoringassistant.cpp
index faa466d..457317f 100644
--- a/umbrello/refactoring/refactoringassistant.cpp
+++ b/umbrello/refactoring/refactoringassistant.cpp
@@ -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
diff --git a/umbrello/umldoc.cpp b/umbrello/umldoc.cpp
index 77afc14..1e95e06 100644
--- a/umbrello/umldoc.cpp
+++ b/umbrello/umldoc.cpp
@@ -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;
diff --git a/umbrello/umllistview.cpp b/umbrello/umllistview.cpp
index 4d60914..33621a8 100644
--- a/umbrello/umllistview.cpp
+++ b/umbrello/umllistview.cpp
@@ -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);
}
diff --git a/umbrello/umllistviewitem.cpp b/umbrello/umllistviewitem.cpp
index edb007e..a47634b 100644
--- a/umbrello/umllistviewitem.cpp
+++ b/umbrello/umllistviewitem.cpp
@@ -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
diff --git a/umbrello/umlmodel/association.cpp b/umbrello/umlmodel/association.cpp
index 9901026..54d123b 100644
--- a/umbrello/umlmodel/association.cpp
+++ b/umbrello/umlmodel/association.cpp
@@ -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);
diff --git a/umbrello/umlmodel/attribute.cpp b/umbrello/umlmodel/attribute.cpp
index 863b7f9..5a94072 100644
--- a/umbrello/umlmodel/attribute.cpp
+++ b/umbrello/umlmodel/attribute.cpp
@@ -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;
diff --git a/umbrello/umlmodel/checkconstraint.cpp b/umbrello/umlmodel/checkconstraint.cpp
index b394433..1d87f25 100644
--- a/umbrello/umlmodel/checkconstraint.cpp
+++ b/umbrello/umlmodel/checkconstraint.cpp
@@ -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;
}
diff --git a/umbrello/umlmodel/classifierlistitem.cpp b/umbrello/umlmodel/classifierlistitem.cpp
index b03bdb8..128929c 100644
--- a/umbrello/umlmodel/classifierlistitem.cpp
+++ b/umbrello/umlmodel/classifierlistitem.cpp
@@ -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();
}
diff --git a/umbrello/umlmodel/entity.cpp b/umbrello/umlmodel/entity.cpp
index 84fd046..a87e493 100644
--- a/umbrello/umlmodel/entity.cpp
+++ b/umbrello/umlmodel/entity.cpp
@@ -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;
diff --git a/umbrello/umlmodel/entityattribute.cpp b/umbrello/umlmodel/entityattribute.cpp
index a41f604..4e9ed96 100644
--- a/umbrello/umlmodel/entityattribute.cpp
+++ b/umbrello/umlmodel/entityattribute.cpp
@@ -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;
diff --git a/umbrello/umlmodel/enumliteral.cpp b/umbrello/umlmodel/enumliteral.cpp
index 2f558a3..8652acf 100644
--- a/umbrello/umlmodel/enumliteral.cpp
+++ b/umbrello/umlmodel/enumliteral.cpp
@@ -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;
diff --git a/umbrello/umlmodel/folder.cpp b/umbrello/umlmodel/folder.cpp
index b32110a..e97668f 100644
--- a/umbrello/umlmodel/folder.cpp
+++ b/umbrello/umlmodel/folder.cpp
@@ -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);
diff --git a/umbrello/umlmodel/foreignkeyconstraint.cpp b/umbrello/umlmodel/foreignkeyconstraint.cpp
index 36a766c..683dadf 100644
--- a/umbrello/umlmodel/foreignkeyconstraint.cpp
+++ b/umbrello/umlmodel/foreignkeyconstraint.cpp
@@ -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();
diff --git a/umbrello/umlmodel/operation.cpp b/umbrello/umlmodel/operation.cpp
index d43f170..abcd57c 100644
--- a/umbrello/umlmodel/operation.cpp
+++ b/umbrello/umlmodel/operation.cpp
@@ -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();
diff --git a/umbrello/umlmodel/template.cpp b/umbrello/umlmodel/template.cpp
index c59f314..fc40d62 100644
--- a/umbrello/umlmodel/template.cpp
+++ b/umbrello/umlmodel/template.cpp
@@ -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;
diff --git a/umbrello/umlmodel/umlobject.cpp b/umbrello/umlmodel/umlobject.cpp
index 2c30b03..febc287 100644
--- a/umbrello/umlmodel/umlobject.cpp
+++ b/umbrello/umlmodel/umlobject.cpp
@@ -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
+ *
+ * @return parent of uml object
+ */
+UMLObject *UMLObject::umlParent() const
{
- return m_pUMLPackage;
+ return dynamic_cast<UMLObject *>(parent());
}
/**
@@ -751,7 +777,7 @@ bool UMLObject::resolveRef()
// of on-the-fly scope creation:
if (m_SecondaryId.contains(QLatin1String("::"))) {
// TODO: Merge Import_Utils::createUMLObject() into Object_Factory::createUMLObject()
- m_pSecondary = Import_Utils::createUMLObject(ot_UMLObject, m_SecondaryId, m_pUMLPackage);
+ m_pSecondary = Import_Utils::createUMLObject(ot_UMLObject, m_SecondaryId, umlPackage());
if (m_pSecondary) {
if (Import_Utils::newUMLObjectWasCreated()) {
maybeSignalObjectCreated();
@@ -826,8 +852,8 @@ QDomElement UMLObject::save(const QString &tag, QDomDocument & qDoc)
m_BaseType != ot_Role &&
m_BaseType != ot_Attribute) {
Uml::ID::Type nmSpc;
- if (m_pUMLPackage)
- nmSpc = m_pUMLPackage->id();
+ if (umlPackage())
+ nmSpc = umlPackage()->id();
else
nmSpc = UMLApp::app()->document()->modelID();
qElement.setAttribute(QLatin1String("namespace"), Uml::ID::toString(nmSpc));
@@ -835,8 +861,8 @@ QDomElement UMLObject::save(const QString &tag, QDomDocument & qDoc)
if (! m_Doc.isEmpty())
qElement.setAttribute(QLatin1String("comment"), m_Doc); //CHECK: uml13.dtd compliance
#ifdef XMI_FLAT_PACKAGES
- if (m_pUMLPackage) //FIXME: uml13.dtd compliance
- qElement.setAttribute(QLatin1String("package"), m_pUMLPackage->ID());
+ if (umlParent()->asUMLPackage()) //FIXME: uml13.dtd compliance
+ qElement.setAttribute(QLatin1String("package"), umlParent()->asUMLPackage()->ID());
#endif
QString visibility = Uml::Visibility::toString(m_visibility, false);
qElement.setAttribute(QLatin1String("visibility"), visibility);
@@ -1063,11 +1089,11 @@ bool UMLObject::loadFromXMI(QDomElement & element)
m_BaseType != ot_Template && m_BaseType != ot_Stereotype &&
m_BaseType != ot_Role && m_BaseType != ot_UniqueConstraint &&
m_BaseType != ot_ForeignKeyConstraint && m_BaseType != ot_CheckConstraint) {
- if (m_pUMLPackage) {
- m_pUMLPackage->addObject(this);
+ if (umlPackage()) {
+ umlPackage()->addObject(this);
} else if (umldoc->rootFolderType(this) == Uml::ModelType::N_MODELTYPES) {
- // m_pUMLPackage is not set on the root folders.
- uDebug() << m_name << ": m_pUMLPackage is not set";
+ // umlPackage() is not set on the root folders.
+ uDebug() << m_name << ": umlPackage() is not set";
}
}
return load(element);
diff --git a/umbrello/umlmodel/umlobject.h b/umbrello/umlmodel/umlobject.h
index ff5cb3f..b71bb94 100644
--- a/umbrello/umlmodel/umlobject.h
+++ b/umbrello/umlmodel/umlobject.h
@@ -146,7 +146,10 @@ public:
UMLPackageList packages(bool includeRoot = false) const;
bool setUMLPackage(UMLPackage* pPkg);
- UMLPackage* umlPackage();
+ UMLPackage* umlPackage() const;
+
+ void setUMLParent(UMLObject* parent);
+ UMLObject* umlParent() const;
virtual void setName(const QString &strName);
void setNameCmd(const QString &strName) ;
@@ -253,7 +256,6 @@ protected:
Uml::ID::Type m_nId; ///< object's id
QString m_Doc; ///< object's documentation
- UMLPackage* m_pUMLPackage; ///< package the object belongs to if applicable
QPointer<UMLStereotype> m_pStereotype; ///< stereotype of the object if applicable
QString m_name; ///< objects name
ObjectType m_BaseType; ///< objects type
diff --git a/umbrello/umlmodel/uniqueconstraint.cpp b/umbrello/umlmodel/uniqueconstraint.cpp
index c04f06e..6c62a0a 100644
--- a/umbrello/umlmodel/uniqueconstraint.cpp
+++ b/umbrello/umlmodel/uniqueconstraint.cpp
@@ -98,7 +98,7 @@ void UMLUniqueConstraint::copyInto(UMLObject *lhs) const
UMLObject* UMLUniqueConstraint::clone() const
{
//FIXME: The new attribute should be slaved to the NEW parent not the old.
- UMLUniqueConstraint *clone = new UMLUniqueConstraint(parent()->asUMLObject());
+ UMLUniqueConstraint *clone = new UMLUniqueConstraint(umlParent());
copyInto(clone);
return clone;
}
@@ -116,7 +116,8 @@ QString UMLUniqueConstraint::toString(Uml::SignatureType::Enum sig)
if (sig == Uml::SignatureType::ShowSig || sig == Uml::SignatureType::SigNoVis) {
s = name() + QLatin1Char(':');
- if (parent()->asUMLEntity()->isPrimaryKey(this)) {
+ UMLEntity *e = umlParent()->asUMLEntity();
+ if (e && e->isPrimaryKey(this)) {
s += QLatin1String("Primary Key (");
} else {
s += QLatin1String("Unique (");
@@ -150,8 +151,8 @@ void UMLUniqueConstraint::saveToXMI(QDomDocument & qDoc, QDomElement & qElement)
{
QDomElement uniqueConstraintElement = UMLObject::save(QLatin1String("UML:UniqueConstraint"), qDoc);
- UMLEntity* parentEnt = parent()->asUMLEntity();
- if (parentEnt->isPrimaryKey(this)) {
+ UMLEntity* parentEnt = umlParent()->asUMLEntity();
+ if (parentEnt && parentEnt->isPrimaryKey(this)) {
uniqueConstraintElement.setAttribute(QLatin1String("isPrimary"), QLatin1String("1"));
} else {
uniqueConstraintElement.setAttribute(QLatin1String("isPrimary"), QLatin1String("0"));
@@ -179,7 +180,7 @@ bool UMLUniqueConstraint::showPropertiesDialog(QWidget* parent)
bool UMLUniqueConstraint::load(QDomElement & element)
{
int isPrimary = element.attribute(QLatin1String("isPrimary"), QLatin1String("0")).toInt();
- UMLEntity* parentEnt = parent()->asUMLEntity();
+ UMLEntity* parentEnt = umlParent()->asUMLEntity();
if (isPrimary == 1) {
parentEnt->setAsPrimaryKey(this);
@@ -242,7 +243,7 @@ bool UMLUniqueConstraint::hasEntityAttribute(UMLEntityAttribute* attr)
*/
bool UMLUniqueConstraint::addEntityAttribute(UMLEntityAttribute* attr)
{
- UMLEntity *owningParent = dynamic_cast<UMLEntity*>(parent());
+ UMLEntity *owningParent = umlParent()->asUMLEntity();
if (hasEntityAttribute(attr)) {
uDebug() << "Unique Constraint already contains" << attr->name();
@@ -275,7 +276,7 @@ bool UMLUniqueConstraint::addEntityAttribute(UMLEntityAttribute* attr)
*/
bool UMLUniqueConstraint::removeEntityAttribute(UMLEntityAttribute* attr)
{
- UMLEntity *owningParent = dynamic_cast<UMLEntity*>(parent());
+ UMLEntity *owningParent = umlParent()->asUMLEntity();
if (owningParent == NULL) {
uError() << name() << ": parent is not a UMLEntity";
diff --git a/umbrello/umlwidgets/associationwidget.cpp b/umbrello/umlwidgets/associationwidget.cpp
index ba5e4ee..43fa39f 100644
--- a/umbrello/umlwidgets/associationwidget.cpp
+++ b/umbrello/umlwidgets/associationwidget.cpp
@@ -251,19 +251,19 @@ void AssociationWidget::setUMLObject(UMLObject *obj)
setOperation(obj->asUMLOperation());
break;
case UMLObject::ot_Attribute:
- klass = static_cast<UMLClassifier*>(obj->parent());
+ klass = obj->umlParent()->asUMLClassifier();
connect(klass, SIGNAL(attributeRemoved(UMLClassifierListItem*)),
this, SLOT(slotClassifierListItemRemoved(UMLClassifierListItem*)));
attr = obj->asUMLAttribute();
connect(attr, SIGNAL(attributeChanged()), this, SLOT(slotAttributeChanged()));
break;
case UMLObject::ot_EntityAttribute:
- ent = static_cast<UMLEntity*>(obj->parent());
+ ent = obj->umlParent()->asUMLEntity();
connect(ent, SIGNAL(entityAttributeRemoved(UMLClassifierListItem*)),
this, SLOT(slotClassifierListItemRemoved(UMLClassifierListItem*)));
break;
case UMLObject::ot_ForeignKeyConstraint:
- ent = static_cast<UMLEntity*>(obj->parent());
+ ent = obj->umlParent()->asUMLEntity();
connect(ent, SIGNAL(entityConstraintRemoved(UMLClassifierListItem*)),
this, SLOT(slotClassifierListItemRemoved(UMLClassifierListItem*)));
break;
diff --git a/umbrello/umlwidgets/linkwidget.cpp b/umbrello/umlwidgets/linkwidget.cpp
index f81a523..246f39b 100644
--- a/umbrello/umlwidgets/linkwidget.cpp
+++ b/umbrello/umlwidgets/linkwidget.cpp
@@ -34,7 +34,7 @@ UMLClassifier *LinkWidget::operationOwner()
UMLOperation *op = operation();
if (op == NULL)
return NULL;
- return static_cast<UMLClassifier*>(op->parent());
+ return op->umlParent()->asUMLClassifier();
}
/**