/**************************************************************************** ** ** 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 "qumlextend.h" #include "private/qumlextendobject_p.h" #include #include #include #include #include #include #include #include #include QT_BEGIN_NAMESPACE /*! \class QUmlExtend \inmodule QtUml \brief A relationship from an extending use case to an extended use case that specifies how and when the behavior defined in the extending use case can be inserted into the behavior defined in the extended use case. */ /*! Creates a new QUmlExtend. Also creates the corresponding QObject-based representation returned by asQModelingObject() if \a createQModelingObject is true. */ QUmlExtend::QUmlExtend(bool createQModelingObject) : _condition(0), _extendedCase(0), _extension(0) { if (createQModelingObject) _qModelingObject = qobject_cast(new QUmlExtendObject(this)); } /*! Destroys the QUmlExtend. */ QUmlExtend::~QUmlExtend() { QModelingElement::deleteQModelingObject(); } /*! Returns a deep-copied clone of the QUmlExtend. */ QModelingElement *QUmlExtend::clone() const { QUmlExtend *c = new QUmlExtend; c->asQModelingObject()->setObjectName(this->asQModelingObject()->objectName()); c->asQModelingObject()->setProperty("role", this->asQModelingObject()->property("role")); foreach (QUmlComment *element, ownedComments()) c->addOwnedComment(dynamic_cast(element->clone())); c->setName(name()); if (nameExpression()) c->setNameExpression(dynamic_cast(nameExpression()->clone())); c->setVisibility(visibility()); if (condition()) c->setCondition(dynamic_cast(condition()->clone())); return c; } // OWNED ATTRIBUTES /*! References the condition that must hold when the first extension point is reached for the extension to take place. If no constraint is associated with the extend relationship, the extension is unconditional. \b {Subsetted property(ies):} QUmlElement::ownedElements(). */ QUmlConstraint *QUmlExtend::condition() const { // This is a read-write association end return _condition; } /*! Adjusts condition to \a condition. */ void QUmlExtend::setCondition(QUmlConstraint *condition) { // This is a read-write association end if (_condition != condition) { // Adjust subsetted properties removeOwnedElement(_condition); _condition = condition; if (condition && condition->asQModelingObject() && this->asQModelingObject()) QObject::connect(condition->asQModelingObject(), SIGNAL(destroyed()), this->asQModelingObject(), SLOT(setCondition())); condition->asQModelingObject()->setParent(this->asQModelingObject()); // Adjust subsetted properties if (condition) { addOwnedElement(condition); } } } /*! References the use case that is being extended. \b {Subsetted property(ies):} QUmlDirectedRelationship::targets(). */ QUmlUseCase *QUmlExtend::extendedCase() const { // This is a read-write association end return _extendedCase; } /*! Adjusts extendedCase to \a extendedCase. */ void QUmlExtend::setExtendedCase(QUmlUseCase *extendedCase) { // This is a read-write association end if (_extendedCase != extendedCase) { // Adjust subsetted properties removeTarget(_extendedCase); _extendedCase = extendedCase; if (extendedCase && extendedCase->asQModelingObject() && this->asQModelingObject()) QObject::connect(extendedCase->asQModelingObject(), SIGNAL(destroyed()), this->asQModelingObject(), SLOT(setExtendedCase())); // Adjust subsetted properties if (extendedCase) { addTarget(extendedCase); } } } /*! References the use case that represents the extension and owns the extend relationship. \b {Subsetted property(ies):} QUmlDirectedRelationship::sources(), QUmlNamedElement::namespace_(). \b {Opposite property(ies):} QUmlUseCase::extends(). */ QUmlUseCase *QUmlExtend::extension() const { // This is a read-write association end return _extension; } /*! Adjusts extension to \a extension. */ void QUmlExtend::setExtension(QUmlUseCase *extension) { // This is a read-write association end if (_extension != extension) { // Adjust subsetted properties removeSource(_extension); _extension = extension; if (extension && extension->asQModelingObject() && this->asQModelingObject()) QObject::connect(extension->asQModelingObject(), SIGNAL(destroyed()), this->asQModelingObject(), SLOT(setExtension())); // Adjust subsetted properties if (extension) { addSource(extension); } setNamespace(extension); } } /*! An ordered list of extension points belonging to the extended use case, specifying where the respective behavioral fragments of the extending use case are to be inserted. The first fragment in the extending use case is associated with the first extension point in the list, the second fragment with the second point, and so on. (Note that, in most practical cases, the extending use case has just a single behavior fragment, so that the list of extension points is trivial.) \sa addExtensionLocation(), removeExtensionLocation() */ const QList QUmlExtend::extensionLocations() const { // This is a read-write association end return _extensionLocations; } /*! Adds \a extensionLocation to extensionLocations. \sa extensionLocations(), removeExtensionLocation() */ void QUmlExtend::addExtensionLocation(QUmlExtensionPoint *extensionLocation) { // This is a read-write association end if (!_extensionLocations.contains(extensionLocation)) { _extensionLocations.append(extensionLocation); if (extensionLocation && extensionLocation->asQModelingObject() && this->asQModelingObject()) QObject::connect(extensionLocation->asQModelingObject(), SIGNAL(destroyed(QObject*)), this->asQModelingObject(), SLOT(removeExtensionLocation(QObject *))); } } /*! Removes \a extensionLocation from extensionLocations. \sa extensionLocations(), addExtensionLocation() */ void QUmlExtend::removeExtensionLocation(QUmlExtensionPoint *extensionLocation) { // This is a read-write association end if (_extensionLocations.contains(extensionLocation)) { _extensionLocations.removeAll(extensionLocation); } } QT_END_NAMESPACE