1 /* 2 SPDX-License-Identifier: GPL-2.0-or-later 3 SPDX-FileCopyrightText: 2004-2021 Umbrello UML Modeller Authors <umbrello-devel@kde.org> 4 */ 5 6 #ifndef CLASSIFIERWIDGET_H 7 #define CLASSIFIERWIDGET_H 8 9 #include "basictypes.h" 10 #include "umlobject.h" 11 #include "umlwidget.h" 12 13 class AssociationWidget; 14 class FloatingTextWidget; 15 class QPainter; 16 class UMLClassifier; 17 18 /** 19 * @short Common implementation for class widget and interface widget 20 * 21 * @author Oliver Kellogg 22 * @author Gopala Krishna 23 * 24 * @see UMLWidget 25 * Bugs and comments to umbrello-devel@kde.org or https://bugs.kde.org 26 */ 27 class ClassifierWidget : public UMLWidget 28 { 29 Q_OBJECT 30 Q_ENUMS(VisualProperty) 31 public: 32 /** 33 * This enumeration lists the visual properties that can be easily 34 * set, reset and toggled and all these operate on an integer 35 * which stores all the flag status. 36 */ 37 enum VisualProperty { 38 ShowStereotype = 0x1, // DEPRECATED - see umlwidgets/widgetbase.cpp 39 // WidgetBase::slotMenuSelection(QAction*) 40 // case ListPopupMenu::mt_{Show,Hide}_Stereotypes_Selection 41 ShowOperations = 0x2, 42 ShowPublicOnly = 0x4, 43 ShowVisibility = 0x8, 44 ShowPackage = 0x10, 45 ShowAttributes = 0x20, 46 DrawAsCircle = 0x40, 47 ShowOperationSignature = 0x60, ///< only in setter 48 ShowAttributeSignature = 0x80, ///< only in setter 49 DrawAsPackage = 0x100, 50 ShowDocumentation = 0x200, 51 }; 52 53 Q_DECLARE_FLAGS(VisualProperties, VisualProperty) 54 55 ClassifierWidget(UMLScene * scene, UMLClassifier * umlc); 56 ClassifierWidget(UMLScene * scene, UMLInstance * umli); 57 ClassifierWidget(UMLScene * scene, UMLPackage * o); 58 virtual ~ClassifierWidget(); 59 60 UMLClassifier *classifier() const; 61 62 void setShowStereotype(Uml::ShowStereoType::Enum flag); 63 64 VisualProperties visualProperties() const; 65 void setVisualProperties(VisualProperties properties); 66 67 bool visualProperty(VisualProperty property) const; 68 void setVisualProperty(VisualProperty property, bool enable = true); 69 void setVisualPropertyCmd(VisualProperty property, bool enable = true); 70 void toggleVisualProperty(VisualProperty property); 71 72 int displayedAttributes() const; 73 int displayedOperations() const; 74 75 Uml::SignatureType::Enum attributeSignature() const; 76 void setAttributeSignature(Uml::SignatureType::Enum sig); 77 78 Uml::SignatureType::Enum operationSignature() const; 79 void setOperationSignature(Uml::SignatureType::Enum sig); 80 81 void setShowAttSigs(bool _show); 82 void toggleShowAttSigs(); 83 84 bool getDrawAsCircle() const; 85 void setDrawAsCircle(bool drawAsCircle); 86 void toggleDrawAsCircle(); 87 88 void changeToClass(); 89 void changeToInterface(); 90 void changeToPackage(); 91 92 AssociationWidget *classAssociationWidget() const; 93 void setClassAssociationWidget(AssociationWidget *assocwidget); 94 95 UMLWidget* onWidget(const QPointF& p); 96 UMLWidget* widgetWithID(Uml::ID::Type id); 97 98 virtual void setDocumentation(const QString& doc); 99 100 QSizeF calculateSize(bool withExtensions = true) const; 101 102 virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); 103 virtual QPainterPath shape() const; 104 105 virtual void saveToXMI1(QXmlStreamWriter& writer); 106 virtual bool loadFromXMI1(QDomElement & qElement); 107 108 virtual bool showPropertiesDialog(); 109 void setUMLObject(UMLObject *obj); 110 111 public Q_SLOTS: 112 virtual void slotMenuSelection(QAction* action); 113 114 private Q_SLOTS: 115 void slotShowAttributes(bool state); 116 void slotShowOperations(bool state); 117 118 protected: 119 virtual void mouseDoubleClickEvent(QGraphicsSceneMouseEvent *event); 120 121 private: 122 void updateSignatureTypes(); 123 QSize calculateTemplatesBoxSize() const; 124 125 QSizeF minimumSize() const; 126 127 void drawAsCircle(QPainter *p, const QStyleOptionGraphicsItem *option); 128 QSize calculateAsCircleSize() const; 129 130 void drawAsPackage(QPainter *painter, const QStyleOptionGraphicsItem *option); 131 QSize calculateAsPackageSize() const; 132 133 int displayedMembers(UMLObject::ObjectType ot) const; 134 void drawMembers(QPainter *painter, UMLObject::ObjectType ot, Uml::SignatureType::Enum sigType, 135 int x, int y, int textWidth, int fontHeight); 136 137 static const int CIRCLE_SIZE; ///< size of circle when interface is rendered as such 138 static const int SOCKET_INCREMENT; ///< augmentation of circle for socket (required interface) 139 140 VisualProperties m_visualProperties; 141 Uml::SignatureType::Enum m_attributeSignature; ///< Loaded/saved item. 142 Uml::SignatureType::Enum m_operationSignature; ///< Loaded/saved item. 143 AssociationWidget *m_pAssocWidget; ///< related AssociationWidget in case this classifier acts as an association class 144 QPointer<FloatingTextWidget> m_pInterfaceName; ///< Separate widget for name in case of interface drawn as circle 145 146 }; 147 148 Q_DECLARE_OPERATORS_FOR_FLAGS(ClassifierWidget::VisualProperties) 149 150 #endif 151