diff options
Diffstat (limited to 'src/uml/qumllifeline.cpp')
-rw-r--r-- | src/uml/qumllifeline.cpp | 304 |
1 files changed, 101 insertions, 203 deletions
diff --git a/src/uml/qumllifeline.cpp b/src/uml/qumllifeline.cpp index b24f1d1e..09d2a6a2 100644 --- a/src/uml/qumllifeline.cpp +++ b/src/uml/qumllifeline.cpp @@ -40,283 +40,181 @@ ****************************************************************************/ #include "qumllifeline.h" -#include <QtUml/QUmlComment> +#include "private/qumllifelineobject_p.h" + #include <QtUml/QUmlConnectableElement> -#include <QtUml/QUmlDependency> -#include <QtUml/QUmlElement> #include <QtUml/QUmlInteraction> #include <QtUml/QUmlInteractionFragment> -#include <QtUml/QUmlNamedElement> -#include <QtUml/QUmlNamespace> -#include <QtUml/QUmlPackage> #include <QtUml/QUmlPartDecomposition> -#include <QtUml/QUmlStringExpression> #include <QtUml/QUmlValueSpecification> -QT_BEGIN_NAMESPACE - /*! - \class UmlLifeline + \class QUmlLifeline \inmodule QtUml \brief A lifeline represents an individual participant in the interaction. While parts and structural features may have multiplicity greater than 1, lifelines represent only one interacting entity. */ - -QUmlLifeline::QUmlLifeline(QObject *parent) : - QObject(parent) +QUmlLifeline::QUmlLifeline(bool createQObject) : + _decomposedAs(0), + _interaction(0), + _represents(0), + _selector(0) { + if (createQObject) + _qObject = new QUmlLifelineObject(this); } -// OWNED ATTRIBUTES [Element] - -/*! - The Comments owned by this element. - */ -const QSet<QUmlComment *> QUmlLifeline::ownedComment() const +QUmlLifeline::~QUmlLifeline() { - return *(reinterpret_cast<const QSet<QUmlComment *> *>(&_ownedComment)); + if (!deletingFromQObject) { + _qObject->setProperty("deletingFromModelingObject", true); + delete _qObject; + } } -/*! - The Elements owned by this element. - */ -const QSet<QUmlElement *> QUmlLifeline::ownedElement() const -{ - return *(reinterpret_cast<const QSet<QUmlElement *> *>(&_ownedElement)); -} +// OWNED ATTRIBUTES /*! - The Element that owns this element. + References the InteractionFragments in which this Lifeline takes part. */ -QUmlElement *QUmlLifeline::owner() const +const QSet<QUmlInteractionFragment *> +QUmlLifeline::coveredBy() const { - return reinterpret_cast<QUmlElement *>(_owner); -} - -// OWNED ATTRIBUTES [NamedElement] + // This is a read-write association end -/*! - Indicates the dependencies that reference the client. - */ -const QSet<QUmlDependency *> QUmlLifeline::clientDependency() const -{ - return *(reinterpret_cast<const QSet<QUmlDependency *> *>(&_clientDependency)); + return _coveredBy; } -/*! - The name of the NamedElement. - */ -QString QUmlLifeline::name() const +void QUmlLifeline::addCoveredBy(QUmlInteractionFragment *coveredBy) { - return _name; -} + // This is a read-write association end -/*! - The string expression used to define the name of this named element. - */ -QUmlStringExpression *QUmlLifeline::nameExpression() const -{ - return reinterpret_cast<QUmlStringExpression *>(_nameExpression); -} + if (!_coveredBy.contains(coveredBy)) { + _coveredBy.insert(coveredBy); + if (coveredBy->asQObject() && this->asQObject()) + QObject::connect(coveredBy->asQObject(), SIGNAL(destroyed(QObject*)), this->asQObject(), SLOT(removeCoveredBy(QObject *))); -/*! - Specifies the namespace that owns the NamedElement. - */ -QUmlNamespace *QUmlLifeline::namespace_() const -{ - return reinterpret_cast<QUmlNamespace *>(_namespace_); + // Adjust opposite properties + if (coveredBy) { + coveredBy->addCovered(this); + } + } } -/*! - A name which allows the NamedElement to be identified within a hierarchy of nested Namespaces. It is constructed from the names of the containing namespaces starting at the root of the hierarchy and ending with the name of the NamedElement itself. - */ -QString QUmlLifeline::qualifiedName() const +void QUmlLifeline::removeCoveredBy(QUmlInteractionFragment *coveredBy) { - return UmlNamedElement::qualifiedName(); -} + // This is a read-write association end -/*! - Determines where the NamedElement appears within different Namespaces within the overall model, and its accessibility. - */ -QtUml::VisibilityKind QUmlLifeline::visibility() const -{ - return _visibility; -} - -// OWNED ATTRIBUTES [Lifeline] + if (_coveredBy.contains(coveredBy)) { + _coveredBy.remove(coveredBy); -/*! - References the InteractionFragments in which this Lifeline takes part. - */ -const QSet<QUmlInteractionFragment *> QUmlLifeline::coveredBy() const -{ - return *(reinterpret_cast<const QSet<QUmlInteractionFragment *> *>(&_coveredBy)); + // Adjust opposite properties + if (coveredBy) { + coveredBy->removeCovered(this); + } + } } /*! References the Interaction that represents the decomposition. */ -QUmlPartDecomposition *QUmlLifeline::decomposedAs() const +QUmlPartDecomposition * +QUmlLifeline::decomposedAs() const { - return reinterpret_cast<QUmlPartDecomposition *>(_decomposedAs); -} + // This is a read-write association end -/*! - References the Interaction enclosing this Lifeline. - */ -QUmlInteraction *QUmlLifeline::interaction() const -{ - return reinterpret_cast<QUmlInteraction *>(_interaction); + return _decomposedAs; } -/*! - References the ConnectableElement within the classifier that contains the enclosing interaction. - */ -QUmlConnectableElement *QUmlLifeline::represents() const +void QUmlLifeline::setDecomposedAs(QUmlPartDecomposition *decomposedAs) { - return reinterpret_cast<QUmlConnectableElement *>(_represents); -} + // This is a read-write association end -/*! - If the referenced ConnectableElement is multivalued, then this specifies the specific individual part within that set. - */ -QUmlValueSpecification *QUmlLifeline::selector() const -{ - return reinterpret_cast<QUmlValueSpecification *>(_selector); + if (_decomposedAs != decomposedAs) { + _decomposedAs = decomposedAs; + if (decomposedAs->asQObject() && this->asQObject()) + QObject::connect(decomposedAs->asQObject(), SIGNAL(destroyed()), this->asQObject(), SLOT(setDecomposedAs())); + } } -// OPERATIONS [Element] - /*! - The query allOwnedElements() gives all of the direct and indirect owned elements of an element. + References the Interaction enclosing this Lifeline. */ -QSet<QUmlElement *> QUmlLifeline::allOwnedElements() const +QUmlInteraction * +QUmlLifeline::interaction() const { - QSet<QUmlElement *> r; - foreach (UmlElement *element, UmlElement::allOwnedElements()) - r.insert(reinterpret_cast<QUmlElement *>(element)); - return r; -} + // This is a read-write association end -/*! - The query mustBeOwned() indicates whether elements of this type must have an owner. Subclasses of Element that do not require an owner must override this operation. - */ -bool QUmlLifeline::mustBeOwned() const -{ - return UmlElement::mustBeOwned(); + return _interaction; } -// OPERATIONS [NamedElement] - -/*! - The query allNamespaces() gives the sequence of namespaces in which the NamedElement is nested, working outwards. - */ -QList<QUmlNamespace *> QUmlLifeline::allNamespaces() const +void QUmlLifeline::setInteraction(QUmlInteraction *interaction) { - QList<QUmlNamespace *> r; - foreach (UmlNamespace *element, UmlNamedElement::allNamespaces()) - r.append(reinterpret_cast<QUmlNamespace *>(element)); - return r; -} + // This is a read-write association end -/*! - The query allOwningPackages() returns all the directly or indirectly owning packages. - */ -QSet<QUmlPackage *> QUmlLifeline::allOwningPackages() const -{ - QSet<QUmlPackage *> r; - foreach (UmlPackage *element, UmlNamedElement::allOwningPackages()) - r.insert(reinterpret_cast<QUmlPackage *>(element)); - return r; -} + if (_interaction != interaction) { + // Adjust subsetted properties -/*! - The query isDistinguishableFrom() determines whether two NamedElements may logically co-exist within a Namespace. By default, two named elements are distinguishable if (a) they have unrelated types or (b) they have related types but different names. - */ -bool QUmlLifeline::isDistinguishableFrom(QUmlNamedElement *n, QUmlNamespace *ns) const -{ - return UmlNamedElement::isDistinguishableFrom(n, ns); + _interaction = interaction; + if (interaction->asQObject() && this->asQObject()) + QObject::connect(interaction->asQObject(), SIGNAL(destroyed()), this->asQObject(), SLOT(setInteraction())); + + // Adjust subsetted properties + setNamespace(interaction); + } } /*! - The query separator() gives the string that is used to separate names when constructing a qualified name. + References the ConnectableElement within the classifier that contains the enclosing interaction. */ -QString QUmlLifeline::separator() const -{ - return UmlNamedElement::separator(); -} - -// SLOTS FOR OWNED ATTRIBUTES [Element] - -void QUmlLifeline::addOwnedComment(UmlComment *ownedComment) -{ - UmlElement::addOwnedComment(ownedComment); -} - -void QUmlLifeline::removeOwnedComment(UmlComment *ownedComment) -{ - UmlElement::removeOwnedComment(ownedComment); -} - -// SLOTS FOR OWNED ATTRIBUTES [NamedElement] - -void QUmlLifeline::addClientDependency(UmlDependency *clientDependency) +QUmlConnectableElement * +QUmlLifeline::represents() const { - UmlNamedElement::addClientDependency(clientDependency); -} + // This is a read-write association end -void QUmlLifeline::removeClientDependency(UmlDependency *clientDependency) -{ - UmlNamedElement::removeClientDependency(clientDependency); + return _represents; } -void QUmlLifeline::setName(QString name) +void QUmlLifeline::setRepresents(QUmlConnectableElement *represents) { - UmlNamedElement::setName(name); -} + // This is a read-write association end -void QUmlLifeline::setNameExpression(QUmlStringExpression *nameExpression) -{ - UmlNamedElement::setNameExpression(nameExpression); + if (_represents != represents) { + _represents = represents; + if (represents->asQObject() && this->asQObject()) + QObject::connect(represents->asQObject(), SIGNAL(destroyed()), this->asQObject(), SLOT(setRepresents())); + } } -void QUmlLifeline::setVisibility(QtUml::VisibilityKind visibility) +/*! + If the referenced ConnectableElement is multivalued, then this specifies the specific individual part within that set. + */ +QUmlValueSpecification * +QUmlLifeline::selector() const { - UmlNamedElement::setVisibility(visibility); -} - -// SLOTS FOR OWNED ATTRIBUTES [Lifeline] + // This is a read-write association end -void QUmlLifeline::addCoveredBy(UmlInteractionFragment *coveredBy) -{ - UmlLifeline::addCoveredBy(coveredBy); + return _selector; } -void QUmlLifeline::removeCoveredBy(UmlInteractionFragment *coveredBy) -{ - UmlLifeline::removeCoveredBy(coveredBy); -} - -void QUmlLifeline::setDecomposedAs(QUmlPartDecomposition *decomposedAs) +void QUmlLifeline::setSelector(QUmlValueSpecification *selector) { - UmlLifeline::setDecomposedAs(decomposedAs); -} + // This is a read-write association end -void QUmlLifeline::setInteraction(QUmlInteraction *interaction) -{ - UmlLifeline::setInteraction(interaction); -} + if (_selector != selector) { + // Adjust subsetted properties + removeOwnedElement(_selector); -void QUmlLifeline::setRepresents(QUmlConnectableElement *represents) -{ - UmlLifeline::setRepresents(represents); -} + _selector = selector; + if (selector->asQObject() && this->asQObject()) + QObject::connect(selector->asQObject(), SIGNAL(destroyed()), this->asQObject(), SLOT(setSelector())); + selector->asQObject()->setParent(this->asQObject()); -void QUmlLifeline::setSelector(QUmlValueSpecification *selector) -{ - UmlLifeline::setSelector(selector); + // Adjust subsetted properties + if (selector) { + addOwnedElement(selector); + } + } } -QT_END_NAMESPACE - |