/**************************************************************************** ** ** 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 "qumlprotocolstatemachine.h" #include "private/qumlprotocolstatemachineobject_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 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include QT_BEGIN_NAMESPACE /*! \class QUmlProtocolStateMachine \inmodule QtUml \brief A protocol state machine is always defined in the context of a classifier. It specifies which operations of the classifier can be called in which state and under which condition, thus specifying the allowed call sequences on the classifier's operations. A protocol state machine presents the possible and permitted transitions on the instances of its context classifier, together with the operations which carry the transitions. In this manner, an instance lifecycle can be created for a classifier, by specifying the order in which the operations can be activated and the states through which an instance progresses during its existence. */ /*! Creates a new QUmlProtocolStateMachine. Also creates the corresponding QObject-based representation returned by asQModelingObject() if \a createQModelingObject is true. */ QUmlProtocolStateMachine::QUmlProtocolStateMachine(bool createQModelingObject) : QUmlStateMachine(false) { if (createQModelingObject) _qModelingObject = qobject_cast(new QUmlProtocolStateMachineObject(this)); } /*! Destroys the QUmlProtocolStateMachine. */ QUmlProtocolStateMachine::~QUmlProtocolStateMachine() { QModelingElement::deleteQModelingObject(); } /*! Returns a deep-copied clone of the QUmlProtocolStateMachine. */ QModelingElement *QUmlProtocolStateMachine::clone() const { QUmlProtocolStateMachine *c = new QUmlProtocolStateMachine; 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->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())); foreach (QUmlConnector *element, ownedConnectors()) c->addOwnedConnector(dynamic_cast(element->clone())); foreach (QUmlInterfaceRealization *element, interfaceRealizations()) c->addInterfaceRealization(dynamic_cast(element->clone())); foreach (QUmlBehavior *element, ownedBehaviors()) c->addOwnedBehavior(dynamic_cast(element->clone())); c->setAbstract(isAbstract()); c->setActive(isActive()); foreach (QUmlClassifier *element, nestedClassifiers()) c->addNestedClassifier(dynamic_cast(element->clone())); foreach (QUmlProperty *element, ownedAttributes()) c->addOwnedAttribute(dynamic_cast(element->clone())); foreach (QUmlOperation *element, ownedOperations()) c->addOwnedOperation(dynamic_cast(element->clone())); foreach (QUmlReception *element, ownedReceptions()) c->addOwnedReception(dynamic_cast(element->clone())); c->setReentrant(isReentrant()); foreach (QUmlParameter *element, ownedParameters()) c->addOwnedParameter(dynamic_cast(element->clone())); foreach (QUmlParameterSet *element, ownedParameterSets()) c->addOwnedParameterSet(dynamic_cast(element->clone())); foreach (QUmlConstraint *element, postconditions()) c->addPostcondition(dynamic_cast(element->clone())); foreach (QUmlConstraint *element, preconditions()) c->addPrecondition(dynamic_cast(element->clone())); foreach (QUmlPseudostate *element, connectionPoints()) c->addConnectionPoint(dynamic_cast(element->clone())); foreach (QUmlRegion *element, regions()) c->addRegion(dynamic_cast(element->clone())); foreach (QUmlProtocolConformance *element, conformance()) c->addConformance(dynamic_cast(element->clone())); return c; } // OWNED ATTRIBUTES /*! Conformance between protocol state machines. \sa addConformance(), removeConformance() \b {Subsetted property(ies):} QUmlElement::ownedElements(). \b {Opposite property(ies):} QUmlProtocolConformance::specificMachine(). */ const QSet QUmlProtocolStateMachine::conformance() const { // This is a read-write association end return _conformance; } /*! Adds \a conformance to conformance. \sa conformance(), removeConformance() */ void QUmlProtocolStateMachine::addConformance(QUmlProtocolConformance *conformance) { // This is a read-write association end if (!_conformance.contains(conformance)) { _conformance.insert(conformance); if (conformance && conformance->asQModelingObject() && this->asQModelingObject()) QObject::connect(conformance->asQModelingObject(), SIGNAL(destroyed(QObject*)), this->asQModelingObject(), SLOT(removeConformance(QObject *))); conformance->asQModelingObject()->setParent(this->asQModelingObject()); // Adjust subsetted properties addOwnedElement(conformance); // Adjust opposite properties if (conformance) { conformance->setSpecificMachine(this); } } } /*! Removes \a conformance from conformance. \sa conformance(), addConformance() */ void QUmlProtocolStateMachine::removeConformance(QUmlProtocolConformance *conformance) { // This is a read-write association end if (_conformance.contains(conformance)) { _conformance.remove(conformance); if (conformance->asQModelingObject()) conformance->asQModelingObject()->setParent(0); // Adjust subsetted properties removeOwnedElement(conformance); // Adjust opposite properties if (conformance) { conformance->setSpecificMachine(0); } } } QT_END_NAMESPACE