summaryrefslogtreecommitdiffstats
path: root/umbrello/umbrello/classifierwidget.h
blob: ac5681496c88ba52ec19302fec4249911fea5868 (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
/***************************************************************************
 *                                                                         *
 *   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) 2004-2006                                               *
 *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
 ***************************************************************************/

#ifndef CLASSIFIERWIDGET_H
#define CLASSIFIERWIDGET_H

#include "umlwidget.h"

class TQPainter;
class UMLClassifier;
class AssociationWidget;

/**
 * @short Common implementation for class widget and interface widget
 * @author Oliver Kellogg
 * @see UMLWidget
 * Bugs and comments to uml-devel@lists.sf.net or http://bugs.trinitydesktop.org
 */
class ClassifierWidget : public UMLWidget {
public:

    /**
     * Constructs a ClassifierWidget.
     *
     * @param view      The parent of this ClassifierWidget.
     * @param o The UMLObject to represent.
     */
    ClassifierWidget(UMLView * view, UMLClassifier * o);

    /**
     * Destructor.
     */
    virtual ~ClassifierWidget();

    /**
     * Toggles the status of whether to show StereoType.
     */
    void toggleShowStereotype();

    /**
     * Return the status of showing operations.
     *
     * @return  Return the status of showing operations.
     */
    bool getShowOps() const;

    /**
     *  Set the status of whether to show Operations
     *
     * @param _show             True if operations shall be shown.
     */
    void setShowOps(bool _show);

    /**
     * Toggles the status of showing operations.
     */
    void toggleShowOps();

    /**
     * Return true if public operations/attributes are shown only.
     */
    bool getShowPublicOnly() const;

    /**
     * Set whether to show public operations/attributes only.
     */
    void setShowPublicOnly(bool _status);

    /**
     * Toggle whether to show public operations/attributes only.
     */
    void toggleShowPublicOnly();

    /**
     * Returns the status of whether to show visibility.
     *
     * @return  True if visibility is shown.
     */
    bool getShowVisibility() const;

    /**
     * Set the status of whether to show visibility
     *
     * @param _visibility    True if visibility shall be shown.
     */
    void setShowVisibility(bool _visibility);

    /**
     * Toggles the status of whether to show visibility
     */
    void toggleShowVisibility();

    /**
     * Return the status of showing operation signatures.
     *
     * @return  Status of showing operation signatures.
     */
    Uml::Signature_Type getShowOpSigs() const;

    /**
     * Set the status of whether to show Operation signature
     *
     * @param _show             True if operation signatures shall be shown.
     */
    void setShowOpSigs(bool _show);

    /**
     * Toggles the status of showing operation signatures.
     */
    void toggleShowOpSigs();

    /**
     * Returns the status of whether to show Package.
     *
     * @return  True if package is shown.
     */
    bool getShowPackage() const;

    /**
     * Set the status of whether to show Package.
     *
     * @param _status             True if package shall be shown.
     */
    void setShowPackage(bool _status);

    /**
     * Toggles the status of whether to show package.
     */
    void toggleShowPackage();

    /**
     * Set the type of signature to display for an Operation
     *
     * @param sig       Type of signature to display for an operation.
     */
    void setOpSignature(Uml::Signature_Type sig);

    /**
     * Return the number of displayed attributes.
     */
    int displayedAttributes();

    /**
     * Return the number of displayed operations.
     */
    int displayedOperations();

    /**
     * Returns whether to show attributes.
     * Only applies when m_pObject->getBaseType() is ot_Class.
     *
     * @return  True if attributes are shown.
     */
    bool getShowAtts() const {
        return m_bShowAttributes;
    }

    /**
     * Toggles whether to show attributes.
     * Only applies when m_pObject->getBaseType() is ot_Class.
     */
    void toggleShowAtts();

    /**
     * Returns whether to show attribute signatures.
     * Only applies when m_pObject->getBaseType() is ot_Class.
     *
     * @return  Status of how attribute signatures are shown.
     */
    Uml::Signature_Type getShowAttSigs() {
        return m_ShowAttSigs;
    }

    /**
     * Toggles whether to show attribute signatures.
     * Only applies when m_pObject->getBaseType() is ot_Class.
     */
    void toggleShowAttSigs();

    /**
     * Sets whether to show attributes.
     * Only applies when m_pObject->getBaseType() is ot_Class.
     *
     * @param _show             True if attributes shall be shown.
     */
    void setShowAtts(bool _show);

    /**
     * Sets whether to show attribute signature
     * Only applies when m_pObject->getBaseType() is ot_Class.
     *
     * @param _show             True if attribute signatures shall be shown.
     */
    void setShowAttSigs(bool _show);

    /**
     * Sets the type of signature to display for an attribute.
     * Only applies when m_pObject->getBaseType() is ot_Class.
     *
     * @param sig       Type of signature to display for an attribute.
     */
    void setAttSignature(Uml::Signature_Type sig);

    /**
     * Returns whether to draw as circle.
     * Only applies when m_pObject->getBaseType() is ot_Interface.
     *
     * @return  True if widget is drawn as circle.
     */
    bool getDrawAsCircle() const;

    /**
     * Toggles whether to draw as circle.
     * Only applies when m_pObject->getBaseType() is ot_Interface.
     */
    void toggleDrawAsCircle();

    /**
     * Sets whether to draw as circle.
     * Only applies when m_pObject->getBaseType() is ot_Interface.
     *
     * @param drawAsCircle      True if widget shall be drawn as circle.
     */
    void setDrawAsCircle(bool drawAsCircle);

    /**
     * Changes this classifier from an interface to a class.
     * Attributes and stereotype visibility is got from the view OptionState.
     * This widget is also updated.
     */
    void changeToClass();

    /**
     * Changes this classifier from a class to an interface.
     * Attributes are hidden and stereotype is shown.
     * This widget is also updated.
     */
    void changeToInterface();

    /**
     * Set the AssociationWidget when this ClassWidget acts as
     * an association class.
     */
    void setClassAssocWidget(AssociationWidget *assocwidget);

    /**
     * Return the AssociationWidget when this classifier acts as
     * an association class (else return NULL.)
     */
    AssociationWidget *getClassAssocWidget();

    /**
     * Return the UMLClassifier which this ClassifierWidget
     * represents.
     */
    UMLClassifier *getClassifier();

    /**
     * Overrides standard method.
     * Auxiliary to reimplementations in the derived classes.
     */
    void draw(TQPainter & p, int offsetX, int offsetY);

    /**
     * Extends base method to adjust also the association of a class
     * association.
     * Executes the base method and then, if file isn't loading and the
     * classifier acts as a class association, the association position is
     * updated.
     *
     * @param x The x-coordinate.
     * @param y The y-coordinate.
     */
    virtual void adjustAssocs(int x, int y);

    /**
     * Creates the "classwidget" or "interfacewidget" XML element.
     */
    void saveToXMI(TQDomDocument & qDoc, TQDomElement & qElement);

    /**
     * Loads the "classwidget" or "interfacewidget" XML element.
     */
    bool loadFromXMI(TQDomElement & qElement);

public slots:
    /**
     * Will be called when a menu selection has been made from the
     * popup menu.
     *
     * @param sel       The selection id that has been selected.
     */
    void slotMenuSelection(int sel);

protected:

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

    /**
     * Calculcates the size of the templates box in the top left
     * if it exists, returns TQSize(0,0) if it doesn't.
     *
     * @return  TQSize of the templates flap.
     */
    TQSize calculateTemplatesBoxSize();

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

    /**
     * Draws the interface as a circle with name underneath.
     * Only applies when m_pObject->getBaseType() is ot_Interface.
     */
    void drawAsCircle(TQPainter& p, int offsetX, int offsetY);

    /**
     * Calculates the size of the object when drawn as a circle.
     * Only applies when m_pObject->getBaseType() is ot_Interface.
     */
    TQSize calculateAsCircleSize();

    /**
     * Updates m_ShowOpSigs to match m_bShowVisibility.
     */
    void updateSigs();

    /**
     * Return the number of displayed members of the given Object_Type.
     * Takes into consideration m_bShowPublicOnly but not other settings,
     */
    int displayedMembers(Uml::Object_Type ot);

    /**
     * Auxiliary method for draw() of child classes:
     * Draw the attributes or operations.
     *
     * @param p         TQPainter to paint to.
     * @param ot                Object type to draw, either ot_Attribute or ot_Operation.
     * @param sigType   Governs details of the member display.
     * @param x         X coordinate at which to draw the texts.
     * @param y         Y coordinate at which text drawing commences.
     * @param fontHeight        The font height.
     */
    void drawMembers(TQPainter & p, Uml::Object_Type ot, Uml::Signature_Type sigType,
                     int x, int y, int fontHeight);

    bool m_bShowOperations;            ///< Loaded/saved item.
    bool m_bShowPublicOnly;            ///< Loaded/saved item.
    bool m_bShowAccess;                ///< Loaded/saved item.
    bool m_bShowPackage;               ///< Loaded/saved item.
    bool m_bShowAttributes;            ///< Loaded/saved item.
    bool m_bDrawAsCircle;              ///< Loaded/saved item.
    Uml::Signature_Type m_ShowAttSigs; ///< Loaded/saved item.
    Uml::Signature_Type m_ShowOpSigs;  ///< Loaded/saved item.

    /**
     * Text width margin
     */
    static const int MARGIN;

    /**
     * Size of circle when interface is rendered as such
     */
    static const int CIRCLE_SIZE;

    /// Auxiliary variable for size calculations and drawing
    int m_bodyOffsetY;

    /**
     * The related AssociationWidget in case this classifier
     * acts as an association class
     */
    AssociationWidget *m_pAssocWidget;

};

#endif