~ubuntu-branches/ubuntu/vivid/kdesdk/vivid

« back to all changes in this revision

Viewing changes to umbrello/umbrello/widgets/classifierwidget.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2012-06-06 11:49:54 UTC
  • mfrom: (0.4.21)
  • Revision ID: package-import@ubuntu.com-20120606114954-rdls73fzlpzxglbx
Tags: 4:4.8.80-0ubuntu1
* New uptream beta release
* Update dont_export_private_classes.diff

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 *   the Free Software Foundation; either version 2 of the License, or     *
5
5
 *   (at your option) any later version.                                   *
6
6
 *                                                                         *
7
 
 *   copyright (C) 2004-2011                                               *
 
7
 *   copyright (C) 2004-2012                                               *
8
8
 *   Umbrello UML Modeller Authors <uml-devel@uml.sf.net>                  *
9
9
 ***************************************************************************/
10
10
 
11
11
// own header
12
12
#include "classifierwidget.h"
13
 
// qt/kde includes
14
 
#include <QtGui/QPainter>
 
13
 
15
14
// app includes
 
15
#include "associationwidget.h"
16
16
#include "classifier.h"
17
17
#include "debug_utils.h"
 
18
#include "listpopupmenu.h"
 
19
#include "object_factory.h"
18
20
#include "operation.h"
19
21
#include "template.h"
20
 
#include "associationwidget.h"
 
22
#include "uml.h"
 
23
#include "umldoc.h"
21
24
#include "umlview.h"
22
 
#include "umldoc.h"
23
 
#include "uml.h"
24
 
#include "listpopupmenu.h"
25
 
#include "object_factory.h"
26
 
 
27
 
ClassifierWidget::ClassifierWidget(UMLScene * scene, UMLClassifier *c)
28
 
  : UMLWidget(scene, WidgetBase::wt_Class, c)
29
 
{
30
 
    init();
31
 
    if (c != NULL && c->isInterface()) {
32
 
        setBaseType(WidgetBase::wt_Interface);
33
 
        m_showStereotype = true;
34
 
        m_showAttributes = false;
35
 
        updateSigs();
36
 
    }
37
 
}
38
 
 
39
 
ClassifierWidget::~ClassifierWidget()
40
 
{
41
 
    if (m_pAssocWidget)
42
 
        m_pAssocWidget->removeAssocClassLine();
43
 
}
 
25
 
 
26
// qt includes
 
27
#include <QtGui/QPainter>
44
28
 
45
29
const int ClassifierWidget::MARGIN = 5;
46
30
const int ClassifierWidget::CIRCLE_SIZE = 30;
47
31
 
48
 
void ClassifierWidget::init()
 
32
/**
 
33
 * Constructs a ClassifierWidget.
 
34
 *
 
35
 * @param scene   The parent of this ClassifierWidget.
 
36
 * @param o       The UMLObject to represent.
 
37
 */
 
38
ClassifierWidget::ClassifierWidget(UMLScene * scene, UMLClassifier *c)
 
39
  : UMLWidget(scene, WidgetBase::wt_Class, c),
 
40
    m_pAssocWidget(0)
49
41
{
50
42
    const Settings::OptionState& ops = m_scene->optionState();
51
 
    m_showAccess = ops.classState.showVisibility;
52
 
    m_showOperations = ops.classState.showOps;
53
 
    m_showPublicOnly = ops.classState.showPublicOnly;
54
 
    m_showPackage = ops.classState.showPackage;
55
 
    m_ShowAttSigs = Uml::SignatureType::ShowSig;
56
 
    /* setShowOpSigs( ops.classState.showOpSig );
 
43
    setVisualProperty(ShowVisibility, ops.classState.showVisibility);
 
44
    setVisualProperty(ShowOperations, ops.classState.showOps);
 
45
    setVisualProperty(ShowPublicOnly, ops.classState.showPublicOnly);
 
46
    setVisualProperty(ShowPackage,    ops.classState.showPackage);
 
47
    m_attributeSignature = Uml::SignatureType::ShowSig;
 
48
    /*:TODO:
 
49
    setVisualProperty(ShowOperationSignature, ops.classState.showOpSig);
57
50
      Cannot do that because we get "pure virtual method called". Open code:
58
51
     */
59
52
    if( !ops.classState.showOpSig ) {
60
 
        if (m_showAccess)
61
 
            m_ShowOpSigs = Uml::SignatureType::NoSig;
 
53
        if (visualProperty(ShowVisibility))
 
54
            m_operationSignature = Uml::SignatureType::NoSig;
62
55
        else
63
 
            m_ShowOpSigs = Uml::SignatureType::NoSigNoVis;
 
56
            m_operationSignature = Uml::SignatureType::NoSigNoVis;
64
57
 
65
 
    } else if (m_showAccess)
66
 
        m_ShowOpSigs = Uml::SignatureType::ShowSig;
 
58
    } else if (visualProperty(ShowVisibility))
 
59
        m_operationSignature = Uml::SignatureType::ShowSig;
67
60
    else
68
 
        m_ShowOpSigs = Uml::SignatureType::SigNoVis;
 
61
        m_operationSignature = Uml::SignatureType::SigNoVis;
69
62
 
70
 
    m_showAttributes = ops.classState.showAtts;
71
 
    m_showStereotype = ops.classState.showStereoType;
72
 
    m_drawAsCircle = false;
73
 
    m_pAssocWidget = NULL;
 
63
    setVisualProperty(ShowAttributes, ops.classState.showAtts);
 
64
    setVisualProperty(ShowStereotype, ops.classState.showStereoType);
 
65
    setVisualProperty(DrawAsCircle, false);
74
66
 
75
67
    setShowAttSigs( ops.classState.showAttSig );
76
 
}
77
 
 
78
 
void ClassifierWidget::updateSigs()
 
68
 
 
69
    if (c && c->isInterface()) {
 
70
        m_baseType = WidgetBase::wt_Interface;
 
71
        m_visualProperties = ShowOperations | ShowVisibility | ShowStereotype;
 
72
        setShowStereotype(true);
 
73
        updateSignatureTypes();
 
74
    }
 
75
 
 
76
    DEBUG_REGISTER(DBG_SRC);
 
77
}
 
78
 
 
79
/**
 
80
 * Destructor.
 
81
 */
 
82
ClassifierWidget::~ClassifierWidget()
 
83
{
 
84
    if (m_pAssocWidget)
 
85
        m_pAssocWidget->removeAssocClassLine();
 
86
}
 
87
 
 
88
/**
 
89
 * Return the UMLClassifier which this ClassifierWidget
 
90
 * represents.
 
91
 */
 
92
UMLClassifier *ClassifierWidget::classifier() const
 
93
{
 
94
    return static_cast<UMLClassifier*>(m_pObject);
 
95
}
 
96
 
 
97
/**
 
98
 * @return the visual properties
 
99
 */
 
100
ClassifierWidget::VisualProperties ClassifierWidget::visualProperties() const
 
101
{
 
102
    return m_visualProperties;
 
103
}
 
104
 
 
105
/**
 
106
 * Set an OR combination of properties stored in \a properties on this
 
107
 * widget.
 
108
 */
 
109
void ClassifierWidget::setVisualProperties(VisualProperties properties)
 
110
{
 
111
    // Don't do anything if the argument is equal to current status.
 
112
    if (quint32(m_visualProperties) == quint32(properties)) {
 
113
        return;
 
114
    }
 
115
 
 
116
    m_visualProperties = properties;
 
117
    updateSignatureTypes();
 
118
}
 
119
 
 
120
/**
 
121
 * @return The status of the property passed in.
 
122
 *
 
123
 * @note Use @ref attributeSignatureType() and @ref
 
124
 *       operationSignatureType() to get signature status.  This
 
125
 *       method only indicates whether signature is visible or not.
 
126
 */
 
127
bool ClassifierWidget::visualProperty(VisualProperty property) const
 
128
{
 
129
    if (property == ShowAttributeSignature) {
 
130
        return (m_attributeSignature == Uml::SignatureType::ShowSig
 
131
                || m_attributeSignature == Uml::SignatureType::SigNoVis);
 
132
    }
 
133
 
 
134
    else if(property == ShowOperationSignature) {
 
135
        return (m_operationSignature == Uml::SignatureType::ShowSig
 
136
                || m_operationSignature == Uml::SignatureType::SigNoVis);
 
137
    }
 
138
 
 
139
    return m_visualProperties.testFlag(property);
 
140
}
 
141
 
 
142
/**
 
143
 * A convenient method to set and reset individual VisualProperty
 
144
 *
 
145
 * @param property The property to be set/reset.
 
146
 * @param enable   True/false to set/reset. (default = true)
 
147
 *
 
148
 * @note This method handles ShowAttributeSignature and
 
149
 *       ShowOperationSignature specially.
 
150
 */
 
151
void ClassifierWidget::setVisualProperty(VisualProperty property, bool enable)
 
152
{
 
153
    // Handle ShowAttributeSignature and ShowOperationSignature
 
154
    // specially.
 
155
 
 
156
    if (property == ShowAttributeSignature) {
 
157
        if (!enable) {
 
158
            m_attributeSignature = visualProperty(ShowVisibility) ?
 
159
                Uml::SignatureType::NoSig : Uml::SignatureType::NoSigNoVis;
 
160
        }
 
161
        else {
 
162
            m_attributeSignature = visualProperty(ShowVisibility) ?
 
163
                Uml::SignatureType::ShowSig : Uml::SignatureType::SigNoVis;
 
164
        }
 
165
        //:TODO: updateTextItemGroups();
 
166
        updateSignatureTypes();
 
167
    }
 
168
 
 
169
    else if (property == ShowOperationSignature) {
 
170
        if (!enable) {
 
171
            m_operationSignature = visualProperty(ShowVisibility) ?
 
172
                Uml::SignatureType::NoSig : Uml::SignatureType::NoSigNoVis;
 
173
        }
 
174
        else {
 
175
            m_operationSignature = visualProperty(ShowVisibility) ?
 
176
                Uml::SignatureType::ShowSig : Uml::SignatureType::SigNoVis;
 
177
        }
 
178
        //:TODO: updateTextItemGroups();
 
179
        updateSignatureTypes();
 
180
    }
 
181
 
 
182
    else if (property == ShowStereotype) {
 
183
        // Now just update flag and use base method for actual work.
 
184
        if (enable) {
 
185
            m_visualProperties |= property;
 
186
        }
 
187
        else {
 
188
            enable &= ~property;
 
189
        }
 
190
        setShowStereotype(enable);
 
191
    }
 
192
 
 
193
    // Some other flag.
 
194
    else {
 
195
        // Don't do anything if the flag status is same.
 
196
        if (visualProperty(property) == enable) {
 
197
            return;
 
198
        }
 
199
 
 
200
        // Call setVisualProperties appropriately based on enbable.
 
201
        if (enable) {
 
202
            setVisualProperties(visualProperties() | property);
 
203
        }
 
204
        else {
 
205
            setVisualProperties(visualProperties() & ~property);
 
206
        }
 
207
    }
 
208
}
 
209
 
 
210
/**
 
211
 * A convenient method to toggle individual VisualProperty of this
 
212
 * widget.
 
213
 *
 
214
 * @param property The property to be toggled.
 
215
 *
 
216
 * @note This method handles ShowAttributeSignature and
 
217
 *       ShowOperationSignature specially.
 
218
 */
 
219
void ClassifierWidget::toggleVisualProperty(VisualProperty property)
 
220
{
 
221
    bool oppositeStatus;
 
222
    if (property == ShowOperationSignature) {
 
223
        oppositeStatus = !(m_operationSignature == Uml::SignatureType::ShowSig
 
224
                           || m_operationSignature == Uml::SignatureType::SigNoVis);
 
225
    }
 
226
    else if (property == ShowAttributeSignature) {
 
227
        oppositeStatus = !(m_attributeSignature == Uml::SignatureType::ShowSig
 
228
                           || m_attributeSignature == Uml::SignatureType::SigNoVis);
 
229
    }
 
230
    else {
 
231
        oppositeStatus = !visualProperty(property);
 
232
    }
 
233
 
 
234
    DEBUG(DBG_SRC) << "VisualProperty: " << property << " to opposite status " << oppositeStatus;
 
235
    setVisualProperty(property, oppositeStatus);
 
236
}
 
237
 
 
238
/**
 
239
 * Updates m_operationSignature to match m_showVisibility.
 
240
 */
 
241
void ClassifierWidget::updateSignatureTypes()
79
242
{
80
243
    //turn on scope
81
 
    if (m_showAccess) {
82
 
        if (m_ShowOpSigs == Uml::SignatureType::NoSigNoVis) {
83
 
            m_ShowOpSigs = Uml::SignatureType::NoSig;
84
 
        } else if (m_ShowOpSigs == Uml::SignatureType::SigNoVis) {
85
 
            m_ShowOpSigs = Uml::SignatureType::ShowSig;
86
 
        }
87
 
    } else { //turn off scope
88
 
        if (m_ShowOpSigs == Uml::SignatureType::ShowSig) {
89
 
            m_ShowOpSigs = Uml::SignatureType::SigNoVis;
90
 
        } else if (m_ShowOpSigs == Uml::SignatureType::NoSig) {
91
 
            m_ShowOpSigs = Uml::SignatureType::NoSigNoVis;
92
 
        }
93
 
    }
94
 
    if (m_showAccess) {
95
 
        if (m_ShowAttSigs == Uml::SignatureType::NoSigNoVis)
96
 
            m_ShowAttSigs = Uml::SignatureType::NoSig;
97
 
        else if (m_ShowAttSigs == Uml::SignatureType::SigNoVis)
98
 
            m_ShowAttSigs = Uml::SignatureType::ShowSig;
99
 
    } else {
100
 
        if (m_ShowAttSigs == Uml::SignatureType::ShowSig)
101
 
            m_ShowAttSigs = Uml::SignatureType::SigNoVis;
102
 
        else if(m_ShowAttSigs == Uml::SignatureType::NoSig)
103
 
            m_ShowAttSigs = Uml::SignatureType::NoSigNoVis;
104
 
    }
105
 
    updateComponentSize();
106
 
    update();
107
 
}
108
 
 
109
 
void ClassifierWidget::toggleShowStereotype()
110
 
{
111
 
    m_showStereotype = !m_showStereotype;
112
 
    updateSigs();
113
 
    updateComponentSize();
114
 
    update();
115
 
}
116
 
 
117
 
bool ClassifierWidget::getShowOps() const
118
 
{
119
 
    return m_showOperations;
120
 
}
121
 
 
122
 
void ClassifierWidget::setShowOps(bool _show)
123
 
{
124
 
    m_showOperations = _show;
125
 
    updateSigs();
126
 
    updateComponentSize();
127
 
    update();
128
 
}
129
 
 
130
 
void ClassifierWidget::toggleShowOps()
131
 
{
132
 
    m_showOperations = !m_showOperations;
133
 
    updateSigs();
134
 
    updateComponentSize();
135
 
    update();
136
 
}
137
 
 
138
 
bool ClassifierWidget::getShowPublicOnly() const
139
 
{
140
 
    return m_showPublicOnly;
141
 
}
142
 
 
143
 
void ClassifierWidget::setShowPublicOnly(bool _status)
144
 
{
145
 
    m_showPublicOnly = _status;
146
 
    updateComponentSize();
147
 
    update();
148
 
}
149
 
 
150
 
void ClassifierWidget::toggleShowPublicOnly()
151
 
{
152
 
    m_showPublicOnly = !m_showPublicOnly;
153
 
    updateComponentSize();
154
 
    update();
155
 
}
156
 
 
157
 
bool ClassifierWidget::getShowVisibility() const
158
 
{
159
 
    return m_showAccess;
160
 
}
161
 
 
162
 
void ClassifierWidget::setShowVisibility(bool _visibility)
163
 
{
164
 
    m_showAccess = _visibility;
165
 
    updateSigs();
166
 
    updateComponentSize();
167
 
    update();
168
 
}
169
 
 
170
 
void ClassifierWidget::toggleShowVisibility()
171
 
{
172
 
    m_showAccess = !m_showAccess;
173
 
    updateSigs();
174
 
    updateComponentSize();
175
 
    update();
176
 
}
177
 
 
178
 
Uml::SignatureType ClassifierWidget::operationSignatureType() const
179
 
{
180
 
    return m_ShowOpSigs;
181
 
}
182
 
 
183
 
void ClassifierWidget::setShowOpSigs(bool _status)
184
 
{
185
 
    if( !_status ) {
186
 
        if (m_showAccess)
187
 
            m_ShowOpSigs = Uml::SignatureType::NoSig;
188
 
        else
189
 
            m_ShowOpSigs = Uml::SignatureType::NoSigNoVis;
190
 
    } else if (m_showAccess)
191
 
        m_ShowOpSigs = Uml::SignatureType::ShowSig;
192
 
    else
193
 
        m_ShowOpSigs = Uml::SignatureType::SigNoVis;
194
 
    updateComponentSize();
195
 
    update();
196
 
}
197
 
 
198
 
void ClassifierWidget::toggleShowOpSigs()
199
 
{
200
 
    if (m_ShowOpSigs == Uml::SignatureType::ShowSig || m_ShowOpSigs == Uml::SignatureType::SigNoVis) {
201
 
        if (m_showAccess) {
202
 
            m_ShowOpSigs = Uml::SignatureType::NoSig;
203
 
        } else {
204
 
            m_ShowOpSigs = Uml::SignatureType::NoSigNoVis;
205
 
        }
206
 
    } else if (m_showAccess) {
207
 
        m_ShowOpSigs = Uml::SignatureType::ShowSig;
208
 
    } else {
209
 
        m_ShowOpSigs = Uml::SignatureType::SigNoVis;
210
 
    }
211
 
    updateComponentSize();
212
 
    update();
213
 
}
214
 
 
215
 
bool ClassifierWidget::getShowPackage() const
216
 
{
217
 
    return m_showPackage;
218
 
}
219
 
 
220
 
void ClassifierWidget::setShowPackage(bool _status)
221
 
{
222
 
    m_showPackage = _status;
223
 
    updateComponentSize();
224
 
    update();
225
 
}
226
 
 
227
 
void ClassifierWidget::toggleShowPackage()
228
 
{
229
 
    m_showPackage = !m_showPackage;
230
 
    updateSigs();
231
 
    updateComponentSize();
232
 
    update();
233
 
}
234
 
 
235
 
void ClassifierWidget::setOpSignature(Uml::SignatureType sig)
236
 
{
237
 
    m_ShowOpSigs = sig;
238
 
    updateSigs();
239
 
    updateComponentSize();
240
 
    update();
241
 
}
242
 
 
243
 
void ClassifierWidget::setShowAtts(bool _show)
244
 
{
245
 
    m_showAttributes = _show;
246
 
    updateSigs();
247
 
 
248
 
    updateComponentSize();
249
 
    update();
250
 
}
251
 
 
252
 
void ClassifierWidget::setAttSignature(Uml::SignatureType sig)
253
 
{
254
 
    m_ShowAttSigs = sig;
255
 
    updateSigs();
256
 
    updateComponentSize();
257
 
    update();
258
 
}
259
 
 
 
244
    if (visualProperty(ShowVisibility)) {
 
245
        if (m_operationSignature == Uml::SignatureType::NoSigNoVis) {
 
246
            m_operationSignature = Uml::SignatureType::NoSig;
 
247
        } else if (m_operationSignature == Uml::SignatureType::SigNoVis) {
 
248
            m_operationSignature = Uml::SignatureType::ShowSig;
 
249
        }
 
250
    }
 
251
    //turn off scope
 
252
    else {
 
253
        if (m_operationSignature == Uml::SignatureType::ShowSig) {
 
254
            m_operationSignature = Uml::SignatureType::SigNoVis;
 
255
        } else if (m_operationSignature == Uml::SignatureType::NoSig) {
 
256
            m_operationSignature = Uml::SignatureType::NoSigNoVis;
 
257
        }
 
258
    }
 
259
    if (visualProperty(ShowVisibility)) {
 
260
        if (m_attributeSignature == Uml::SignatureType::NoSigNoVis)
 
261
            m_attributeSignature = Uml::SignatureType::NoSig;
 
262
        else if (m_attributeSignature == Uml::SignatureType::SigNoVis)
 
263
            m_attributeSignature = Uml::SignatureType::ShowSig;
 
264
    } else {
 
265
        if (m_attributeSignature == Uml::SignatureType::ShowSig)
 
266
            m_attributeSignature = Uml::SignatureType::SigNoVis;
 
267
        else if(m_attributeSignature == Uml::SignatureType::NoSig)
 
268
            m_attributeSignature = Uml::SignatureType::NoSigNoVis;
 
269
    }
 
270
    updateComponentSize();
 
271
    update();
 
272
}
 
273
 
 
274
/**
 
275
 * Returns whether to show attribute signatures.
 
276
 * Only applies when m_pObject->getBaseType() is ot_Class.
 
277
 *
 
278
 * @return  Status of how attribute signatures are shown.
 
279
 */
 
280
Uml::SignatureType ClassifierWidget::attributeSignature() const
 
281
{
 
282
    return m_attributeSignature;
 
283
}
 
284
 
 
285
/**
 
286
 * Sets the type of signature to display for an attribute.
 
287
 * Only applies when m_pObject->getBaseType() is ot_Class.
 
288
 *
 
289
 * @param sig   Type of signature to display for an attribute.
 
290
 */
 
291
void ClassifierWidget::setAttributeSignature(Uml::SignatureType sig)
 
292
{
 
293
    m_attributeSignature = sig;
 
294
    updateSignatureTypes();
 
295
    updateComponentSize();
 
296
    update();
 
297
}
 
298
 
 
299
/**
 
300
 * @return The Uml::SignatureType value for the operations.
 
301
 */
 
302
Uml::SignatureType ClassifierWidget::operationSignature() const
 
303
{
 
304
    return m_operationSignature;
 
305
}
 
306
 
 
307
/**
 
308
 * Set the type of signature to display for an Operation
 
309
 *
 
310
 * @param sig   Type of signature to display for an operation.
 
311
 */
 
312
void ClassifierWidget::setOperationSignature(Uml::SignatureType sig)
 
313
{
 
314
    m_operationSignature = sig;
 
315
    updateSignatureTypes();
 
316
    updateComponentSize();
 
317
    update();
 
318
}
 
319
 
 
320
/**
 
321
 * Sets whether to show attribute signature
 
322
 * Only applies when m_pObject->getBaseType() is ot_Class.
 
323
 *
 
324
 * @param _show   True if attribute signatures shall be shown.
 
325
 */
260
326
void ClassifierWidget::setShowAttSigs(bool _status)
261
327
{
262
328
    if( !_status ) {
263
 
        if (m_showAccess)
264
 
            m_ShowAttSigs = Uml::SignatureType::NoSig;
 
329
        if (visualProperty(ShowVisibility))
 
330
            m_attributeSignature = Uml::SignatureType::NoSig;
265
331
        else
266
 
            m_ShowAttSigs = Uml::SignatureType::NoSigNoVis;
 
332
            m_attributeSignature = Uml::SignatureType::NoSigNoVis;
267
333
    }
268
 
    else if (m_showAccess)
269
 
        m_ShowAttSigs = Uml::SignatureType::ShowSig;
 
334
    else if (visualProperty(ShowVisibility))
 
335
        m_attributeSignature = Uml::SignatureType::ShowSig;
270
336
    else
271
 
        m_ShowAttSigs = Uml::SignatureType::SigNoVis;
 
337
        m_attributeSignature = Uml::SignatureType::SigNoVis;
272
338
    if (UMLApp::app()->document()->loading())
273
339
        return;
274
340
    updateComponentSize();
275
341
    update();
276
342
}
277
343
 
278
 
void ClassifierWidget::toggleShowAtts()
279
 
{
280
 
    m_showAttributes = !m_showAttributes;
281
 
    updateSigs();
282
 
    updateComponentSize();
283
 
    update();
284
 
}
285
 
 
 
344
/**
 
345
 * Toggles whether to show attribute signatures.
 
346
 * Only applies when m_pObject->getBaseType() is ot_Class.
 
347
 */
286
348
void ClassifierWidget::toggleShowAttSigs()
287
349
{
288
 
    if (m_ShowAttSigs == Uml::SignatureType::ShowSig ||
289
 
            m_ShowAttSigs == Uml::SignatureType::SigNoVis) {
290
 
        if (m_showAccess) {
291
 
            m_ShowAttSigs = Uml::SignatureType::NoSig;
 
350
    if (m_attributeSignature == Uml::SignatureType::ShowSig ||
 
351
            m_attributeSignature == Uml::SignatureType::SigNoVis) {
 
352
        if (visualProperty(ShowVisibility)) {
 
353
            m_attributeSignature = Uml::SignatureType::NoSig;
292
354
        } else {
293
 
            m_ShowAttSigs = Uml::SignatureType::NoSigNoVis;
 
355
            m_attributeSignature = Uml::SignatureType::NoSigNoVis;
294
356
        }
295
 
    } else if (m_showAccess) {
296
 
        m_ShowAttSigs = Uml::SignatureType::ShowSig;
 
357
    } else if (visualProperty(ShowVisibility)) {
 
358
        m_attributeSignature = Uml::SignatureType::ShowSig;
297
359
    } else {
298
 
        m_ShowAttSigs = Uml::SignatureType::SigNoVis;
 
360
        m_attributeSignature = Uml::SignatureType::SigNoVis;
299
361
    }
300
362
    updateComponentSize();
301
363
    update();
302
364
}
303
365
 
 
366
/**
 
367
 * Return the number of displayed members of the given ObjectType.
 
368
 * Takes into consideration m_showPublicOnly but not other settings.
 
369
 */
304
370
int ClassifierWidget::displayedMembers(UMLObject::ObjectType ot)
305
371
{
306
372
    int count = 0;
307
373
    UMLClassifierListItemList list = classifier()->getFilteredList(ot);
308
374
    foreach (UMLClassifierListItem *m , list ) {
309
 
      if (!(m_showPublicOnly && m->visibility() != Uml::Visibility::Public))
 
375
      if (!(visualProperty(ShowPublicOnly) && m->visibility() != Uml::Visibility::Public))
310
376
            count++;
311
377
    }
312
378
    return count;
313
379
}
314
380
 
315
 
int ClassifierWidget::displayedOperations()
316
 
{
317
 
    if (!m_showOperations)
318
 
        return 0;
319
 
    return displayedMembers(UMLObject::ot_Operation);
320
 
}
321
 
 
 
381
/**
 
382
 * Overrides method from UMLWidget.
 
383
 */
322
384
UMLSceneSize ClassifierWidget::minimumSize()
323
385
{
324
386
    if (!m_pObject) {
325
387
        return UMLWidget::minimumSize();
326
388
    }
327
 
    if (classifier()->isInterface() && m_drawAsCircle) {
 
389
    if (classifier()->isInterface() && visualProperty(DrawAsCircle)) {
328
390
        return calculateAsCircleSize();
329
391
    }
330
392
 
347
409
    height += fontHeight;
348
410
    // ... width
349
411
    QString displayedName;
350
 
    if (m_showPackage)
 
412
    if (visualProperty(ShowPackage))
351
413
        displayedName = m_pObject->fullyQualifiedName();
352
414
    else
353
415
        displayedName = m_pObject->name();
365
427
        // calculate width of the attributes
366
428
        UMLClassifierListItemList list = classifier()->getFilteredList(UMLObject::ot_Attribute);
367
429
        foreach (UMLClassifierListItem *a , list ) {
368
 
            if (m_showPublicOnly && a->visibility() != Uml::Visibility::Public)
 
430
            if (visualProperty(ShowPublicOnly) && a->visibility() != Uml::Visibility::Public)
369
431
                continue;
370
 
            const int attWidth = fm.size(0,a->toString(m_ShowAttSigs)).width();
 
432
            const int attWidth = fm.size(0,a->toString(m_attributeSignature)).width();
371
433
            if (attWidth > width)
372
434
                width = attWidth;
373
435
        }
382
444
        // ... width
383
445
        UMLOperationList list(classifier()->getOpList());
384
446
        foreach (UMLOperation* op ,  list) {
385
 
                  if (m_showPublicOnly && op->visibility() != Uml::Visibility::Public)
 
447
                  if (visualProperty(ShowPublicOnly) && op->visibility() != Uml::Visibility::Public)
386
448
                continue;
387
 
            const QString displayedOp = op->toString(m_ShowOpSigs);
 
449
            const QString displayedOp = op->toString(m_operationSignature);
388
450
            UMLWidget::FontType oft;
389
451
            oft = (op->isAbstract() ? UMLWidget::FT_ITALIC : UMLWidget::FT_NORMAL);
390
452
            const int w = UMLWidget::getFontMetrics(oft).size(0,displayedOp).width();
405
467
 
406
468
 
407
469
    // allow for height margin
408
 
    if (!m_showOperations && !m_showAttributes && !m_showStereotype) {
 
470
    if (!visualProperty(ShowOperations) && !visualProperty(ShowAttributes) && !m_showStereotype) {
409
471
        height += MARGIN * 2;
410
472
    }
411
473
 
415
477
    return UMLSceneSize(width, height);
416
478
}
417
479
 
418
 
void ClassifierWidget::slotMenuSelection(QAction* action)
419
 
{
420
 
    ListPopupMenu::MenuType sel = m_pMenu->getMenuType(action);
421
 
    switch (sel) {
422
 
    case ListPopupMenu::mt_Attribute:
423
 
    case ListPopupMenu::mt_Operation:
424
 
    case ListPopupMenu::mt_Template:
425
 
        {
426
 
            UMLObject::ObjectType ot = ListPopupMenu::convert_MT_OT(sel);
427
 
            if (Object_Factory::createChildObject(classifier(), ot)) {
428
 
                updateComponentSize();
429
 
                update();
430
 
                UMLApp::app()->document()->setModified();
431
 
            }
432
 
            break;
433
 
        }
434
 
    case ListPopupMenu::mt_Show_Operations:
435
 
    case ListPopupMenu::mt_Show_Operations_Selection:
436
 
        toggleShowOps();
437
 
        break;
438
 
 
439
 
    case ListPopupMenu::mt_Show_Attributes:
440
 
    case ListPopupMenu::mt_Show_Attributes_Selection:
441
 
        toggleShowAtts();
442
 
        break;
443
 
 
444
 
    case ListPopupMenu::mt_Show_Public_Only:
445
 
    case ListPopupMenu::mt_Show_Public_Only_Selection:
446
 
        toggleShowPublicOnly();
447
 
        break;
448
 
 
449
 
    case ListPopupMenu::mt_Show_Operation_Signature:
450
 
    case ListPopupMenu::mt_Show_Operation_Signature_Selection:
451
 
        toggleShowOpSigs();
452
 
        break;
453
 
 
454
 
    case ListPopupMenu::mt_Show_Attribute_Signature:
455
 
    case ListPopupMenu::mt_Show_Attribute_Signature_Selection:
456
 
        toggleShowAttSigs();
457
 
        break;
458
 
 
459
 
    case ListPopupMenu::mt_Visibility:
460
 
    case ListPopupMenu::mt_Visibility_Selection:
461
 
        toggleShowVisibility();
462
 
        break;
463
 
 
464
 
    case ListPopupMenu::mt_Show_Packages:
465
 
    case ListPopupMenu::mt_Show_Packages_Selection:
466
 
        toggleShowPackage();
467
 
        break;
468
 
 
469
 
    case ListPopupMenu::mt_Show_Stereotypes:
470
 
    case ListPopupMenu::mt_Show_Stereotypes_Selection:
471
 
        toggleShowStereotype();
472
 
        break;
473
 
 
474
 
    case ListPopupMenu::mt_DrawAsCircle:
475
 
    case ListPopupMenu::mt_DrawAsCircle_Selection:
476
 
        toggleDrawAsCircle();
477
 
        break;
478
 
 
479
 
    case ListPopupMenu::mt_ChangeToClass:
480
 
    case ListPopupMenu::mt_ChangeToClass_Selection:
481
 
        changeToClass();
482
 
        break;
483
 
 
484
 
    case ListPopupMenu::mt_ChangeToInterface:
485
 
    case ListPopupMenu::mt_ChangeToInterface_Selection:
486
 
        changeToInterface();
487
 
        break;
488
 
 
489
 
    default:
490
 
        UMLWidget::slotMenuSelection(action);
491
 
        break;
492
 
    }
493
 
}
494
 
 
 
480
/**
 
481
 * Calculcates the size of the templates box in the top left
 
482
 * if it exists, returns QSize(0,0) if it doesn't.
 
483
 *
 
484
 * @return  QSize of the templates flap.
 
485
 */
495
486
QSize ClassifierWidget::calculateTemplatesBoxSize()
496
487
{
497
488
    UMLTemplateList list = classifier()->getTemplateList();
521
512
    return QSize(width, height);
522
513
}
523
514
 
 
515
/**
 
516
 * Return the number of displayed attributes.
 
517
 */
524
518
int ClassifierWidget::displayedAttributes()
525
519
{
526
 
    if (!m_showAttributes)
 
520
    if (!visualProperty(ShowAttributes))
527
521
        return 0;
528
522
    return displayedMembers(UMLObject::ot_Attribute);
529
523
}
530
524
 
531
 
void ClassifierWidget::setClassAssocWidget(AssociationWidget *assocwidget)
 
525
/**
 
526
 * Return the number of displayed operations.
 
527
 */
 
528
int ClassifierWidget::displayedOperations()
 
529
{
 
530
    if (!visualProperty(ShowOperations))
 
531
        return 0;
 
532
    return displayedMembers(UMLObject::ot_Operation);
 
533
}
 
534
 
 
535
/**
 
536
 * Set the AssociationWidget when this ClassWidget acts as
 
537
 * an association class.
 
538
 */
 
539
void ClassifierWidget::setClassAssociationWidget(AssociationWidget *assocwidget)
532
540
{
533
541
    m_pAssocWidget = assocwidget;
534
542
    UMLAssociation *umlassoc = NULL;
535
543
    if (assocwidget)
536
 
        umlassoc = assocwidget->getAssociation();
 
544
        umlassoc = assocwidget->association();
537
545
    classifier()->setClassAssoc(umlassoc);
538
546
}
539
547
 
540
 
AssociationWidget *ClassifierWidget::getClassAssocWidget()
 
548
/**
 
549
 * Return the AssociationWidget when this classifier acts as
 
550
 * an association class (else return NULL.)
 
551
 */
 
552
AssociationWidget *ClassifierWidget::classAssociationWidget() const
541
553
{
542
554
    return m_pAssocWidget;
543
555
}
544
556
 
545
 
UMLClassifier *ClassifierWidget::classifier()
546
 
{
547
 
    return static_cast<UMLClassifier*>(m_pObject);
548
 
}
549
 
 
 
557
/**
 
558
 * Overrides standard method.
 
559
 * Auxiliary to reimplementations in the derived classes.
 
560
 */
550
561
void ClassifierWidget::paint(QPainter & p, int offsetX, int offsetY)
551
562
{
552
563
    setPenFromSettings(p);
553
564
    if ( UMLWidget::useFillColor() )
554
565
        p.setBrush( UMLWidget::fillColor() );
555
566
    else
556
 
        p.setBrush( m_scene->viewport()->palette().color(QPalette::Background) );
 
567
        p.setBrush( m_scene->view()->viewport()->palette().color(QPalette::Background) );
557
568
 
558
 
    if (classifier()->isInterface() && m_drawAsCircle) {
 
569
    if (classifier()->isInterface() && visualProperty(DrawAsCircle)) {
559
570
        drawAsCircle(p, offsetX, offsetY);
560
571
        return;
561
572
    }
562
573
 
563
574
    // Draw the bounding rectangle
564
575
    QSize templatesBoxSize = calculateTemplatesBoxSize();
565
 
    m_bodyOffsetY = offsetY;
 
576
    int m_bodyOffsetY = offsetY;
566
577
    if (templatesBoxSize.height() > 0)
567
578
        m_bodyOffsetY += templatesBoxSize.height() - MARGIN;
568
579
    int w = width();
588
599
        p.setPen(pen);
589
600
        p.drawRect( offsetX + width() - templatesBoxSize.width(), offsetY,
590
601
                    templatesBoxSize.width(), templatesBoxSize.height() );
591
 
        p.setPen( QPen(Qt::black) );
 
602
        p.setPen( QPen(textColor()));
592
603
        font.setBold(false);
593
604
        p.setFont(font);
594
605
        const int x = offsetX + width() - templatesBoxSize.width() + MARGIN;
603
614
    const int textX = offsetX + MARGIN;
604
615
    const int textWidth = w - MARGIN * 2;
605
616
 
606
 
    p.setPen(QPen(Qt::black));
 
617
    p.setPen(QPen(textColor()));
607
618
 
608
619
    // draw stereotype
609
620
    font.setBold(true);
610
621
    QString stereo = m_pObject->stereotype();
611
622
    /* if no stereotype is given we don't want to show the empty << >> */
612
623
    const bool showStereotype = (m_showStereotype && !stereo.isEmpty());
613
 
    const bool showNameOnly = (!m_showOperations && !m_showAttributes && !showStereotype);
 
624
    const bool showNameOnly = (!visualProperty(ShowOperations) &&
 
625
                               !visualProperty(ShowAttributes) &&
 
626
                               !visualProperty(ShowStereotype));
614
627
    int nameHeight = fontHeight;
615
628
    if (showNameOnly) {
616
629
        nameHeight = h;
623
636
 
624
637
    // draw name
625
638
    QString name;
626
 
    if (m_showPackage) {
 
639
    if (visualProperty(ShowPackage)) {
627
640
        name = m_pObject->fullyQualifiedName();
628
641
    } else {
629
642
        name = this->name();
635
648
        m_bodyOffsetY += fontHeight;
636
649
        setPenFromSettings(p);
637
650
        p.drawLine(offsetX, m_bodyOffsetY, offsetX + w - 1, m_bodyOffsetY);
638
 
        p.setPen(QPen(Qt::black));
 
651
        p.setPen(textColor());
639
652
    }
640
653
    font.setBold(false);
641
654
    font.setItalic(false);
643
656
 
644
657
    // draw attributes
645
658
    const int numAtts = displayedAttributes();
646
 
    if (m_showAttributes) {
647
 
        drawMembers(p, UMLObject::ot_Attribute, m_ShowAttSigs, textX,
 
659
    if (visualProperty(ShowAttributes)) {
 
660
        drawMembers(p, UMLObject::ot_Attribute, m_attributeSignature, textX,
648
661
                    m_bodyOffsetY, fontHeight);
649
662
    }
650
663
 
656
669
            m_bodyOffsetY += fontHeight * numAtts;
657
670
        setPenFromSettings(p);
658
671
        p.drawLine(offsetX, m_bodyOffsetY, offsetX + w - 1, m_bodyOffsetY);
659
 
        p.setPen(QPen(Qt::black));
 
672
        p.setPen(QPen(textColor()));
660
673
    }
661
674
 
662
675
    // draw operations
663
 
    if (m_showOperations) {
664
 
        drawMembers(p, UMLObject::ot_Operation, m_ShowOpSigs, textX,
 
676
    if (visualProperty(ShowOperations)) {
 
677
        drawMembers(p, UMLObject::ot_Operation, m_operationSignature, textX,
665
678
                    m_bodyOffsetY, fontHeight);
666
679
    }
667
680
 
669
682
        UMLWidget::drawSelected(&p, offsetX, offsetY);
670
683
}
671
684
 
 
685
/**
 
686
 * Draws the interface as a circle with name underneath.
 
687
 * Only applies when m_pObject->getBaseType() is ot_Interface.
 
688
 */
672
689
void ClassifierWidget::drawAsCircle(QPainter& p, int offsetX, int offsetY)
673
690
{
674
691
    int w = width();
676
693
    const QFontMetrics &fm = getFontMetrics(FT_NORMAL);
677
694
    const int fontHeight  = fm.lineSpacing();
678
695
    QString name;
679
 
    if ( m_showPackage ) {
 
696
    if (visualProperty(ShowPackage)) {
680
697
        name = m_pObject->fullyQualifiedName();
681
698
    } else {
682
699
        name = this->name();
683
700
    }
684
701
 
685
702
    p.drawEllipse(offsetX + w/2 - CIRCLE_SIZE/2, offsetY, CIRCLE_SIZE, CIRCLE_SIZE);
686
 
    p.setPen( QPen(Qt::black) );
 
703
    p.setPen( QPen(textColor()));
687
704
 
688
705
    QFont font = UMLWidget::font();
689
706
    p.setFont(font);
694
711
    }
695
712
}
696
713
 
 
714
/**
 
715
 * Calculates the size of the object when drawn as a circle.
 
716
 * Only applies when m_pObject->getBaseType() is ot_Interface.
 
717
 */
697
718
QSize ClassifierWidget::calculateAsCircleSize()
698
719
{
699
720
    const QFontMetrics &fm = UMLWidget::getFontMetrics(UMLWidget::FT_ITALIC_UNDERLINE);
703
724
 
704
725
    int width = CIRCLE_SIZE;
705
726
    QString displayedName;
706
 
    if (m_showPackage) {
 
727
    if (visualProperty(ShowPackage)) {
707
728
        displayedName = m_pObject->fullyQualifiedName();
708
729
    } else {
709
730
        displayedName = m_pObject->name();
716
737
    return QSize(width, height);
717
738
}
718
739
 
 
740
/**
 
741
 * Auxiliary method for draw() of child classes:
 
742
 * Draw the attributes or operations.
 
743
 *
 
744
 * @param p          QPainter to paint to.
 
745
 * @param ot         Object type to draw, either ot_Attribute or ot_Operation.
 
746
 * @param sigType    Governs details of the member display.
 
747
 * @param x          X coordinate at which to draw the texts.
 
748
 * @param y          Y coordinate at which text drawing commences.
 
749
 * @param fontHeight The font height.
 
750
 */
719
751
void ClassifierWidget::drawMembers(QPainter & p, UMLObject::ObjectType ot, Uml::SignatureType sigType,
720
752
                                   int x, int y, int fontHeight)
721
753
{
723
755
    f.setBold(false);
724
756
    UMLClassifierListItemList list = classifier()->getFilteredList(ot);
725
757
    foreach (UMLClassifierListItem *obj , list ) {
726
 
          if (m_showPublicOnly && obj->visibility() != Uml::Visibility::Public)
 
758
          if (visualProperty(ShowPublicOnly) && obj->visibility() != Uml::Visibility::Public)
727
759
            continue;
728
760
        QString text = obj->toString(sigType);
729
761
        f.setItalic( obj->isAbstract() );
738
770
    }
739
771
}
740
772
 
 
773
/**
 
774
 * Sets whether to draw as circle.
 
775
 * Only applies when m_pObject->getBaseType() is ot_Interface.
 
776
 *
 
777
 * @param drawAsCircle   True if widget shall be drawn as circle.
 
778
 */
741
779
void ClassifierWidget::setDrawAsCircle(bool drawAsCircle)
742
780
{
743
 
    m_drawAsCircle = drawAsCircle;
 
781
    setVisualProperty(DrawAsCircle, drawAsCircle);
744
782
    updateComponentSize();
745
783
    update();
746
784
}
747
785
 
 
786
/**
 
787
 * Returns whether to draw as circle.
 
788
 * Only applies when m_pObject->getBaseType() is ot_Interface.
 
789
 *
 
790
 * @return   True if widget is drawn as circle.
 
791
 */
748
792
bool ClassifierWidget::getDrawAsCircle() const
749
793
{
750
 
    return m_drawAsCircle;
 
794
    return visualProperty(DrawAsCircle);
751
795
}
752
796
 
 
797
/**
 
798
 * Toggles whether to draw as circle.
 
799
 * Only applies when m_pObject->getBaseType() is ot_Interface.
 
800
 */
753
801
void ClassifierWidget::toggleDrawAsCircle()
754
802
{
755
 
    m_drawAsCircle = !m_drawAsCircle;
756
 
    updateSigs();
 
803
    toggleVisualProperty(DrawAsCircle);
 
804
    updateSignatureTypes();
757
805
    updateComponentSize();
758
806
    update();
759
807
}
760
808
 
 
809
/**
 
810
 * Changes this classifier from an interface to a class.
 
811
 * Attributes and stereotype visibility is got from the view OptionState.
 
812
 * This widget is also updated.
 
813
 */
761
814
void ClassifierWidget::changeToClass()
762
815
{
763
 
    WidgetBase::setBaseType(WidgetBase::wt_Class);
 
816
    m_baseType = WidgetBase::wt_Class;
764
817
    classifier()->setBaseType(UMLObject::ot_Class);
765
818
 
766
819
    const Settings::OptionState& ops = m_scene->optionState();
767
 
    m_showAttributes = ops.classState.showAtts;
768
 
    m_showStereotype = ops.classState.showStereoType;
 
820
    setVisualProperty(ShowAttributes, ops.classState.showAtts);
 
821
    setVisualProperty(ShowStereotype, ops.classState.showStereoType);
769
822
 
770
823
    updateComponentSize();
771
824
    update();
772
825
}
773
826
 
 
827
/**
 
828
 * Changes this classifier from a class to an interface.
 
829
 * Attributes are hidden and stereotype is shown.
 
830
 * This widget is also updated.
 
831
 */
774
832
void ClassifierWidget::changeToInterface()
775
833
{
776
 
    WidgetBase::setBaseType(WidgetBase::wt_Interface);
 
834
    m_baseType = WidgetBase::wt_Interface;
777
835
    classifier()->setBaseType(UMLObject::ot_Interface);
778
836
 
779
 
    m_showAttributes = false;
780
 
    m_showStereotype = true;
 
837
    setVisualProperty(ShowAttributes, false);
 
838
    setVisualProperty(ShowStereotype, true);
781
839
 
782
840
    updateComponentSize();
783
841
    update();
784
842
}
785
843
 
786
 
void ClassifierWidget::adjustAssocs(int x, int y)
 
844
/**
 
845
 * Extends base method to adjust also the association of a class
 
846
 * association.
 
847
 * Executes the base method and then, if file isn't loading and the
 
848
 * classifier acts as a class association, the association position is
 
849
 * updated.
 
850
 *
 
851
 * @param x The x-coordinate.
 
852
 * @param y The y-coordinate.
 
853
 */
 
854
void ClassifierWidget::adjustAssociations(int x, int y)
787
855
{
788
856
    UMLWidget::adjustAssocs(x, y);
789
857
 
794
862
    m_pAssocWidget->computeAssocClassLine();
795
863
}
796
864
 
797
 
void ClassifierWidget::saveToXMI(QDomDocument & qDoc, QDomElement & qElement)
798
 
{
799
 
    QDomElement conceptElement;
800
 
    UMLClassifier *umlc = classifier();
801
 
    if (umlc->isInterface())
802
 
        conceptElement = qDoc.createElement("interfacewidget");
803
 
    else
804
 
        conceptElement = qDoc.createElement("classwidget");
805
 
    UMLWidget::saveToXMI( qDoc, conceptElement );
806
 
    conceptElement.setAttribute( "showoperations", m_showOperations );
807
 
    conceptElement.setAttribute( "showpubliconly", m_showPublicOnly );
808
 
    conceptElement.setAttribute( "showopsigs", m_ShowOpSigs );
809
 
    conceptElement.setAttribute( "showpackage", m_showPackage );
810
 
    conceptElement.setAttribute( "showscope", m_showAccess );
811
 
    if (! umlc->isInterface()) {
812
 
        conceptElement.setAttribute("showattributes", m_showAttributes);
813
 
        conceptElement.setAttribute("showattsigs", m_ShowAttSigs);
814
 
    }
815
 
    if (umlc->isInterface() || umlc->isAbstract())
816
 
        conceptElement.setAttribute("drawascircle", m_drawAsCircle);
817
 
    qElement.appendChild( conceptElement );
818
 
}
819
 
 
 
865
/**
 
866
 * Loads the "classwidget" or "interfacewidget" XML element.
 
867
 */
820
868
bool ClassifierWidget::loadFromXMI(QDomElement & qElement)
821
869
{
822
 
    if (!UMLWidget::loadFromXMI(qElement))
 
870
    if (!UMLWidget::loadFromXMI(qElement)) {
823
871
        return false;
 
872
    }
 
873
 
824
874
    QString showatts = qElement.attribute( "showattributes", "0" );
825
875
    QString showops = qElement.attribute( "showoperations", "1" );
826
876
    QString showpubliconly = qElement.attribute( "showpubliconly", "0" );
830
880
    QString showscope = qElement.attribute( "showscope", "0" );
831
881
    QString drawascircle = qElement.attribute("drawascircle", "0");
832
882
 
833
 
    m_showAttributes = (bool)showatts.toInt();
834
 
    m_showOperations = (bool)showops.toInt();
835
 
    m_showPublicOnly = (bool)showpubliconly.toInt();
836
 
    m_ShowAttSigs = Uml::SignatureType::Value(showattsigs.toInt());
837
 
    m_ShowOpSigs = Uml::SignatureType::Value(showopsigs.toInt());
838
 
    m_showPackage = (bool)showpackage.toInt();
839
 
    m_showAccess = (bool)showscope.toInt();
840
 
    m_drawAsCircle = (bool)drawascircle.toInt();
 
883
    setVisualProperty(ShowAttributes, (bool)showatts.toInt());
 
884
    setVisualProperty(ShowOperations, (bool)showops.toInt());
 
885
    setVisualProperty(ShowPublicOnly, (bool)showpubliconly.toInt());
 
886
    setVisualProperty(ShowPackage,    (bool)showpackage.toInt());
 
887
    setVisualProperty(ShowVisibility, (bool)showscope.toInt());
 
888
    setVisualProperty(DrawAsCircle,   (bool)drawascircle.toInt());
 
889
 
 
890
    m_attributeSignature = Uml::SignatureType::Value(showattsigs.toInt());
 
891
    m_operationSignature = Uml::SignatureType::Value(showopsigs.toInt());
841
892
 
842
893
    return true;
843
894
}
844
895
 
 
896
/**
 
897
 * Creates the "classwidget" or "interfacewidget" XML element.
 
898
 */
 
899
void ClassifierWidget::saveToXMI(QDomDocument & qDoc, QDomElement & qElement)
 
900
{
 
901
    QDomElement conceptElement;
 
902
    UMLClassifier *umlc = classifier();
 
903
    if (umlc->isInterface())
 
904
        conceptElement = qDoc.createElement("interfacewidget");
 
905
    else
 
906
        conceptElement = qDoc.createElement("classwidget");
 
907
    UMLWidget::saveToXMI( qDoc, conceptElement );
 
908
    conceptElement.setAttribute("showoperations", visualProperty(ShowOperations));
 
909
    conceptElement.setAttribute("showpubliconly", visualProperty(ShowPublicOnly));
 
910
    conceptElement.setAttribute("showopsigs",     m_operationSignature );
 
911
    conceptElement.setAttribute("showpackage",    visualProperty(ShowPackage));
 
912
    conceptElement.setAttribute("showscope",      visualProperty(ShowVisibility));
 
913
    if (! umlc->isInterface()) {
 
914
        conceptElement.setAttribute("showattributes", visualProperty(ShowAttributes));
 
915
        conceptElement.setAttribute("showattsigs",    m_attributeSignature);
 
916
    }
 
917
    if (umlc->isInterface() || umlc->isAbstract())
 
918
        conceptElement.setAttribute("drawascircle", visualProperty(DrawAsCircle));
 
919
    qElement.appendChild( conceptElement );
 
920
}
 
921
 
 
922
/**
 
923
 * Will be called when a menu selection has been made from the
 
924
 * popup menu.
 
925
 *
 
926
 * @param action   The action that has been selected.
 
927
 */
 
928
void ClassifierWidget::slotMenuSelection(QAction* action)
 
929
{
 
930
    ListPopupMenu::MenuType sel = m_pMenu->getMenuType(action);
 
931
    switch (sel) {
 
932
    case ListPopupMenu::mt_Attribute:
 
933
    case ListPopupMenu::mt_Operation:
 
934
    case ListPopupMenu::mt_Template:
 
935
        {
 
936
            UMLObject::ObjectType ot = ListPopupMenu::convert_MT_OT(sel);
 
937
            if (Object_Factory::createChildObject(classifier(), ot)) {
 
938
                updateComponentSize();
 
939
                update();
 
940
                UMLApp::app()->document()->setModified();
 
941
            }
 
942
            break;
 
943
        }
 
944
    case ListPopupMenu::mt_Show_Operations:
 
945
    case ListPopupMenu::mt_Show_Operations_Selection:
 
946
        toggleVisualProperty(ShowOperations);
 
947
        break;
 
948
 
 
949
    case ListPopupMenu::mt_Show_Attributes:
 
950
    case ListPopupMenu::mt_Show_Attributes_Selection:
 
951
        toggleVisualProperty(ShowAttributes);
 
952
        break;
 
953
 
 
954
    case ListPopupMenu::mt_Show_Public_Only:
 
955
    case ListPopupMenu::mt_Show_Public_Only_Selection:
 
956
        toggleVisualProperty(ShowPublicOnly);
 
957
        break;
 
958
 
 
959
    case ListPopupMenu::mt_Show_Operation_Signature:
 
960
    case ListPopupMenu::mt_Show_Operation_Signature_Selection:
 
961
        toggleVisualProperty(ShowOperationSignature);
 
962
        break;
 
963
 
 
964
    case ListPopupMenu::mt_Show_Attribute_Signature:
 
965
    case ListPopupMenu::mt_Show_Attribute_Signature_Selection:
 
966
        toggleVisualProperty(ShowAttributeSignature);
 
967
        break;
 
968
 
 
969
    case ListPopupMenu::mt_Visibility:
 
970
    case ListPopupMenu::mt_Visibility_Selection:
 
971
        toggleVisualProperty(ShowVisibility);
 
972
        break;
 
973
 
 
974
    case ListPopupMenu::mt_Show_Packages:
 
975
    case ListPopupMenu::mt_Show_Packages_Selection:
 
976
        toggleVisualProperty(ShowPackage);
 
977
        break;
 
978
 
 
979
    case ListPopupMenu::mt_Show_Stereotypes:
 
980
    case ListPopupMenu::mt_Show_Stereotypes_Selection:
 
981
        toggleVisualProperty(ShowStereotype);
 
982
        break;
 
983
 
 
984
    case ListPopupMenu::mt_DrawAsCircle:
 
985
    case ListPopupMenu::mt_DrawAsCircle_Selection:
 
986
        toggleVisualProperty(DrawAsCircle);
 
987
        break;
 
988
 
 
989
    case ListPopupMenu::mt_ChangeToClass:
 
990
    case ListPopupMenu::mt_ChangeToClass_Selection:
 
991
        changeToClass();
 
992
        break;
 
993
 
 
994
    case ListPopupMenu::mt_ChangeToInterface:
 
995
    case ListPopupMenu::mt_ChangeToInterface_Selection:
 
996
        changeToInterface();
 
997
        break;
 
998
 
 
999
    default:
 
1000
        UMLWidget::slotMenuSelection(action);
 
1001
        break;
 
1002
    }
 
1003
}
 
1004
 
 
1005
/**
 
1006
 * Slot to show/hide attributes based on \a state.
 
1007
 */
 
1008
void ClassifierWidget::slotShowAttributes(bool state)
 
1009
{
 
1010
    setVisualProperty(ShowAttributes, state);
 
1011
}
 
1012
 
 
1013
/**
 
1014
 * Slot to show/hide operations based on \a state.
 
1015
 */
 
1016
void ClassifierWidget::slotShowOperations(bool state)
 
1017
{
 
1018
    setVisualProperty(ShowOperations, state);
 
1019
}
 
1020