umbrello: AssociationLine Class Reference

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

Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
AssociationLine Class Reference

`#include <associationline.h>`

Inheritance diagram for AssociationLine:

## Public Member Functions
| AssociationLine (AssociationWidget *association)
virtual | ~AssociationLine ()
QPointF | point (int index) const
bool | setPoint (int index, const QPointF &point)
QPointF | startPoint () const
QPointF | endPoint () const
void | addPoint (const QPointF &point)
void | insertPoint (int index, const QPointF &point)
void | removePoint (int index)
int | count () const
void | cleanup ()
void | optimizeLinePoints ()
int | closestPointIndex (const QPointF &point, qreal delta=Delta) const
int | closestSegmentIndex (const QPointF &point, qreal delta=Delta) const
bool | isEndPointIndex (int index) const
bool | isEndSegmentIndex (int index) const
bool | isAutoLayouted () const
bool | enableAutoLayout ()
bool | setEndPoints (const QPointF &start, const QPointF &end)
void | dumpPoints ()
bool | loadFromXMI1 (QDomElement &qElement)
void | saveToXMI1 (QXmlStreamWriter &writer)
QBrush | brush () const
QPen | pen () const
void | setPen (const QPen &pen)
void | updatePenStyle ()
virtual void | paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
QPainterPath | path () const
QRectF | boundingRect () const
QPainterPath | shape () const
Uml::LayoutType::Enum | layout () const
void | setLayout (Uml::LayoutType::Enum layout)
void | mousePressEvent (QGraphicsSceneMouseEvent *event)
void | mouseMoveEvent (QGraphicsSceneMouseEvent *event)
void | mouseReleaseEvent (QGraphicsSceneMouseEvent *event)
void | hoverEnterEvent (QGraphicsSceneHoverEvent *event)
void | hoverMoveEvent (QGraphicsSceneHoverEvent *event)
void | hoverLeaveEvent (QGraphicsSceneHoverEvent *event)
void | calculateInitialEndPoints ()
void | reconstructSymbols ()

## Static Public Member Functions
static QString | toString (Uml::LayoutType::Enum layout)
static Uml::LayoutType::Enum | fromString (const QString &layout)

## Private Member Functions
void | setStartSymbol (Symbol::SymbolType symbolType)
void | setEndSymbol (Symbol::SymbolType symbolType)
void | createSubsetSymbol ()
void | removeSubsetSymbol ()
void | createCollaborationLine ()
void | removeCollaborationLine ()
void | alignSymbols ()
void | createSplinePoints ()

## Static Private Member Functions
static QPainterPath | createBezierCurve (QVector< QPointF > points)
static QPainterPath | createOrthogonalPath (QVector< QPointF > points)

## Private Attributes
AssociationWidget * | m_associationWidget
| association widget which this line represents More...
QVector< QPointF > | m_points
| points representing the association line More...
int | m_activePointIndex
| index of active point which can be dragged to modify association line More...
int | m_activeSegmentIndex
| index of active segment More...
Symbol * | m_startSymbol
| symbol drawn at the end of "first" line segment More...
Symbol * | m_endSymbol
| symbol drawn at the end of "last" line segment More...
Symbol * | m_subsetSymbol
| subset symbol More...
QGraphicsLineItem * | m_collaborationLineItem
| parallel arrow line drawn in case of collaboration message More...
Symbol * | m_collaborationLineHead
| arrow head drawn at end of m_collaborationLineItem More...
Uml::LayoutType::Enum | m_layout
QPen | m_pen
| pen used to draw an association line More...
bool | m_autoLayoutSpline
qreal | c1dx {0.0}
qreal | c1dy {0.0}
qreal | c2dx {0.0}
qreal | c2dy {0.0}

## Static Private Attributes
static const qreal | Delta = 5
| default delta for fuzzy recognition of points closer to point More...
static const qreal | SelectedPointDiameter = 4
| radius of circles drawn to show "selection" More...
static const qreal | SelfAssociationMinimumHeight = 30
| minimum height for self association's loop More...

## Detailed Description

A convenience class that encapsulates geometry management, handles mouse and hover events, embeds and aligns symbols and finally draws the lines and points. Context menu events are handled in AssociationWidget.

This class is infact a draw and event handling proxy for AssociationWidget.

Note
  m_activePointIndex and m_activeSegmentIndex can't be active at same time!

Author
  Gopala Krishna
  Andi Fischer Bugs and comments to uml-d.nosp@m.evel.nosp@m.@list.nosp@m.s.sf.nosp@m..net or https://bugs.kde.org

## Constructor & Destructor Documentation

## ◆ AssociationLine()

AssociationLine::AssociationLine | ( | AssociationWidget * | association | ) |
| explicit

Constructor. Constructs an AssociationLine item with its parent being parent.

## ◆ ~AssociationLine()

AssociationLine::~AssociationLine | ( |  | ) |
| virtual

Destructor.

## Member Function Documentation

## ◆ addPoint()

void AssociationLine::addPoint | ( | const QPointF & | point | ) |

## ◆ alignSymbols()

void AssociationLine::alignSymbols | ( |  | ) |
| private

This method aligns both the "start" and "end" symbols to the current angles of the "first" and the "last" line segment respectively.

## ◆ boundingRect()

QRectF AssociationLine::boundingRect | ( |  | ) | const

The points are used for the bounding rect. The reason is, that for splines the control points are further away from the path.

Returns
  The bounding rectangle for the AssociationLine.

## ◆ brush()

QBrush AssociationLine::brush | ( |  | ) | const

Returns the type of brush to use depending on the type of Association.

## ◆ calculateInitialEndPoints()

void AssociationLine::calculateInitialEndPoints | ( |  | ) |

This method simply ensures presence of two points and adds the needed points for self associations.

## ◆ cleanup()

void AssociationLine::cleanup | ( |  | ) |

Removes all the points and signals a geometry update.

## ◆ closestPointIndex()

int AssociationLine::closestPointIndex | ( | const QPointF & | point,
|  | qreal | delta = `Delta`
| ) |  | const

Return index of point closer a given delta.

Parameters

  point | The point which is to be tested for closeness.
  delta | The distance the point should be closer to.

Return values

  Index | of the first line point closer to the point passed.
  -1 | If no line point is closer to passed in point.

## ◆ closestSegmentIndex()

int AssociationLine::closestSegmentIndex | ( | const QPointF & | point,
|  | qreal | delta = `Delta`
| ) |  | const

Return index of closest segment.

Parameters

  point | The point which is to be tested for closeness.

Returns
  Index of the line segment closest to the point passed; -1 if no line segment is closer to passed in point.

## ◆ count()

int AssociationLine::count | ( |  | ) | const

Returns the amount of POINTS on the line. Includes start and end points.

Returns
  number of points in the AssociationLine

## ◆ createBezierCurve()

QPainterPath AssociationLine::createBezierCurve | ( | QVector< QPointF > | points | ) |
| staticprivate

Returns a Bézier path from given points.

Parameters

  points | points which define the Bézier curve

Returns
  cubic Bézier spline

## ◆ createCollaborationLine()

void AssociationLine::createCollaborationLine | ( |  | ) |
| private

Constructs the open arrow symbol and arrow line, that would represent Collaboration line.

## ◆ createOrthogonalPath()

QPainterPath AssociationLine::createOrthogonalPath | ( | QVector< QPointF > | points | ) |
| staticprivate

Returns an orthogonal path constructed of vertical and horizontal segments through the given points.

Parameters

  points | base points for the path

Returns
  orthogonal path

## ◆ createSplinePoints()

void AssociationLine::createSplinePoints | ( |  | ) |
| private

For a cubic Bezier curve at least four points are needed. If there are less, the missing points will be created. Note: Implementation is only for two points.

## ◆ createSubsetSymbol()

void AssociationLine::createSubsetSymbol | ( |  | ) |
| private

Constructs a new subset symbol.

## ◆ dumpPoints()

void AssociationLine::dumpPoints | ( |  | ) |

Debug helper method to write out the points.

## ◆ enableAutoLayout()

bool AssociationLine::enableAutoLayout | ( |  | ) |

## ◆ endPoint()

QPointF AssociationLine::endPoint | ( |  | ) | const

Shortcut for end point.

## ◆ fromString()

Uml::LayoutType::Enum AssociationLine::fromString | ( | const QString & | layout | ) |
| static

Convert string to enum LayoutType.

## ◆ hoverEnterEvent()

void AssociationLine::hoverEnterEvent | ( | QGraphicsSceneHoverEvent * | event | ) |

Calculates the "to be highlighted" point and segment indicies and updates if necessary.

## ◆ hoverLeaveEvent()

void AssociationLine::hoverLeaveEvent | ( | QGraphicsSceneHoverEvent * | event | ) |

Reset active indicies and updates.

## ◆ hoverMoveEvent()

void AssociationLine::hoverMoveEvent | ( | QGraphicsSceneHoverEvent * | event | ) |

Calculates the "to be highlighted" point and segment indicies and updates if necessary.

## ◆ insertPoint()

void AssociationLine::insertPoint | ( | int | index,
|  | const QPointF & | point
| ) |  |

Inserts the passed in point at the index passed in and recalculates the bounding rect.

## ◆ isAutoLayouted()

bool AssociationLine::isAutoLayouted | ( |  | ) | const

## ◆ isEndPointIndex()

bool AssociationLine::isEndPointIndex | ( | int | index | ) | const

Retval True If point at index is start or end.

## ◆ isEndSegmentIndex()

bool AssociationLine::isEndSegmentIndex | ( | int | index | ) | const

Retval True If segment at index is start or end.

## ◆ layout()

Uml::LayoutType::Enum AssociationLine::layout | ( |  | ) | const

Return the layout type of the association line.

Returns
  the currently used layout

## ◆ loadFromXMI1()

bool AssociationLine::loadFromXMI1 | ( | QDomElement & | qElement | ) |

Loads AssociationLine information saved in qElement XMI element.

## ◆ mouseMoveEvent()

void AssociationLine::mouseMoveEvent | ( | QGraphicsSceneMouseEvent * | event | ) |

Moves the point or line if active.

## ◆ mousePressEvent()

void AssociationLine::mousePressEvent | ( | QGraphicsSceneMouseEvent * | event | ) |

Determines the active point or segment, the latter being given more priority.

## ◆ mouseReleaseEvent()

void AssociationLine::mouseReleaseEvent | ( | QGraphicsSceneMouseEvent * | event | ) |

Reset active indices and also push undo command.

## ◆ optimizeLinePoints()

void AssociationLine::optimizeLinePoints | ( |  | ) |

This method optimizes the number of points in the AssociationLine. This can be used to reduce the clutter caused due to too many points. TODO: Use delta comparison 'closestPointIndex' instead of exact comparison. TODO: Not used anywhere.

## ◆ paint()

void AssociationLine::paint | ( | QPainter * | painter,
|  | const QStyleOptionGraphicsItem * | option,
|  | QWidget * | widget
| ) |  |
| virtual

Reimplemented from QGraphicsItem::paint. Draws the AssociationLine and also takes care of highlighting active point or line.

## ◆ path()

QPainterPath AssociationLine::path | ( |  | ) | const

Returns
  The path of the AssociationLine.

## ◆ pen()

QPen AssociationLine::pen | ( |  | ) | const

Returns the pen used for drawing.

## ◆ point()

QPointF AssociationLine::point | ( | int | index | ) | const

Returns the point at the point index.

Returns
  point at given index

## ◆ reconstructSymbols()

void AssociationLine::reconstructSymbols | ( |  | ) |

This method creates, deletes symbols and collaboration lines based on m_associationWidget->associationType().

Call this method when associationType of m_associationWidget changes.

## ◆ removeCollaborationLine()

void AssociationLine::removeCollaborationLine | ( |  | ) |
| private

Removes collaboration line by deleting the head and line item.

## ◆ removePoint()

void AssociationLine::removePoint | ( | int | index | ) |

Removes the point at index passed in.

See also
  removeNonEndPoint

## ◆ removeSubsetSymbol()

void AssociationLine::removeSubsetSymbol | ( |  | ) |
| private

Removes the subset symbol if it existed by deleting appropriate items.

## ◆ saveToXMI1()

void AssociationLine::saveToXMI1 | ( | QXmlStreamWriter & | writer | ) |

Saves association line information into XMI element named "linepath".

Note
  Stored as linepath for backward compatibility

## ◆ setEndPoints()

bool AssociationLine::setEndPoints | ( | const QPointF & | start,
|  | const QPointF & | end
| ) |  |

Sets the start and end points.

## ◆ setEndSymbol()

void AssociationLine::setEndSymbol | ( | Symbol::SymbolType | symbolType | ) |
| private

Sets the Symbol to appear at the last line segment to symbol.

If symbol == Symbol::None , then it deletes the symbol item.

## ◆ setLayout()

void AssociationLine::setLayout | ( | Uml::LayoutType::Enum | layout | ) |

Set the layout type of the association line.

Parameters

  layout | the desired layout to set

## ◆ setPen()

void AssociationLine::setPen | ( | const QPen & | pen | ) |

Setup new pen.

## ◆ setPoint()

bool AssociationLine::setPoint | ( | int | index,
|  | const QPointF & | point
| ) |  |

Sets the point value at given index to point.

## ◆ setStartSymbol()

void AssociationLine::setStartSymbol | ( | Symbol::SymbolType | symbolType | ) |
| private

Sets the Symbol to appear at the first line segment to symbol.

If symbol == Symbol::None , then it deletes the symbol item.

## ◆ shape()

QPainterPath AssociationLine::shape | ( |  | ) | const

Returns
  The shape of the AssociationLine.

## ◆ startPoint()

QPointF AssociationLine::startPoint | ( |  | ) | const

Shortcut for point(0).

## ◆ toString()

QString AssociationLine::toString | ( | Uml::LayoutType::Enum | layout | ) |
| static

Convert enum LayoutType to string.

## ◆ updatePenStyle()

void AssociationLine::updatePenStyle | ( |  | ) |

Update pen style depending on the association type of the related AssociationWidget instance.

## Member Data Documentation

## ◆ c1dx

qreal AssociationLine::c1dx {0.0}
| private

## ◆ c1dy

qreal AssociationLine::c1dy {0.0}
| private

## ◆ c2dx

qreal AssociationLine::c2dx {0.0}
| private

## ◆ c2dy

qreal AssociationLine::c2dy {0.0}
| private

## ◆ Delta

const qreal AssociationLine::Delta = 5
| staticprivate

default delta for fuzzy recognition of points closer to point

## ◆ m_activePointIndex

int AssociationLine::m_activePointIndex
| private

index of active point which can be dragged to modify association line

## ◆ m_activeSegmentIndex

int AssociationLine::m_activeSegmentIndex
| private

index of active segment

## ◆ m_associationWidget

AssociationWidget* AssociationLine::m_associationWidget
| private

association widget which this line represents

## ◆ m_autoLayoutSpline

bool AssociationLine::m_autoLayoutSpline
| private

## ◆ m_collaborationLineHead

Symbol* AssociationLine::m_collaborationLineHead
| private

arrow head drawn at end of m_collaborationLineItem

## ◆ m_collaborationLineItem

QGraphicsLineItem* AssociationLine::m_collaborationLineItem
| private

parallel arrow line drawn in case of collaboration message

## ◆ m_endSymbol

Symbol* AssociationLine::m_endSymbol
| private

symbol drawn at the end of "last" line segment

## ◆ m_layout

Uml::LayoutType::Enum AssociationLine::m_layout
| private

## ◆ m_pen

QPen AssociationLine::m_pen
| private

pen used to draw an association line

## ◆ m_points

QVector<QPointF> AssociationLine::m_points
| private

points representing the association line

## ◆ m_startSymbol

Symbol* AssociationLine::m_startSymbol
| private

symbol drawn at the end of "first" line segment

## ◆ m_subsetSymbol

Symbol* AssociationLine::m_subsetSymbol
| private

subset symbol

## ◆ SelectedPointDiameter

const qreal AssociationLine::SelectedPointDiameter = 4
| staticprivate

radius of circles drawn to show "selection"

## ◆ SelfAssociationMinimumHeight

const qreal AssociationLine::SelfAssociationMinimumHeight = 30
| staticprivate

minimum height for self association's loop

The documentation for this class was generated from the following files:

- umbrello/umlwidgets/associationline.h
- umbrello/umlwidgets/associationline.cpp