umbrello: umbrello/umlwidgets/associationline.h Source File

umbrello 2.31.1 Umbrello UML Modeller is a Unified Modelling Language (UML) diagram program based on KDE Technology

associationline.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) 2002-2020 *
8 * Umbrello UML Modeller Authors <umbrello-devel@kde.org> *
9 ***************************************************************************/
10
11 #ifndef ASSOCIATIONLINE_H
12 #define ASSOCIATIONLINE_H
13
14 #include "basictypes.h"
15
16 #include <QGraphicsObject>
17 #include <QList>
18 #include <QPen>
19 #include <QPoint>
20
21 // forward declarations
22 class AssociationWidget;
23 class QDomDocument;
24 class QDomElement;
25 class QPainter;
26
32 class Symbol : public QGraphicsItem
33 {
34 public:
35 typedef QPair<QPointF, QPointF> SymbolEndPoints;
36
41 enum SymbolType {
42 None = -1,
43 OpenArrow,
44 ClosedArrow,
45 CrowFeet,
46 Diamond,
47 Subset,
48 Circle,
49 Count
50 };
51
52 explicit Symbol(SymbolType symbolType, QGraphicsItem *parent = 0);
53 virtual ~Symbol();
54
55 SymbolType symbolType() const;
56 void setSymbolType(SymbolType symbolType);
57
58 virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
59
60 virtual QRectF boundingRect() const;
61 virtual QPainterPath shape() const;
62
63 void alignTo(const QLineF& line);
64 SymbolEndPoints symbolEndPoints() const;
65
66 QPen pen() const;
67 void setPen(const QPen &pen);
68
69 QBrush brush() const;
70 void setBrush(const QBrush& brush);
71
72 private:
73 QPen m_pen;
74 QBrush m_brush;
75 SymbolType m_symbolType;
76
78 struct SymbolProperty {
79 QRectF boundRect;
80 QPainterPath shape;
81 QLineF axisLine;
82 SymbolEndPoints endPoints;
83 };
84
85 static SymbolProperty symbolTable[Symbol::Count];
86 static void setupSymbolTable();
87 };
88
105 class AssociationLine : public QGraphicsObject
106 {
107 Q_OBJECT
108 public:
109 static QString toString(Uml::LayoutType::Enum layout);
110 static Uml::LayoutType::Enum fromString(const QString& layout);
111
112 explicit AssociationLine(AssociationWidget *association);
113 virtual ~AssociationLine();
114
115 QPointF point(int index) const;
116 bool setPoint(int index, const QPointF& point);
117 QPointF startPoint() const;
118 QPointF endPoint() const;
119
120 void addPoint(const QPointF& point);
121 void insertPoint(int index, const QPointF& point);
122 void removePoint(int index);
123
124 int count() const;
125 void cleanup();
126
127 void optimizeLinePoints();
128
129 int closestPointIndex(const QPointF& point, qreal delta = Delta) const;
130 int closestSegmentIndex(const QPointF& point, qreal delta = Delta) const;
131
132 bool isEndPointIndex(int index) const;
133 bool isEndSegmentIndex(int index) const;
134 bool isAutoLayouted() const;
135
136 bool enableAutoLayout();
137
138 bool setEndPoints(const QPointF &start, const QPointF &end);
139
140 void dumpPoints();
141
142 bool loadFromXMI1(QDomElement &qElement);
143 void saveToXMI1(QDomDocument &qDoc, QDomElement &qElement);
144
145 QBrush brush() const;
146 QPen pen() const;
147 void setPen(const QPen &pen);
148 void updatePenStyle();
149
150 virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget);
151
152 QPainterPath path() const;
153
154 QRectF boundingRect() const;
155 QPainterPath shape() const;
156
157 Uml::LayoutType::Enum layout() const;
158 void setLayout(Uml::LayoutType::Enum layout);
159
160 void mousePressEvent(QGraphicsSceneMouseEvent *event);
161 void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
162 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
163
164 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
165 void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
166 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
167
168 void calculateInitialEndPoints();
169
170 void reconstructSymbols();
171
172 private:
173 void setStartSymbol(Symbol::SymbolType symbolType);
174 void setEndSymbol(Symbol::SymbolType symbolType);
175
176 void createSubsetSymbol();
177 void removeSubsetSymbol();
178
179 void createCollaborationLine();
180 void removeCollaborationLine();
181
182 void alignSymbols();
183
184 void createSplinePoints();
185
186 AssociationWidget *m_associationWidget;
187 QVector<QPointF> m_points;
188 int m_activePointIndex;
189 int m_activeSegmentIndex;
190 Symbol *m_startSymbol;
191 Symbol *m_endSymbol;
192 Symbol *m_subsetSymbol;
193 QGraphicsLineItem *m_collaborationLineItem;
194 Symbol *m_collaborationLineHead;
195 Uml::LayoutType::Enum m_layout;
196 QPen m_pen;
197 bool m_autoLayoutSpline;
198 static QPainterPath createBezierCurve(QVector<QPointF> points);
199 static QPainterPath createOrthogonalPath(QVector<QPointF> points);
200
201 qreal c1dx{0.0}, c1dy{0.0}, c2dx{0.0}, c2dy{0.0};
202 static const qreal Delta;
203 static const qreal SelectedPointDiameter;
204 static const qreal SelfAssociationMinimumHeight;
205 };
206
207 #endif
Symbol::Circle
@ Circle
Definition: associationline.h:48
AssociationLine::AssociationLine
AssociationLine(AssociationWidget *association)
Definition: associationline.cpp:41
AssociationLine::createBezierCurve
static QPainterPath createBezierCurve(QVector< QPointF > points)
Definition: associationline.cpp:934
AssociationLine::hoverEnterEvent
void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
Definition: associationline.cpp:1233
AssociationLine::removeCollaborationLine
void removeCollaborationLine()
Definition: associationline.cpp:684
UMLWidget::height
qreal height() const
Definition: umlwidget.h:114
AssociationLine::loadFromXMI1
bool loadFromXMI1(QDomElement &qElement)
Definition: associationline.cpp:328
associationline.h
AssociationLine::setPen
void setPen(const QPen &pen)
Definition: associationline.cpp:440
AssociationWidget
This class represents an association inside a diagram. Bugs and comments to umbrello-devel@kde....
Definition: associationwidget.h:52
Symbol::symbolType
SymbolType symbolType() const
Definition: associationline.cpp:1425
WidgetBase::isBoxWidget
bool isBoxWidget()
Definition: widgetbase.h:245
Symbol::SymbolProperty
A structure to hold a table of values for all symbols.
Definition: associationline.h:78
Symbol::setPen
void setPen(const QPen &pen)
Definition: associationline.cpp:1521
Symbol::CrowFeet
@ CrowFeet
Definition: associationline.h:45
Symbol::SymbolEndPoints
QPair< QPointF, QPointF > SymbolEndPoints
Definition: associationline.h:35
Symbol::setBrush
void setBrush(const QBrush &brush)
Definition: associationline.cpp:1539
x
int x
Definition: cxx11-lambda-functions-and-expressions.h:4
AssociationLine::setPoint
bool setPoint(int index, const QPointF &point)
Definition: associationline.cpp:87
Uml::LayoutType::Enum
Enum
Definition: basictypes.h:161
AssociationLine::createCollaborationLine
void createCollaborationLine()
Definition: associationline.cpp:662
Symbol::shape
virtual QPainterPath shape() const
Definition: associationline.cpp:1472
UMLWidget
The base class for graphical UML objects.
Definition: umlwidget.h:41
AssociationLine::pen
QPen pen() const
Definition: associationline.cpp:432
Uml::AssociationType::Containment
@ Containment
Definition: basictypes.h:133
AssociationLine::saveToXMI1
void saveToXMI1(QDomDocument &qDoc, QDomElement &qElement)
Definition: associationline.cpp:382
Uml::AssociationType::Activity
@ Activity
Definition: basictypes.h:139
Tracer::instance
static Tracer * instance()
Definition: debug_utils.cpp:36
AssociationLine::closestSegmentIndex
int closestSegmentIndex(const QPointF &point, qreal delta=Delta) const
Definition: associationline.cpp:228
AssociationLine::count
int count() const
Definition: associationline.cpp:152
AssociationLine::updatePenStyle
void updatePenStyle()
Definition: associationline.cpp:466
AssociationLine::createOrthogonalPath
static QPainterPath createOrthogonalPath(QVector< QPointF > points)
Definition: associationline.cpp:970
WidgetBase::umlScene
UMLScene * umlScene() const
Definition: widgetbase.cpp:162
toDoubleFromAnyLocale
qreal toDoubleFromAnyLocale(const QString &s)
Definition: basictypes.cpp:1298
AssociationLine::SelectedPointDiameter
static const qreal SelectedPointDiameter
radius of circles drawn to show "selection"
Definition: associationline.h:203
Symbol::Subset
@ Subset
Definition: associationline.h:47
DEBUG_REGISTER_DISABLED
#define DEBUG_REGISTER_DISABLED(src)
Definition: debug_utils.h:132
AssociationLine::createSplinePoints
void createSplinePoints()
Definition: associationline.cpp:867
Uml::AssociationType::State
@ State
Definition: basictypes.h:138
AssociationLine::removePoint
void removePoint(int index)
Definition: associationline.cpp:138
AssociationLine::boundingRect
QRectF boundingRect() const
Definition: associationline.cpp:796
AssociationLine::isEndPointIndex
bool isEndPointIndex(int index) const
Definition: associationline.cpp:252
UMLDoc::dpiScale
qreal dpiScale() const
Definition: umldoc.cpp:2036
Uml::AssociationType::Coll_Message_Synchronous
@ Coll_Message_Synchronous
Definition: basictypes.h:144
AssociationLine::endPoint
QPointF endPoint() const
Definition: associationline.cpp:113
Symbol::SymbolProperty::boundRect
QRectF boundRect
Definition: associationline.h:79
AssociationLine::paint
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
Definition: associationline.cpp:1014
AssociationLine::mouseMoveEvent
void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
Definition: associationline.cpp:1162
AssociationLine::insertPoint
void insertPoint(int index, const QPointF &point)
Definition: associationline.cpp:127
Symbol::paint
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
Definition: associationline.cpp:1443
WidgetBase::rect
QRectF rect() const
Definition: widgetbase.cpp:831
AssociationLine::m_startSymbol
Symbol * m_startSymbol
symbol drawn at the end of "first" line segment
Definition: associationline.h:190
Uml::AssociationType::UniAssociation
@ UniAssociation
Definition: basictypes.h:136
Uml::AssociationType::Relationship
@ Relationship
Definition: basictypes.h:143
AssociationLine::path
QPainterPath path() const
Definition: associationline.cpp:760
Symbol::m_brush
QBrush m_brush
brush used to fill Symbol
Definition: associationline.h:74
AssociationLine::m_points
QVector< QPointF > m_points
points representing the association line
Definition: associationline.h:187
AssociationLine::fromString
static Uml::LayoutType::Enum fromString(const QString &layout)
Definition: associationline.cpp:827
Symbol::SymbolProperty::shape
QPainterPath shape
Definition: associationline.h:80
UMLScene::widgetAt
UMLWidget * widgetAt(const QPointF &p)
Definition: umlscene.cpp:1074
AssociationLine::calculateInitialEndPoints
void calculateInitialEndPoints()
Definition: associationline.cpp:483
optionstate.h
AssociationLine::m_collaborationLineItem
QGraphicsLineItem * m_collaborationLineItem
parallel arrow line drawn in case of collaboration message
Definition: associationline.h:193
Uml::AssociationType::Anchor
@ Anchor
Definition: basictypes.h:137
Settings::optionState
OptionState & optionState()
Definition: optionstate.cpp:370
AssociationWidget::associationType
Uml::AssociationType::Enum associationType() const
Definition: associationwidget.cpp:1401
AssociationLine::alignSymbols
void alignSymbols()
Definition: associationline.cpp:698
AssociationLine::~AssociationLine
virtual ~AssociationLine()
Definition: associationline.cpp:63
Uml::AssociationType::Child2Category
@ Child2Category
Definition: basictypes.h:142
AssociationWidget::boundingRect
virtual QRectF boundingRect() const
Definition: associationwidget.cpp:3855
Uml::AssociationType::Aggregation
@ Aggregation
Definition: basictypes.h:125
AssociationLine::optimizeLinePoints
void optimizeLinePoints()
Definition: associationline.cpp:176
Symbol::m_pen
QPen m_pen
pen used to draw Symbol
Definition: associationline.h:73
UMLScene::snappedX
qreal snappedX(qreal x)
Definition: umlscene.cpp:3578
AssociationLine::c2dy
qreal c2dy
Definition: associationline.h:201
AssociationLine::enableAutoLayout
bool enableAutoLayout()
Definition: associationline.cpp:277
AssociationLine::point
QPointF point(int index) const
Definition: associationline.cpp:75
Uml::LayoutType::Spline
@ Spline
Definition: basictypes.h:166
Symbol::setupSymbolTable
static void setupSymbolTable()
Definition: associationline.cpp:1328
AssociationLine::isEndSegmentIndex
bool isEndSegmentIndex(int index) const
Definition: associationline.cpp:263
Uml::LayoutType::Polyline
@ Polyline
Definition: basictypes.h:165
AssociationLine::isAutoLayouted
bool isAutoLayouted() const
Definition: associationline.cpp:272
AssociationLine::c1dx
qreal c1dx
Definition: associationline.h:201
AssociationLine::m_subsetSymbol
Symbol * m_subsetSymbol
subset symbol
Definition: associationline.h:192
Symbol::ClosedArrow
@ ClosedArrow
Definition: associationline.h:44
a
QString a
Definition: petalnode.cpp:18
umlwidget.h
uWarning
#define uWarning()
Definition: debug_utils.h:124
Uml::LayoutType::Direct
@ Direct
Definition: basictypes.h:163
AssociationLine::m_collaborationLineHead
Symbol * m_collaborationLineHead
arrow head drawn at end of m_collaborationLineItem
Definition: associationline.h:194
AssociationLine::brush
QBrush brush() const
Definition: associationline.cpp:414
Symbol::boundingRect
virtual QRectF boundingRect() const
Definition: associationline.cpp:1462
AssociationLine
Definition: associationline.h:106
Symbol::Count
@ Count
Definition: associationline.h:49
Symbol::symbolEndPoints
SymbolEndPoints symbolEndPoints() const
Definition: associationline.cpp:1505
Symbol::symbolTable
static SymbolProperty symbolTable[Symbol::Count]
a table which stores all symbol properties
Definition: associationline.h:85
basictypes.h
AssociationLine::reconstructSymbols
void reconstructSymbols()
Definition: associationline.cpp:524
Symbol::~Symbol
virtual ~Symbol()
Definition: associationline.cpp:1418
AssociationLine::cleanup
void cleanup()
Definition: associationline.cpp:160
AssociationLine::m_pen
QPen m_pen
pen used to draw an association line
Definition: associationline.h:196
Symbol::OpenArrow
@ OpenArrow
Definition: associationline.h:43
Uml::RoleType::B
@ B
Definition: basictypes.h:257
Symbol::Symbol
Symbol(SymbolType symbolType, QGraphicsItem *parent=0)
Definition: associationline.cpp:1407
AssociationLine::removeSubsetSymbol
void removeSubsetSymbol()
Definition: associationline.cpp:653
Uml::AssociationType::Enum
Enum
Definition: basictypes.h:123
Uml::AssociationType::Generalization
@ Generalization
Definition: basictypes.h:124
AssociationLine::hoverLeaveEvent
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
Definition: associationline.cpp:1279
AssociationLine::c2dx
qreal c2dx
Definition: associationline.h:201
AssociationLine::setStartSymbol
void setStartSymbol(Symbol::SymbolType symbolType)
Definition: associationline.cpp:596
UMLApp::app
static UMLApp * app()
Definition: uml.cpp:269
AssociationLine::setLayout
void setLayout(Uml::LayoutType::Enum layout)
Definition: associationline.cpp:851
AssociationLine::startPoint
QPointF startPoint() const
Definition: associationline.cpp:105
AssociationLine::m_activeSegmentIndex
int m_activeSegmentIndex
index of active segment
Definition: associationline.h:189
Symbol::SymbolProperty::endPoints
SymbolEndPoints endPoints
Definition: associationline.h:82
Symbol::m_symbolType
SymbolType m_symbolType
current symbol being represented by this item
Definition: associationline.h:75
Symbol::alignTo
void alignTo(const QLineF &line)
Definition: associationline.cpp:1488
Symbol::setSymbolType
void setSymbolType(SymbolType symbolType)
Definition: associationline.cpp:1433
AssociationLine::mousePressEvent
void mousePressEvent(QGraphicsSceneMouseEvent *event)
Definition: associationline.cpp:1138
AssociationLine::m_autoLayoutSpline
bool m_autoLayoutSpline
Definition: associationline.h:197
AssociationLine::closestPointIndex
int closestPointIndex(const QPointF &point, qreal delta=Delta) const
Definition: associationline.cpp:202
AssociationLine::toString
static QString toString(Uml::LayoutType::Enum layout)
Definition: associationline.cpp:819
AssociationLine::m_associationWidget
AssociationWidget * m_associationWidget
association widget for which this line represents
Definition: associationline.h:186
AssociationLine::c1dy
qreal c1dy
Definition: associationline.h:201
associationwidget.h
Uml::AssociationType::Coll_Message_Asynchronous
@ Coll_Message_Asynchronous
Definition: basictypes.h:129
Settings
Definition: codeviewerstate.cpp:15
AssociationLine::m_layout
Uml::LayoutType::Enum m_layout
Definition: associationline.h:195
AssociationLine::setEndSymbol
void setEndSymbol(Symbol::SymbolType symbolType)
Definition: associationline.cpp:620
DEBUG
#define DEBUG(src)
Definition: debug_utils.h:129
AssociationLine::mouseReleaseEvent
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
Definition: associationline.cpp:1221
WidgetBase::lineColor
QColor lineColor() const
Definition: widgetbase.cpp:356
uError
#define uError()
Definition: debug_utils.h:123
uml.h
Symbol::pen
QPen pen() const
Definition: associationline.cpp:1513
debug_utils.h
UMLScene::snappedY
qreal snappedY(qreal y)
Definition: umlscene.cpp:3596
AssociationLine::m_activePointIndex
int m_activePointIndex
index of active point which can be dragged to modify association line
Definition: associationline.h:188
UMLScene
Definition: umlscene.h:69
DBG_SRC
#define DBG_SRC
Definition: import_utils.cpp:43
AssociationLine::m_endSymbol
Symbol * m_endSymbol
symbol drawn at the end of "last" line segment
Definition: associationline.h:191
AssociationLine::setEndPoints
bool setEndPoints(const QPointF &start, const QPointF &end)
Definition: associationline.cpp:291
AssociationLine::createSubsetSymbol
void createSubsetSymbol()
Definition: associationline.cpp:642
AssociationLine::dumpPoints
void dumpPoints()
Definition: associationline.cpp:317
Uml::AssociationType::Composition
@ Composition
Definition: basictypes.h:134
AssociationLine::addPoint
void addPoint(const QPointF &point)
Definition: associationline.cpp:118
Symbol::SymbolProperty::axisLine
QLineF axisLine
Definition: associationline.h:81
Uml::LayoutType::Orthogonal
@ Orthogonal
Definition: basictypes.h:164
Uml::LayoutType::fromString
Enum fromString(const QString &item)
Definition: basictypes.cpp:522
b
bool b
Definition: cxx11-null-pointer-constant.h:6
Symbol::brush
QBrush brush() const
Definition: associationline.cpp:1531
Uml::AssociationType::Dependency
@ Dependency
Definition: basictypes.h:126
AssociationLine::Delta
static const qreal Delta
default delta for fuzzy recognition of points closer to point
Definition: associationline.h:202
Uml::LayoutType::toString
QString toString(Enum item)
Definition: basictypes.cpp:502
AssociationLine::layout
Uml::LayoutType::Enum layout() const
Definition: associationline.cpp:842
AssociationLine::SelfAssociationMinimumHeight
static const qreal SelfAssociationMinimumHeight
minimum height for self association's loop
Definition: associationline.h:204
Uml::AssociationType::Coll_Message_Self
@ Coll_Message_Self
Definition: basictypes.h:131
UMLWidget::width
qreal width() const
Definition: umlwidget.h:121
Symbol
Definition: associationline.h:33
AssociationLine::shape
QPainterPath shape() const
Definition: associationline.cpp:808
Symbol::Diamond
@ Diamond
Definition: associationline.h:46
UMLApp::document
UMLDoc * document() const
Definition: uml.cpp:1055
Uml::AssociationType::Realization
@ Realization
Definition: basictypes.h:135
AssociationLine::hoverMoveEvent
void hoverMoveEvent(QGraphicsSceneHoverEvent *event)
Definition: associationline.cpp:1257
umldoc.h
AssociationWidget::isSelf
bool isSelf() const
Definition: associationwidget.cpp:1391
Uml::AssociationType::Exception
@ Exception
Definition: basictypes.h:140
Symbol::None
@ None
Definition: associationline.h:42
AssociationWidget::widgetForRole
UMLWidget * widgetForRole(Uml::RoleType::Enum role) const
Definition: associationwidget.cpp:1232
Symbol::SymbolType
SymbolType
Definition: associationline.h:41