|
1 <!DOCTYPE html> |
|
2 <html><head> |
|
3 <title>eric7.Graphics.AssociationItem</title> |
|
4 <meta charset="UTF-8"> |
|
5 <link rel="stylesheet" href="styles.css"> |
|
6 </head> |
|
7 <body> |
|
8 <a NAME="top" ID="top"></a> |
|
9 <h1>eric7.Graphics.AssociationItem</h1> |
|
10 |
|
11 <p> |
|
12 Module implementing a graphics item for an association between two items. |
|
13 </p> |
|
14 <h3>Global Attributes</h3> |
|
15 |
|
16 <table> |
|
17 <tr><td>None</td></tr> |
|
18 </table> |
|
19 <h3>Classes</h3> |
|
20 |
|
21 <table> |
|
22 |
|
23 <tr> |
|
24 <td><a href="#AssociationItem">AssociationItem</a></td> |
|
25 <td>Class implementing a graphics item for an association between two items.</td> |
|
26 </tr> |
|
27 <tr> |
|
28 <td><a href="#AssociationPointRegion">AssociationPointRegion</a></td> |
|
29 <td>Class defining the regions for an association end point.</td> |
|
30 </tr> |
|
31 <tr> |
|
32 <td><a href="#AssociationType">AssociationType</a></td> |
|
33 <td>Class defining the association types.</td> |
|
34 </tr> |
|
35 </table> |
|
36 <h3>Functions</h3> |
|
37 |
|
38 <table> |
|
39 <tr><td>None</td></tr> |
|
40 </table> |
|
41 <hr /> |
|
42 <hr /> |
|
43 <a NAME="AssociationItem" ID="AssociationItem"></a> |
|
44 <h2>AssociationItem</h2> |
|
45 |
|
46 <p> |
|
47 Class implementing a graphics item for an association between two items. |
|
48 </p> |
|
49 <p> |
|
50 The association is drawn as an arrow starting at the first items and |
|
51 ending at the second. |
|
52 </p> |
|
53 <h3>Derived from</h3> |
|
54 EricArrowItem |
|
55 <h3>Class Attributes</h3> |
|
56 |
|
57 <table> |
|
58 <tr><td>None</td></tr> |
|
59 </table> |
|
60 <h3>Class Methods</h3> |
|
61 |
|
62 <table> |
|
63 |
|
64 <tr> |
|
65 <td><a href="#AssociationItem.fromDict">fromDict</a></td> |
|
66 <td>Class method to create an association item from persisted data.</td> |
|
67 </tr> |
|
68 <tr> |
|
69 <td><a href="#AssociationItem.parseAssociationItemDataString">parseAssociationItemDataString</a></td> |
|
70 <td>Class method to parse the given persistence data.</td> |
|
71 </tr> |
|
72 </table> |
|
73 <h3>Methods</h3> |
|
74 |
|
75 <table> |
|
76 |
|
77 <tr> |
|
78 <td><a href="#AssociationItem.__init__">AssociationItem</a></td> |
|
79 <td>Constructor</td> |
|
80 </tr> |
|
81 <tr> |
|
82 <td><a href="#AssociationItem.__calculateEndingPoints_center">__calculateEndingPoints_center</a></td> |
|
83 <td>Private method to calculate the ending points of the association item.</td> |
|
84 </tr> |
|
85 <tr> |
|
86 <td><a href="#AssociationItem.__calculateEndingPoints_rectangle">__calculateEndingPoints_rectangle</a></td> |
|
87 <td>Private method to calculate the ending points of the association item.</td> |
|
88 </tr> |
|
89 <tr> |
|
90 <td><a href="#AssociationItem.__calculateEndingPoints_topToBottom">__calculateEndingPoints_topToBottom</a></td> |
|
91 <td>Private method to calculate the ending points of the association item.</td> |
|
92 </tr> |
|
93 <tr> |
|
94 <td><a href="#AssociationItem.__findIntersection">__findIntersection</a></td> |
|
95 <td>Private method to calculate the intersection point of two lines.</td> |
|
96 </tr> |
|
97 <tr> |
|
98 <td><a href="#AssociationItem.__findPointRegion">__findPointRegion</a></td> |
|
99 <td>Private method to find out, which region of rectangle rect contains the point (PosX, PosY) and returns the region number.</td> |
|
100 </tr> |
|
101 <tr> |
|
102 <td><a href="#AssociationItem.__findRectIntersectionPoint">__findRectIntersectionPoint</a></td> |
|
103 <td>Private method to find the intersection point of a line with a rectangle.</td> |
|
104 </tr> |
|
105 <tr> |
|
106 <td><a href="#AssociationItem.__mapRectFromItem">__mapRectFromItem</a></td> |
|
107 <td>Private method to map item's rectangle to this item's coordinate system.</td> |
|
108 </tr> |
|
109 <tr> |
|
110 <td><a href="#AssociationItem.__updateEndPoint">__updateEndPoint</a></td> |
|
111 <td>Private method to update an endpoint.</td> |
|
112 </tr> |
|
113 <tr> |
|
114 <td><a href="#AssociationItem.toDict">toDict</a></td> |
|
115 <td>Public method to collect data to be persisted.</td> |
|
116 </tr> |
|
117 <tr> |
|
118 <td><a href="#AssociationItem.unassociate">unassociate</a></td> |
|
119 <td>Public method to unassociate from the widgets.</td> |
|
120 </tr> |
|
121 <tr> |
|
122 <td><a href="#AssociationItem.widgetMoved">widgetMoved</a></td> |
|
123 <td>Public method to recalculate the association after a widget was moved.</td> |
|
124 </tr> |
|
125 </table> |
|
126 <h3>Static Methods</h3> |
|
127 |
|
128 <table> |
|
129 <tr><td>None</td></tr> |
|
130 </table> |
|
131 |
|
132 <a NAME="AssociationItem.fromDict" ID="AssociationItem.fromDict"></a> |
|
133 <h4>AssociationItem.fromDict (class method)</h4> |
|
134 <b>fromDict</b>(<i>data, umlItems, colors=None</i>) |
|
135 |
|
136 <p> |
|
137 Class method to create an association item from persisted data. |
|
138 </p> |
|
139 <dl> |
|
140 |
|
141 <dt><i>data</i> (dict)</dt> |
|
142 <dd> |
|
143 dictionary containing the persisted data as generated |
|
144 by toDict() |
|
145 </dd> |
|
146 <dt><i>umlItems</i> (list of UMLItem)</dt> |
|
147 <dd> |
|
148 list of UML items |
|
149 </dd> |
|
150 <dt><i>colors</i> (tuple of (QColor, QColor))</dt> |
|
151 <dd> |
|
152 tuple containing the foreground and background colors |
|
153 </dd> |
|
154 </dl> |
|
155 <dl> |
|
156 <dt>Return:</dt> |
|
157 <dd> |
|
158 created association item |
|
159 </dd> |
|
160 </dl> |
|
161 <dl> |
|
162 <dt>Return Type:</dt> |
|
163 <dd> |
|
164 AssociationItem |
|
165 </dd> |
|
166 </dl> |
|
167 <a NAME="AssociationItem.parseAssociationItemDataString" ID="AssociationItem.parseAssociationItemDataString"></a> |
|
168 <h4>AssociationItem.parseAssociationItemDataString (class method)</h4> |
|
169 <b>parseAssociationItemDataString</b>(<i>data</i>) |
|
170 |
|
171 <p> |
|
172 Class method to parse the given persistence data. |
|
173 </p> |
|
174 <dl> |
|
175 |
|
176 <dt><i>data</i> (str)</dt> |
|
177 <dd> |
|
178 persisted data to be parsed |
|
179 </dd> |
|
180 </dl> |
|
181 <dl> |
|
182 <dt>Return:</dt> |
|
183 <dd> |
|
184 tuple with the IDs of the source and destination items, |
|
185 the association type and a flag indicating to associate from top |
|
186 to bottom |
|
187 </dd> |
|
188 </dl> |
|
189 <dl> |
|
190 <dt>Return Type:</dt> |
|
191 <dd> |
|
192 tuple of (int, int, int, bool) |
|
193 </dd> |
|
194 </dl> |
|
195 <a NAME="AssociationItem.__init__" ID="AssociationItem.__init__"></a> |
|
196 <h4>AssociationItem (Constructor)</h4> |
|
197 <b>AssociationItem</b>(<i>itemA, itemB, assocType=AssociationType.NORMAL, topToBottom=False, colors=None, parent=None</i>) |
|
198 |
|
199 <p> |
|
200 Constructor |
|
201 </p> |
|
202 <dl> |
|
203 |
|
204 <dt><i>itemA</i> (UMLItem)</dt> |
|
205 <dd> |
|
206 first widget of the association |
|
207 </dd> |
|
208 <dt><i>itemB</i> (UMLItem)</dt> |
|
209 <dd> |
|
210 second widget of the association |
|
211 </dd> |
|
212 <dt><i>assocType</i> (AssociationType)</dt> |
|
213 <dd> |
|
214 type of the association |
|
215 </dd> |
|
216 <dt><i>topToBottom</i> (bool)</dt> |
|
217 <dd> |
|
218 flag indicating to draw the association |
|
219 from item A top to item B bottom |
|
220 </dd> |
|
221 <dt><i>colors</i> (tuple of (QColor, QColor))</dt> |
|
222 <dd> |
|
223 tuple containing the foreground and background colors |
|
224 </dd> |
|
225 <dt><i>parent</i> (QGraphicsItem)</dt> |
|
226 <dd> |
|
227 reference to the parent object |
|
228 </dd> |
|
229 </dl> |
|
230 <a NAME="AssociationItem.__calculateEndingPoints_center" ID="AssociationItem.__calculateEndingPoints_center"></a> |
|
231 <h4>AssociationItem.__calculateEndingPoints_center</h4> |
|
232 <b>__calculateEndingPoints_center</b>(<i></i>) |
|
233 |
|
234 <p> |
|
235 Private method to calculate the ending points of the association item. |
|
236 </p> |
|
237 <p> |
|
238 The ending points are calculated from the centers of the |
|
239 two associated items. |
|
240 </p> |
|
241 <a NAME="AssociationItem.__calculateEndingPoints_rectangle" ID="AssociationItem.__calculateEndingPoints_rectangle"></a> |
|
242 <h4>AssociationItem.__calculateEndingPoints_rectangle</h4> |
|
243 <b>__calculateEndingPoints_rectangle</b>(<i></i>) |
|
244 |
|
245 <p> |
|
246 Private method to calculate the ending points of the association item. |
|
247 </p> |
|
248 <p> |
|
249 The ending points are calculated by the following method. |
|
250 </p> |
|
251 <p> |
|
252 For each item the diagram is divided in four Regions by its diagonals |
|
253 as indicated below |
|
254 <pre> |
|
255 +------------------------------+ |
|
256 | \ Region 2 / | |
|
257 | \ / | |
|
258 | |--------| | |
|
259 | | \ / | | |
|
260 | | \ / | | |
|
261 | | \/ | | |
|
262 | Region 1 | /\ | Region 3 | |
|
263 | | / \ | | |
|
264 | | / \ | | |
|
265 | |--------| | |
|
266 | / \ | |
|
267 | / Region 4 \ | |
|
268 +------------------------------+ |
|
269 </pre> |
|
270 </p> |
|
271 <p> |
|
272 Each diagonal is defined by two corners of the bounding rectangle. |
|
273 </p> |
|
274 <p> |
|
275 To calculate the start point we have to find out in which |
|
276 region (defined by itemA's diagonals) is itemB's TopLeft corner |
|
277 (lets call it region M). After that the start point will be |
|
278 the middle point of rectangle's side contained in region M. |
|
279 </p> |
|
280 <p> |
|
281 To calculate the end point we repeat the above but in the opposite |
|
282 direction (from itemB to itemA) |
|
283 </p> |
|
284 <a NAME="AssociationItem.__calculateEndingPoints_topToBottom" ID="AssociationItem.__calculateEndingPoints_topToBottom"></a> |
|
285 <h4>AssociationItem.__calculateEndingPoints_topToBottom</h4> |
|
286 <b>__calculateEndingPoints_topToBottom</b>(<i></i>) |
|
287 |
|
288 <p> |
|
289 Private method to calculate the ending points of the association item. |
|
290 </p> |
|
291 <p> |
|
292 The ending points are calculated from the top center of the lower item |
|
293 to the bottom center of the upper item. |
|
294 </p> |
|
295 <a NAME="AssociationItem.__findIntersection" ID="AssociationItem.__findIntersection"></a> |
|
296 <h4>AssociationItem.__findIntersection</h4> |
|
297 <b>__findIntersection</b>(<i>p1, p2, p3, p4</i>) |
|
298 |
|
299 <p> |
|
300 Private method to calculate the intersection point of two lines. |
|
301 </p> |
|
302 <p> |
|
303 The first line is determined by the points p1 and p2, the second |
|
304 line by p3 and p4. If the intersection point is not contained in |
|
305 the segment p1p2, then it returns (-1.0, -1.0). |
|
306 </p> |
|
307 <p> |
|
308 For the function's internal calculations remember:<br /> |
|
309 QT coordinates start with the point (0,0) as the topleft corner |
|
310 and x-values increase from left to right and y-values increase |
|
311 from top to bottom; it means the visible area is quadrant I in |
|
312 the regular XY coordinate system |
|
313 </p> |
|
314 <p> |
|
315 <pre> |
|
316 Quadrant II | Quadrant I |
|
317 -----------------|----------------- |
|
318 Quadrant III | Quadrant IV |
|
319 </pre> |
|
320 </p> |
|
321 <p> |
|
322 In order for the linear function calculations to work in this method |
|
323 we must switch x and y values (x values become y values and viceversa) |
|
324 </p> |
|
325 <dl> |
|
326 |
|
327 <dt><i>p1</i> (QPointF)</dt> |
|
328 <dd> |
|
329 first point of first line |
|
330 </dd> |
|
331 <dt><i>p2</i> (QPointF)</dt> |
|
332 <dd> |
|
333 second point of first line |
|
334 </dd> |
|
335 <dt><i>p3</i> (QPointF)</dt> |
|
336 <dd> |
|
337 first point of second line |
|
338 </dd> |
|
339 <dt><i>p4</i> (QPointF)</dt> |
|
340 <dd> |
|
341 second point of second line |
|
342 </dd> |
|
343 </dl> |
|
344 <dl> |
|
345 <dt>Return:</dt> |
|
346 <dd> |
|
347 the intersection point |
|
348 </dd> |
|
349 </dl> |
|
350 <dl> |
|
351 <dt>Return Type:</dt> |
|
352 <dd> |
|
353 QPointF |
|
354 </dd> |
|
355 </dl> |
|
356 <a NAME="AssociationItem.__findPointRegion" ID="AssociationItem.__findPointRegion"></a> |
|
357 <h4>AssociationItem.__findPointRegion</h4> |
|
358 <b>__findPointRegion</b>(<i>rect, posX, posY</i>) |
|
359 |
|
360 <p> |
|
361 Private method to find out, which region of rectangle rect contains |
|
362 the point (PosX, PosY) and returns the region number. |
|
363 </p> |
|
364 <dl> |
|
365 |
|
366 <dt><i>rect</i> (QRectF)</dt> |
|
367 <dd> |
|
368 rectangle to calculate the region for |
|
369 </dd> |
|
370 <dt><i>posX</i> (float)</dt> |
|
371 <dd> |
|
372 x position of point |
|
373 </dd> |
|
374 <dt><i>posY</i> (float)</dt> |
|
375 <dd> |
|
376 y position of point |
|
377 </dd> |
|
378 </dl> |
|
379 <dl> |
|
380 <dt>Return:</dt> |
|
381 <dd> |
|
382 the calculated region number<br /> |
|
383 West = Region 1<br /> |
|
384 North = Region 2<br /> |
|
385 East = Region 3<br /> |
|
386 South = Region 4<br /> |
|
387 NorthWest = On diagonal 2 between Region 1 and 2<br /> |
|
388 NorthEast = On diagonal 1 between Region 2 and 3<br /> |
|
389 SouthEast = On diagonal 2 between Region 3 and 4<br /> |
|
390 SouthWest = On diagonal 1 between Region4 and 1<br /> |
|
391 Center = On diagonal 1 and On diagonal 2 (the center)<br /> |
|
392 </dd> |
|
393 </dl> |
|
394 <dl> |
|
395 <dt>Return Type:</dt> |
|
396 <dd> |
|
397 AssociationPointRegion |
|
398 </dd> |
|
399 </dl> |
|
400 <a NAME="AssociationItem.__findRectIntersectionPoint" ID="AssociationItem.__findRectIntersectionPoint"></a> |
|
401 <h4>AssociationItem.__findRectIntersectionPoint</h4> |
|
402 <b>__findRectIntersectionPoint</b>(<i>item, p1, p2</i>) |
|
403 |
|
404 <p> |
|
405 Private method to find the intersection point of a line with a |
|
406 rectangle. |
|
407 </p> |
|
408 <dl> |
|
409 |
|
410 <dt><i>item</i> (UMLItem)</dt> |
|
411 <dd> |
|
412 item to check against |
|
413 </dd> |
|
414 <dt><i>p1</i> (QPointF)</dt> |
|
415 <dd> |
|
416 first point of the line |
|
417 </dd> |
|
418 <dt><i>p2</i> (QPointF)</dt> |
|
419 <dd> |
|
420 second point of the line |
|
421 </dd> |
|
422 </dl> |
|
423 <dl> |
|
424 <dt>Return:</dt> |
|
425 <dd> |
|
426 the intersection point |
|
427 </dd> |
|
428 </dl> |
|
429 <dl> |
|
430 <dt>Return Type:</dt> |
|
431 <dd> |
|
432 QPointF |
|
433 </dd> |
|
434 </dl> |
|
435 <a NAME="AssociationItem.__mapRectFromItem" ID="AssociationItem.__mapRectFromItem"></a> |
|
436 <h4>AssociationItem.__mapRectFromItem</h4> |
|
437 <b>__mapRectFromItem</b>(<i>item</i>) |
|
438 |
|
439 <p> |
|
440 Private method to map item's rectangle to this item's coordinate |
|
441 system. |
|
442 </p> |
|
443 <dl> |
|
444 |
|
445 <dt><i>item</i> (QGraphicsRectItem)</dt> |
|
446 <dd> |
|
447 reference to the item to be mapped |
|
448 </dd> |
|
449 </dl> |
|
450 <dl> |
|
451 <dt>Return:</dt> |
|
452 <dd> |
|
453 item's rectangle in local coordinates |
|
454 </dd> |
|
455 </dl> |
|
456 <dl> |
|
457 <dt>Return Type:</dt> |
|
458 <dd> |
|
459 QRectF |
|
460 </dd> |
|
461 </dl> |
|
462 <a NAME="AssociationItem.__updateEndPoint" ID="AssociationItem.__updateEndPoint"></a> |
|
463 <h4>AssociationItem.__updateEndPoint</h4> |
|
464 <b>__updateEndPoint</b>(<i>region, isWidgetA</i>) |
|
465 |
|
466 <p> |
|
467 Private method to update an endpoint. |
|
468 </p> |
|
469 <dl> |
|
470 |
|
471 <dt><i>region</i> (AssociationPointRegion)</dt> |
|
472 <dd> |
|
473 the region for the endpoint |
|
474 </dd> |
|
475 <dt><i>isWidgetA</i> (bool)</dt> |
|
476 <dd> |
|
477 flag indicating update for itemA is done |
|
478 </dd> |
|
479 </dl> |
|
480 <a NAME="AssociationItem.toDict" ID="AssociationItem.toDict"></a> |
|
481 <h4>AssociationItem.toDict</h4> |
|
482 <b>toDict</b>(<i></i>) |
|
483 |
|
484 <p> |
|
485 Public method to collect data to be persisted. |
|
486 </p> |
|
487 <dl> |
|
488 <dt>Return:</dt> |
|
489 <dd> |
|
490 dictionary containing data to be persisted |
|
491 </dd> |
|
492 </dl> |
|
493 <dl> |
|
494 <dt>Return Type:</dt> |
|
495 <dd> |
|
496 dict |
|
497 </dd> |
|
498 </dl> |
|
499 <a NAME="AssociationItem.unassociate" ID="AssociationItem.unassociate"></a> |
|
500 <h4>AssociationItem.unassociate</h4> |
|
501 <b>unassociate</b>(<i></i>) |
|
502 |
|
503 <p> |
|
504 Public method to unassociate from the widgets. |
|
505 </p> |
|
506 <a NAME="AssociationItem.widgetMoved" ID="AssociationItem.widgetMoved"></a> |
|
507 <h4>AssociationItem.widgetMoved</h4> |
|
508 <b>widgetMoved</b>(<i></i>) |
|
509 |
|
510 <p> |
|
511 Public method to recalculate the association after a widget was moved. |
|
512 </p> |
|
513 <div align="right"><a href="#top">Up</a></div> |
|
514 <hr /> |
|
515 <hr /> |
|
516 <a NAME="AssociationPointRegion" ID="AssociationPointRegion"></a> |
|
517 <h2>AssociationPointRegion</h2> |
|
518 |
|
519 <p> |
|
520 Class defining the regions for an association end point. |
|
521 </p> |
|
522 <h3>Derived from</h3> |
|
523 enum.Enum |
|
524 <h3>Class Attributes</h3> |
|
525 |
|
526 <table> |
|
527 <tr><td>CENTER</td></tr><tr><td>EAST</td></tr><tr><td>NORTH</td></tr><tr><td>NORTH_EAST</td></tr><tr><td>NORTH_WEST</td></tr><tr><td>NO_REGION</td></tr><tr><td>SOUTH</td></tr><tr><td>SOUTH_EAST</td></tr><tr><td>SOUTH_WEST</td></tr><tr><td>WEST</td></tr> |
|
528 </table> |
|
529 <h3>Class Methods</h3> |
|
530 |
|
531 <table> |
|
532 <tr><td>None</td></tr> |
|
533 </table> |
|
534 <h3>Methods</h3> |
|
535 |
|
536 <table> |
|
537 <tr><td>None</td></tr> |
|
538 </table> |
|
539 <h3>Static Methods</h3> |
|
540 |
|
541 <table> |
|
542 <tr><td>None</td></tr> |
|
543 </table> |
|
544 |
|
545 <div align="right"><a href="#top">Up</a></div> |
|
546 <hr /> |
|
547 <hr /> |
|
548 <a NAME="AssociationType" ID="AssociationType"></a> |
|
549 <h2>AssociationType</h2> |
|
550 |
|
551 <p> |
|
552 Class defining the association types. |
|
553 </p> |
|
554 <h3>Derived from</h3> |
|
555 enum.Enum |
|
556 <h3>Class Attributes</h3> |
|
557 |
|
558 <table> |
|
559 <tr><td>GENERALISATION</td></tr><tr><td>IMPORTS</td></tr><tr><td>NORMAL</td></tr> |
|
560 </table> |
|
561 <h3>Class Methods</h3> |
|
562 |
|
563 <table> |
|
564 <tr><td>None</td></tr> |
|
565 </table> |
|
566 <h3>Methods</h3> |
|
567 |
|
568 <table> |
|
569 <tr><td>None</td></tr> |
|
570 </table> |
|
571 <h3>Static Methods</h3> |
|
572 |
|
573 <table> |
|
574 <tr><td>None</td></tr> |
|
575 </table> |
|
576 |
|
577 <div align="right"><a href="#top">Up</a></div> |
|
578 <hr /> |
|
579 </body></html> |