summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/umlobject.h
blob: 37e470654447380512bc31119052ad450cbea4e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   copyright (C) 2002-2007                                               *
 *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
 ***************************************************************************/

#ifndef UMLOBJECT_H
#define UMLOBJECT_H

//qt includes
#include <tqobject.h>
#include <tqstring.h>
#include <tqdom.h>

#include "umlnamespace.h"
#include "umlpackagelist.h"

class kdbgstream;
class UMLStereotype;
class UMLObject;

/**
 * This class is the non-graphical version of @ref UMLWidget.  These are
 * created and maintained in the class @ref UMLDoc.  This class holds all
 * the generic information needed for all UML objects.
 *
 * @short The base class for UML objects.
 * @author Paul Hensgen <phensgen@techie.com>
 * Bugs and comments to uml-devel@lists.sf.net or http://bugs.trinitydesktop.org
 */
class UMLObject : public TQObject {
    Q_OBJECT
  
public:

    /**
     * Creates a UMLObject.
     *
     * @param parent    The parent of the object.
     * @param name              The name of the object.
     * @param id                The ID of the object (optional.) If omitted
     *                  then a new ID will be assigned internally.
     */
    UMLObject(const UMLObject * parent, const TQString &name, Uml::IDType id = Uml::id_None);

    /**
     * Creates a UMLObject.
     *
     * @param   parent          The parent of the object.
     */
    UMLObject(const UMLObject * parent);

    /**
     * Creates a UMLObject with a given name and unique ID.
     *
     * @param   name            The name of the object.
     * @param   id              The unique ID of the object.
     */
    explicit UMLObject(const TQString &name = "" , Uml::IDType id = Uml::id_None);

    /**
     * Overloaded '==' operator
     */
    virtual bool operator==(UMLObject & rhs );

    /**
     * Standard deconstructor.
     */
    virtual ~UMLObject();

    /**
     * Copy the internal presentation of this object into the new
     * object.
     */
    virtual void copyInto(UMLObject *rhs) const;

    /**
     * Make a clone of this object.
     * To be implemented by inheriting classes.
     */
    virtual UMLObject* clone() const = 0;

    /**
     * Returns the type of the object.
     *
     * @return  Returns the type of the object.
     */
    Uml::Object_Type getBaseType() const;

    /**
     * Set the type of the object.
     *
     * @param ot The Uml::Object_Type to set.
     */
    virtual void setBaseType(Uml::Object_Type ot);

    /**
     * Returns the ID of the object.
     *
     * @return  Returns the ID of the object.
     */
    virtual Uml::IDType getID() const;

    /**
     * Sets the documentation for the object.
     *
     * @param d The documentation for the object.
     */
    void setDoc(const TQString &d);

    /**
     * Returns the documentation for the object.
     *
     * @return  Returns the documentation for the object.
     */
    TQString getDoc() const;

    /**
     * Returns the visibility of the object.
     *
     * @return  Returns the visibility of the object.
     */
    Uml::Visibility getVisibility() const;

    /**
     * Sets the visibility of the object.
     *
     * @param s The visibility of the object.
     */
    virtual void setVisibility(Uml::Visibility s);

    /**
     * Sets the classes stereotype name.
     * Internally uses setUMLStereotype().
     *
     * @param _name     Sets the classes stereotype name.
     */
    void setStereotype(const TQString &_name);

    /**
     * Sets the class' UMLStereotype. Adjusts the reference counts
     * at the previously set stereotype and at the new stereotype.
     * If the previously set UMLStereotype's reference count drops
     * to zero then the UMLStereotype is removed at the UMLDoc and
     * it is then physically deleted.
     *
     * @param s Sets the classes UMLStereotype.
     */
    void setUMLStereotype(UMLStereotype *s);

    /**
     * Sets the classes Package.
     * DEPRECATED - use SetUMLPackage instead.
     *
     * @param _name     The classes Package name.
     */
    void setPackage(const TQString &_name);

    /**
     * Sets the UMLPackage in which this class is located.
     *
     * @param pPkg              Pointer to the class' UMLPackage.
     */
    void setUMLPackage(UMLPackage* pPkg);

    /**
     * Returns the classes UMLStereotype object.
     *
     * @return  Returns the classes UMLStereotype object.
     */
    const UMLStereotype * getUMLStereotype();

    /**
     * Returns the classes stereotype name.
     * Returns an empty string if no stereotype object is set.
     *
     * @param includeAdornments Include surrounding angled brackets
     *                          "«" and "»".
     * @return  Returns the classes stereotype name.
     */
    TQString getStereotype(bool includeAdornments = false) const;

    /**
     * Return the package(s) in which this UMLObject is contained
     * as a text.
     *
     * @param separator Separator string for joining together the
     *                  individual package prefixes (optional.)
     *                  If no separator is given then the separator
     *                  of the currently selected language is used.
     * @param includeRoot  Whether to prefix the root folder name.
     *                     Default: false.
     * @return  The UMLObject's enclosing package(s) as a text.
     */
    TQString getPackage(const TQString& separator = TQString(),
                       bool includeRoot = false);

    /**
     * Return a list of the packages in which this class is embedded.
     * The outermost package is first in the list.
     *
     * @param includeRoot  Whether to prefix the root folder name.
     *                     Default: false.
     * @return  UMLPackageList of the containing packages.
     */
    UMLPackageList getPackages(bool includeRoot = false) const;

    /**
     * Returns the UMLPackage that this class is located in.
     *
     * @return  Pointer to the UMLPackage of this class.
     */
    UMLPackage* getUMLPackage();

    /**
     * Assigns a new Id to the object
     */
    virtual void setID(Uml::IDType NewID);

    /**
     * Returns a copy of m_Name
     */
    TQString getName() const;

    /**
     * Set the UMLObject's name
     */
    virtual void setName(const TQString &strName);

    /**
     * Returns the fully qualified name, i.e. all package prefixes and then m_Name.
     *
     * @param separator  The separator string to use (optional.)
     *                   If not given then the separator is chosen according
     *                   to the currently selected active programming language
     *                   of import and code generation.
     * @param includeRoot  Whether to prefix the root folder name to the FQN.
     *                     See UMLDoc::getRootFolder(). Default: false.
     * @return  The fully qualified name of this UMLObject.
     */
    virtual TQString getFullyQualifiedName(const TQString& separator = TQString(),
                                          bool includeRoot = false) const;

    /**
     * Returns the abstract state of the object.
     */
    bool getAbstract() const;

    /**
     * Sets the abstract state of the object.
     */
    void setAbstract(bool bAbstract);

    /**
     * Sets the abstract state of the object.
     */
    void setInPaste(bool bInPaste = true);

    /**
     * This method is called if you wish to see the properties of a
     * UMLObject.  A dialog box will be displayed from which you
     * can change the object's properties.
     *
     * @param page              The page to show.
     * @param assoc             Whether to show association page.
     * @return          True if we modified the object.
     */
    bool showProperties(int page = 0, bool assoc = false);

    /**
     * Resolve referenced objects (if any.)
     * Needs to be called after all UML objects are loaded from file.
     * This needs to be done after all model objects are loaded because
     * some of the xmi.id's might be forward references, i.e. they may
     * identify model objects which were not yet loaded at the point of
     * reference.
     * The default implementation attempts resolution of the m_SecondaryId.
     *
     * @return  True for success.
     */
    virtual bool resolveRef();

    /**
     * This method saves the XMI attributes of each specific model class.
     * It needs to be implemented by each child class.
     * For creating the TQDomElement and saving the common XMI parts,
     * it can use the save() method.
     */
    virtual void saveToXMI( TQDomDocument & qDoc, TQDomElement & qElement ) = 0;

    /**
     * This method loads the generic parts of the XMI common to most model
     * classes.  It is not usually reimplemented by child classes.
     * Instead, it invokes the load() method which implements the loading
     * of the specifics of each child class.
     *
     * @param element   The TQDomElement from which to load.
     */
    virtual bool loadFromXMI( TQDomElement & element );

    /**
     * Analyzes the given TQDomElement for a reference to a stereotype.
     *
     * @param element    TQDomElement to analyze.
     * @return        True if a stereotype reference was found, else false.
     */
    bool loadStereotype(TQDomElement & element);

    /**
     * Returns true if this UMLObject has classifier scope,
     * otherwise false (the default).
     */
    bool getStatic() const;


    /**
     * Sets the value for m_bStatic.
     */
    void setStatic(bool bStatic);

    /**
     * This should be reimplemented by subclasses if they wish to
     * accept certain types of associations. Note that this only
     * tells if this UMLObject can accept the association
     * type. When creating an association another check is made to
     * see if the association is valid. For example a UMLClass
     * (UMLClassifier) can accept generalizations and should
     * return true. If while creating a generalization the
     * superclass is already subclassed from this, the association
     * is not valid and will not be created.  The default accepts
     * nothing (returns false)
     */
    virtual bool acceptAssociationType(Uml::Association_Type);

    /**
     * Return secondary ID. Required by resolveRef().
     */
    TQString getSecondaryId() const;

    /**
     * Set the secondary ID.
     * Currently only required by petalTree2Uml(); all other setting of the
     * m_SecondaryID is internal to the UMLObject class hierarchy.
     */
    void setSecondaryId(const TQString& id);

    /**
     * Return secondary ID fallback.
     * Required by resolveRef() for imported model files.
     */
    TQString getSecondaryFallback() const;

    /**
     * Set the secondary ID fallback.
     * Currently only used by petalTree2Uml().
     */
    void setSecondaryFallback(const TQString& id);

    /**
     * Auxiliary to saveToXMI.
     * Create a TQDomElement with the given tag, and save the XMI attributes
     * that are common to all child classes to the newly created element.
     * This method does not need to be overridden by child classes.
     */
    TQDomElement save( const TQString &tag, TQDomDocument & qDoc );

public slots:
    /**
     * Forces the emission of the modified signal.  Useful when
     * updating several attributes at a time: you can block the
     * signals, update all atts, and then force the signal.
     */
    void emitModified();

signals:
    /** Emitted when the UMLObject has changed. Note that some objects emit
      * this signal when one of its children changes, for example, a UMLClass
      * emits a modified() signal when one of its operation changes while the Operation
      * itself emits the corresponding signal as well.
      */
    void modified();

protected:
    /**
     * Initializes key variables of the class.
     */
    virtual void init();

    /**
     * Calls UMLDoc::signalUMLObjectCreated() if m_BaseType affords
     * doing so.
     */
    void maybeSignalObjectCreated();

    /**
     * Auxiliary to loadFromXMI.
     * This method is usually overridden by child classes.
     * It is responsible for loading the specific XMI structure
     * of the child class.
     */
    virtual bool load( TQDomElement& element );

    /**
     * The object's id.
     */
    Uml::IDType m_nId;

    /**
     * The object's documentation.
     */
    TQString m_Doc;

    /**
     * The package the object belongs to if applicable.
     */
    UMLPackage* m_pUMLPackage;

    /**
     * The stereotype of the object if applicable.
     */
    UMLStereotype* m_pStereotype;

    /**
     * The objects name.
     */
    TQString m_Name;

    /**
     * The objects type.
     */
    Uml::Object_Type m_BaseType;

    /**
     * The objects visibility.
     */
    Uml::Visibility m_Vis;

    /**
     * The state of whether the object is abstract or not.
     */
    bool m_bAbstract;

    /**
     * This attribute holds whether the UMLObject has instance scope
     * (false - the default) or classifier scope (true).
     */
    bool m_bStatic;

    /**
     * Caller sets this true when in paste operation.
     */
    bool m_bInPaste;

    /**
     * Auxiliary to maybeSignalObjectCreated().
     */
    bool m_bCreationWasSignalled;

    /**
     * Pointer to an associated object.
     * Only a few of the classes inheriting from UMLObject use this.
     * However, it needs to be here because of inheritance graph
     * disjunctness.
     */
    UMLObject* m_pSecondary;

    /**
     * xmi.id of the secondary object for intermediate use during
     * loading.  The secondary ID is resolved to the m_pSecondary
     * in the course of resolveRef() at the end of loading.
     */
    TQString m_SecondaryId;

    /**
     * Last-chance backup for when m_SecondaryId is not found.
     * Used by Rose import: MDL files specify both a "quidu"
     * (which corresponds to m_SecondaryId) and the human readable
     * fully qualified target name of a reference.
     * In case the quidu is not found, the human readable name is
     * used which we store in m_SecondaryFallback.
     */
    TQString m_SecondaryFallback;
};

/**
 * Print UML Object to kdgstream, so it can be used like
 *   kdWarn() << "This object shouldn't be here:" << illegalObject << endl;
 */
kdbgstream& operator<< (kdbgstream& s, const UMLObject& a);

#endif