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

Arrow

Methods

AssociationWidget Constructor
calculateEndingPoints_center Method to calculate the ending points of the association widget.
calculateEndingPoints_rectangle Method to calculate the ending points of the association widget.
findIntersection Method to calculate the intersection point of two lines.
findPointRegion Method to find out, which region of rectangle rect contains the point
findRectIntersectionPoint Method to find the intersetion point of a line with a rectangle.
updateEndPoint Method to update an endpoint.
widgetMoved 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)
type
type of the association. This must be one of
widgetA
first widget of the association
widgetB
second widget of the association

AssociationWidget.calculateEndingPoints_center

calculateEndingPoints_center()

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()

Method to calculate the ending points of the association widget. The ending points are calculate 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, -1). 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 (QPoint)
p2
second point of first line (QPoint)
p3
first point of second line (QPoint)
p4
second point of second line (QPoint)
Returns:
the intersection point (QPoint)

AssociationWidget.findPointRegion

findPointRegion(rect, posX, posY)

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

posX
x position of point
posY
y position of point
rect
rectangle to calculate the region for
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)

Method to find the intersetion point of a line with a rectangle.

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

AssociationWidget.updateEndPoint

updateEndPoint(region, widgetA)

Method to update an endpoint.

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

AssociationWidget.widgetMoved

widgetMoved()

Method to recalculate the association after a widget was moved.

Up