umbrello: umbrello/umlwidgets/associationline.h Source File

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

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

associationline.h
Go to the documentation of this file.
1/*
2 SPDX-License-Identifier: GPL-2.0-or-later
3 SPDX-FileCopyrightText: 2002-2021 Umbrello UML Modeller Authors <umbrello-devel@kde.org>
4*/
5
6#ifndef ASSOCIATIONLINE_H
7#define ASSOCIATIONLINE_H
8
9#include "basictypes.h"
10
11#include <QGraphicsObject>
12#include <QList>
13#include <QPen>
14#include <QPoint>
15
16// forward declarations
17class AssociationWidget;
18class QDomDocument;
19class QDomElement;
20class QPainter;
21class QXmlStreamWriter;
22
27 class Symbol : public QGraphicsItem
28{
29 public:
30 typedef QPair<QPointF, QPointF> SymbolEndPoints;
31
36 enum SymbolType {
37 None = -1,
38 OpenArrow,
39 ClosedArrow,
40 CrowFeet,
41 Diamond,
42 Subset,
43 Circle,
44 Count
45 };
46
47 explicit Symbol(SymbolType symbolType, QGraphicsItem *parent = 0);
48 virtual ~Symbol();
49
50 SymbolType symbolType() const;
51 void setSymbolType(SymbolType symbolType);
52
53 virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
54
55 virtual QRectF boundingRect() const;
56 virtual QPainterPath shape() const;
57
58 void alignTo(const QLineF& line);
59 SymbolEndPoints symbolEndPoints() const;
60
61 QPen pen() const;
62 void setPen(const QPen &pen);
63
64 QBrush brush() const;
65 void setBrush(const QBrush& brush);
66
67 private:
68 QPen m_pen;
69 QBrush m_brush;
70 SymbolType m_symbolType;
71
73 struct SymbolProperty {
74 QRectF boundRect;
75 QPainterPath shape;
76 QLineF axisLine;
77 SymbolEndPoints endPoints;
78 };
79
80 static SymbolProperty *symbolTable;
81 static void setupSymbolTable();
82};
83
100 class AssociationLine : public QGraphicsObject
101{
102 Q_OBJECT
103public:
104 static QString toString(Uml::LayoutType::Enum layout);
105 static Uml::LayoutType::Enum fromString(const QString& layout);
106
107 explicit AssociationLine(AssociationWidget *association);
108 virtual ~AssociationLine();
109
110 QPointF point(int index) const;
111 bool setPoint(int index, const QPointF& point);
112 QPointF startPoint() const;
113 QPointF endPoint() const;
114
115 void addPoint(const QPointF& point);
116 void insertPoint(int index, const QPointF& point);
117 void removePoint(int index);
118
119 int count() const;
120 void cleanup();
121
122 void optimizeLinePoints();
123
124 int closestPointIndex(const QPointF& point, qreal delta = Delta) const;
125 int closestSegmentIndex(const QPointF& point, qreal delta = Delta) const;
126
127 bool isEndPointIndex(int index) const;
128 bool isEndSegmentIndex(int index) const;
129 bool isAutoLayouted() const;
130
131 bool enableAutoLayout();
132
133 bool setEndPoints(const QPointF &start, const QPointF &end);
134
135 void dumpPoints();
136
137 bool loadFromXMI(QDomElement &qElement);
138 void saveToXMI(QXmlStreamWriter& writer);
139
140 QBrush brush() const;
141 QPen pen() const;
142 void setPen(const QPen &pen);
143 void updatePenStyle();
144
145 virtual void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget);
146
147 QPainterPath path() const;
148
149 QRectF boundingRect() const;
150 QPainterPath shape() const;
151
152 Uml::LayoutType::Enum layout() const;
153 void setLayout(Uml::LayoutType::Enum layout);
154
155 void mousePressEvent(QGraphicsSceneMouseEvent *event);
156 void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
157 void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);
158
159 void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
160 void hoverMoveEvent(QGraphicsSceneHoverEvent *event);
161 void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
162
163 void calculateInitialEndPoints();
164
165 void reconstructSymbols();
166
167private:
168 void setStartSymbol(Symbol::SymbolType symbolType);
169 void setEndSymbol(Symbol::SymbolType symbolType);
170
171 void createSubsetSymbol();
172 void removeSubsetSymbol();
173
174 void createCollaborationLine();
175 void removeCollaborationLine();
176
177 void alignSymbols();
178
179 void createSplinePoints();
180
181 AssociationWidget *m_associationWidget;
182 QVector<QPointF> m_points;
183 int m_activePointIndex;
184 int m_activeSegmentIndex;
185 Symbol *m_startSymbol;
186 Symbol *m_endSymbol;
187 Symbol *m_subsetSymbol;
188 QGraphicsLineItem *m_collaborationLineItem;
189 Symbol *m_collaborationLineHead;
190 Uml::LayoutType::Enum m_layout;
191 QPen m_pen;
192 bool m_autoLayoutSpline;
193 static QPainterPath createBezierCurve(QVector<QPointF> points);
194 static QPainterPath createOrthogonalPath(QVector<QPointF> points);
195
196 qreal m_c1dx{0.0}, m_c1dy{0.0}, m_c2dx{0.0}, m_c2dy{0.0};
197 static const qreal Delta;
198 static const qreal SelectedPointDiameter;
199 static const qreal SelfAssociationMinimumHeight;
200};
201
202#endif
basictypes.h
AssociationLine
Definition: associationline.h:101
AssociationLine::Delta
static const qreal Delta
default delta for fuzzy recognition of points closer to point
Definition: associationline.h:197
AssociationLine::isAutoLayouted
bool isAutoLayouted() const
Definition: associationline.cpp:272
AssociationLine::m_autoLayoutSpline
bool m_autoLayoutSpline
Definition: associationline.h:192
AssociationLine::insertPoint
void insertPoint(int index, const QPointF &point)
Definition: associationline.cpp:125
AssociationLine::~AssociationLine
virtual ~AssociationLine()
Definition: associationline.cpp:59
AssociationLine::addPoint
void addPoint(const QPointF &point)
Definition: associationline.cpp:116
AssociationLine::reconstructSymbols
void reconstructSymbols()
Definition: associationline.cpp:526
AssociationLine::m_associationWidget
AssociationWidget * m_associationWidget
association widget which this line represents
Definition: associationline.h:181
AssociationLine::setStartSymbol
void setStartSymbol(Symbol::SymbolType symbolType)
Definition: associationline.cpp:599
AssociationLine::setEndPoints
bool setEndPoints(const QPointF &start, const QPointF &end)
Definition: associationline.cpp:291
AssociationLine::m_collaborationLineItem
QGraphicsLineItem * m_collaborationLineItem
parallel arrow line drawn in case of collaboration message
Definition: associationline.h:188
AssociationLine::setLayout
void setLayout(Uml::LayoutType::Enum layout)
Definition: associationline.cpp:852
AssociationLine::setPen
void setPen(const QPen &pen)
Definition: associationline.cpp:441
AssociationLine::createCollaborationLine
void createCollaborationLine()
Definition: associationline.cpp:665
AssociationLine::count
int count() const
Definition: associationline.cpp:150
AssociationLine::m_c2dy
qreal m_c2dy
Definition: associationline.h:196
AssociationLine::m_subsetSymbol
Symbol * m_subsetSymbol
subset symbol
Definition: associationline.h:187
AssociationLine::m_c1dx
qreal m_c1dx
Definition: associationline.h:196
AssociationLine::removeSubsetSymbol
void removeSubsetSymbol()
Definition: associationline.cpp:656
AssociationLine::SelfAssociationMinimumHeight
static const qreal SelfAssociationMinimumHeight
minimum height for self association's loop
Definition: associationline.h:199
AssociationLine::removePoint
void removePoint(int index)
Definition: associationline.cpp:136
AssociationLine::updatePenStyle
void updatePenStyle()
Definition: associationline.cpp:467
AssociationLine::isEndSegmentIndex
bool isEndSegmentIndex(int index) const
Definition: associationline.cpp:263
AssociationLine::m_pen
QPen m_pen
pen used to draw an association line
Definition: associationline.h:191
AssociationLine::hoverLeaveEvent
void hoverLeaveEvent(QGraphicsSceneHoverEvent *event)
Definition: associationline.cpp:1277
AssociationLine::startPoint
QPointF startPoint() const
Definition: associationline.cpp:103
AssociationLine::createOrthogonalPath
static QPainterPath createOrthogonalPath(QVector< QPointF > points)
Definition: associationline.cpp:971
AssociationLine::m_startSymbol
Symbol * m_startSymbol
symbol drawn at the end of "first" line segment
Definition: associationline.h:185
AssociationLine::mouseReleaseEvent
void mouseReleaseEvent(QGraphicsSceneMouseEvent *event)
Definition: associationline.cpp:1219
AssociationLine::closestPointIndex
int closestPointIndex(const QPointF &point, qreal delta=Delta) const
Definition: associationline.cpp:200
AssociationLine::layout
Uml::LayoutType::Enum layout() const
Definition: associationline.cpp:843
AssociationLine::boundingRect
QRectF boundingRect() const
Definition: associationline.cpp:797
AssociationLine::m_c1dy
qreal m_c1dy
Definition: associationline.h:196
AssociationLine::m_c2dx
qreal m_c2dx
Definition: associationline.h:196
AssociationLine::alignSymbols
void alignSymbols()
Definition: associationline.cpp:701
AssociationLine::shape
QPainterPath shape() const
Definition: associationline.cpp:809
AssociationLine::hoverEnterEvent
void hoverEnterEvent(QGraphicsSceneHoverEvent *event)
Definition: associationline.cpp:1231
AssociationLine::m_endSymbol
Symbol * m_endSymbol
symbol drawn at the end of "last" line segment
Definition: associationline.h:186
AssociationLine::setEndSymbol
void setEndSymbol(Symbol::SymbolType symbolType)
Definition: associationline.cpp:623
AssociationLine::point
QPointF point(int index) const
Definition: associationline.cpp:71
AssociationLine::m_activePointIndex
int m_activePointIndex
index of active point which can be dragged to modify association line
Definition: associationline.h:183
AssociationLine::cleanup
void cleanup()
Definition: associationline.cpp:158
AssociationLine::mouseMoveEvent
void mouseMoveEvent(QGraphicsSceneMouseEvent *event)
Definition: associationline.cpp:1159
AssociationLine::m_layout
Uml::LayoutType::Enum m_layout
Definition: associationline.h:190
AssociationLine::isEndPointIndex
bool isEndPointIndex(int index) const
Definition: associationline.cpp:252
AssociationLine::enableAutoLayout
bool enableAutoLayout()
Definition: associationline.cpp:277
AssociationLine::brush
QBrush brush() const
Definition: associationline.cpp:415
AssociationLine::paint
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
Definition: associationline.cpp:1015
AssociationLine::optimizeLinePoints
void optimizeLinePoints()
Definition: associationline.cpp:174
AssociationLine::calculateInitialEndPoints
void calculateInitialEndPoints()
Definition: associationline.cpp:484
AssociationLine::toString
static QString toString(Uml::LayoutType::Enum layout)
Definition: associationline.cpp:820
AssociationLine::createSubsetSymbol
void createSubsetSymbol()
Definition: associationline.cpp:645
AssociationLine::createBezierCurve
static QPainterPath createBezierCurve(QVector< QPointF > points)
Definition: associationline.cpp:935
AssociationLine::removeCollaborationLine
void removeCollaborationLine()
Definition: associationline.cpp:687
AssociationLine::mousePressEvent
void mousePressEvent(QGraphicsSceneMouseEvent *event)
Definition: associationline.cpp:1139
AssociationLine::endPoint
QPointF endPoint() const
Definition: associationline.cpp:111
AssociationLine::createSplinePoints
void createSplinePoints()
Definition: associationline.cpp:868
AssociationLine::m_activeSegmentIndex
int m_activeSegmentIndex
index of active segment
Definition: associationline.h:184
AssociationLine::path
QPainterPath path() const
Definition: associationline.cpp:763
AssociationLine::closestSegmentIndex
int closestSegmentIndex(const QPointF &point, qreal delta=Delta) const
Definition: associationline.cpp:228
AssociationLine::SelectedPointDiameter
static const qreal SelectedPointDiameter
radius of circles drawn to show "selection"
Definition: associationline.h:198
AssociationLine::fromString
static Uml::LayoutType::Enum fromString(const QString &layout)
Definition: associationline.cpp:828
AssociationLine::pen
QPen pen() const
Definition: associationline.cpp:433
AssociationLine::m_collaborationLineHead
Symbol * m_collaborationLineHead
arrow head drawn at end of m_collaborationLineItem
Definition: associationline.h:189
AssociationLine::loadFromXMI
bool loadFromXMI(QDomElement &qElement)
Definition: associationline.cpp:328
AssociationLine::m_points
QVector< QPointF > m_points
points representing the association line
Definition: associationline.h:182
AssociationLine::dumpPoints
void dumpPoints()
Definition: associationline.cpp:317
AssociationLine::saveToXMI
void saveToXMI(QXmlStreamWriter &writer)
Definition: associationline.cpp:383
AssociationLine::setPoint
bool setPoint(int index, const QPointF &point)
Definition: associationline.cpp:84
AssociationLine::hoverMoveEvent
void hoverMoveEvent(QGraphicsSceneHoverEvent *event)
Definition: associationline.cpp:1255
AssociationWidget
This class represents an association inside a diagram. Bugs and comments to umbrello-devel@kde....
Definition: associationwidget.h:47
Symbol
Definition: associationline.h:28
Symbol::setSymbolType
void setSymbolType(SymbolType symbolType)
Definition: associationline.cpp:1463
Symbol::setPen
void setPen(const QPen &pen)
Definition: associationline.cpp:1551
Symbol::m_brush
QBrush m_brush
brush used to fill Symbol
Definition: associationline.h:69
Symbol::boundingRect
virtual QRectF boundingRect() const
Definition: associationline.cpp:1492
Symbol::m_pen
QPen m_pen
pen used to draw Symbol
Definition: associationline.h:68
Symbol::setBrush
void setBrush(const QBrush &brush)
Definition: associationline.cpp:1569
Symbol::symbolTable
static SymbolProperty * symbolTable
a table which stores all symbol properties
Definition: associationline.h:80
Symbol::~Symbol
virtual ~Symbol()
Definition: associationline.cpp:1448
Symbol::symbolEndPoints
SymbolEndPoints symbolEndPoints() const
Definition: associationline.cpp:1535
Symbol::pen
QPen pen() const
Definition: associationline.cpp:1543
Symbol::m_symbolType
SymbolType m_symbolType
current symbol being represented by this item
Definition: associationline.h:70
Symbol::brush
QBrush brush() const
Definition: associationline.cpp:1561
Symbol::SymbolType
SymbolType
Definition: associationline.h:36
Symbol::None
@ None
Definition: associationline.h:37
Symbol::ClosedArrow
@ ClosedArrow
Definition: associationline.h:39
Symbol::Count
@ Count
Definition: associationline.h:44
Symbol::Diamond
@ Diamond
Definition: associationline.h:41
Symbol::OpenArrow
@ OpenArrow
Definition: associationline.h:38
Symbol::CrowFeet
@ CrowFeet
Definition: associationline.h:40
Symbol::Subset
@ Subset
Definition: associationline.h:42
Symbol::Circle
@ Circle
Definition: associationline.h:43
Symbol::symbolType
SymbolType symbolType() const
Definition: associationline.cpp:1455
Symbol::alignTo
void alignTo(const QLineF &line)
Definition: associationline.cpp:1518
Symbol::setupSymbolTable
static void setupSymbolTable()
Definition: associationline.cpp:1344
Symbol::SymbolEndPoints
QPair< QPointF, QPointF > SymbolEndPoints
Definition: associationline.h:30
Symbol::paint
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
Definition: associationline.cpp:1473
Symbol::shape
virtual QPainterPath shape() const
Definition: associationline.cpp:1502
Uml::LayoutType::Enum
Enum
Definition: basictypes.h:130
Symbol::SymbolProperty
A structure to hold a table of values for all symbols.
Definition: associationline.h:73
Symbol::SymbolProperty::boundRect
QRectF boundRect
Definition: associationline.h:74
Symbol::SymbolProperty::axisLine
QLineF axisLine
Definition: associationline.h:76
Symbol::SymbolProperty::endPoints
SymbolEndPoints endPoints
Definition: associationline.h:77
Symbol::SymbolProperty::shape
QPainterPath shape
Definition: associationline.h:75