Commit ec44b8bc authored by Ralf Habacker's avatar Ralf Habacker

Let client code use UMLCancasObject::subordinates() instead of accessing class member directly.

Make UMLCancasObject::m_List a private variable and replace references
to UMLCancasObject::m_List with UMLCancasObject::subordinates().

This makes it possible to deal with zero pointers in one place.
parent 028ecc83
This diff is collapsed.
......@@ -52,7 +52,7 @@ UMLEntity::UMLEntity(const QString& name, Uml::ID::Type id)
*/
UMLEntity::~UMLEntity()
{
m_List.clear();
subordinates().clear();
}
/**
......@@ -305,7 +305,7 @@ UMLCheckConstraint* UMLEntity::createCheckConstraint(const QString &name)
UMLObject* UMLEntity::addEntityAttribute(const QString& name, Uml::ID::Type id)
{
UMLEntityAttribute* literal = new UMLEntityAttribute(this, name, id);
m_List.append(literal);
subordinates().append(literal);
emit entityAttributeAdded(literal);
UMLObject::emitModified();
connect(literal, SIGNAL(modified()), this, SIGNAL(modified()));
......@@ -324,7 +324,7 @@ bool UMLEntity::addEntityAttribute(UMLEntityAttribute* att, IDChangeLog* log /*
QString name = (QString)att->name();
if (findChildObject(name) == 0) {
att->setParent(this);
m_List.append(att);
subordinates().append(att);
emit entityAttributeAdded(att);
UMLObject::emitModified();
connect(att, SIGNAL(modified()), this, SIGNAL(modified()));
......@@ -351,10 +351,10 @@ bool UMLEntity::addEntityAttribute(UMLEntityAttribute* att, int position)
QString name = (QString)att->name();
if (findChildObject(name) == 0) {
att->setParent(this);
if (position >= 0 && position <= (int)m_List.count()) {
m_List.insert(position, att);
if (position >= 0 && position <= (int)subordinates().count()) {
subordinates().insert(position, att);
} else {
m_List.append(att);
subordinates().append(att);
}
emit entityAttributeAdded(att);
UMLObject::emitModified();
......@@ -372,7 +372,7 @@ bool UMLEntity::addEntityAttribute(UMLEntityAttribute* att, int position)
*/
int UMLEntity::removeEntityAttribute(UMLClassifierListItem* att)
{
if (!m_List.removeAll((UMLEntityAttribute*)att)) {
if (!subordinates().removeAll((UMLEntityAttribute*)att)) {
uDebug() << "cannot find att given in list";
return -1;
}
......@@ -382,7 +382,7 @@ int UMLEntity::removeEntityAttribute(UMLClassifierListItem* att)
// for us by QObject. -b.t.
// disconnect(att, SIGNAL(modified()), this, SIGNAL(modified()));
delete att;
return m_List.count();
return subordinates().count();
}
/**
......@@ -410,7 +410,7 @@ void UMLEntity::signalEntityAttributeRemoved(UMLClassifierListItem *eattr)
bool UMLEntity::resolveRef()
{
bool success = UMLClassifier::resolveRef();
for (UMLObjectListIt oit(m_List); oit.hasNext();) {
for (UMLObjectListIt oit(subordinates()); oit.hasNext();) {
UMLObject* obj = oit.next();
if (obj->resolveRef()) {
UMLClassifierListItem *cli = obj->asUMLClassifierListItem();
......@@ -471,7 +471,7 @@ bool UMLEntity::load1(QDomElement& element)
if(!pEntityAttribute->loadFromXMI1(tempElement)) {
return false;
}
m_List.append(pEntityAttribute);
subordinates().append(pEntityAttribute);
} else if (UMLDoc::tagEq(tag, QLatin1String("UniqueConstraint"))) {
UMLUniqueConstraint* pUniqueConstraint = new UMLUniqueConstraint(this);
if (!pUniqueConstraint->loadFromXMI1(tempElement)) {
......@@ -582,7 +582,7 @@ bool UMLEntity::addConstraint(UMLEntityConstraint* constr)
return false;
}
m_List.append(constr);
subordinates().append(constr);
emit entityConstraintAdded(constr);
UMLObject::emitModified();
......@@ -609,7 +609,7 @@ bool UMLEntity::removeConstraint(UMLEntityConstraint* constr)
unsetPrimaryKey();
}
m_List.removeAll(constr);
subordinates().removeAll(constr);
emit entityConstraintRemoved(constr);
UMLObject::emitModified();
......@@ -693,7 +693,7 @@ bool UMLEntity::isPrimaryKey(UMLUniqueConstraint* uConstr) const
UMLEntityAttributeList UMLEntity::getEntityAttributes() const
{
UMLEntityAttributeList entityAttributeList;
for (UMLObjectListIt lit(m_List); lit.hasNext();) {
for (UMLObjectListIt lit(subordinates()); lit.hasNext();) {
UMLObject *listItem = lit.next();
if (listItem->baseType() == UMLObject::ot_EntityAttribute) {
entityAttributeList.append(listItem->asUMLEntityAttribute());
......
......@@ -97,7 +97,7 @@ private:
/**
* Primary Key of this Entity
* This is a pointer kept for easy access to the primary key, and to distinguish it
* from all other UniqueConstraints. It is also there in m_List (inherited from
* from all other UniqueConstraints. It is also there in subordinates (inherited from
* UMLCanvasObject)
*/
UMLUniqueConstraint* m_PrimaryKey;
......
......@@ -38,7 +38,7 @@ UMLEnum::UMLEnum(const QString& name, Uml::ID::Type id) : UMLClassifier(name, id
*/
UMLEnum::~UMLEnum()
{
m_List.clear();
subordinates().clear();
}
/**
......@@ -137,7 +137,7 @@ UMLObject* UMLEnum::addEnumLiteral(const QString &name, Uml::ID::Type id, const
return el;
}
UMLEnumLiteral* literal = new UMLEnumLiteral(this, name, id, value);
m_List.append(literal);
subordinates().append(literal);
UMLObject::emitModified();
emit enumLiteralAdded(literal);
connect(literal, SIGNAL(modified()), this, SIGNAL(modified()));
......@@ -156,7 +156,7 @@ bool UMLEnum::addEnumLiteral(UMLEnumLiteral* literal, IDChangeLog* Log /* = 0*/)
QString name = (QString)literal->name();
if (findChildObject(name) == 0) {
literal->setParent(this);
m_List.append(literal);
subordinates().append(literal);
UMLObject::emitModified();
emit enumLiteralAdded(literal);
connect(literal, SIGNAL(modified()), this, SIGNAL(modified()));
......@@ -183,10 +183,10 @@ bool UMLEnum::addEnumLiteral(UMLEnumLiteral* literal, int position)
QString name = (QString)literal->name();
if (findChildObject(name) == 0) {
literal->setParent(this);
if (position >= 0 && position <= (int)m_List.count()) {
m_List.insert(position, literal);
if (position >= 0 && position <= (int)subordinates().count()) {
subordinates().insert(position, literal);
} else {
m_List.append(literal);
subordinates().append(literal);
}
UMLObject::emitModified();
emit enumLiteralAdded(literal);
......@@ -204,7 +204,7 @@ bool UMLEnum::addEnumLiteral(UMLEnumLiteral* literal, int position)
*/
int UMLEnum::removeEnumLiteral(UMLEnumLiteral* literal)
{
if (!m_List.removeAll(literal)) {
if (!subordinates().removeAll(literal)) {
uDebug() << "cannot find att given in list";
return -1;
}
......@@ -214,7 +214,7 @@ int UMLEnum::removeEnumLiteral(UMLEnumLiteral* literal)
// for us by QObject. -b.t.
// disconnect(a, SIGNAL(modified()), this, SIGNAL(modified()));
delete literal;
return m_List.count();
return subordinates().count();
}
/**
......@@ -223,7 +223,7 @@ int UMLEnum::removeEnumLiteral(UMLEnumLiteral* literal)
*/
int UMLEnum::enumLiterals()
{
return m_List.count();
return subordinates().count();
}
/**
......@@ -270,7 +270,7 @@ bool UMLEnum::load1(QDomElement& element)
if(!pEnumLiteral->loadFromXMI1(tempElement)) {
return false;
}
m_List.append(pEnumLiteral);
subordinates().append(pEnumLiteral);
} else if (UMLDoc::tagEq(tag, QLatin1String("Enumeration.literal"))) { // UML 1.4
if (! load1(tempElement))
return false;
......
......@@ -277,7 +277,7 @@ void UMLFolder::saveContents1(QDomDocument& qDoc, QDomElement& qElement)
obj->saveToXMI1 (qDoc, ownedElement);
}
// Save asscociations if any.
for (UMLObjectListIt ait(m_List); ait.hasNext();) {
for (UMLObjectListIt ait(subordinates()); ait.hasNext();) {
obj = ait.next();
obj->saveToXMI1 (qDoc, ownedElement);
}
......
......@@ -176,7 +176,7 @@ bool UMLInstance::load1(QDomElement &element)
if(!pInstanceAttribute->loadFromXMI1(tempElement)) {
return false;
}
m_List.append(pInstanceAttribute);
subordinates().append(pInstanceAttribute);
}
node = node.nextSibling();
}//end while
......
......@@ -403,7 +403,7 @@ void UMLPackage::saveToXMI1(QDomDocument& qDoc, QDomElement& qElement)
obj->saveToXMI1 (qDoc, ownedElement);
}
// save associations
for (UMLObjectListIt ait(m_List); ait.hasNext();) {
for (UMLObjectListIt ait(subordinates()); ait.hasNext();) {
obj = ait.next();
obj->saveToXMI1 (qDoc, ownedElement);
}
......
......@@ -53,7 +53,7 @@ UMLCanvasObject::~UMLCanvasObject()
}
/**
* Return the subset of m_List that matches the given type.
* Return the subset of subordinates that matches the given type.
*
* @param assocType The AssociationType::Enum to match.
* @return The list of associations that match assocType.
......@@ -62,7 +62,7 @@ UMLAssociationList UMLCanvasObject::getSpecificAssocs(Uml::AssociationType::Enum
{
UMLAssociationList list;
UMLObject *o = 0;
for (UMLObjectListIt oit(m_List); oit.hasNext();) {
for (UMLObjectListIt oit(subordinates()); oit.hasNext();) {
o = oit.next();
uIgnoreZeroPointer(o);
if (o->baseType() != UMLObject::ot_Association)
......@@ -75,7 +75,7 @@ UMLAssociationList UMLCanvasObject::getSpecificAssocs(Uml::AssociationType::Enum
}
/**
* Adds an association end to m_List.
* Adds an association end to subordinates.
*
* @param assoc The association to add.
* @todo change param type to UMLRole
......@@ -86,7 +86,7 @@ bool UMLCanvasObject::addAssociationEnd(UMLAssociation* assoc)
// add association only if not already present in list
if (!hasAssociation(assoc))
{
m_List.append(assoc);
subordinates().append(assoc);
// Don't emit signals during load from XMI
UMLObject::emitModified();
......@@ -103,7 +103,7 @@ bool UMLCanvasObject::addAssociationEnd(UMLAssociation* assoc)
*/
bool UMLCanvasObject::hasAssociation(UMLAssociation* assoc)
{
uint cnt = m_List.count(assoc);
uint cnt = subordinates().count(assoc);
DEBUG(DBG_SRC) << "count is " << cnt;
return (cnt > 0);
}
......@@ -116,14 +116,14 @@ bool UMLCanvasObject::hasAssociation(UMLAssociation* assoc)
*/
int UMLCanvasObject::removeAssociationEnd(UMLAssociation * assoc)
{
if (!hasAssociation(assoc) || !m_List.removeAll(assoc)) {
if (!hasAssociation(assoc) || !subordinates().removeAll(assoc)) {
DEBUG(DBG_SRC) << "cannot find given assoc " << assoc << " in list";
return -1;
}
UMLApp::app()->document()->removeAssociation(assoc, false);
UMLObject::emitModified();
emit sigAssociationEndRemoved(assoc);
return m_List.count();
return subordinates().count();
}
/**
......@@ -131,8 +131,8 @@ int UMLCanvasObject::removeAssociationEnd(UMLAssociation * assoc)
*/
void UMLCanvasObject::removeAllAssociationEnds()
{
for (int i = 0; i < m_List.count(); i++) {
UMLObject *o = m_List.at(i);
for (int i = 0; i < subordinates().count(); i++) {
UMLObject *o = subordinates().at(i);
uIgnoreZeroPointer(o);
if (o->baseType() != UMLObject::ot_Association) {
continue;
......@@ -165,9 +165,9 @@ void UMLCanvasObject::removeAllAssociationEnds()
*/
void UMLCanvasObject::removeAllChildObjects()
{
if (!m_List.isEmpty()) {
if (!subordinates().isEmpty()) {
removeAllAssociationEnds();
m_List.clear();
subordinates().clear();
}
}
......@@ -244,7 +244,7 @@ UMLObject * UMLCanvasObject::findChildObject(const QString &n, UMLObject::Object
{
const bool caseSensitive = UMLApp::app()->activeLanguageIsCaseSensitive();
UMLObject *obj = 0;
for (UMLObjectListIt oit(m_List); oit.hasNext();) {
for (UMLObjectListIt oit(subordinates()); oit.hasNext();) {
obj = oit.next();
uIgnoreZeroPointer(obj);
if (t != UMLObject::ot_UMLObject && obj->baseType() != t)
......@@ -270,7 +270,7 @@ UMLObject* UMLCanvasObject::findChildObjectById(Uml::ID::Type id, bool considerA
{
Q_UNUSED(considerAncestors);
UMLObject *o = 0;
for (UMLObjectListIt oit(m_List); oit.hasNext();) {
for (UMLObjectListIt oit(subordinates()); oit.hasNext();) {
o = oit.next();
uIgnoreZeroPointer(o);
if (o->id() == id)
......@@ -290,10 +290,10 @@ bool UMLCanvasObject::operator==(const UMLCanvasObject& rhs) const
if (!UMLObject::operator==(rhs)) {
return false;
}
if (m_List.count() != rhs.m_List.count()) {
if (subordinates().count() != rhs.subordinates().count()) {
return false;
}
if (&m_List != &(rhs.m_List)) {
if (&subordinates() != &(rhs.subordinates())) {
return false;
}
return true;
......@@ -310,7 +310,7 @@ void UMLCanvasObject::copyInto(UMLObject *lhs) const
// TODO Associations are not copied at the moment. This because
// the duplicate function (on umlwidgets) do not copy the associations.
//
//target->m_List = m_List;
//target->subordinates() = subordinates();
}
/**
......@@ -323,7 +323,7 @@ int UMLCanvasObject::associations()
{
int count = 0;
UMLObject *obj = 0;
for (UMLObjectListIt oit(m_List); oit.hasNext();) {
for (UMLObjectListIt oit(subordinates()); oit.hasNext();) {
obj = oit.next();
uIgnoreZeroPointer(obj);
if (obj->baseType() == UMLObject::ot_Association)
......@@ -341,7 +341,7 @@ UMLAssociationList UMLCanvasObject::getAssociations()
{
UMLAssociationList assocs;
UMLObject *o = 0;
for (UMLObjectListIt oit(m_List); oit.hasNext() ;) {
for (UMLObjectListIt oit(subordinates()); oit.hasNext() ;) {
o = oit.next();
uIgnoreZeroPointer(o);
if (o->baseType() != UMLObject::ot_Association)
......@@ -454,11 +454,11 @@ UMLAssociationList UMLCanvasObject::getRelationships()
bool UMLCanvasObject::resolveRef()
{
bool overallSuccess = UMLObject::resolveRef();
for (UMLObjectListIt ait(m_List); ait.hasNext();) {
for (UMLObjectListIt ait(subordinates()); ait.hasNext();) {
UMLObject *obj = ait.next();
uIgnoreZeroPointer(obj);
if (! obj->resolveRef()) {
m_List.removeAll(obj);
subordinates().removeAll(obj);
overallSuccess = false;
}
}
......
......@@ -77,7 +77,7 @@ public:
virtual void removeAllChildObjects();
UMLObjectList &subordinates() {
UMLObjectList &subordinates() const {
return m_List;
}
......@@ -86,7 +86,7 @@ public:
// The abstract method UMLObject::saveToXMI1() is implemented
// in the classes inheriting from UMLCanvasObject.
protected:
private:
/**
* List of all the associations in this object.
......@@ -96,7 +96,7 @@ protected:
* @todo Only a pointer to the appropriate assocation end object
* (UMLRole) should be saved here, not the entire UMLAssociation.
*/
UMLObjectList m_List;
mutable UMLObjectList m_List;
signals:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment