umbrello  2.31.70
Umbrello UML Modeller is a Unified Modelling Language (UML) diagram program based on KDE Technology
widgetbase.h
Go to the documentation of this file.
1 /***************************************************************************
2  * This program is free software; you can redistribute it and/or modify *
3  * it under the terms of the GNU General Public License as published by *
4  * the Free Software Foundation; either version 2 of the License, or *
5  * (at your option) any later version. *
6  * *
7  * copyright (C) 2004-2020 *
8  * Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
9  ***************************************************************************/
10 
11 #ifndef WIDGETBASE_H
12 #define WIDGETBASE_H
13 
14 #include "basictypes.h"
15 #include "icon_utils.h"
16 
17 #include <QColor>
18 #include <QDomDocument>
19 #include <QFont>
20 #include <QGraphicsObject>
21 #include <QObject>
22 #include <QPainter>
23 #include <QPointer>
24 
25 // forward declarations
26 class QAction;
27 class ActivityWidget;
28 class ActorWidget;
29 class ArtifactWidget;
30 class AssociationWidget;
31 class BoxWidget;
32 class CategoryWidget;
33 class ClassifierWidget;
35 class ComponentWidget;
36 class DatatypeWidget;
37 class EntityWidget;
38 class EnumWidget;
40 class FloatingTextWidget;
41 class ForkJoinWidget;
42 class IDChangeLog;
43 class InterfaceWidget;
44 class MessageWidget;
45 class NodeWidget;
46 class NoteWidget;
47 class ObjectNodeWidget;
48 class ObjectWidget;
49 class PackageWidget;
50 class PinWidget;
51 class PortWidget;
52 class PinPortBase;
53 class PreconditionWidget;
54 class RegionWidget;
55 class SignalWidget;
56 class StateWidget;
57 //class TextWidget;
58 class UseCaseWidget;
59 class UMLDoc;
60 class UMLObject;
61 class UMLScene;
62 class UMLWidget; // required by function onWidget()
63 
90 class QGraphicsObjectWrapper: public QGraphicsObject
91 {
92 public:
93  virtual void setSelected(bool state);
94 protected:
96  QVariant itemChange(GraphicsItemChange change, const QVariant &value);
97 };
98 
105 {
106  Q_OBJECT
107  Q_ENUMS(WidgetType)
108 
109 public:
111  {
112  wt_Min = 299, // lower bounds check value
113  wt_UMLWidget, // does not have UMLObject representation
114  wt_Actor, // has UMLObject representation
115  wt_UseCase, // has UMLObject representation
116  wt_Class, // has UMLObject representation
117  wt_Interface, // has UMLObject representation
118  wt_Datatype, // has UMLObject representation
119  wt_Enum, // has UMLObject representation
120  wt_Entity, // has UMLObject representation
121  wt_Package, // has UMLObject representation
122  wt_Object, // has UMLObject representation
123  wt_Note, // does not have UMLObject representation
124  wt_Box, // does not have UMLObject representation
125  wt_Message, // does not have UMLObject representation
126  wt_Text, // does not have UMLObject representation
127  wt_State, // does not have UMLObject representation
128  wt_Activity, // does not have UMLObject representation
129  wt_Component, // has UMLObject representation
130  wt_Artifact, // has UMLObject representation
131  wt_Node, // has UMLObject representation
132  wt_Association, // has UMLObject representation
133  wt_ForkJoin, // does not have UMLObject representation
134  wt_Precondition, // does not have UMLObject representation
135  wt_CombinedFragment, // does not have UMLObject representation
136  wt_FloatingDashLine, // does not have UMLObject representation
137  wt_Signal, // does not have UMLObject representation
141  wt_Category, // has UMLObject representation
142  wt_Port, // has UMLObject representation
143  wt_Instance, // has UMLObject representation == wt_Object
144  wt_Max // upper bounds check value
145  };
146 
147  static QString toString(WidgetType wt);
148  static QString toI18nString(WidgetType wt);
149  static Icon_Utils::IconType toIcon(WidgetType wt);
150 
151  explicit WidgetBase(UMLScene * scene, WidgetType type= wt_UMLWidget, Uml::ID::Type id = Uml::ID::None);
152  virtual ~WidgetBase();
153 
154  UMLObject* umlObject() const;
155  virtual void setUMLObject(UMLObject *obj);
156 
157  Uml::ID::Type id() const;
158  void setID(Uml::ID::Type id);
159 
160  void setLocalID(Uml::ID::Type id);
161  Uml::ID::Type localID() const;
162 
163  virtual UMLWidget *widgetWithID(Uml::ID::Type id);
164 
165  WidgetType baseType() const;
166  void setBaseType(const WidgetType& baseType);
167  QLatin1String baseTypeStr() const;
168  QString baseTypeStrWithoutPrefix() const;
169 
170  virtual void setSelected(bool select);
171 
172  UMLScene* umlScene() const;
173  UMLDoc* umlDoc() const;
174 
175  QString documentation() const;
176  bool hasDocumentation();
177  virtual void setDocumentation(const QString& doc);
178 
179  QString name() const;
180  virtual void setName(const QString &strName);
181 
182  QColor lineColor() const;
183  virtual void setLineColor(const QColor& color);
184 
185  uint lineWidth() const;
186  virtual void setLineWidth(uint width);
187 
188  QColor textColor() const;
189  virtual void setTextColor(const QColor& color);
190 
191  QColor fillColor() const;
192  virtual void setFillColor(const QColor& color);
193 
194  bool usesDiagramLineColor() const;
195  void setUsesDiagramLineColor(bool state);
196 
197  bool usesDiagramLineWidth() const;
198  void setUsesDiagramLineWidth(bool state);
199 
200  bool useFillColor();
201  virtual void setUseFillColor(bool state);
202 
203  bool usesDiagramTextColor() const;
204  void setUsesDiagramTextColor(bool state);
205 
206  bool usesDiagramFillColor() const;
207  void setUsesDiagramFillColor(bool state);
208 
209  bool usesDiagramUseFillColor() const;
210  void setUsesDiagramUseFillColor(bool state);
211 
212  virtual QFont font() const;
213  virtual void setFont(const QFont& font);
214 
215  bool autoResize();
216  void setAutoResize(bool state);
217 
218  bool changesShape();
219  void setChangesShape(bool state);
220 
221  virtual bool showPropertiesDialog();
222 
223  virtual bool loadFromXMI1(QDomElement &qElement);
224  virtual void saveToXMI1(QDomDocument &qDoc, QDomElement &qElement);
225 
226  virtual void removeAssoc(AssociationWidget* pAssoc);
227  virtual void addAssoc(AssociationWidget* pAssoc);
228 
229  WidgetBase& operator=(const WidgetBase& other);
230 
231  QRectF rect() const;
232  void setRect(const QRectF& rect);
233  void setRect(qreal x, qreal y, qreal width, qreal height);
234 
235  virtual QRectF boundingRect() const;
236 
237  virtual UMLWidget* onWidget(const QPointF &p);
238 
239  virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
240 
241  bool isActivityWidget() { return baseType() == wt_Activity; }
242  bool isActorWidget() { return baseType() == wt_Actor; }
243  bool isArtifactWidget() { return baseType() == wt_Artifact; }
244  bool isAssociationWidget() { return baseType() == wt_Association; }
245  bool isBoxWidget() { return baseType() == wt_Box; }
246  bool isCategoryWidget() { return baseType() == wt_Category; }
247  bool isClassWidget() { return baseType() == wt_Class; }
248  bool isCombinedFragmentWidget() { return baseType() == wt_CombinedFragment; }
249  bool isComponentWidget() { return baseType() == wt_Component; }
250  bool isDatatypeWidget() { return baseType() == wt_Datatype; }
251  bool isEntityWidget() { return baseType() == wt_Entity; }
252  bool isEnumWidget() { return baseType() == wt_Enum; }
253  bool isFloatingDashLineWidget() { return baseType() == wt_FloatingDashLine; }
254  bool isForkJoinWidget() { return baseType() == wt_ForkJoin; }
255  bool isInterfaceWidget() { return baseType() == wt_Interface; }
256  bool isMessageWidget() { return baseType() == wt_Message; }
257  bool isNodeWidget() { return baseType() == wt_Node; }
258  bool isNoteWidget() { return baseType() == wt_Note; }
259  bool isObjectNodeWidget() { return baseType() == wt_ObjectNode; }
260  bool isObjectWidget() { return baseType() == wt_Object; }
261  bool isPackageWidget() { return baseType() == wt_Package; }
262  bool isPinWidget() { return baseType() == wt_Pin; }
263  bool isPortWidget() { return baseType() == wt_Port; }
264  bool isPreconditionWidget() { return baseType() == wt_Precondition; }
265  bool isRegionWidget() { return baseType() == wt_Region; }
266  bool isSignalWidget() { return baseType() == wt_Signal; }
267  bool isStateWidget() { return baseType() == wt_State; }
268  bool isTextWidget() { return baseType() == wt_Text; }
269  bool isUseCaseWidget() { return baseType() == wt_UseCase; }
270 
271  ActivityWidget* asActivityWidget();
272  ActorWidget* asActorWidget();
273  ArtifactWidget* asArtifactWidget();
274  AssociationWidget* asAssociationWidget();
275  BoxWidget* asBoxWidget();
276  CategoryWidget* asCategoryWidget();
277  ClassifierWidget* asClassifierWidget();
278  CombinedFragmentWidget* asCombinedFragmentWidget();
279  ComponentWidget* asComponentWidget();
280  DatatypeWidget* asDatatypeWidget();
281  EntityWidget* asEntityWidget();
282  EnumWidget* asEnumWidget();
283  FloatingDashLineWidget* asFloatingDashLineWidget();
284  ForkJoinWidget* asForkJoinWidget();
285  InterfaceWidget* asInterfaceWidget();
286  MessageWidget* asMessageWidget();
287  NodeWidget* asNodeWidget();
288  NoteWidget* asNoteWidget();
289  ObjectNodeWidget* asObjectNodeWidget();
290  ObjectWidget* asObjectWidget();
291  PackageWidget* asPackageWidget();
292  PinWidget* asPinWidget();
293  PinPortBase* asPinPortBase();
294  PortWidget* asPortWidget();
295  PreconditionWidget* asPreconditionWidget();
296  RegionWidget* asRegionWidget();
297  SignalWidget* asSignalWidget();
298  StateWidget* asStateWidget();
299  FloatingTextWidget* asFloatingTextWidget();
300 // TextWidget* asTextWidget();
301  UseCaseWidget* asUseCaseWidget();
302  UMLWidget* asUMLWidget();
303 
304  static bool widgetHasUMLObject(WidgetBase::WidgetType type);
305  virtual bool activate(IDChangeLog *changeLog = 0);
306 
307 public Q_SLOTS:
308  virtual void slotMenuSelection(QAction *trigger);
309 
310 protected:
311  virtual void contextMenuEvent(QGraphicsSceneContextMenuEvent *event);
312 
313 private:
315 protected:
317  QPointer<UMLObject> m_umlObject;
318  QString m_Doc;
319  QString m_Text;
320  QRectF m_rect;
321 
328 
333 
334  QColor m_textColor;
335  QColor m_lineColor;
336  QColor m_fillColor;
337  QBrush m_brush;
338  QFont m_font;
339  uint m_lineWidth;
341 
354 };
355 
356 #endif
Displays an instance of a Concept.
Definition: objectwidget.h:32
bool isClassWidget()
Definition: widgetbase.h:247
bool m_usesDiagramTextColor
Definition: widgetbase.h:350
A graphical version of a UML Activity.
Definition: objectnodewidget.h:28
bool isActorWidget()
Definition: widgetbase.h:242
bool m_usesDiagramLineWidth
Definition: widgetbase.h:349
Uml::ID::Type m_nLocalID
Definition: widgetbase.h:332
Definition: widgetbase.h:134
Definition: widgetbase.h:121
Definition: regionwidget.h:19
QColor m_textColor
Color of the text of the widget. Is saved to XMI.
Definition: widgetbase.h:334
A graphical version of a Node.
Definition: nodewidget.h:27
Displays a note box.
Definition: notewidget.h:30
Definition: widgetbase.h:132
A graphical version of a UML Precondition (new in UML 2.0).
Definition: preconditionwidget.h:32
Definition: widgetbase.h:118
Definition: widgetbase.h:114
Displays a fork/join plate in a state diagram.
Definition: forkjoinwidget.h:25
bool isFloatingDashLineWidget()
Definition: widgetbase.h:253
bool isComponentWidget()
Definition: widgetbase.h:249
Common base class for UMLWidget and AssociationWidget.
Definition: widgetbase.h:104
Definition: idchangelog.h:26
bool isStateWidget()
Definition: widgetbase.h:267
bool m_usesDiagramUseFillColor
Definition: widgetbase.h:351
uint m_lineWidth
Width of the lines of the widget. Is saved to XMI.
Definition: widgetbase.h:339
QFont m_font
Definition: widgetbase.h:338
bool isCategoryWidget()
Definition: widgetbase.h:246
Definition: signalwidget.h:27
Definition: widgetbase.h:141
Definition: widgetbase.h:127
Definition: widgetbase.h:143
bool isPortWidget()
Definition: widgetbase.h:263
WidgetType
Definition: widgetbase.h:110
QString m_Doc
Only used if m_umlObject is not set.
Definition: widgetbase.h:318
Definition: widgetbase.h:117
int x
Definition: cxx11-lambda-functions-and-expressions.h:4
WidgetType m_baseType
Type of widget.
Definition: widgetbase.h:314
bool isObjectNodeWidget()
Definition: widgetbase.h:259
Definition: widgetbase.h:129
Definition: widgetbase.h:135
Definition: widgetbase.h:90
A graphical version of a port on a component.
Definition: portwidget.h:27
Definition: widgetbase.h:133
The base class for UML objects.
Definition: umlobject.h:73
This class represents an association inside a diagram. Bugs and comments to umbrello-devel@kde.org or https://bugs.kde.org.
Definition: associationwidget.h:51
bool m_calledFromItemChange
Definition: widgetbase.h:95
bool isActivityWidget()
Definition: widgetbase.h:241
bool isEnumWidget()
Definition: widgetbase.h:252
bool isTextWidget()
Definition: widgetbase.h:268
bool m_usesDiagramFillColor
Definition: widgetbase.h:347
QString m_Text
Definition: widgetbase.h:319
QColor m_fillColor
color of the background of the widget
Definition: widgetbase.h:336
Definition: widgetbase.h:119
Definition: widgetbase.h:116
bool isSignalWidget()
Definition: widgetbase.h:266
Displays a message.
Definition: messagewidget.h:40
bool isAssociationWidget()
Definition: widgetbase.h:244
A graphical version of a UML State.
Definition: statewidget.h:38
bool isDatatypeWidget()
Definition: widgetbase.h:250
bool m_usesDiagramLineColor
Definition: widgetbase.h:348
bool isBoxWidget()
Definition: widgetbase.h:245
Definition: widgetbase.h:126
bool isPinWidget()
Definition: widgetbase.h:262
Definition: widgetbase.h:136
A dash line for UML combined fragments.
Definition: floatingdashlinewidget.h:33
QBrush m_brush
Definition: widgetbase.h:337
bool isArtifactWidget()
Definition: widgetbase.h:243
bool isNodeWidget()
Definition: widgetbase.h:257
Definition: widgetbase.h:130
QVariant itemChange(GraphicsItemChange change, const QVariant &value)
Definition: widgetbase.cpp:45
bool isPreconditionWidget()
Definition: widgetbase.h:264
QPointer< UMLObject > m_umlObject
Definition: widgetbase.h:317
A graphical version of a UMLUseCase.
Definition: usecasewidget.h:42
bool isMessageWidget()
Definition: widgetbase.h:256
A graphical version of an Artifact.
Definition: artifactwidget.h:30
A graphical version of a UML Activity.
Definition: activitywidget.h:33
A graphical version of an entity.
Definition: entitywidget.h:29
Definition: interfacewidget.h:24
Definition: widgetbase.h:113
std::string Type
Definition: basictypes.h:351
QColor m_lineColor
Color of the lines of the widget. Is saved to XMI.
Definition: widgetbase.h:335
A graphical version of a UMLCategory.
Definition: categorywidget.h:36
bool isUseCaseWidget()
Definition: widgetbase.h:269
Definition: widgetbase.h:128
Uml::ID::Type m_nId
Definition: widgetbase.h:327
A graphical version of a UML Actor.
Definition: actorwidget.h:41
QString toString(Enum item)
Definition: basictypes.cpp:47
QRectF m_rect
widget size
Definition: widgetbase.h:320
Definition: widgetbase.h:137
Definition: widgetbase.h:123
Definition: widgetbase.h:120
bool isForkJoinWidget()
Definition: widgetbase.h:254
Displays a line of text or an operation.
Definition: floatingtextwidget.h:36
bool isInterfaceWidget()
Definition: widgetbase.h:255
bool isPackageWidget()
Definition: widgetbase.h:261
A graphical version of an enum.
Definition: enumwidget.h:27
bool isObjectWidget()
Definition: widgetbase.h:260
Displays a box.
Definition: boxwidget.h:27
Definition: widgetbase.h:138
Definition: widgetbase.h:125
bool isEntityWidget()
Definition: widgetbase.h:251
Definition: widgetbase.h:115
Definition: widgetbase.h:124
A graphical version of a UML combined fragment.
Definition: combinedfragmentwidget.h:32
bool m_changesShape
The widget changes its shape when the number of connections or their positions are changed...
Definition: widgetbase.h:353
Definition: widgetbase.h:122
bool m_useFillColor
flag indicates if the UMLWidget uses the Diagram FillColour
Definition: widgetbase.h:340
bool isNoteWidget()
Definition: widgetbase.h:258
bool isCombinedFragmentWidget()
Definition: widgetbase.h:248
IconType
Definition: icon_utils.h:46
A graphical version of a UML pin.
Definition: pinwidget.h:28
virtual void setSelected(bool state)
Definition: widgetbase.cpp:38
Definition: widgetbase.h:131
Definition: widgetbase.h:139
Common implementation for class widget and interface widget.
Definition: classifierwidget.h:32
const Type None
special value for uninitialized ID
Definition: basictypes.h:353
A graphical version of a Component.
Definition: componentwidget.h:29
A graphical version of an datatype.
Definition: datatypewidget.h:29
bool isRegionWidget()
Definition: widgetbase.h:265
Definition: widgetbase.h:140
Definition: umlscene.h:68
bool m_autoResize
Definition: widgetbase.h:352
Definition: widgetbase.h:142
UMLScene * m_scene
Definition: widgetbase.h:316
Abstract base class for PinWidget and PortWidget.
Definition: pinportbase.h:27
A graphical version of a Package.
Definition: packagewidget.h:30
Definition: umldoc.h:74
The base class for graphical UML objects.
Definition: umlwidget.h:40