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