4
4
* the Free Software Foundation; either version 2 of the License, or *
5
5
* (at your option) any later version. *
7
* copyright (C) 2004-2011 *
7
* copyright (C) 2004-2012 *
8
8
* Umbrello UML Modeller Authors <uml-devel@uml.sf.net> *
9
9
***************************************************************************/
12
12
#include "classifierwidget.h"
14
#include <QtGui/QPainter>
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"
21
24
#include "umlview.h"
24
#include "listpopupmenu.h"
25
#include "object_factory.h"
27
ClassifierWidget::ClassifierWidget(UMLScene * scene, UMLClassifier *c)
28
: UMLWidget(scene, WidgetBase::wt_Class, c)
31
if (c != NULL && c->isInterface()) {
32
setBaseType(WidgetBase::wt_Interface);
33
m_showStereotype = true;
34
m_showAttributes = false;
39
ClassifierWidget::~ClassifierWidget()
42
m_pAssocWidget->removeAssocClassLine();
27
#include <QtGui/QPainter>
45
29
const int ClassifierWidget::MARGIN = 5;
46
30
const int ClassifierWidget::CIRCLE_SIZE = 30;
48
void ClassifierWidget::init()
33
* Constructs a ClassifierWidget.
35
* @param scene The parent of this ClassifierWidget.
36
* @param o The UMLObject to represent.
38
ClassifierWidget::ClassifierWidget(UMLScene * scene, UMLClassifier *c)
39
: UMLWidget(scene, WidgetBase::wt_Class, c),
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;
49
setVisualProperty(ShowOperationSignature, ops.classState.showOpSig);
57
50
Cannot do that because we get "pure virtual method called". Open code:
59
52
if( !ops.classState.showOpSig ) {
61
m_ShowOpSigs = Uml::SignatureType::NoSig;
53
if (visualProperty(ShowVisibility))
54
m_operationSignature = Uml::SignatureType::NoSig;
63
m_ShowOpSigs = Uml::SignatureType::NoSigNoVis;
56
m_operationSignature = Uml::SignatureType::NoSigNoVis;
65
} else if (m_showAccess)
66
m_ShowOpSigs = Uml::SignatureType::ShowSig;
58
} else if (visualProperty(ShowVisibility))
59
m_operationSignature = Uml::SignatureType::ShowSig;
68
m_ShowOpSigs = Uml::SignatureType::SigNoVis;
61
m_operationSignature = Uml::SignatureType::SigNoVis;
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);
75
67
setShowAttSigs( ops.classState.showAttSig );
78
void ClassifierWidget::updateSigs()
69
if (c && c->isInterface()) {
70
m_baseType = WidgetBase::wt_Interface;
71
m_visualProperties = ShowOperations | ShowVisibility | ShowStereotype;
72
setShowStereotype(true);
73
updateSignatureTypes();
76
DEBUG_REGISTER(DBG_SRC);
82
ClassifierWidget::~ClassifierWidget()
85
m_pAssocWidget->removeAssocClassLine();
89
* Return the UMLClassifier which this ClassifierWidget
92
UMLClassifier *ClassifierWidget::classifier() const
94
return static_cast<UMLClassifier*>(m_pObject);
98
* @return the visual properties
100
ClassifierWidget::VisualProperties ClassifierWidget::visualProperties() const
102
return m_visualProperties;
106
* Set an OR combination of properties stored in \a properties on this
109
void ClassifierWidget::setVisualProperties(VisualProperties properties)
111
// Don't do anything if the argument is equal to current status.
112
if (quint32(m_visualProperties) == quint32(properties)) {
116
m_visualProperties = properties;
117
updateSignatureTypes();
121
* @return The status of the property passed in.
123
* @note Use @ref attributeSignatureType() and @ref
124
* operationSignatureType() to get signature status. This
125
* method only indicates whether signature is visible or not.
127
bool ClassifierWidget::visualProperty(VisualProperty property) const
129
if (property == ShowAttributeSignature) {
130
return (m_attributeSignature == Uml::SignatureType::ShowSig
131
|| m_attributeSignature == Uml::SignatureType::SigNoVis);
134
else if(property == ShowOperationSignature) {
135
return (m_operationSignature == Uml::SignatureType::ShowSig
136
|| m_operationSignature == Uml::SignatureType::SigNoVis);
139
return m_visualProperties.testFlag(property);
143
* A convenient method to set and reset individual VisualProperty
145
* @param property The property to be set/reset.
146
* @param enable True/false to set/reset. (default = true)
148
* @note This method handles ShowAttributeSignature and
149
* ShowOperationSignature specially.
151
void ClassifierWidget::setVisualProperty(VisualProperty property, bool enable)
153
// Handle ShowAttributeSignature and ShowOperationSignature
156
if (property == ShowAttributeSignature) {
158
m_attributeSignature = visualProperty(ShowVisibility) ?
159
Uml::SignatureType::NoSig : Uml::SignatureType::NoSigNoVis;
162
m_attributeSignature = visualProperty(ShowVisibility) ?
163
Uml::SignatureType::ShowSig : Uml::SignatureType::SigNoVis;
165
//:TODO: updateTextItemGroups();
166
updateSignatureTypes();
169
else if (property == ShowOperationSignature) {
171
m_operationSignature = visualProperty(ShowVisibility) ?
172
Uml::SignatureType::NoSig : Uml::SignatureType::NoSigNoVis;
175
m_operationSignature = visualProperty(ShowVisibility) ?
176
Uml::SignatureType::ShowSig : Uml::SignatureType::SigNoVis;
178
//:TODO: updateTextItemGroups();
179
updateSignatureTypes();
182
else if (property == ShowStereotype) {
183
// Now just update flag and use base method for actual work.
185
m_visualProperties |= property;
190
setShowStereotype(enable);
195
// Don't do anything if the flag status is same.
196
if (visualProperty(property) == enable) {
200
// Call setVisualProperties appropriately based on enbable.
202
setVisualProperties(visualProperties() | property);
205
setVisualProperties(visualProperties() & ~property);
211
* A convenient method to toggle individual VisualProperty of this
214
* @param property The property to be toggled.
216
* @note This method handles ShowAttributeSignature and
217
* ShowOperationSignature specially.
219
void ClassifierWidget::toggleVisualProperty(VisualProperty property)
222
if (property == ShowOperationSignature) {
223
oppositeStatus = !(m_operationSignature == Uml::SignatureType::ShowSig
224
|| m_operationSignature == Uml::SignatureType::SigNoVis);
226
else if (property == ShowAttributeSignature) {
227
oppositeStatus = !(m_attributeSignature == Uml::SignatureType::ShowSig
228
|| m_attributeSignature == Uml::SignatureType::SigNoVis);
231
oppositeStatus = !visualProperty(property);
234
DEBUG(DBG_SRC) << "VisualProperty: " << property << " to opposite status " << oppositeStatus;
235
setVisualProperty(property, oppositeStatus);
239
* Updates m_operationSignature to match m_showVisibility.
241
void ClassifierWidget::updateSignatureTypes()
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;
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;
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;
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;
105
updateComponentSize();
109
void ClassifierWidget::toggleShowStereotype()
111
m_showStereotype = !m_showStereotype;
113
updateComponentSize();
117
bool ClassifierWidget::getShowOps() const
119
return m_showOperations;
122
void ClassifierWidget::setShowOps(bool _show)
124
m_showOperations = _show;
126
updateComponentSize();
130
void ClassifierWidget::toggleShowOps()
132
m_showOperations = !m_showOperations;
134
updateComponentSize();
138
bool ClassifierWidget::getShowPublicOnly() const
140
return m_showPublicOnly;
143
void ClassifierWidget::setShowPublicOnly(bool _status)
145
m_showPublicOnly = _status;
146
updateComponentSize();
150
void ClassifierWidget::toggleShowPublicOnly()
152
m_showPublicOnly = !m_showPublicOnly;
153
updateComponentSize();
157
bool ClassifierWidget::getShowVisibility() const
162
void ClassifierWidget::setShowVisibility(bool _visibility)
164
m_showAccess = _visibility;
166
updateComponentSize();
170
void ClassifierWidget::toggleShowVisibility()
172
m_showAccess = !m_showAccess;
174
updateComponentSize();
178
Uml::SignatureType ClassifierWidget::operationSignatureType() const
183
void ClassifierWidget::setShowOpSigs(bool _status)
187
m_ShowOpSigs = Uml::SignatureType::NoSig;
189
m_ShowOpSigs = Uml::SignatureType::NoSigNoVis;
190
} else if (m_showAccess)
191
m_ShowOpSigs = Uml::SignatureType::ShowSig;
193
m_ShowOpSigs = Uml::SignatureType::SigNoVis;
194
updateComponentSize();
198
void ClassifierWidget::toggleShowOpSigs()
200
if (m_ShowOpSigs == Uml::SignatureType::ShowSig || m_ShowOpSigs == Uml::SignatureType::SigNoVis) {
202
m_ShowOpSigs = Uml::SignatureType::NoSig;
204
m_ShowOpSigs = Uml::SignatureType::NoSigNoVis;
206
} else if (m_showAccess) {
207
m_ShowOpSigs = Uml::SignatureType::ShowSig;
209
m_ShowOpSigs = Uml::SignatureType::SigNoVis;
211
updateComponentSize();
215
bool ClassifierWidget::getShowPackage() const
217
return m_showPackage;
220
void ClassifierWidget::setShowPackage(bool _status)
222
m_showPackage = _status;
223
updateComponentSize();
227
void ClassifierWidget::toggleShowPackage()
229
m_showPackage = !m_showPackage;
231
updateComponentSize();
235
void ClassifierWidget::setOpSignature(Uml::SignatureType sig)
239
updateComponentSize();
243
void ClassifierWidget::setShowAtts(bool _show)
245
m_showAttributes = _show;
248
updateComponentSize();
252
void ClassifierWidget::setAttSignature(Uml::SignatureType sig)
256
updateComponentSize();
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;
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;
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;
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;
270
updateComponentSize();
275
* Returns whether to show attribute signatures.
276
* Only applies when m_pObject->getBaseType() is ot_Class.
278
* @return Status of how attribute signatures are shown.
280
Uml::SignatureType ClassifierWidget::attributeSignature() const
282
return m_attributeSignature;
286
* Sets the type of signature to display for an attribute.
287
* Only applies when m_pObject->getBaseType() is ot_Class.
289
* @param sig Type of signature to display for an attribute.
291
void ClassifierWidget::setAttributeSignature(Uml::SignatureType sig)
293
m_attributeSignature = sig;
294
updateSignatureTypes();
295
updateComponentSize();
300
* @return The Uml::SignatureType value for the operations.
302
Uml::SignatureType ClassifierWidget::operationSignature() const
304
return m_operationSignature;
308
* Set the type of signature to display for an Operation
310
* @param sig Type of signature to display for an operation.
312
void ClassifierWidget::setOperationSignature(Uml::SignatureType sig)
314
m_operationSignature = sig;
315
updateSignatureTypes();
316
updateComponentSize();
321
* Sets whether to show attribute signature
322
* Only applies when m_pObject->getBaseType() is ot_Class.
324
* @param _show True if attribute signatures shall be shown.
260
326
void ClassifierWidget::setShowAttSigs(bool _status)
264
m_ShowAttSigs = Uml::SignatureType::NoSig;
329
if (visualProperty(ShowVisibility))
330
m_attributeSignature = Uml::SignatureType::NoSig;
266
m_ShowAttSigs = Uml::SignatureType::NoSigNoVis;
332
m_attributeSignature = Uml::SignatureType::NoSigNoVis;
268
else if (m_showAccess)
269
m_ShowAttSigs = Uml::SignatureType::ShowSig;
334
else if (visualProperty(ShowVisibility))
335
m_attributeSignature = Uml::SignatureType::ShowSig;
271
m_ShowAttSigs = Uml::SignatureType::SigNoVis;
337
m_attributeSignature = Uml::SignatureType::SigNoVis;
272
338
if (UMLApp::app()->document()->loading())
274
340
updateComponentSize();
278
void ClassifierWidget::toggleShowAtts()
280
m_showAttributes = !m_showAttributes;
282
updateComponentSize();
345
* Toggles whether to show attribute signatures.
346
* Only applies when m_pObject->getBaseType() is ot_Class.
286
348
void ClassifierWidget::toggleShowAttSigs()
288
if (m_ShowAttSigs == Uml::SignatureType::ShowSig ||
289
m_ShowAttSigs == Uml::SignatureType::SigNoVis) {
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;
293
m_ShowAttSigs = Uml::SignatureType::NoSigNoVis;
355
m_attributeSignature = Uml::SignatureType::NoSigNoVis;
295
} else if (m_showAccess) {
296
m_ShowAttSigs = Uml::SignatureType::ShowSig;
357
} else if (visualProperty(ShowVisibility)) {
358
m_attributeSignature = Uml::SignatureType::ShowSig;
298
m_ShowAttSigs = Uml::SignatureType::SigNoVis;
360
m_attributeSignature = Uml::SignatureType::SigNoVis;
300
362
updateComponentSize();
367
* Return the number of displayed members of the given ObjectType.
368
* Takes into consideration m_showPublicOnly but not other settings.
304
370
int ClassifierWidget::displayedMembers(UMLObject::ObjectType ot)
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))
315
int ClassifierWidget::displayedOperations()
317
if (!m_showOperations)
319
return displayedMembers(UMLObject::ot_Operation);
382
* Overrides method from UMLWidget.
322
384
UMLSceneSize ClassifierWidget::minimumSize()
324
386
if (!m_pObject) {
325
387
return UMLWidget::minimumSize();
327
if (classifier()->isInterface() && m_drawAsCircle) {
389
if (classifier()->isInterface() && visualProperty(DrawAsCircle)) {
328
390
return calculateAsCircleSize();
830
880
QString showscope = qElement.attribute( "showscope", "0" );
831
881
QString drawascircle = qElement.attribute("drawascircle", "0");
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());
890
m_attributeSignature = Uml::SignatureType::Value(showattsigs.toInt());
891
m_operationSignature = Uml::SignatureType::Value(showopsigs.toInt());
897
* Creates the "classwidget" or "interfacewidget" XML element.
899
void ClassifierWidget::saveToXMI(QDomDocument & qDoc, QDomElement & qElement)
901
QDomElement conceptElement;
902
UMLClassifier *umlc = classifier();
903
if (umlc->isInterface())
904
conceptElement = qDoc.createElement("interfacewidget");
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);
917
if (umlc->isInterface() || umlc->isAbstract())
918
conceptElement.setAttribute("drawascircle", visualProperty(DrawAsCircle));
919
qElement.appendChild( conceptElement );
923
* Will be called when a menu selection has been made from the
926
* @param action The action that has been selected.
928
void ClassifierWidget::slotMenuSelection(QAction* action)
930
ListPopupMenu::MenuType sel = m_pMenu->getMenuType(action);
932
case ListPopupMenu::mt_Attribute:
933
case ListPopupMenu::mt_Operation:
934
case ListPopupMenu::mt_Template:
936
UMLObject::ObjectType ot = ListPopupMenu::convert_MT_OT(sel);
937
if (Object_Factory::createChildObject(classifier(), ot)) {
938
updateComponentSize();
940
UMLApp::app()->document()->setModified();
944
case ListPopupMenu::mt_Show_Operations:
945
case ListPopupMenu::mt_Show_Operations_Selection:
946
toggleVisualProperty(ShowOperations);
949
case ListPopupMenu::mt_Show_Attributes:
950
case ListPopupMenu::mt_Show_Attributes_Selection:
951
toggleVisualProperty(ShowAttributes);
954
case ListPopupMenu::mt_Show_Public_Only:
955
case ListPopupMenu::mt_Show_Public_Only_Selection:
956
toggleVisualProperty(ShowPublicOnly);
959
case ListPopupMenu::mt_Show_Operation_Signature:
960
case ListPopupMenu::mt_Show_Operation_Signature_Selection:
961
toggleVisualProperty(ShowOperationSignature);
964
case ListPopupMenu::mt_Show_Attribute_Signature:
965
case ListPopupMenu::mt_Show_Attribute_Signature_Selection:
966
toggleVisualProperty(ShowAttributeSignature);
969
case ListPopupMenu::mt_Visibility:
970
case ListPopupMenu::mt_Visibility_Selection:
971
toggleVisualProperty(ShowVisibility);
974
case ListPopupMenu::mt_Show_Packages:
975
case ListPopupMenu::mt_Show_Packages_Selection:
976
toggleVisualProperty(ShowPackage);
979
case ListPopupMenu::mt_Show_Stereotypes:
980
case ListPopupMenu::mt_Show_Stereotypes_Selection:
981
toggleVisualProperty(ShowStereotype);
984
case ListPopupMenu::mt_DrawAsCircle:
985
case ListPopupMenu::mt_DrawAsCircle_Selection:
986
toggleVisualProperty(DrawAsCircle);
989
case ListPopupMenu::mt_ChangeToClass:
990
case ListPopupMenu::mt_ChangeToClass_Selection:
994
case ListPopupMenu::mt_ChangeToInterface:
995
case ListPopupMenu::mt_ChangeToInterface_Selection:
1000
UMLWidget::slotMenuSelection(action);
1006
* Slot to show/hide attributes based on \a state.
1008
void ClassifierWidget::slotShowAttributes(bool state)
1010
setVisualProperty(ShowAttributes, state);
1014
* Slot to show/hide operations based on \a state.
1016
void ClassifierWidget::slotShowOperations(bool state)
1018
setVisualProperty(ShowOperations, state);