2016-01-15 14:58:39 +01:00
|
|
|
/****************************************************************************
|
2015-08-16 13:11:15 +02:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** Copyright (C) 2016 Jochen Becher
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2015-08-16 13:11:15 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:58:39 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2015-08-16 13:11:15 +02:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2015-08-16 13:11:15 +02:00
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "dupdatevisitor.h"
|
|
|
|
|
|
|
|
|
|
#include "qmt/diagram/delement.h"
|
|
|
|
|
#include "qmt/diagram/dobject.h"
|
|
|
|
|
#include "qmt/diagram/dclass.h"
|
|
|
|
|
#include "qmt/diagram/ditem.h"
|
|
|
|
|
#include "qmt/diagram/drelation.h"
|
|
|
|
|
#include "qmt/diagram/ddependency.h"
|
|
|
|
|
#include "qmt/diagram/dassociation.h"
|
2016-08-23 21:47:12 +02:00
|
|
|
#include "qmt/diagram/dconnection.h"
|
2015-08-16 13:11:15 +02:00
|
|
|
|
|
|
|
|
#include "qmt/model/melement.h"
|
|
|
|
|
#include "qmt/model/mobject.h"
|
|
|
|
|
#include "qmt/model/mclass.h"
|
|
|
|
|
#include "qmt/model/mcomponent.h"
|
|
|
|
|
#include "qmt/model/mpackage.h"
|
|
|
|
|
#include "qmt/model/mdiagram.h"
|
|
|
|
|
#include "qmt/model/mcanvasdiagram.h"
|
|
|
|
|
#include "qmt/model/mitem.h"
|
|
|
|
|
#include "qmt/model/mrelation.h"
|
|
|
|
|
#include "qmt/model/massociation.h"
|
|
|
|
|
#include "qmt/model/mdependency.h"
|
|
|
|
|
#include "qmt/model/minheritance.h"
|
|
|
|
|
|
|
|
|
|
namespace qmt {
|
|
|
|
|
|
2015-11-04 07:52:44 +01:00
|
|
|
DUpdateVisitor::DUpdateVisitor(DElement *target, const MDiagram *diagram, bool checkNeedsUpdate)
|
2015-11-03 22:30:46 +01:00
|
|
|
: m_target(target),
|
|
|
|
|
m_diagram(diagram),
|
2015-11-04 07:52:44 +01:00
|
|
|
m_checkNeedsUpdate(checkNeedsUpdate),
|
2015-11-12 20:25:36 +01:00
|
|
|
m_isUpdateNeeded(!checkNeedsUpdate)
|
2015-08-16 13:11:15 +02:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-04 07:52:44 +01:00
|
|
|
void DUpdateVisitor::setCheckNeedsUpdate(bool checkNeedsUpdate)
|
2015-08-16 13:11:15 +02:00
|
|
|
{
|
2015-11-04 07:52:44 +01:00
|
|
|
m_checkNeedsUpdate = checkNeedsUpdate;
|
2015-11-12 20:25:36 +01:00
|
|
|
m_isUpdateNeeded = !checkNeedsUpdate;
|
2015-08-16 13:11:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DUpdateVisitor::visitMElement(const MElement *element)
|
|
|
|
|
{
|
|
|
|
|
Q_UNUSED(element);
|
|
|
|
|
|
2015-11-03 22:30:46 +01:00
|
|
|
QMT_CHECK(m_target);
|
2015-08-16 13:11:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DUpdateVisitor::visitMObject(const MObject *object)
|
|
|
|
|
{
|
2015-11-21 20:54:19 +01:00
|
|
|
auto dobject = dynamic_cast<DObject *>(m_target);
|
2017-07-09 11:49:13 +02:00
|
|
|
QMT_ASSERT(dobject, return);
|
2015-11-14 16:59:30 +01:00
|
|
|
if (isUpdating(object->stereotypes() != dobject->stereotypes()))
|
2015-11-04 22:44:41 +01:00
|
|
|
dobject->setStereotypes(object->stereotypes());
|
|
|
|
|
const MObject *objectOwner = object->owner();
|
|
|
|
|
const MObject *diagramOwner = m_diagram->owner();
|
|
|
|
|
if (objectOwner && diagramOwner && objectOwner->uid() != diagramOwner->uid()) {
|
2015-11-14 16:59:30 +01:00
|
|
|
if (isUpdating(objectOwner->name() != dobject->context()))
|
2015-11-04 22:44:41 +01:00
|
|
|
dobject->setContext(objectOwner->name());
|
2015-08-16 13:11:15 +02:00
|
|
|
} else {
|
2015-11-14 16:59:30 +01:00
|
|
|
if (isUpdating(!dobject->context().isEmpty()))
|
2015-08-16 13:11:15 +02:00
|
|
|
dobject->setContext(QString());
|
|
|
|
|
}
|
2015-11-14 16:59:30 +01:00
|
|
|
if (isUpdating(object->name() != dobject->name()))
|
2015-11-04 22:44:41 +01:00
|
|
|
dobject->setName(object->name());
|
2015-08-16 13:11:15 +02:00
|
|
|
// TODO unlikely that this is called for all objects if hierarchy is modified
|
|
|
|
|
// PERFORM remove loop
|
|
|
|
|
int depth = 1;
|
2015-11-04 22:44:41 +01:00
|
|
|
const MObject *owner = object->owner();
|
2015-08-16 13:11:15 +02:00
|
|
|
while (owner) {
|
2015-11-04 22:44:41 +01:00
|
|
|
owner = owner->owner();
|
2015-08-16 13:11:15 +02:00
|
|
|
depth += 1;
|
|
|
|
|
}
|
2015-11-14 16:59:30 +01:00
|
|
|
if (isUpdating(depth != dobject->depth()))
|
2015-08-16 13:11:15 +02:00
|
|
|
dobject->setDepth(depth);
|
|
|
|
|
visitMElement(object);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DUpdateVisitor::visitMPackage(const MPackage *package)
|
|
|
|
|
{
|
|
|
|
|
visitMObject(package);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DUpdateVisitor::visitMClass(const MClass *klass)
|
|
|
|
|
{
|
2015-11-21 20:54:19 +01:00
|
|
|
auto dclass = dynamic_cast<DClass *>(m_target);
|
2017-07-09 11:49:13 +02:00
|
|
|
QMT_ASSERT(dclass, return);
|
2015-11-14 16:59:30 +01:00
|
|
|
if (isUpdating(klass->umlNamespace() != dclass->umlNamespace()))
|
2015-11-12 20:05:49 +01:00
|
|
|
dclass->setUmlNamespace(klass->umlNamespace());
|
2015-11-14 16:59:30 +01:00
|
|
|
if (isUpdating(klass->templateParameters() != dclass->templateParameters()))
|
2015-11-04 22:44:41 +01:00
|
|
|
dclass->setTemplateParameters(klass->templateParameters());
|
2015-11-14 16:59:30 +01:00
|
|
|
if (isUpdating(klass->members() != dclass->members()))
|
2015-11-04 22:44:41 +01:00
|
|
|
dclass->setMembers(klass->members());
|
2015-08-16 13:11:15 +02:00
|
|
|
visitMObject(klass);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DUpdateVisitor::visitMComponent(const MComponent *component)
|
|
|
|
|
{
|
|
|
|
|
visitMObject(component);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DUpdateVisitor::visitMDiagram(const MDiagram *diagram)
|
|
|
|
|
{
|
|
|
|
|
visitMObject(diagram);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DUpdateVisitor::visitMCanvasDiagram(const MCanvasDiagram *diagram)
|
|
|
|
|
{
|
|
|
|
|
visitMDiagram(diagram);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DUpdateVisitor::visitMItem(const MItem *item)
|
|
|
|
|
{
|
2015-11-21 20:54:19 +01:00
|
|
|
auto ditem = dynamic_cast<DItem *>(m_target);
|
2017-07-09 11:49:13 +02:00
|
|
|
QMT_ASSERT(ditem, return);
|
2015-11-14 16:59:30 +01:00
|
|
|
if (isUpdating(item->isShapeEditable() != ditem->isShapeEditable()))
|
2015-08-16 13:11:15 +02:00
|
|
|
ditem->setShapeEditable(item->isShapeEditable());
|
2015-11-14 16:59:30 +01:00
|
|
|
if (isUpdating(item->variety() != ditem->variety()))
|
2015-11-04 22:44:41 +01:00
|
|
|
ditem->setVariety(item->variety());
|
2015-08-16 13:11:15 +02:00
|
|
|
visitMObject(item);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DUpdateVisitor::visitMRelation(const MRelation *relation)
|
|
|
|
|
{
|
2015-11-21 20:54:19 +01:00
|
|
|
auto drelation = dynamic_cast<DRelation *>(m_target);
|
2017-07-09 11:49:13 +02:00
|
|
|
QMT_ASSERT(drelation, return);
|
2015-11-14 16:59:30 +01:00
|
|
|
if (isUpdating(relation->stereotypes() != drelation->stereotypes()))
|
2015-11-04 22:44:41 +01:00
|
|
|
drelation->setStereotypes(relation->stereotypes());
|
2015-11-14 16:59:30 +01:00
|
|
|
if (isUpdating(relation->name() != drelation->name()))
|
2015-11-04 22:44:41 +01:00
|
|
|
drelation->setName(relation->name());
|
2015-12-03 17:12:30 +01:00
|
|
|
// TODO improve performance of MDiagram::findDiagramElement
|
|
|
|
|
DObject *endAObject = dynamic_cast<DObject *>(m_diagram->findDiagramElement(drelation->endAUid()));
|
|
|
|
|
if (!endAObject || relation->endAUid() != endAObject->modelUid()) {
|
2017-07-08 09:57:38 +02:00
|
|
|
(void) isUpdating(true);
|
2015-12-03 17:12:30 +01:00
|
|
|
endAObject = 0;
|
|
|
|
|
// TODO use DiagramController::findDelegate (and improve performance of that method)
|
|
|
|
|
foreach (DElement *diagramElement, m_diagram->diagramElements()) {
|
|
|
|
|
if (diagramElement->modelUid().isValid() && diagramElement->modelUid() == relation->endAUid()) {
|
|
|
|
|
endAObject = dynamic_cast<DObject *>(diagramElement);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (endAObject)
|
|
|
|
|
drelation->setEndAUid(endAObject->uid());
|
|
|
|
|
else
|
|
|
|
|
drelation->setEndAUid(Uid::invalidUid());
|
|
|
|
|
}
|
|
|
|
|
DObject *endBObject = dynamic_cast<DObject *>(m_diagram->findDiagramElement(drelation->endBUid()));
|
|
|
|
|
if (!endBObject || relation->endBUid() != endBObject->modelUid()) {
|
2017-07-08 09:57:38 +02:00
|
|
|
(void) isUpdating(true);
|
2015-12-03 17:12:30 +01:00
|
|
|
endBObject = 0;
|
|
|
|
|
// TODO use DiagramController::findDelegate
|
|
|
|
|
foreach (DElement *diagramElement, m_diagram->diagramElements()) {
|
|
|
|
|
if (diagramElement->modelUid().isValid() && diagramElement->modelUid() == relation->endBUid()) {
|
|
|
|
|
endBObject = dynamic_cast<DObject *>(diagramElement);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (endBObject)
|
|
|
|
|
drelation->setEndBUid(endBObject->uid());
|
|
|
|
|
else
|
|
|
|
|
drelation->setEndBUid(Uid::invalidUid());
|
|
|
|
|
}
|
2015-08-16 13:11:15 +02:00
|
|
|
visitMElement(relation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DUpdateVisitor::visitMDependency(const MDependency *dependency)
|
|
|
|
|
{
|
2015-11-21 20:54:19 +01:00
|
|
|
auto ddependency = dynamic_cast<DDependency *>(m_target);
|
2017-07-09 11:49:13 +02:00
|
|
|
QMT_ASSERT(ddependency, return);
|
2015-11-14 16:59:30 +01:00
|
|
|
if (isUpdating(dependency->direction() != ddependency->direction()))
|
2015-11-04 22:44:41 +01:00
|
|
|
ddependency->setDirection(dependency->direction());
|
2015-08-16 13:11:15 +02:00
|
|
|
visitMRelation(dependency);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DUpdateVisitor::visitMInheritance(const MInheritance *inheritance)
|
|
|
|
|
{
|
|
|
|
|
visitMRelation(inheritance);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void DUpdateVisitor::visitMAssociation(const MAssociation *association)
|
|
|
|
|
{
|
2015-11-21 20:54:19 +01:00
|
|
|
auto dassociation = dynamic_cast<DAssociation *>(m_target);
|
2017-07-09 11:49:13 +02:00
|
|
|
QMT_ASSERT(dassociation, return);
|
2015-11-04 07:52:44 +01:00
|
|
|
DAssociationEnd endA;
|
2015-11-04 22:44:41 +01:00
|
|
|
endA.setName(association->endA().name());
|
|
|
|
|
endA.setCardinatlity(association->endA().cardinality());
|
|
|
|
|
endA.setNavigable(association->endA().isNavigable());
|
|
|
|
|
endA.setKind(association->endA().kind());
|
2015-11-14 16:59:30 +01:00
|
|
|
if (isUpdating(endA != dassociation->endA()))
|
2015-11-04 22:44:41 +01:00
|
|
|
dassociation->setEndA(endA);
|
2015-11-04 07:52:44 +01:00
|
|
|
DAssociationEnd endB;
|
2015-11-04 22:44:41 +01:00
|
|
|
endB.setName(association->endB().name());
|
|
|
|
|
endB.setCardinatlity(association->endB().cardinality());
|
|
|
|
|
endB.setNavigable(association->endB().isNavigable());
|
|
|
|
|
endB.setKind(association->endB().kind());
|
2015-11-14 16:59:30 +01:00
|
|
|
if (isUpdating(endB != dassociation->endB()))
|
2015-11-04 22:44:41 +01:00
|
|
|
dassociation->setEndB(endB);
|
2015-08-16 13:11:15 +02:00
|
|
|
visitMRelation(association);
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-23 21:47:12 +02:00
|
|
|
void DUpdateVisitor::visitMConnection(const MConnection *connection)
|
|
|
|
|
{
|
|
|
|
|
auto dconnection = dynamic_cast<DConnection *>(m_target);
|
|
|
|
|
QMT_CHECK(dconnection);
|
|
|
|
|
if (isUpdating(connection->customRelationId() != dconnection->customRelationId()))
|
|
|
|
|
dconnection->setCustomRelationId(connection->customRelationId());
|
|
|
|
|
DConnectionEnd endA;
|
|
|
|
|
endA.setName(connection->endA().name());
|
|
|
|
|
endA.setCardinatlity(connection->endA().cardinality());
|
|
|
|
|
endA.setNavigable(connection->endA().isNavigable());
|
|
|
|
|
if (isUpdating(endA != dconnection->endA()))
|
|
|
|
|
dconnection->setEndA(endA);
|
|
|
|
|
DConnectionEnd endB;
|
|
|
|
|
endB.setName(connection->endB().name());
|
|
|
|
|
endB.setCardinatlity(connection->endB().cardinality());
|
|
|
|
|
endB.setNavigable(connection->endB().isNavigable());
|
|
|
|
|
if (isUpdating(endB != dconnection->endB()))
|
|
|
|
|
dconnection->setEndB(endB);
|
|
|
|
|
visitMRelation(connection);
|
|
|
|
|
}
|
|
|
|
|
|
2015-11-04 07:52:44 +01:00
|
|
|
bool DUpdateVisitor::isUpdating(bool valueChanged)
|
2015-08-16 13:11:15 +02:00
|
|
|
{
|
2015-11-03 22:30:46 +01:00
|
|
|
if (m_checkNeedsUpdate) {
|
2015-11-14 16:59:30 +01:00
|
|
|
if (valueChanged)
|
2015-11-12 20:25:36 +01:00
|
|
|
m_isUpdateNeeded = true;
|
2015-08-16 13:11:15 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
2015-11-04 07:52:44 +01:00
|
|
|
return valueChanged;
|
2015-08-16 13:11:15 +02:00
|
|
|
}
|
|
|
|
|
|
2015-11-14 16:59:30 +01:00
|
|
|
} // namespace qmt
|