eric4.Graphics.AssociationWidget

Module implementing a canvas widget for an association between two widgets.

Classes

AssociationWidget Class implementing a canvas widget for an association between two widgets.

Functions

None


AssociationWidget

Class implementing a canvas widget for an association between two widgets.

The association is drawn as an arrow starting at the first widget and ending at the second.

Derived from

E4CanvasArrow

Methods

AssociationWidget Constructor
__calculateEndingPoints_center Private method to calculate the ending points of the association widget.
__calculateEndingPoints_rectangle Private method to calculate the ending points of the association widget.
__findIntersection Method to calculate the intersection point of two lines.
__findPointRegion Private method to find out, which region of rectangle rect contains the point (PosX, PosY) and returns the region number.
__findRectIntersectionPoint Private method to find the intersetion point of a line with a rectangle.
__updateEndPoint Private method to update an endpoint.
unassociate Public method to unassociate from the widgets.
widgetMoved Public method to recalculate the association after a widget was moved.

AssociationWidget (Constructor)

AssociationWidget(canvas, widgetA, widgetB, type = Normal)

Constructor

canvas
canvas containing the association (QCanvas)
widgetA
first widget of the association
widgetB
second widget of the association
type
type of the association. This must be one of

AssociationWidget.__calculateEndingPoints_center

__calculateEndingPoints_center()

Private method to calculate the ending points of the association widget.

The ending points are calculated from the centers of the two associated widgets.

AssociationWidget.__calculateEndingPoints_rectangle

__calculateEndingPoints_rectangle()

Private method to calculate the ending points of the association widget.

The ending points are calculated by the following method.

For each Widget the diagram is divided in four Regions by its diagonals as indicated below

                   \  Region 2  /
                    \          /
                     |--------|
                     | \    / |
                     |  \  /  |
                     |   \/   |
            Region 1 |   /\   | Region 3
                     |  /  \  |
                     | /    \ |
                     |--------|
                    /          \
                   /  Region 4  \
        

Each diagonal is defined by two corners of the bounding rectangle

To calculate the start point we have to find out in which region (defined by widgetA's diagonals) is widgetB's TopLeft corner (lets call it region M) after that the start point will be the middle point of rectangle's side contained in region M.

To calculate the end point we repeat the above but in the opposite direction (from widgetB to widgetA)

AssociationWidget.__findIntersection

__findIntersection(p1, p2, p3, p4)

Method to calculate the intersection point of two lines.

The first line is determined by the points p1 and p2, the second line by p3 and p4. If the intersection point is not contained in the segment p1p2, then it returns (-1.0, -1.0).

For the function's internal calculations remember:
QT coordinates start with the point (0,0) as the topleft corner and x-values increase from left to right and y-values increase from top to bottom; it means the visible area is quadrant I in the regular XY coordinate system

            Quadrant II     |   Quadrant I
           -----------------|-----------------
            Quadrant III    |   Quadrant IV
        

In order for the linear function calculations to work in this method we must switch x and y values (x values become y values and viceversa)

p1
first point of first line (QPointF)
p2
second point of first line (QPointF)
p3
first point of second line (QPointF)
p4
second point of second line (QPointF)
Returns:
the intersection point (QPointF)

AssociationWidget.__findPointRegion

__findPointRegion(rect, posX, posY)

Private method to find out, which region of rectangle rect contains the point (PosX, PosY) and returns the region number.

rect
rectangle to calculate the region for (QRectF)
posX
x position of point (float)
posY
y position of point (float)
Returns:
the calculated region number
West = Region 1
North = Region 2
East = Region 3
South = Region 4
NorthWest = On diagonal 2 between Region 1 and 2
NorthEast = On diagonal 1 between Region 2 and 3
SouthEast = On diagonal 2 between Region 3 and 4
SouthWest = On diagonal 1 between Region4 and 1
Center = On diagonal 1 and On diagonal 2 (the center)

AssociationWidget.__findRectIntersectionPoint

__findRectIntersectionPoint(widget, p1, p2)

Private method to find the intersetion point of a line with a rectangle.

widget
widget to check against
p1
first point of the line (QPointF)
p2
second point of the line (QPointF)
Returns:
the intersection point (QPointF)

AssociationWidget.__updateEndPoint

__updateEndPoint(region, isWidgetA)

Private method to update an endpoint.

region
the region for the endpoint (integer)
isWidgetA
flag indicating update for widgetA is done (boolean)

AssociationWidget.unassociate

unassociate()

Public method to unassociate from the widgets.

AssociationWidget.widgetMoved

widgetMoved()

Public method to recalculate the association after a widget was moved.

Up