umbrello 2.34.70-5524f40e1
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:
Collaboration 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 loadFromXMI (QDomElement &qElement)
 
void saveToXMI (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

AssociationWidgetm_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...
 
Symbolm_startSymbol
 symbol drawn at the end of "first" line segment More...
 
Symbolm_endSymbol
 symbol drawn at the end of "last" line segment More...
 
Symbolm_subsetSymbol
 subset symbol More...
 
QGraphicsLineItem * m_collaborationLineItem
 parallel arrow line drawn in case of collaboration message More...
 
Symbolm_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 m_c1dx {0.0}
 
qreal m_c1dy {0.0}
 
qreal m_c2dx {0.0}
 
qreal m_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 slaved to the given AssociationWidget.

◆ ~AssociationLine()

AssociationLine::~AssociationLine ( )
virtual

Destructor.

Here is the call graph for this function:

Member Function Documentation

◆ addPoint()

void AssociationLine::addPoint ( const QPointF &  point)
Here is the call graph for this function:

◆ 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.

Here is the call graph for this function:

◆ 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.

Here is the call graph for this function:

◆ calculateInitialEndPoints()

void AssociationLine::calculateInitialEndPoints ( )

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

Here is the call graph for this function:

◆ cleanup()

void AssociationLine::cleanup ( )

Removes all the points and signals a geometry update.

Here is the call graph for this function:

◆ closestPointIndex()

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

Return index of point closer a given delta.

Parameters
pointThe point which is to be tested for closeness.
deltaThe distance the point should be closer to.
Return values
Indexof the first line point closer to the point passed.
-1If no line point is closer to passed in point.
Here is the call graph for this function:

◆ closestSegmentIndex()

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

Return index of closest segment.

Parameters
pointThe point which is to be tested for closeness.
deltaThe distance in pixels that the point may be removed from a segment but is still considered to be on the segment.
Returns
Index of the line segment closest to the point passed; -1 if no line segment is closer to passed in point.
Here is the call graph for this function:

◆ 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
pointspoints which define the Bézier curve
Returns
cubic Bézier spline
Here is the call graph for this function:

◆ createCollaborationLine()

void AssociationLine::createCollaborationLine ( )
private

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

Here is the call graph for this function:

◆ createOrthogonalPath()

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

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

Parameters
pointsbase points for the path
Returns
orthogonal path
Here is the call graph for this function:

◆ 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.

Here is the call graph for this function:

◆ createSubsetSymbol()

void AssociationLine::createSubsetSymbol ( )
private

Constructs a new subset symbol.

Here is the call graph for this function:

◆ dumpPoints()

void AssociationLine::dumpPoints ( )

Debug helper method to write out the points.

◆ enableAutoLayout()

bool AssociationLine::enableAutoLayout ( )
Here is the call graph for this function:

◆ endPoint()

QPointF AssociationLine::endPoint ( ) const

Shortcut for end point.

◆ fromString()

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

Convert string to enum LayoutType.

Here is the call graph for this function:

◆ hoverEnterEvent()

void AssociationLine::hoverEnterEvent ( QGraphicsSceneHoverEvent *  event)

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

Here is the call graph for this function:

◆ hoverLeaveEvent()

void AssociationLine::hoverLeaveEvent ( QGraphicsSceneHoverEvent *  event)

Reset active indices and updates.

◆ hoverMoveEvent()

void AssociationLine::hoverMoveEvent ( QGraphicsSceneHoverEvent *  event)

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

Here is the call graph for this function:

◆ insertPoint()

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

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

Here is the call graph for this function:

◆ 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

◆ loadFromXMI()

bool AssociationLine::loadFromXMI ( QDomElement &  qElement)

Loads AssociationLine information saved in qElement XMI element.

Here is the call graph for this function:

◆ mouseMoveEvent()

void AssociationLine::mouseMoveEvent ( QGraphicsSceneMouseEvent *  event)

Moves the point or line if active.

Here is the call graph for this function:

◆ mousePressEvent()

void AssociationLine::mousePressEvent ( QGraphicsSceneMouseEvent *  event)

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

Here is the call graph for this function:

◆ 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.

Here is the call graph for this function:

◆ 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.

Here is the call graph for this function:

◆ path()

QPainterPath AssociationLine::path ( ) const
Returns
The path of the AssociationLine.
Here is the call graph for this function:

◆ 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.

Here is the call graph for this function:

◆ 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
Here is the call graph for this function:

◆ removeSubsetSymbol()

void AssociationLine::removeSubsetSymbol ( )
private

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

◆ saveToXMI()

void AssociationLine::saveToXMI ( QXmlStreamWriter &  writer)

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

Note
Stored as linepath for backward compatibility
Here is the call graph for this function:

◆ setEndPoints()

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

Sets the start and end points.

Here is the call graph for this function:

◆ 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.

Here is the call graph for this function:

◆ setLayout()

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

Set the layout type of the association line.

Parameters
layoutthe desired layout to set
Here is the call graph for this function:

◆ setPen()

void AssociationLine::setPen ( const QPen &  pen)

Setup new pen.

Here is the call graph for this function:

◆ setPoint()

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

Sets the point value at given index to point.

Here is the call graph for this function:

◆ 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.

Here is the call graph for this function:

◆ shape()

QPainterPath AssociationLine::shape ( ) const
Returns
The shape of the AssociationLine.
Here is the call graph for this function:

◆ startPoint()

QPointF AssociationLine::startPoint ( ) const

Shortcut for point(0).

◆ toString()

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

Convert enum LayoutType to string.

Here is the call graph for this function:

◆ updatePenStyle()

void AssociationLine::updatePenStyle ( )

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

Here is the call graph for this function:

Member Data Documentation

◆ 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_c1dx

qreal AssociationLine::m_c1dx {0.0}
private

◆ m_c1dy

qreal AssociationLine::m_c1dy {0.0}
private

◆ m_c2dx

qreal AssociationLine::m_c2dx {0.0}
private

◆ m_c2dy

qreal AssociationLine::m_c2dy {0.0}
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: