Commit 3337da29 authored by Oliver Kellogg's avatar Oliver Kellogg
Browse files

Followup to commit 3203b16a work on UML Instances,

> Inheritance cleanup:
> - UMLInstance is derived from UMLObject (this might be changed to
>   UMLCanvasObject in future).

umbrello/uml1model/instance.{h,cpp}
- Derive UMLInstance from UMLCanvasObject.
- Remove function findChildObjectById, use inherited function.
- Remove type AttributeValues and function getAttrValues, use function
  subordinates() of superclass.
- Remove member m_attrValues, it is obsoleted by UMLCanvasObject member
  m_List.

umbrello/umlwidgets/classifierwidget.cpp
- Synchronize function drawMembers with the above changes.

umbrello/umllistview.cpp
- In function connectNewObjectsSlots fix indentation of switch cases.
- Synchronize functions addNewItem and loadChildrenFromXMI with the
  changes in class UMLInstance.

CCBUG: 123633
parent 401f6cee
......@@ -37,7 +37,7 @@
*/
UMLInstance::UMLInstance(const QString &instanceName, Uml::ID::Type id,
UMLClassifier *c /* = nullptr */)
: UMLObject(instanceName, id)
: UMLCanvasObject(instanceName, id)
{
m_BaseType = UMLObject::ot_Instance;
setClassifierCmd(c, false); // Signal shall not be emitted here
......@@ -68,7 +68,7 @@ void UMLInstance::setClassifierCmd(UMLClassifier *classifier, bool emitSignal /*
return;
if (m_pSecondary) {
m_attrValues.clear();
subordinates().clear();
disconnect(m_pSecondary, SIGNAL(attributeAdded(UMLClassifierListItem*)),
this, SLOT(attributeAdded(UMLClassifierListItem*)));
disconnect(m_pSecondary, SIGNAL(attributeRemoved(UMLClassifierListItem*)),
......@@ -82,7 +82,7 @@ void UMLInstance::setClassifierCmd(UMLClassifier *classifier, bool emitSignal /*
UMLAttribute *umla = item->asUMLAttribute();
if (umla) {
UMLInstanceAttribute *ia = new UMLInstanceAttribute(this, umla, umla->getInitialValue());
m_attrValues.append(ia);
subordinates().append(ia);
} else {
uError() << "UMLInstance::setClassifierCmd : item is not an attriubte";
}
......@@ -101,26 +101,6 @@ UMLClassifier *UMLInstance::classifier()
return (m_pSecondary ? m_pSecondary->asUMLClassifier() : nullptr);
}
/**
* Find an instance attribute.
*
* @param id ID of the UMLInstanceAttribute to find.
* @return Pointer to the object found (NULL if not found.)
*/
UMLInstanceAttribute* UMLInstance::findChildObjectById(Uml::ID::Type id)
{
foreach (UMLInstanceAttribute *o, m_attrValues) {
if (o->id() == id)
return o;
}
return 0;
}
UMLInstance::AttributeValues& UMLInstance::getAttrValues()
{
return m_attrValues;
}
/**
* Creates the <UML:Instance> element including its slots.
*/
......@@ -130,8 +110,8 @@ void UMLInstance::saveToXMI1(QXmlStreamWriter& writer)
if (m_pSecondary) {
writer.writeAttribute(QLatin1String("classifier"), Uml::ID::toString(m_pSecondary->id()));
//save attributes
foreach (UMLInstanceAttribute *pInstanceAttribute, m_attrValues) {
pInstanceAttribute->saveToXMI1(writer);
foreach (UMLObject *pObject, subordinates()) {
pObject->saveToXMI1(writer);
}
}
UMLObject::save1end(writer);
......@@ -156,7 +136,7 @@ bool UMLInstance::load1(QDomElement &element)
if (!pInstanceAttribute->loadFromXMI1(tempElement)) {
return false;
}
m_attrValues.append(pInstanceAttribute);
subordinates().append(pInstanceAttribute);
}
node = node.nextSibling();
} // end while
......@@ -199,9 +179,9 @@ bool UMLInstance::showPropertiesDialog(QWidget* parent)
void UMLInstance::attributeAdded(UMLClassifierListItem *item)
{
for (int i = 0; i < m_attrValues.count(); i++) {
UMLInstanceAttribute *ia = m_attrValues.at(i);
if (ia->parent() == item) {
for (int i = 0; i < subordinates().count(); i++) {
UMLObject *o = subordinates().at(i);
if (o->parent() == item) {
uDebug() << "UMLInstance::attributeAdded(" << item->name()
<< ") : instanceAttribute already present";
return;
......@@ -212,7 +192,7 @@ void UMLInstance::attributeAdded(UMLClassifierListItem *item)
uDebug() << "UMLInstance::attributeAdded(" << item->name()
<< ") : creating UMLInstanceAttribute";
UMLInstanceAttribute *ia = new UMLInstanceAttribute(this, umla, umla->getInitialValue());
m_attrValues.append(ia);
subordinates().append(ia);
} else {
uError() << "UMLInstance::attributeAdded(" << item->name()
<< ") : item is not a UMLAttribute";
......@@ -221,12 +201,12 @@ void UMLInstance::attributeAdded(UMLClassifierListItem *item)
void UMLInstance::attributeRemoved(UMLClassifierListItem *item)
{
for (int i = 0; i < m_attrValues.count(); i++) {
UMLInstanceAttribute *ia = m_attrValues.at(i);
if (ia->parent() == item) {
for (int i = 0; i < subordinates().count(); i++) {
UMLObject *o = subordinates().at(i);
if (o->parent() == item) {
uDebug() << "UMLInstance::attributeRemoved(" << item->name()
<< ") : removing instanceAttribute at index " << i;
m_attrValues.removeAt(i);
subordinates().removeAt(i);
return;
}
}
......
......@@ -11,7 +11,7 @@
#ifndef UMLINSTANCE_H
#define UMLINSTANCE_H
#include "umlobject.h"
#include "umlcanvasobject.h"
#include "instanceattribute.h"
class UMLClassifier;
......@@ -22,7 +22,7 @@ class UMLClassifierListItem;
* Instance. An Instance may be either standalone not tied to any other
* object, or it may be the instance of a classifier.
* If it represents a classifier then it will contain concrete values for
* the attributes of the classifier (see m_attrValues).
* the attributes of the classifier (see UMLCanvasObject::m_List).
* Conversely, in Umbrello a standalone instance cannot have attributes.
* UMLObject::m_pSecondary is used for storing the reference to the
* classifier. In case of a standalone instance, m_pSecondary is NULL.
......@@ -35,7 +35,7 @@ class UMLClassifierListItem;
* instanceName :
* The notation for an anonymous instance of a classifier is
* : classifierName
* This class inherits from @ref UMLObject which contains most of the
* This class inherits from @ref UMLCanvasObject which contains most of the
* information.
*
* @short Non-graphical Information for an Instance.
......@@ -44,7 +44,7 @@ class UMLClassifierListItem;
* @author Oliver Kellogg
* Bugs and comments to umbrello-devel@kde.org or https://bugs.kde.org
*/
class UMLInstance : public UMLObject
class UMLInstance : public UMLCanvasObject
{
Q_OBJECT
public:
......@@ -56,29 +56,13 @@ public:
void setClassifierCmd(UMLClassifier *classifier, bool emitSignal = true);
UMLClassifier *classifier();
UMLInstanceAttribute *findChildObjectById(Uml::ID::Type id);
virtual void saveToXMI1(QXmlStreamWriter& writer);
/**
* List of attribute values in case this UMLInstance is an instance of a
* classifier.
*/
typedef QList<UMLInstanceAttribute*> AttributeValues;
AttributeValues& getAttrValues();
protected:
bool load1(QDomElement& element);
virtual bool resolveRef();
bool showPropertiesDialog(QWidget *parent);
/**
* Attribute values in case this instance represents a classifier
* (m_pSecondary != nullptr)
*/
AttributeValues m_attrValues;
public slots:
void attributeAdded(UMLClassifierListItem*);
void attributeRemoved(UMLClassifierListItem*);
......
......@@ -1039,49 +1039,53 @@ void UMLListView::connectNewObjectsSlots(UMLObject* object)
UMLObject::ObjectType type = object->baseType();
switch (type) {
case UMLObject::ot_Class:
case UMLObject::ot_Interface: {
UMLClassifier *c = object->asUMLClassifier();
connect(c, SIGNAL(attributeAdded(UMLClassifierListItem*)),
this, SLOT(childObjectAdded(UMLClassifierListItem*)));
connect(c, SIGNAL(attributeRemoved(UMLClassifierListItem*)),
this, SLOT(childObjectRemoved(UMLClassifierListItem*)));
connect(c, SIGNAL(operationAdded(UMLClassifierListItem*)),
this, SLOT(childObjectAdded(UMLClassifierListItem*)));
connect(c, SIGNAL(operationRemoved(UMLClassifierListItem*)),
this, SLOT(childObjectRemoved(UMLClassifierListItem*)));
connect(c, SIGNAL(templateAdded(UMLClassifierListItem*)),
this, SLOT(childObjectAdded(UMLClassifierListItem*)));
connect(c, SIGNAL(templateRemoved(UMLClassifierListItem*)),
this, SLOT(childObjectRemoved(UMLClassifierListItem*)));
case UMLObject::ot_Interface:
{
UMLClassifier *c = object->asUMLClassifier();
connect(c, SIGNAL(attributeAdded(UMLClassifierListItem*)),
this, SLOT(childObjectAdded(UMLClassifierListItem*)));
connect(c, SIGNAL(attributeRemoved(UMLClassifierListItem*)),
this, SLOT(childObjectRemoved(UMLClassifierListItem*)));
connect(c, SIGNAL(operationAdded(UMLClassifierListItem*)),
this, SLOT(childObjectAdded(UMLClassifierListItem*)));
connect(c, SIGNAL(operationRemoved(UMLClassifierListItem*)),
this, SLOT(childObjectRemoved(UMLClassifierListItem*)));
connect(c, SIGNAL(templateAdded(UMLClassifierListItem*)),
this, SLOT(childObjectAdded(UMLClassifierListItem*)));
connect(c, SIGNAL(templateRemoved(UMLClassifierListItem*)),
this, SLOT(childObjectRemoved(UMLClassifierListItem*)));
connect(object, SIGNAL(modified()), this, SLOT(slotObjectChanged()));
}
break;
case UMLObject::ot_Instance:
{
connect(object, SIGNAL(modified()), this, SLOT(slotObjectChanged()));
}
break;
case UMLObject::ot_Enum:
{
UMLEnum *e = object->asUMLEnum();
connect(e, SIGNAL(enumLiteralAdded(UMLClassifierListItem*)),
this, SLOT(childObjectAdded(UMLClassifierListItem*)));
connect(e, SIGNAL(enumLiteralRemoved(UMLClassifierListItem*)),
this, SLOT(childObjectRemoved(UMLClassifierListItem*)));
}
connect(object, SIGNAL(modified()), this, SLOT(slotObjectChanged()));
}
break;
case UMLObject::ot_Instance: {
break;
case UMLObject::ot_Entity:
{
UMLEntity *ent = object->asUMLEntity();
connect(ent, SIGNAL(entityAttributeAdded(UMLClassifierListItem*)),
this, SLOT(childObjectAdded(UMLClassifierListItem*)));
connect(ent, SIGNAL(entityAttributeRemoved(UMLClassifierListItem*)),
this, SLOT(childObjectRemoved(UMLClassifierListItem*)));
connect(ent, SIGNAL(entityConstraintAdded(UMLClassifierListItem*)),
this, SLOT(childObjectAdded(UMLClassifierListItem*)));
connect(ent, SIGNAL(entityConstraintRemoved(UMLClassifierListItem*)),
this, SLOT(childObjectRemoved(UMLClassifierListItem*)));
}
connect(object, SIGNAL(modified()), this, SLOT(slotObjectChanged()));
}
break;
case UMLObject::ot_Enum: {
UMLEnum *e = object->asUMLEnum();
connect(e, SIGNAL(enumLiteralAdded(UMLClassifierListItem*)),
this, SLOT(childObjectAdded(UMLClassifierListItem*)));
connect(e, SIGNAL(enumLiteralRemoved(UMLClassifierListItem*)),
this, SLOT(childObjectRemoved(UMLClassifierListItem*)));
}
connect(object, SIGNAL(modified()), this, SLOT(slotObjectChanged()));
break;
case UMLObject::ot_Entity: {
UMLEntity *ent = object->asUMLEntity();
connect(ent, SIGNAL(entityAttributeAdded(UMLClassifierListItem*)),
this, SLOT(childObjectAdded(UMLClassifierListItem*)));
connect(ent, SIGNAL(entityAttributeRemoved(UMLClassifierListItem*)),
this, SLOT(childObjectRemoved(UMLClassifierListItem*)));
connect(ent, SIGNAL(entityConstraintAdded(UMLClassifierListItem*)),
this, SLOT(childObjectAdded(UMLClassifierListItem*)));
connect(ent, SIGNAL(entityConstraintRemoved(UMLClassifierListItem*)),
this, SLOT(childObjectRemoved(UMLClassifierListItem*)));
}
connect(object, SIGNAL(modified()), this, SLOT(slotObjectChanged()));
break;
break;
case UMLObject::ot_Datatype:
case UMLObject::ot_Attribute:
case UMLObject::ot_Operation:
......@@ -2307,10 +2311,12 @@ void UMLListView::addNewItem(UMLListViewItem *parentItem, UMLListViewItem::ListV
scrollToItem(instanceItem);
clearSelection();
instanceItem->setSelected(true);
UMLInstance::AttributeValues& values = inst->getAttrValues();
foreach (UMLInstanceAttribute *child, values) {
UMLObjectList& values = inst->subordinates();
foreach (UMLObject *child, values) {
if (!child->isUMLInstanceAttribute())
continue;
connectNewObjectsSlots(child);
const QString text = child->toString();
const QString text = child->asUMLInstanceAttribute()->toString();
UMLListViewItem *childItem =
new UMLListViewItem(instanceItem, text, UMLListViewItem::lvt_InstanceAttribute , child);
Q_UNUSED(childItem);
......@@ -2603,8 +2609,9 @@ bool UMLListView::loadChildrenFromXMI(UMLListViewItem * parent, QDomElement & el
} else if (lvType == UMLListViewItem::lvt_InstanceAttribute) {
UMLInstance *instance = umlObject->asUMLInstance();
if (instance) {
UMLInstanceAttribute *instAttr = instance->findChildObjectById(nID);
if (instAttr) {
umlObject = instance->findChildObjectById(nID);
if (umlObject) {
UMLInstanceAttribute *instAttr = umlObject->asUMLInstanceAttribute();
connectNewObjectsSlots(instAttr);
label = instAttr->toString();
item = new UMLListViewItem(parent, label, lvType, instAttr);
......
......@@ -1132,23 +1132,29 @@ void ClassifierWidget::drawMembers(QPainter * painter,
f.setBold(false);
painter->setClipping(true);
painter->setClipRect(rect());
UMLInstance::AttributeValues ialist;
UMLObjectList ialist;
if (drawInstanceAttributes) {
UMLInstance *umlinst = m_umlObject->asUMLInstance();
umlc = umlinst->classifier();
ialist = umlinst->getAttrValues();
ialist = umlinst->subordinates();
}
UMLClassifierListItemList list = umlc->getFilteredList(ot);
for (int i = 0; i < list.count(); i++) {
UMLClassifierListItem *obj = list.at(i);
uIgnoreZeroPointer(obj);
if (visualProperty(ShowPublicOnly) && obj->visibility() != Uml::Visibility::Public)
continue;
QString text;
if (drawInstanceAttributes) {
UMLInstanceAttribute *iatt = ialist.at(i);
UMLInstanceAttribute *iatt = ialist.at(i)->asUMLInstanceAttribute();
if (!iatt) {
uDebug() << "ClassifierWidget::drawMembers(" << obj->name()
<< ") : skipping non InstanceAttribute subordinate";
continue;
}
/* CHECK: Do we want visibility indication on instance attributes?
if (sigType == Uml::SignatureType::ShowSig || sigType == Uml::SignatureType::NoSig)
text = Uml::Visibility::toString(obj->visibility(), true) + QLatin1Char(' ');
text = Uml::Visibility::toString(iatt->visibility(), true) + QLatin1Char(' ');
*/
text.append(iatt->toString());
} else {
......
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