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 #ifndef UMLOBJECT_H 7 #define UMLOBJECT_H 8 9 #include "basictypes.h" 10 #include "icon_utils.h" 11 #include "umlpackagelist.h" 12 13 //qt includes 14 #include <QDomDocument> 15 #include <QDomElement> 16 #include <QObject> 17 #include <QPointer> 18 #include <QString> 19 #include <QXmlStreamWriter> 20 21 class UMLActor; 22 class UMLArtifact; 23 class UMLAssociation; 24 class UMLAttribute; 25 class UMLCanvasObject; 26 class UMLCategory; 27 class UMLCheckConstraint; 28 class UMLClassifier; 29 class UMLClassifierListItem; 30 class UMLClassifierSet; 31 class UMLComponent; 32 class UMLDatatype; 33 class UMLEntity; 34 class UMLEntityAttribute; 35 class UMLEntityConstraint; 36 class UMLEnum; 37 class UMLEnumLiteral; 38 class UMLFolder; 39 class UMLForeignKeyConstraint; 40 class UMLInstance; 41 class UMLInstanceAttribute; 42 class UMLNode; 43 class UMLOperation; 44 class UMLPackage; 45 class UMLPort; 46 class UMLRole; 47 class UMLStereotype; 48 class UMLTemplate; 49 class UMLUniqueConstraint; 50 class UMLUseCase; 51 class UMLObjectPrivate; 52 53 /** 54 * This class is the non-graphical version of @ref UMLWidget. These are 55 * created and maintained in the class @ref UMLDoc. This class holds all 56 * the generic information needed for all UML objects. 57 * 58 * @ref clone needs to be implemented by each child class. 59 * 60 * @ref saveToXMI1 saves the XMI attributes of each specific model class. 61 * It needs to be implemented by each child class. 62 * For creating the XMI element and saving the common XMI parts, 63 * it can use the save1() method. 64 * 65 * @short The base class for UML objects. 66 * @author Paul Hensgen <phensgen@techie.com> 67 * Bugs and comments to umbrello-devel@kde.org or https://bugs.kde.org 68 */ 69 class UMLObject : public QObject 70 { 71 Q_OBJECT 72 Q_ENUMS(ObjectType) 73 74 public: 75 enum ObjectType 76 { 77 ot_Unknown = -1, 78 ot_UMLObject = 100, 79 ot_Actor, 80 ot_UseCase, 81 ot_Package, 82 ot_Interface, 83 ot_Datatype, 84 ot_Enum, 85 ot_Class, 86 ot_Instance, 87 ot_Association, 88 ot_Attribute, 89 ot_Operation, 90 ot_EnumLiteral, 91 ot_Template, 92 ot_Component, 93 ot_Artifact, 94 ot_Node, 95 ot_Stereotype, 96 ot_Role, 97 ot_Entity, 98 ot_EntityAttribute, 99 ot_Folder, 100 ot_EntityConstraint, 101 ot_UniqueConstraint, 102 ot_ForeignKeyConstraint, 103 ot_CheckConstraint, 104 ot_Category, 105 ot_Port, 106 ot_InstanceAttribute, 107 ot_SubSystem ///< no real object type 108 }; 109 110 static QString toString(ObjectType ot); 111 static QString toI18nString(ObjectType t); 112 static Icon_Utils::IconType toIcon(ObjectType t); 113 114 explicit UMLObject(const UMLObject& other); 115 explicit UMLObject(UMLObject* parent, const QString& name, Uml::ID::Type id = Uml::ID::None); 116 explicit UMLObject(UMLObject* parent); 117 explicit UMLObject(const QString& name = QString(), Uml::ID::Type id = Uml::ID::None); 118 virtual ~UMLObject(); 119 120 bool operator==(const UMLObject & rhs) const; 121 122 virtual void copyInto(UMLObject *lhs) const; 123 124 virtual UMLObject* clone() const; 125 126 virtual void setBaseType(ObjectType ot); 127 ObjectType baseType() const; 128 QLatin1String baseTypeStr() const; 129 130 virtual void setID(Uml::ID::Type NewID); 131 virtual Uml::ID::Type id() const; 132 133 QString doc() const; 134 bool hasDoc() const; 135 void setDoc(const QString &d); 136 137 void setVisibility(Uml::Visibility::Enum visibility); 138 void setVisibilityCmd(Uml::Visibility::Enum visibility); 139 Uml::Visibility::Enum visibility() const; 140 141 void setStereotype(const QString &_name); 142 void setStereotypeCmd(const QString &_name); 143 QString stereotype(bool includeAdornments = false) const; 144 145 void setUMLStereotype(UMLStereotype *stereo); 146 UMLStereotype *umlStereotype() const; 147 148 QStringList& tags(); 149 150 QString package(const QString& separator = QString(), 151 bool includeRoot = false) const; 152 153 UMLPackageList packages(bool includeRoot = false) const; 154 155 bool setUMLPackage(UMLPackage* pPkg); 156 UMLPackage* umlPackage() const; 157 158 void setUMLParent(UMLObject* parent); 159 UMLObject* umlParent() const; 160 161 virtual void setName(const QString &strName); 162 virtual void setNameCmd(const QString &strName) ; 163 QString name() const; 164 165 virtual QString fullyQualifiedName(const QString& separator = QString(), 166 bool includeRoot = false) const; 167 168 void setAbstract(bool bAbstract); 169 bool isAbstract() const; 170 171 virtual bool showPropertiesDialog(QWidget* parent = 0); 172 173 virtual bool resolveRef(); 174 175 virtual void saveToXMI1(QXmlStreamWriter& writer); 176 virtual bool loadFromXMI1(QDomElement & element); 177 178 bool loadStereotype(QDomElement & element); 179 180 void setStatic(bool bStatic); 181 bool isStatic() const; 182 183 virtual bool acceptAssociationType(Uml::AssociationType::Enum) const; //:TODO: check if this is really needed here 184 185 void setSecondaryId(const QString& id); 186 QString secondaryId() const; 187 188 void setSecondaryFallback(const QString& id); 189 QString secondaryFallback() const; 190 191 void save1(const QString& tag, QXmlStreamWriter& writer); 192 193 friend QDebug operator<< (QDebug out, const UMLObject& obj); 194 isUMLActor()195 bool isUMLActor() const { return baseType() == ot_Actor; } isUMLArtifact()196 bool isUMLArtifact() const { return baseType() == ot_Artifact; } isUMLAssociation()197 bool isUMLAssociation() const { return baseType() == ot_Association; } isUMLAttribute()198 bool isUMLAttribute() const { return baseType() == ot_Attribute; } 199 //bool isUMLCanvasObject() const { return baseType() == ot_CanvasObject; } isUMLCategory()200 bool isUMLCategory() const { return baseType() == ot_Category; } isUMLCheckConstraint()201 bool isUMLCheckConstraint() const { return baseType() == ot_CheckConstraint; } isUMLClassifier()202 bool isUMLClassifier() const { return baseType() == ot_Class; } isUMLComponent()203 bool isUMLComponent() const { return baseType() == ot_Component; } isUMLDatatype()204 bool isUMLDatatype() const { return baseType() == ot_Datatype; } isUMLEntity()205 bool isUMLEntity() const { return baseType() == ot_Entity; } isUMLEntityAttribute()206 bool isUMLEntityAttribute() const { return baseType() == ot_EntityAttribute; } isUMLEntityConstraint()207 bool isUMLEntityConstraint() const { return baseType() == ot_EntityConstraint; } isUMLEnum()208 bool isUMLEnum() const { return baseType() == ot_Enum; } isUMLEnumLiteral()209 bool isUMLEnumLiteral() const { return baseType() == ot_EnumLiteral; } isUMLFolder()210 bool isUMLFolder() const { return baseType() == ot_Folder; } isUMLForeignKeyConstraint()211 bool isUMLForeignKeyConstraint() const { return baseType() == ot_ForeignKeyConstraint; } isUMLInstance()212 bool isUMLInstance() const { return baseType() == ot_Instance; } isUMLInstanceAttribute()213 bool isUMLInstanceAttribute() const { return baseType() == ot_InstanceAttribute; } isUMLNode()214 bool isUMLNode() const { return baseType() == ot_Node; } isUMLObject()215 bool isUMLObject() const { return baseType() == ot_UMLObject; } isUMLOperation()216 bool isUMLOperation() const { return baseType() == ot_Operation; } isUMLPackage()217 bool isUMLPackage() const { return baseType() == ot_Package; } isUMLPort()218 bool isUMLPort() const { return baseType() == ot_Port; } isUMLRole()219 bool isUMLRole() const { return baseType() == ot_Role; } isUMLStereotype()220 bool isUMLStereotype() const { return baseType() == ot_Stereotype; } isUMLTemplate()221 bool isUMLTemplate() const { return baseType() == ot_Template; } isUMLUniqueConstraint()222 bool isUMLUniqueConstraint() const { return baseType() == ot_UniqueConstraint; } isUMLUseCase()223 bool isUMLUseCase() const { return baseType() == ot_UseCase; } 224 225 UMLActor * asUMLActor(); 226 UMLArtifact * asUMLArtifact(); 227 UMLAssociation * asUMLAssociation(); 228 UMLAttribute * asUMLAttribute(); 229 UMLCanvasObject * asUMLCanvasObject(); 230 UMLCategory * asUMLCategory(); 231 UMLCheckConstraint * asUMLCheckConstraint(); 232 UMLClassifier * asUMLClassifier(); 233 UMLClassifierListItem * asUMLClassifierListItem(); 234 UMLClassifierSet * asUMLClassifierSet(); 235 UMLComponent * asUMLComponent(); 236 UMLDatatype * asUMLDatatype(); 237 UMLEntity * asUMLEntity(); 238 UMLEntityAttribute * asUMLEntityAttribute(); 239 UMLEntityConstraint * asUMLEntityConstraint(); 240 UMLEnum * asUMLEnum(); 241 UMLEnumLiteral * asUMLEnumLiteral(); 242 UMLFolder * asUMLFolder(); 243 UMLForeignKeyConstraint * asUMLForeignKeyConstraint(); 244 UMLInstance * asUMLInstance(); 245 UMLInstanceAttribute * asUMLInstanceAttribute(); 246 UMLNode * asUMLNode(); 247 UMLObject * asUMLObject(); 248 UMLOperation * asUMLOperation(); 249 UMLPackage * asUMLPackage(); 250 UMLPort * asUMLPort(); 251 UMLRole * asUMLRole(); 252 UMLStereotype * asUMLStereotype(); 253 UMLTemplate * asUMLTemplate(); 254 UMLUniqueConstraint * asUMLUniqueConstraint(); 255 UMLUseCase * asUMLUseCase(); 256 257 public slots: 258 void emitModified(); 259 260 signals: 261 void modified(); 262 263 protected: 264 void init(); 265 266 void maybeSignalObjectCreated(); 267 268 void save1end(QXmlStreamWriter& writer); 269 270 virtual bool load1(QDomElement& element); 271 272 Uml::ID::Type m_nId; ///< object's id 273 QString m_Doc; ///< object's documentation 274 QPointer<UMLStereotype> m_pStereotype; ///< stereotype of the object if applicable 275 QString m_name; ///< objects name 276 ObjectType m_BaseType; ///< objects type 277 Uml::Visibility::Enum m_visibility; ///< objects visibility 278 bool m_bAbstract; ///< state of whether the object is abstract or not 279 bool m_bStatic; ///< flag for instance scope 280 bool m_bInPaste; ///< caller sets this true when in paste operation 281 bool m_bCreationWasSignalled; ///< auxiliary to maybeSignalObjectCreated() 282 QPointer<UMLObject> m_pSecondary; ///< pointer to an associated object 283 ///< Only a few of the classes inheriting from UMLObject use this. 284 ///< However, it needs to be here because of inheritance graph 285 ///< disjunctness. 286 QString m_SecondaryId; ///< xmi.id of the secondary object for intermediate use during 287 ///< loading. The secondary ID is resolved to the m_pSecondary 288 ///< in the course of resolveRef() at the end of loading. 289 QString m_SecondaryFallback; ///< Last-chance backup for when m_SecondaryId is not found. 290 ///< Used by Rose import: MDL files specify both a "quidu" 291 ///< (which corresponds to m_SecondaryId) and the human readable 292 ///< fully qualified target name of a reference. 293 ///< In case the quidu is not found, the human readable name is 294 ///< used which we store in m_SecondaryFallback. 295 QStringList m_TaggedValues; ///< Concrete values of UMLStereotype::AttributeDefs if a 296 ///< stereotype is applied and has attributes. 297 ///< The order of elements is the same as in 298 ///< UMLStereotype::AttributeDefs. 299 ///< At most N_STEREOATTRS are used (see dialogs/n_stereoattrs.h) 300 UMLObjectPrivate *m_d; ///< private data 301 friend class ObjectsModel; 302 }; 303 304 #endif 305