72 |
72 |
73 self.setFlag(QGraphicsItem.ItemIsMovable, False) |
73 self.setFlag(QGraphicsItem.ItemIsMovable, False) |
74 self.setFlag(QGraphicsItem.ItemIsSelectable, False) |
74 self.setFlag(QGraphicsItem.ItemIsSelectable, False) |
75 |
75 |
76 if topToBottom: |
76 if topToBottom: |
77 self.calculateEndingPoints = \ |
77 self.calculateEndingPoints = ( |
78 self.__calculateEndingPoints_topToBottom |
78 self.__calculateEndingPoints_topToBottom |
|
79 ) |
79 else: |
80 else: |
80 ## self.calculateEndingPoints = self.__calculateEndingPoints_center |
81 ## self.calculateEndingPoints = self.__calculateEndingPoints_center |
81 self.calculateEndingPoints = self.__calculateEndingPoints_rectangle |
82 self.calculateEndingPoints = self.__calculateEndingPoints_rectangle |
82 |
83 |
83 self.itemA = itemA |
84 self.itemA = itemA |
152 midB = QPointF(rectB.x() + rectB.width() / 2.0, |
153 midB = QPointF(rectB.x() + rectB.width() / 2.0, |
153 rectB.y() + rectB.height() / 2.0) |
154 rectB.y() + rectB.height() / 2.0) |
154 startP = self.__findRectIntersectionPoint(self.itemA, midA, midB) |
155 startP = self.__findRectIntersectionPoint(self.itemA, midA, midB) |
155 endP = self.__findRectIntersectionPoint(self.itemB, midB, midA) |
156 endP = self.__findRectIntersectionPoint(self.itemB, midB, midA) |
156 |
157 |
157 if startP.x() != -1 and startP.y() != -1 and \ |
158 if ( |
158 endP.x() != -1 and endP.y() != -1: |
159 startP.x() != -1 and |
|
160 startP.y() != -1 and |
|
161 endP.x() != -1 and |
|
162 endP.y() != -1 |
|
163 ): |
159 self.setPoints(startP.x(), startP.y(), endP.x(), endP.y()) |
164 self.setPoints(startP.x(), startP.y(), endP.x(), endP.y()) |
160 |
165 |
161 def __calculateEndingPoints_rectangle(self): |
166 def __calculateEndingPoints_rectangle(self): |
162 r""" |
167 r""" |
163 Private method to calculate the ending points of the association item. |
168 Private method to calculate the ending points of the association item. |
165 The ending points are calculated by the following method. |
170 The ending points are calculated by the following method. |
166 |
171 |
167 For each item the diagram is divided in four Regions by its diagonals |
172 For each item the diagram is divided in four Regions by its diagonals |
168 as indicated below |
173 as indicated below |
169 <pre> |
174 <pre> |
170 \ Region 2 / |
175 +------------------------------+ |
171 \ / |
176 | \ Region 2 / | |
172 |--------| |
177 | \ / | |
173 | \ / | |
178 | |--------| | |
174 | \ / | |
179 | | \ / | | |
175 | \/ | |
180 | | \ / | | |
176 Region 1 | /\ | Region 3 |
181 | | \/ | | |
177 | / \ | |
182 | Region 1 | /\ | Region 3 | |
178 | / \ | |
183 | | / \ | | |
179 |--------| |
184 | | / \ | | |
180 / \ |
185 | |--------| | |
181 / Region 4 \ |
186 | / \ | |
|
187 | / Region 4 \ | |
|
188 +------------------------------+ |
182 </pre> |
189 </pre> |
183 |
190 |
184 Each diagonal is defined by two corners of the bounding rectangle |
191 Each diagonal is defined by two corners of the bounding rectangle. |
185 |
192 |
186 To calculate the start point we have to find out in which |
193 To calculate the start point we have to find out in which |
187 region (defined by itemA's diagonals) is itemB's TopLeft corner |
194 region (defined by itemA's diagonals) is itemB's TopLeft corner |
188 (lets call it region M). After that the start point will be |
195 (lets call it region M). After that the start point will be |
189 the middle point of rectangle's side contained in region M. |
196 the middle point of rectangle's side contained in region M. |
369 QLineF(rect.bottomRight(), rect.topRight()) |
376 QLineF(rect.bottomRight(), rect.topRight()) |
370 ] |
377 ] |
371 intersectLine = QLineF(p1, p2) |
378 intersectLine = QLineF(p1, p2) |
372 intersectPoint = QPointF(0, 0) |
379 intersectPoint = QPointF(0, 0) |
373 for line in lines: |
380 for line in lines: |
374 if intersectLine.intersect(line, intersectPoint) == \ |
381 if ( |
375 QLineF.BoundedIntersection: |
382 intersectLine.intersect(line, intersectPoint) == |
|
383 QLineF.BoundedIntersection |
|
384 ): |
376 return intersectPoint |
385 return intersectPoint |
377 return QPointF(-1.0, -1.0) |
386 return QPointF(-1.0, -1.0) |
378 |
387 |
379 def __findIntersection(self, p1, p2, p3, p4): |
388 def __findIntersection(self, p1, p2, p3, p4): |
380 """ |
389 """ |