/**************************************************************************** ** ** Copyright (C) 2013 Sandro S. Andrade ** Contact: http://www.qt-project.org/legal ** ** This file is part of the QtUml module of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ ** 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 ** a written agreement between you and Digia. For licensing terms and ** conditions see http://qt.digia.com/licensing. For further information ** use the contact form at http://qt.digia.com/contact-us. ** ** GNU Lesser General Public License Usage ** Alternatively, this file may be used under the terms of the GNU Lesser ** General Public License version 2.1 as published by the Free Software ** Foundation and appearing in the file LICENSE.LGPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU Lesser General Public License version 2.1 requirements ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. ** ** In addition, as a special exception, Digia gives you certain additional ** rights. These rights are described in the Digia Qt LGPL Exception ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. ** ** GNU General Public License Usage ** Alternatively, this file may be used under the terms of the GNU ** General Public License version 3.0 as published by the Free Software ** Foundation and appearing in the file LICENSE.GPL included in the ** packaging of this file. Please review the following information to ** ensure the GNU General Public License version 3.0 requirements will be ** met: http://www.gnu.org/copyleft/gpl.html. ** ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include "qumlassociation.h" #include "private/qumlassociationobject_p.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include QT_BEGIN_NAMESPACE /*! \class QUmlAssociation \inmodule QtUml \brief An association describes a set of tuples whose values refer to typed instances. An instance of an association is called a link.A link is a tuple with one value for each end of the association, where each value is an instance of the type of the end.An association describes a set of tuples whose values refer to typed instances. An instance of an association is called a link. A link is a tuple with one value for each end of the association, where each value is an instance of the type of the end. */ /*! Creates a new QUmlAssociation. Also creates the corresponding QObject-based representation returned by asQModelingObject() if \a createQModelingObject is true. */ QUmlAssociation::QUmlAssociation(bool createQModelingObject) : _isDerived(false) { if (createQModelingObject) _qModelingObject = qobject_cast(new QUmlAssociationObject(this)); } /*! Destroys the QUmlAssociation. */ QUmlAssociation::~QUmlAssociation() { QModelingElement::deleteQModelingObject(); } /*! Returns a deep-copied clone of the QUmlAssociation. */ QModelingElement *QUmlAssociation::clone() const { QUmlAssociation *c = new QUmlAssociation; foreach (QUmlComment *element, ownedComments()) c->addOwnedComment(dynamic_cast(element->clone())); c->setName(name()); if (nameExpression()) c->setNameExpression(dynamic_cast(nameExpression()->clone())); foreach (QUmlElementImport *element, elementImports()) c->addElementImport(dynamic_cast(element->clone())); foreach (QUmlConstraint *element, ownedRules()) c->addOwnedRule(dynamic_cast(element->clone())); foreach (QUmlPackageImport *element, packageImports()) c->addPackageImport(dynamic_cast(element->clone())); c->setVisibility(visibility()); c->setLeaf(isLeaf()); foreach (QUmlTemplateBinding *element, templateBindings()) c->addTemplateBinding(dynamic_cast(element->clone())); foreach (QUmlCollaborationUse *element, collaborationUses()) c->addCollaborationUse(dynamic_cast(element->clone())); foreach (QUmlGeneralization *element, generalizations()) c->addGeneralization(dynamic_cast(element->clone())); c->setAbstract(isAbstract()); c->setFinalSpecialization(isFinalSpecialization()); if (ownedTemplateSignature()) c->setOwnedTemplateSignature(dynamic_cast(ownedTemplateSignature()->clone())); foreach (QUmlUseCase *element, ownedUseCases()) c->addOwnedUseCase(dynamic_cast(element->clone())); foreach (QUmlSubstitution *element, substitutions()) c->addSubstitution(dynamic_cast(element->clone())); c->setDerived(isDerived()); foreach (QUmlProperty *element, ownedEnds()) c->addOwnedEnd(dynamic_cast(element->clone())); return c; } // OWNED ATTRIBUTES /*! References the classifiers that are used as types of the ends of the association. \b {This is a read-only derived property.} \b {Subsetted property(ies):} QUmlRelationship::relatedElements(). */ const QList QUmlAssociation::endTypes() const { // This is a read-only derived association end qWarning("QUmlAssociation::endTypes(): to be implemented (this is a derived association end)"); return QList(); } /*! Adds \a endType to endTypes. \sa endTypes(), removeEndType() */ void QUmlAssociation::addEndType(QUmlType *endType) { // This is a read-only derived association end qWarning("QUmlAssociation::addEndType(): to be implemented (this is a derived association end)"); Q_UNUSED(endType); if (false /* */) { // // Adjust subsetted properties addRelatedElement(endType); } } /*! Removes \a endType from endTypes. \sa endTypes(), addEndType() */ void QUmlAssociation::removeEndType(QUmlType *endType) { // This is a read-only derived association end qWarning("QUmlAssociation::removeEndType(): to be implemented (this is a derived association end)"); Q_UNUSED(endType); if (false /* */) { // // Adjust subsetted properties removeRelatedElement(endType); } } /*! Specifies whether the association is derived from other model elements such as other associations or constraints. */ bool QUmlAssociation::isDerived() const { // This is a read-write property return _isDerived; } /*! Adjusts isDerived to \a isDerived. */ void QUmlAssociation::setDerived(bool isDerived) { // This is a read-write property if (_isDerived != isDerived) { _isDerived = isDerived; _qModelingObject->modifiedResettableProperties() << QStringLiteral("isDerived"); } } /*! Each end represents participation of instances of the classifier connected to the end in links of the association. \sa addMemberEnd(), removeMemberEnd() \b {Subsetted property(ies):} QUmlNamespace::members(). \b {Opposite property(ies):} QUmlProperty::association(). */ const QList QUmlAssociation::memberEnds() const { // This is a read-write association end return _memberEnds; } /*! Adds \a memberEnd to memberEnds. \sa memberEnds(), removeMemberEnd() */ void QUmlAssociation::addMemberEnd(QUmlProperty *memberEnd) { // This is a read-write association end if (!_memberEnds.contains(memberEnd)) { _memberEnds.append(memberEnd); if (memberEnd && memberEnd->asQModelingObject() && this->asQModelingObject()) QObject::connect(memberEnd->asQModelingObject(), SIGNAL(destroyed(QObject*)), this->asQModelingObject(), SLOT(removeMemberEnd(QObject *))); // Adjust subsetted properties addMember(memberEnd); // Adjust opposite properties if (memberEnd) { memberEnd->setAssociation(this); } } } /*! Removes \a memberEnd from memberEnds. \sa memberEnds(), addMemberEnd() */ void QUmlAssociation::removeMemberEnd(QUmlProperty *memberEnd) { // This is a read-write association end if (_memberEnds.contains(memberEnd)) { _memberEnds.removeAll(memberEnd); // Adjust subsetted properties removeMember(memberEnd); // Adjust opposite properties if (memberEnd) { memberEnd->setAssociation(0); } } } /*! The navigable ends that are owned by the association itself. \sa addNavigableOwnedEnd(), removeNavigableOwnedEnd() \b {Subsetted property(ies):} QUmlAssociation::ownedEnds(). */ const QSet QUmlAssociation::navigableOwnedEnds() const { // This is a read-write association end return _navigableOwnedEnds; } /*! Adds \a navigableOwnedEnd to navigableOwnedEnds. \sa navigableOwnedEnds(), removeNavigableOwnedEnd() */ void QUmlAssociation::addNavigableOwnedEnd(QUmlProperty *navigableOwnedEnd) { // This is a read-write association end if (!_navigableOwnedEnds.contains(navigableOwnedEnd)) { _navigableOwnedEnds.insert(navigableOwnedEnd); if (navigableOwnedEnd && navigableOwnedEnd->asQModelingObject() && this->asQModelingObject()) QObject::connect(navigableOwnedEnd->asQModelingObject(), SIGNAL(destroyed(QObject*)), this->asQModelingObject(), SLOT(removeNavigableOwnedEnd(QObject *))); // Adjust subsetted properties addOwnedEnd(navigableOwnedEnd); } } /*! Removes \a navigableOwnedEnd from navigableOwnedEnds. \sa navigableOwnedEnds(), addNavigableOwnedEnd() */ void QUmlAssociation::removeNavigableOwnedEnd(QUmlProperty *navigableOwnedEnd) { // This is a read-write association end if (_navigableOwnedEnds.contains(navigableOwnedEnd)) { _navigableOwnedEnds.remove(navigableOwnedEnd); // Adjust subsetted properties removeOwnedEnd(navigableOwnedEnd); } } /*! The ends that are owned by the association itself. \sa addOwnedEnd(), removeOwnedEnd() \b {Subsetted property(ies):} QUmlAssociation::memberEnds(), QUmlClassifier::features(), QUmlNamespace::ownedMembers(). \b {Opposite property(ies):} QUmlProperty::owningAssociation(). */ const QList QUmlAssociation::ownedEnds() const { // This is a read-write association end return _ownedEnds; } /*! Adds \a ownedEnd to ownedEnds. \sa ownedEnds(), removeOwnedEnd() */ void QUmlAssociation::addOwnedEnd(QUmlProperty *ownedEnd) { // This is a read-write association end if (!_ownedEnds.contains(ownedEnd)) { _ownedEnds.append(ownedEnd); if (ownedEnd && ownedEnd->asQModelingObject() && this->asQModelingObject()) QObject::connect(ownedEnd->asQModelingObject(), SIGNAL(destroyed(QObject*)), this->asQModelingObject(), SLOT(removeOwnedEnd(QObject *))); ownedEnd->asQModelingObject()->setParent(this->asQModelingObject()); // Adjust subsetted properties addMemberEnd(ownedEnd); addFeature(ownedEnd); addOwnedMember(ownedEnd); // Adjust opposite properties if (ownedEnd) { ownedEnd->setOwningAssociation(this); } } } /*! Removes \a ownedEnd from ownedEnds. \sa ownedEnds(), addOwnedEnd() */ void QUmlAssociation::removeOwnedEnd(QUmlProperty *ownedEnd) { // This is a read-write association end if (_ownedEnds.contains(ownedEnd)) { _ownedEnds.removeAll(ownedEnd); if (ownedEnd->asQModelingObject()) ownedEnd->asQModelingObject()->setParent(0); // Adjust subsetted properties removeMemberEnd(ownedEnd); removeFeature(ownedEnd); removeOwnedMember(ownedEnd); // Adjust opposite properties if (ownedEnd) { ownedEnd->setOwningAssociation(0); } } } QT_END_NAMESPACE