1 /*
2 SPDX-License-Identifier: GPL-2.0-or-later
3 SPDX-FileCopyrightText: 2002-2021 Umbrello UML Modeller Authors <umbrello-devel@kde.org>
4 */
5
6 //own header
7 #include "checkconstraint.h"
8
9 // app includes
10 #include "debug_utils.h"
11 #include "umlcheckconstraintdialog.h"
12
13 /**
14 * Sets up a constraint.
15 *
16 * @param parent The parent of this UMLCheckConstraint.
17 * @param name The name of this UMLCheckConstraint.
18 * @param id The unique id given to this UMLCheckConstraint.
19 */
UMLCheckConstraint(UMLObject * parent,const QString & name,Uml::ID::Type id)20 UMLCheckConstraint::UMLCheckConstraint(UMLObject *parent,
21 const QString& name, Uml::ID::Type id)
22 : UMLEntityConstraint(parent, name, id)
23 {
24 init();
25 }
26
27 /**
28 * Sets up a constraint.
29 *
30 * @param parent The parent of this UMLCheckConstraint.
31 */
UMLCheckConstraint(UMLObject * parent)32 UMLCheckConstraint::UMLCheckConstraint(UMLObject *parent)
33 : UMLEntityConstraint(parent)
34 {
35 init();
36 }
37
38 /**
39 * Overloaded '==' operator.
40 */
operator ==(const UMLCheckConstraint & rhs) const41 bool UMLCheckConstraint::operator==(const UMLCheckConstraint &rhs) const
42 {
43 if (this == &rhs)
44 return true;
45
46 if (!UMLObject::operator==(rhs))
47 return false;
48
49 return true;
50 }
51
52 /**
53 * Destructor.
54 */
~UMLCheckConstraint()55 UMLCheckConstraint::~UMLCheckConstraint()
56 {
57 }
58
59 /**
60 * Copy the internal presentation of this object into the UMLCheckConstraint
61 * object.
62 */
copyInto(UMLObject * lhs) const63 void UMLCheckConstraint::copyInto(UMLObject *lhs) const
64 {
65 UMLCheckConstraint *target = lhs->asUMLCheckConstraint();
66
67 // call the parent first.
68 UMLEntityConstraint::copyInto(target);
69
70 // Copy all datamembers
71 target->m_CheckCondition = m_CheckCondition;
72 }
73
74 /**
75 * Make a clone of the UMLCheckConstraint.
76 */
clone() const77 UMLObject* UMLCheckConstraint::clone() const
78 {
79 //FIXME: The new attribute should be slaved to the NEW parent not the old.
80 UMLCheckConstraint *clone = new UMLCheckConstraint(umlParent());
81 copyInto(clone);
82 return clone;
83 }
84
85 /**
86 * Returns a string representation of the UMLCheckConstraint.
87 *
88 * @param sig If true will show the attribute type and initial value.
89 * @return Returns a string representation of the UMLAttribute.
90 */
toString(Uml::SignatureType::Enum sig,bool withStereotype) const91 QString UMLCheckConstraint::toString(Uml::SignatureType::Enum sig,
92 bool withStereotype) const
93 {
94 Q_UNUSED(withStereotype);
95 QString s;
96
97 if (sig == Uml::SignatureType::ShowSig || sig == Uml::SignatureType::SigNoVis) {
98 s = name() ;
99 }
100
101 return s;
102 }
103
getFullyQualifiedName(const QString & separator,bool includeRoot) const104 QString UMLCheckConstraint::getFullyQualifiedName(const QString& separator,
105 bool includeRoot) const
106 {
107 Q_UNUSED(separator); Q_UNUSED(includeRoot);
108 return this->name();
109 }
110
111 /**
112 * Creates the <UML:UniqueConstraint> XMI element.
113 */
saveToXMI1(QXmlStreamWriter & writer)114 void UMLCheckConstraint::saveToXMI1(QXmlStreamWriter& writer)
115 {
116 UMLObject::save1(QLatin1String("UML:CheckConstraint"), writer);
117
118 writer.writeTextElement(QString(), m_CheckCondition);
119
120 UMLObject::save1end(writer);
121 }
122
123 /**
124 * Display the properties configuration dialog for the attribute.
125 */
showPropertiesDialog(QWidget * parent)126 bool UMLCheckConstraint::showPropertiesDialog(QWidget* parent)
127 {
128 UMLCheckConstraintDialog dialog(parent, this);
129 return dialog.exec();
130 }
131
132 /**
133 * Loads the <UML:CheckConstraint> XMI element.
134 */
load1(QDomElement & element)135 bool UMLCheckConstraint::load1(QDomElement & element)
136 {
137 QDomNode node = element.firstChild();
138
139 QDomText checkConstraintText = node.toText();
140 if (checkConstraintText.isNull())
141 m_CheckCondition = QString();
142 else
143 m_CheckCondition = checkConstraintText.data();
144
145 return true;
146 }
147
148 /**
149 * Initialises Check Constraint
150 */
init()151 void UMLCheckConstraint::init()
152 {
153 m_BaseType = UMLObject::ot_CheckConstraint;
154 m_CheckCondition.clear();
155 }
156
157