Skip to content
Commit 3203b16a authored by Oliver Kellogg's avatar Oliver Kellogg
Browse files

Further work on UML Instances. Main changes:

- Design cleanup: UMLInstance is slaved to UMLClassifier.
  Prominently, UMLInstance does not duplicate the UML attributes but
  holds references to the UML attributes.  The only additional item
  stored in UMLInstanceAttribute is the concrete attribute value.
- Inheritance cleanup:
  - UMLInstanceAttribute is derived from UMLObject.
  - UMLInstance is derived from UMLObject (this might be changed to
    UMLCanvasObject in future).
- Improvements in ClassifierWidget for handling instances.
- In list view,
  - in the menu popping up on right click on a class there is an
    additional choice "Instance". When selected, the attributes of
    the class are automatically transformed into the instance attributes
    of the new instance;
  - when a classifier derived instance has been created, an instance
    attribute value can be modified by double clicking on the instance
    attribute. Note that attribute _name_ change is not possible here;
    name change shall be done only using the master classifier.
- Improved XMI format for saving UMLInstanceAttribute.

Detailed changes:

umbrello/uml1model/instance.h
- Extend class documentation.  Distinguish standalone instance from
  instance slaved to classifier.
- Inherit from UMLObject instead of from UMLClassifier.
- Add Q_OBJECT declaration.
- At constructor add optional argument UMLClassifier *classifier
  defaulting to nullptr.
- Remove setter/getter for classifier name.
- At function setClassifierCmd add optional argument bool emitSignal
  defaulting to true.
- Remove function createAttribute (attribute creation and removal is
  done only via UMLClassifier; instance attributes are strictly slaved
  to the classifier attributes).
- Add function findChildObjectById(Uml::ID::Type) returning pointer to
  UMLInstanceAttribute.
- New type AttributeValues is a typedef of QList<UMLInstanceAttribute*>.
  It contains the attribute values in case this UMLInstance is slaved
  to a classifier.
- Add function getAttrValues returning AttributeValues&.
- Remove member m_classifier.
  The related classifier is now stored in UMLObject::m_pSecondary.
- Add member m_attrValues of type AttributeValues.
- Add public slots attributeAdded(UMLClassifierListItem*) and
  attributeRemoved(UMLClassifierListItem*).  In case the instance is
  slaved to a classifier they are connected to the corresponding signals
  of m_classifier.

umbrello/uml1model/instance.cpp
- In constructor,
  - remove call to Object_Factory::createUMLObject for creating the
    master class;
  - assign m_classifier from argument `c';
  - call setClassifierCmd(c, false).
- Adapt functions setClassifier and setClassifierCmd to replacement of
  m_classifier by UMLObject::m_pSecondary.
- In function setClassifierCmd, if classifier is non null then
  - create a UMLInstanceAttribute for each of the classifier's
    attributes and fill m_attrValues;
  - connect the classifier's attributeAdded/attributeRemoved signals to
    the instance's corresponding slots.
- Adjust function classifier() to m_pSecondary possibly being null (in
  case of an untyped instance).
- New function findChildObjectById seeks the given ID in the XMI IDs of
  m_attrValues and returns pointer to the UMLInstanceAttribute if found.
- New function getAttrValues returns m_attrValues.
- Adjust function saveToXMI1 to use of m_pSecondary for the classifier.
- Adjust function load1 to load the instance attributes from XML tag
  "slot" instead of "UML:InstanceAttribute".
- Adjust function resolveRef to the possibility of m_pSecondary
  legitimately being nullptr.
- In new slot function attributeAdded, add UMLInstanceAttribute
  corresponding to the UMLAttribute into m_attrValues.
- In new slot function attributeRemoved, iterate over m_attrValues and
  test whether the given item is equal to one of the InstanceAttribute's
  parent. Remove the matching instance attribute from m_attrValues.

umbrello/uml1model/instanceattribute.{h,cpp}
- Extend class documentation mentioning that the UMLInstanceAttribute is
  strictly slaved to its corresponding classifier's UMLAttribute.
- Inherit from UMLObject instead of from UMLAttribute.
- At constructor,
  - change type of `parent' to UMLInstance* to more precisely express
    the expected parent type;
  - replace arguments `name', `id', `s', `type' by argument umlAttr of
    type UMLAttribute*.
    UMLObject::m_pSecondary is used for saving the master attribute.
- Remove explicit constructor with single argument `parent'.
- Add accessors setAttribute, getAttribute.
- Remove accessors setAttributes, getAttributes.
- New function toString returns the textual notation for the instance
  attribute.
- Remove member m_attributes.
- Add member m_value.

umbrello/uml1model/instanceattribute.cpp
- In new accessor functions setAttribute/getAttribute manipulate
  UMLObject::m_pSecondary.
  In function setAttribute require the incoming umlAttr to be non null.
- In new accessor functions setValue/getValue manipulate m_value.
- In function saveToXMI1:
  - Replace tag "UML:InstanceAttribute" by "slot".
    This is somewhat more UML 1.4 compliant and is more in line with
    UML2 InstanceSpecification save format.
  - Replace saving of XML attribute "attributes" by "attribute"
    referencing the parent UMLAttribute XMI ID.
  - Replace saving of XML attribute "initialValue" by "value" writing
    member m_value.
- Change function load1 commensurate to saveToXMI1. Load XML attribute
  "attribute" into m_SecondaryId. If m_SecondaryId can be resolved ad
  hoc then set m_pSecondary to the master UMLAttribute, else defer
  resolution to the resolveRef() pass.

umbrello/cmds/generic/cmdrenameumlinstancetype.{h,cpp}
- Remove. Reason: Renaming the instance's associated classifier is not
  supported.  Rather, the classifier itself shall be renamed.

umbrello/CMakeLists.txt
- Remove cmds/generic/cmdrenameumlinstancetype.cpp from libcmds_SRCS.

umbrello/cmds.h
- Remove #include "cmds/generic/cmdrenameumlinstancetype.h".

umbrello/dialogs/pages/classgeneralpage.cpp
- In function apply() non null m_pObject remove call to
  m_pObject->asUMLInstance()->setClassifierName().

umbrello/dialogs/umlinstanceattributedialog.{h,cpp}
- #include "instanceattribute.h" instead of attribute.h.
- At constructor change argument
    UMLAttribute *pAttribute
  to
    UMLInstanceAttribute *pInstanceAttr.
- Change private member
    UMLAttribute *m_pAttribute
  to
    UMLInstanceAttribute *m_pInstanceAttr.
- Remove slots section with slotNameChanged(const QString &).

umbrello/dialogs/umlinstanceattributedialog.cpp
- #include "attribute.h" instead of classifier.h.
- In constructor:
  - Remove signal textChanged() to slotNameChanged() connection.
  - Set ui->nameLE ReadOnly - renaming of the master classifier shall be
    done via the classifier dialog.
  - Initialize text of ui->valueLE to pInstanceAttr->getValue(), or if
    empty then to pInstanceAttr->getAttribute()->getInitialValue().
- In function apply():
  - Remove logic related to changing the classifier name.
  - Call m_pInstanceAttr->setValue(value) and
    m_pInstanceAttr->emitModified().

umbrello/uml1model/classifier.cpp
- In function takeItem remove case UMLObject::ot_InstanceAttribute.
  Reason: subordinates() no longer contain instance attributes because
  class UMLInstanceAttribute does not inherit UMLClassifierListItem.

umbrello/umlwidgets/classifierwidget.{h,cpp}
- At constructor change type of argument `c' from UMLClassifier* to
  UMLObject*.  Reason: UMLInstance does not inherit UMLClassifier.

umbrello/umlwidgets/classifierwidget.cpp
- In function displayedMembers, if umlc is null and m_umlObject is a
  UMLInstance and `ot' is ot_Attribute then set umlc to
  m_umlObject->asUMLInstance()->classifier().
- In function calculateSize,
  - if umlc is null and m_umlObject is a UMLInstance then set umlc to
    m_umlObject->asUMLInstance()->classifier();
  - adjust code to the possibility that m_umlObject is legitimately a
    nullptr.
- In function displayedAttributes call displayedMembers() with argument
  UMLObject::ot_Attribute regardless of baseType().
  Reason: Function displayedMembers handles UMLInstance autonomously.
- In function setClassAssociationWidget improve error message for case
  !classifier().
- In function paint() :
  - If umlc is null and m_umlObject is a UMLInstance then set umlc to
    m_umlObject->asUMLInstance()->classifier();
  - Adjust code to the possibility of m_umlObject legitimately being a
    nullptr;
  - In code for drawing name,
    - streamline calculation of displayedName;
    - if baseType() is wt_Object or wt_Instance then enable underlining.
  - In code for drawing attributes call drawMembers() with argument
    UMLObject::ot_Attribute regardless of baseType().
    Reason: Function drawMembers handles UMLInstance autonomously.
- In function drawMembers :
  - Local bool drawInstanceAttributes is set true when m_umlObject is a
    UMLInstance and argument `ot' is ot_Attribute.
  - Return without action if umlc is null and drawInstanceAttributes is
    false.
  - If drawInstanceAttributes is true then
    - local UMLInstance::AttributeValues ialist is filled using
        m_umlObject->asUMLInstance()->getAttrValues();
    - umlc is set to m_umlObject->asUMLInstance()->classifier().
  - For iterating over `list' replace foreach-loop by for-loop.
    Reason: Index `i' is used for indexing both `list' and `ialist'.
    If drawInstanceAttributes is true then the name is taken from
    list.at(i) and the value is taken from ialist.at(i).
- In function slotMenuSelection remove case mt_InstanceAttribute from
  classifier list item handling.
  Reason: UMLInstanceAttribute is not a UMLClassifierListItem.

umbrello/umllistviewitem.{h,cpp}
- Rename function addClassifierListItem to addChildItem and change its
  `child' argument type to UMLObject*.
  Reason: The function is extended to handle instance attributes (which
  are not of type UMLClassifierListItem).
- At functions deleteChildItem and findChildObject change argument type
  to UMLObject*.  Reason: The functions are extended to handle instance
  attributes (which are not of type UMLClassifierListItem).
- At type ChildObjectMap change key of QMap from UMLClassifierListItem*
  to UMLObject*.  Reason: The map now also stores instance attributes.

umbrello/umllistviewitem.cpp
- In function updateObject handle case (ot == ot_InstanceAttribute).

umbrello/umllistview.cpp
- In function slotMenuSelection add case ListPopupMenu::mt_Instance.
- In function mayHaveChildItems return false for case ot_Instance.
  Reason: UMLInstanceAttribute is not a UMLClassifierListItem.
- In function connectNewObjectsSlots case UMLObject::ot_Instance remove
  connecting of childObjectAdded.
  Reason: On constructing new UMLInstance the instance attributes are
  automatically added using the master classifier.
  Adding/removing attributes is done at the classifier only; dependent
  instances are updated automatically by a different signal connection.
- In function moveObject handle case lvt_Instance alongside Interface/
  Enum/Datatype.
- In function addNewItem case !Model_Utils::typeIsClassifierList(type),
  - local bool instanceOfClass is true if type is lvt_Instance and
    parent is a UMLClassifier;
  - local `package' is set to parent->umlPackage() if instanceOfClass
    is true;
  - if instanceOfClass is true then construct list view items for the
    UMLInstance::AttributeValues of object->asUMLInstance().
- In function isUnique add handling of UMLListViewItem::lvt_Instance.
- In function loadChildrenFromXMI add handling of lvt_InstanceAttribute.

umbrello/object_factory.cpp
- In function createNewUMLObject case UMLObject::ot_Instance, if
  parentPkg is a UMLClassifier then
  - local temporary UMLClassifier *c acts as shorthand for
    parentPkg->asUMLClassifier();
  - call to o->asUMLInstance()->setClassifierCmd(c) automatically
    constructs the instance attributes corresponding to the attributes
    of `c';
  - parentPkg is set to c->umlPackage() to normalize parentage for the
    new UMLInstance.
- In function createChildObject :
  - In switch (type) remove case UMLObject::ot_InstanceAttribute.
    Reason: We use special logic for creating instance attributes.
  - Before returning, check that returnObject can be cast to
    UMLClassifierListItem* and log an error if it can't.

umbrello/model_utils.cpp
- In function findObjectInList handle case UMLObject::ot_Instance
  separately from classifier derived types.
  Reason: UMLInstance is not a UMLClassifier.
- In function isClassifierListitem return false for type
  UMLObject::ot_InstanceAttribute.
  Reason: UMLInstanceAttribute is not a UMLClassifierListItem.
- In function typeIsCanvasWidget return true for case lvt_Instance.
- In function typeIsClassifierList return false for type
  UMLListViewItem::lvt_InstanceAttribute.
  Reason: UMLInstanceAttribute is not a UMLClassifierListItem.
- In function typeIsAllowedInType,
  - for case lvt_Attribute return (parentType == lvt_Class);
  - for case lvt_InstanceAttribute return (parentType == lvt_Instance).
- In function typeIsAllowedInDiagram :
  - In case Uml::DiagramType::Class accept UMLObject::ot_Instance.
    This prepares for using class diagram in style of UML2 composite
    structure diagram.
  - In case Uml::DiagramType::Object accept UMLObject::ot_Instance.

umbrello/assocrules.cpp
- In m_AssocRules[] AssociationType Coll_Mesg_Sync and Coll_Mesg_Async,
  - permit wt_Instance as widgetA/widgetB;
  - permit combinations of wt_Object/wt_Instance as widgetA/widgetB.
  This prepares for supporting instances in collaboration diagrams.

umbrello/version.h
- Increase XMI_FILE_VERSION to "1.7.2" due to changed save format of
  UMLInstanceAttribute.

CCBUG: 123633
parent c068be02
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment