|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' |
|
3 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'> |
|
4 <html><head> |
|
5 <title>eric5.Graphics.AssociationItem</title> |
|
6 <style> |
|
7 b'body {\n background:white;\n margin: 0em 1em 10em 1em;\n color: black;\n}\n\nh1 { color: white; background: #4FA4FF; }\nh2 { color: white; background: #4FA4FF; }\nh3 { color: white; background: #00557F; }\nh4 { color: white; background: #00557F; }\n \na { color: #AA5500; }\n' |
|
8 </style> |
|
9 </head> |
|
10 <body><a NAME="top" ID="top"></a> |
|
11 <h1>eric5.Graphics.AssociationItem</h1> |
|
12 <p> |
|
13 Module implementing a graphics item for an association between two items. |
|
14 </p> |
|
15 <h3>Global Attributes</h3> |
|
16 <table> |
|
17 <tr><td>Center</td></tr><tr><td>East</td></tr><tr><td>Generalisation</td></tr><tr><td>Imports</td></tr><tr><td>NoRegion</td></tr><tr><td>Normal</td></tr><tr><td>North</td></tr><tr><td>NorthEast</td></tr><tr><td>NorthWest</td></tr><tr><td>South</td></tr><tr><td>SouthEast</td></tr><tr><td>SouthWest</td></tr><tr><td>West</td></tr> |
|
18 </table> |
|
19 <h3>Classes</h3> |
|
20 <table> |
|
21 <tr> |
|
22 <td><a href="#AssociationItem">AssociationItem</a></td> |
|
23 <td>Class implementing a graphics item for an association between two items.</td> |
|
24 </tr> |
|
25 </table> |
|
26 <h3>Functions</h3> |
|
27 <table> |
|
28 <tr><td>None</td></tr> |
|
29 </table> |
|
30 <hr /><hr /> |
|
31 <a NAME="AssociationItem" ID="AssociationItem"></a> |
|
32 <h2>AssociationItem</h2> |
|
33 <p> |
|
34 Class implementing a graphics item for an association between two items. |
|
35 </p><p> |
|
36 The association is drawn as an arrow starting at the first items and |
|
37 ending at the second. |
|
38 </p> |
|
39 <h3>Derived from</h3> |
|
40 E4ArrowItem |
|
41 <h3>Class Attributes</h3> |
|
42 <table> |
|
43 <tr><td>None</td></tr> |
|
44 </table> |
|
45 <h3>Methods</h3> |
|
46 <table> |
|
47 <tr> |
|
48 <td><a href="#AssociationItem.__init__">AssociationItem</a></td> |
|
49 <td>Constructor</td> |
|
50 </tr><tr> |
|
51 <td><a href="#AssociationItem.__calculateEndingPoints_center">__calculateEndingPoints_center</a></td> |
|
52 <td>Private method to calculate the ending points of the association item.</td> |
|
53 </tr><tr> |
|
54 <td><a href="#AssociationItem.__calculateEndingPoints_rectangle">__calculateEndingPoints_rectangle</a></td> |
|
55 <td>Private method to calculate the ending points of the association item.</td> |
|
56 </tr><tr> |
|
57 <td><a href="#AssociationItem.__findIntersection">__findIntersection</a></td> |
|
58 <td>Method to calculate the intersection point of two lines.</td> |
|
59 </tr><tr> |
|
60 <td><a href="#AssociationItem.__findPointRegion">__findPointRegion</a></td> |
|
61 <td>Private method to find out, which region of rectangle rect contains the point (PosX, PosY) and returns the region number.</td> |
|
62 </tr><tr> |
|
63 <td><a href="#AssociationItem.__findRectIntersectionPoint">__findRectIntersectionPoint</a></td> |
|
64 <td>Private method to find the intersetion point of a line with a rectangle.</td> |
|
65 </tr><tr> |
|
66 <td><a href="#AssociationItem.__mapRectFromItem">__mapRectFromItem</a></td> |
|
67 <td>Private method to map item's rectangle to this item's coordinate system.</td> |
|
68 </tr><tr> |
|
69 <td><a href="#AssociationItem.__updateEndPoint">__updateEndPoint</a></td> |
|
70 <td>Private method to update an endpoint.</td> |
|
71 </tr><tr> |
|
72 <td><a href="#AssociationItem.unassociate">unassociate</a></td> |
|
73 <td>Public method to unassociate from the widgets.</td> |
|
74 </tr><tr> |
|
75 <td><a href="#AssociationItem.widgetMoved">widgetMoved</a></td> |
|
76 <td>Public method to recalculate the association after a widget was moved.</td> |
|
77 </tr> |
|
78 </table> |
|
79 <a NAME="AssociationItem.__init__" ID="AssociationItem.__init__"></a> |
|
80 <h4>AssociationItem (Constructor)</h4> |
|
81 <b>AssociationItem</b>(<i>itemA, itemB, type = Normal, parent = None</i>) |
|
82 <p> |
|
83 Constructor |
|
84 </p><dl> |
|
85 <dt><i>itemA</i></dt> |
|
86 <dd> |
|
87 first widget of the association |
|
88 </dd><dt><i>itemB</i></dt> |
|
89 <dd> |
|
90 second widget of the association |
|
91 </dd><dt><i>type</i></dt> |
|
92 <dd> |
|
93 type of the association. This must be one of |
|
94 <ul> |
|
95 <li>Normal (default)</li> |
|
96 <li>Generalisation</li> |
|
97 <li>Imports</li> |
|
98 </ul> |
|
99 </dd><dt><i>parent=</i></dt> |
|
100 <dd> |
|
101 reference to the parent object (QGraphicsItem) |
|
102 </dd> |
|
103 </dl><a NAME="AssociationItem.__calculateEndingPoints_center" ID="AssociationItem.__calculateEndingPoints_center"></a> |
|
104 <h4>AssociationItem.__calculateEndingPoints_center</h4> |
|
105 <b>__calculateEndingPoints_center</b>(<i></i>) |
|
106 <p> |
|
107 Private method to calculate the ending points of the association item. |
|
108 </p><p> |
|
109 The ending points are calculated from the centers of the |
|
110 two associated items. |
|
111 </p><a NAME="AssociationItem.__calculateEndingPoints_rectangle" ID="AssociationItem.__calculateEndingPoints_rectangle"></a> |
|
112 <h4>AssociationItem.__calculateEndingPoints_rectangle</h4> |
|
113 <b>__calculateEndingPoints_rectangle</b>(<i></i>) |
|
114 <p> |
|
115 Private method to calculate the ending points of the association item. |
|
116 </p><p> |
|
117 The ending points are calculated by the following method. |
|
118 </p><p> |
|
119 For each item the diagram is divided in four Regions by its diagonals |
|
120 as indicated below |
|
121 <pre> |
|
122 \ Region 2 / |
|
123 \ / |
|
124 |--------| |
|
125 | \ / | |
|
126 | \ / | |
|
127 | \/ | |
|
128 Region 1 | /\ | Region 3 |
|
129 | / \ | |
|
130 | / \ | |
|
131 |--------| |
|
132 / \ |
|
133 / Region 4 \ |
|
134 </pre> |
|
135 </p><p> |
|
136 Each diagonal is defined by two corners of the bounding rectangle |
|
137 </p><p> |
|
138 To calculate the start point we have to find out in which |
|
139 region (defined by itemA's diagonals) is itemB's TopLeft corner |
|
140 (lets call it region M). After that the start point will be |
|
141 the middle point of rectangle's side contained in region M. |
|
142 </p><p> |
|
143 To calculate the end point we repeat the above but in the opposite direction |
|
144 (from itemB to itemA) |
|
145 </p><a NAME="AssociationItem.__findIntersection" ID="AssociationItem.__findIntersection"></a> |
|
146 <h4>AssociationItem.__findIntersection</h4> |
|
147 <b>__findIntersection</b>(<i>p1, p2, p3, p4</i>) |
|
148 <p> |
|
149 Method to calculate the intersection point of two lines. |
|
150 </p><p> |
|
151 The first line is determined by the points p1 and p2, the second |
|
152 line by p3 and p4. If the intersection point is not contained in |
|
153 the segment p1p2, then it returns (-1.0, -1.0). |
|
154 </p><p> |
|
155 For the function's internal calculations remember:<br /> |
|
156 QT coordinates start with the point (0,0) as the topleft corner |
|
157 and x-values increase from left to right and y-values increase |
|
158 from top to bottom; it means the visible area is quadrant I in |
|
159 the regular XY coordinate system |
|
160 </p><p> |
|
161 <pre> |
|
162 Quadrant II | Quadrant I |
|
163 -----------------|----------------- |
|
164 Quadrant III | Quadrant IV |
|
165 </pre> |
|
166 </p><p> |
|
167 In order for the linear function calculations to work in this method |
|
168 we must switch x and y values (x values become y values and viceversa) |
|
169 </p><dl> |
|
170 <dt><i>p1</i></dt> |
|
171 <dd> |
|
172 first point of first line (QPointF) |
|
173 </dd><dt><i>p2</i></dt> |
|
174 <dd> |
|
175 second point of first line (QPointF) |
|
176 </dd><dt><i>p3</i></dt> |
|
177 <dd> |
|
178 first point of second line (QPointF) |
|
179 </dd><dt><i>p4</i></dt> |
|
180 <dd> |
|
181 second point of second line (QPointF) |
|
182 </dd> |
|
183 </dl><dl> |
|
184 <dt>Returns:</dt> |
|
185 <dd> |
|
186 the intersection point (QPointF) |
|
187 </dd> |
|
188 </dl><a NAME="AssociationItem.__findPointRegion" ID="AssociationItem.__findPointRegion"></a> |
|
189 <h4>AssociationItem.__findPointRegion</h4> |
|
190 <b>__findPointRegion</b>(<i>rect, posX, posY</i>) |
|
191 <p> |
|
192 Private method to find out, which region of rectangle rect contains the point |
|
193 (PosX, PosY) and returns the region number. |
|
194 </p><dl> |
|
195 <dt><i>rect</i></dt> |
|
196 <dd> |
|
197 rectangle to calculate the region for (QRectF) |
|
198 </dd><dt><i>posX</i></dt> |
|
199 <dd> |
|
200 x position of point (float) |
|
201 </dd><dt><i>posY</i></dt> |
|
202 <dd> |
|
203 y position of point (float) |
|
204 </dd> |
|
205 </dl><dl> |
|
206 <dt>Returns:</dt> |
|
207 <dd> |
|
208 the calculated region number<br /> |
|
209 West = Region 1<br /> |
|
210 North = Region 2<br /> |
|
211 East = Region 3<br /> |
|
212 South = Region 4<br /> |
|
213 NorthWest = On diagonal 2 between Region 1 and 2<br /> |
|
214 NorthEast = On diagonal 1 between Region 2 and 3<br /> |
|
215 SouthEast = On diagonal 2 between Region 3 and 4<br /> |
|
216 SouthWest = On diagonal 1 between Region4 and 1<br /> |
|
217 Center = On diagonal 1 and On diagonal 2 (the center)<br /> |
|
218 </dd> |
|
219 </dl><a NAME="AssociationItem.__findRectIntersectionPoint" ID="AssociationItem.__findRectIntersectionPoint"></a> |
|
220 <h4>AssociationItem.__findRectIntersectionPoint</h4> |
|
221 <b>__findRectIntersectionPoint</b>(<i>item, p1, p2</i>) |
|
222 <p> |
|
223 Private method to find the intersetion point of a line with a rectangle. |
|
224 </p><dl> |
|
225 <dt><i>item</i></dt> |
|
226 <dd> |
|
227 item to check against |
|
228 </dd><dt><i>p1</i></dt> |
|
229 <dd> |
|
230 first point of the line (QPointF) |
|
231 </dd><dt><i>p2</i></dt> |
|
232 <dd> |
|
233 second point of the line (QPointF) |
|
234 </dd> |
|
235 </dl><dl> |
|
236 <dt>Returns:</dt> |
|
237 <dd> |
|
238 the intersection point (QPointF) |
|
239 </dd> |
|
240 </dl><a NAME="AssociationItem.__mapRectFromItem" ID="AssociationItem.__mapRectFromItem"></a> |
|
241 <h4>AssociationItem.__mapRectFromItem</h4> |
|
242 <b>__mapRectFromItem</b>(<i>item</i>) |
|
243 <p> |
|
244 Private method to map item's rectangle to this item's coordinate system. |
|
245 </p><dl> |
|
246 <dt><i>item</i></dt> |
|
247 <dd> |
|
248 reference to the item to be mapped (QGraphicsRectItem) |
|
249 </dd> |
|
250 </dl><dl> |
|
251 <dt>Returns:</dt> |
|
252 <dd> |
|
253 item's rectangle in local coordinates (QRectF) |
|
254 </dd> |
|
255 </dl><a NAME="AssociationItem.__updateEndPoint" ID="AssociationItem.__updateEndPoint"></a> |
|
256 <h4>AssociationItem.__updateEndPoint</h4> |
|
257 <b>__updateEndPoint</b>(<i>region, isWidgetA</i>) |
|
258 <p> |
|
259 Private method to update an endpoint. |
|
260 </p><dl> |
|
261 <dt><i>region</i></dt> |
|
262 <dd> |
|
263 the region for the endpoint (integer) |
|
264 </dd><dt><i>isWidgetA</i></dt> |
|
265 <dd> |
|
266 flag indicating update for itemA is done (boolean) |
|
267 </dd> |
|
268 </dl><a NAME="AssociationItem.unassociate" ID="AssociationItem.unassociate"></a> |
|
269 <h4>AssociationItem.unassociate</h4> |
|
270 <b>unassociate</b>(<i></i>) |
|
271 <p> |
|
272 Public method to unassociate from the widgets. |
|
273 </p><a NAME="AssociationItem.widgetMoved" ID="AssociationItem.widgetMoved"></a> |
|
274 <h4>AssociationItem.widgetMoved</h4> |
|
275 <b>widgetMoved</b>(<i></i>) |
|
276 <p> |
|
277 Public method to recalculate the association after a widget was moved. |
|
278 </p> |
|
279 <div align="right"><a href="#top">Up</a></div> |
|
280 <hr /> |
|
281 </body></html> |