summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/objectwidget.h
blob: 2136f767f2fc0a7f3ad0e83a57f6a46007623f3e (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
/***************************************************************************
 *                                                                         *
 *   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 OBJECTWIDGET_H
#define OBJECTWIDGET_H

#define O_MARGIN 5
#define O_WIDTH 40
#define A_WIDTH 20
#define A_HEIGHT 40
#define A_MARGIN 5

#include "messagewidgetlist.h"
#include "messagewidget.h"


class SeqLineWidget;

/**
 * Displays an instance UMLObject of a concept.
 *
 * @short Displays an instance of a Concept.
 * @author Paul Hensgen <phensgen@techie.com>
 * @see UMLWidget
 * Bugs and comments to uml-devel@lists.sf.net or http://bugs.trinitydesktop.org
 */
class ObjectWidget : public UMLWidget {
    Q_OBJECT
  
public:
    /**
     * Creates an ObjectWidget.
     *
     * @param view              The parent to this object.
     * @param o         The object it will be representing.
     * @param lid               The local id for the object.
     */
    ObjectWidget(UMLView * view, UMLObject *o, Uml::IDType lid = Uml::id_None );

    /**
     * destructor
     */
    virtual ~ObjectWidget();

    /**
     * Sets the x-coordinate.
     * Reimplements the method from UMLWidget.
     *
     * @param x The x-coordinate to be set.
     */
    virtual void setX( int x );

    /**
     * Sets the y-coordinate.
     * Reimplements the method from UMLWidget.
     *
     * @param y The y-coordinate to be set.
     */
    virtual void setY( int y );

    /**
     * Returns the local ID for this object.  This ID is used so that
     * many objects of the same @ref UMLObject instance can be on the
     * same diagram.
     *
     * @return  The local ID.
     */
    Uml::IDType getLocalID() const {
        return m_nLocalID;
    }

    /**
     * Returns the instance name.
     *
     * @return  The instance name.
     */
    TQString getInstanceName() const {
        return m_InstanceName;
    }

    /**
     * Sets the instance name.
     *
     * @param name              The name to set the instance name to.
     */
    void setInstanceName(const TQString &name) {
        m_InstanceName = name;
    }

    /**
     * Returns whether object is representing a multi-object.
     *
     * @return  True if object is representing a multi-object.
     */
    bool getMultipleInstance() const {
        return m_bMultipleInstance;
    }

    /**
     * Sets whether representing a multi-instance object.
     *
     * @param multiple  Object state. true- multi, false - single.
     */
    void setMultipleInstance(bool multiple);

    /**
     * Sets the local id of the object.
     *
     * @param id                The local id of the object.
     */
    void setLocalID(Uml::IDType id) {
        m_nLocalID = id;
    }

    /**
     * Activate the object after serializing it from a TQDataStream
     */
    bool activate(IDChangeLog* ChangeLog = 0);

    /**
     * Override default method.
     */
    void draw(TQPainter & p, int offsetX, int offsetY);

    /**
     * Overrides the standard operation.
     */
    virtual void moveEvent(TQMoveEvent */*m*/);

    /**
     * Used to cleanup any other widget it may need to delete.
     */
    void cleanup();

    /**
     * Show a properties dialog for an ObjectWidget.
     */
    void showProperties();

    /**
     * Returns whether to draw as an Actor or not.
     *
     * @return  True if widget is drawn as an actor.
     */
    bool getDrawAsActor() const {
        return m_bDrawAsActor;
    }

    /**
     * Sets whether to draw as an Actor.
     *
     * @param drawAsActor       True if widget shall be drawn as an actor.
     */
    void setDrawAsActor( bool drawAsActor );

    /**
     * Sets whether to show deconstruction on sequence line.
     *
     * @param bShow             True if destruction on line shall be shown.
     */
    void setShowDestruction( bool bShow );

    /**
     * Returns whether to show deconstruction on sequence line.
     *
     * @return  True if destruction on sequence line is shown.
     */
    bool getShowDestruction() const {
        return m_bShowDestruction;
    }

    /**
     * Returns the top margin constant (Y axis value)
     *
     * @return  Y coordinate of the space between the diagram top
     *          and the upper edge of the ObjectWidget.
     */
    int topMargin();

    /**
     * Returns the end Y co-ord of the seq. line.
     *
     * @return  Y coordinate of the endpoint of the sequence line.
     */
    int getEndLineY();

    /**
     * Add a message widget to the list.
     *
     * @param message   Pointer to the MessageWidget to add.
     */
    void messageAdded(MessageWidget* message);

    /**
     * Remove a message widget from the list.
     *
     * @param message   Pointer to the MessageWidget to remove.
     */
    void messageRemoved(MessageWidget* message);

    /**
     * Returns whether or not the widget can be moved vertically up.
     *
     * @return  True if widget can be moved upwards vertically.
     */
    bool canTabUp();

    /**
     * Returns whether a message is overlapping with another message.
     * Used by MessageWidget::draw() methods.
     *
     * @param y         The top of your message.
     * @param messageWidget     A pointer to your message so it doesn't
     *                  check against itself.
     */
    bool messageOverlap(int y, MessageWidget* messageWidget);

    /**
     * Return the SeqLineWidget.
     * Returns a non NULL pointer if this ObjectWidget is part of a
     * sequence diagram.
     */
    SeqLineWidget *getSeqLine();

    /**
     * Saves to the "objectwidget" XMI element.
     */
    void saveToXMI( TQDomDocument & qDoc, TQDomElement & qElement );

    /**
     * Loads from a "objectwidget" XMI element.
     */
    bool loadFromXMI( TQDomElement & qElement );

public slots:
    /**
     * Handles a popup menu selection.
     */
    void slotMenuSelection(int sel);

    /**
     * Handles a color change signal.
     */
    virtual void slotColorChanged(Uml::IDType viewID);

    /**
     * Called when a message widget with an end on this object has
     * moved up or down.
     * Sets the bottom of the line to a nice position.
     */
    void slotMessageMoved();

protected:
    SeqLineWidget * m_pLine;

    /**
     * Overrides method from UMLWidget
     */
    TQSize calculateSize();

    /**
     * Draw the object as an actor.
     */
    void drawActor(TQPainter & p, int offsetX, int offsetY);

    /**
     * Draw the object as an object (default).
     */
    void drawObject(TQPainter & p, int offsetX, int offsetY);

    /**
     * Move the object up on a sequence diagram.
     */
    void tabUp();

    /**
     * Move the object down on a sequence diagram.
     */
    void tabDown();

    // Data loaded/saved:

    /**
     * Instance name of object.
     */
    TQString m_InstanceName;

    /**
     * Local ID used on views.  Needed as a it can represent a class
     * that has many objects representing it.
     */
    Uml::IDType m_nLocalID;

    /**
     * Determines whether to draw an object as a multiple object
     * instance.
     */
    bool m_bMultipleInstance;

    /**
     * Determines whether the object should be drawn as an Actor or
     * an Object.
     */
    bool m_bDrawAsActor;

    /**
     * Determines whether to show object destruction on sequence
     * diagram line.
     */
    bool m_bShowDestruction;

private:
    /**
     * Initializes the key attributes of the class.
     */
    void init();

    /**
     * A list of the message widgets with an end on this widget.
     */
    MessageWidgetList messageWidgetList;
};

#endif