eric6/Graphics/AssociationItem.py

changeset 8287
30eb7bc13d63
parent 8270
6ba3564b7161
child 8291
3d79b1e5bf3c
equal deleted inserted replaced
8286:62ae22eae123 8287:30eb7bc13d63
105 def __mapRectFromItem(self, item): 105 def __mapRectFromItem(self, item):
106 """ 106 """
107 Private method to map item's rectangle to this item's coordinate 107 Private method to map item's rectangle to this item's coordinate
108 system. 108 system.
109 109
110 @param item reference to the item to be mapped (QGraphicsRectItem) 110 @param item reference to the item to be mapped
111 @return item's rectangle in local coordinates (QRectF) 111 @type QGraphicsRectItem
112 @return item's rectangle in local coordinates
113 @rtype QRectF
112 """ 114 """
113 rect = item.rect() 115 rect = item.rect()
114 tl = self.mapFromItem(item, rect.topLeft()) 116 tl = self.mapFromItem(item, rect.topLeft())
115 return QRectF(tl.x(), tl.y(), rect.width(), rect.height()) 117 return QRectF(tl.x(), tl.y(), rect.width(), rect.height())
116 118
258 def __findPointRegion(self, rect, posX, posY): 260 def __findPointRegion(self, rect, posX, posY):
259 """ 261 """
260 Private method to find out, which region of rectangle rect contains 262 Private method to find out, which region of rectangle rect contains
261 the point (PosX, PosY) and returns the region number. 263 the point (PosX, PosY) and returns the region number.
262 264
263 @param rect rectangle to calculate the region for (QRectF) 265 @param rect rectangle to calculate the region for
264 @param posX x position of point (float) 266 @type QRectF
265 @param posY y position of point (float) 267 @param posX x position of point
268 @type float
269 @param posY y position of point
270 @type float
266 @return the calculated region number<br /> 271 @return the calculated region number<br />
267 West = Region 1<br /> 272 West = Region 1<br />
268 North = Region 2<br /> 273 North = Region 2<br />
269 East = Region 3<br /> 274 East = Region 3<br />
270 South = Region 4<br /> 275 South = Region 4<br />
271 NorthWest = On diagonal 2 between Region 1 and 2<br /> 276 NorthWest = On diagonal 2 between Region 1 and 2<br />
272 NorthEast = On diagonal 1 between Region 2 and 3<br /> 277 NorthEast = On diagonal 1 between Region 2 and 3<br />
273 SouthEast = On diagonal 2 between Region 3 and 4<br /> 278 SouthEast = On diagonal 2 between Region 3 and 4<br />
274 SouthWest = On diagonal 1 between Region4 and 1<br /> 279 SouthWest = On diagonal 1 between Region4 and 1<br />
275 Center = On diagonal 1 and On diagonal 2 (the center)<br /> 280 Center = On diagonal 1 and On diagonal 2 (the center)<br />
281 @rtype AssociationPointRegion
276 """ 282 """
277 w = rect.width() 283 w = rect.width()
278 h = rect.height() 284 h = rect.height()
279 x = rect.x() 285 x = rect.x()
280 y = rect.y() 286 y = rect.y()
328 334
329 def __updateEndPoint(self, region, isWidgetA): 335 def __updateEndPoint(self, region, isWidgetA):
330 """ 336 """
331 Private method to update an endpoint. 337 Private method to update an endpoint.
332 338
333 @param region the region for the endpoint (integer) 339 @param region the region for the endpoint
334 @param isWidgetA flag indicating update for itemA is done (boolean) 340 @type AssociationPointRegion
341 @param isWidgetA flag indicating update for itemA is done
342 @type bool
335 """ 343 """
336 if region == AssociationPointRegion.NO_REGION: 344 if region == AssociationPointRegion.NO_REGION:
337 return 345 return
338 346
339 rect = ( 347 rect = (
369 else: 377 else:
370 self.setEndPoint(px, py) 378 self.setEndPoint(px, py)
371 379
372 def __findRectIntersectionPoint(self, item, p1, p2): 380 def __findRectIntersectionPoint(self, item, p1, p2):
373 """ 381 """
374 Private method to find the intersetion point of a line with a 382 Private method to find the intersection point of a line with a
375 rectangle. 383 rectangle.
376 384
377 @param item item to check against 385 @param item item to check against
378 @param p1 first point of the line (QPointF) 386 @type UMLItem
379 @param p2 second point of the line (QPointF) 387 @param p1 first point of the line
380 @return the intersection point (QPointF) 388 @type QPointF
389 @param p2 second point of the line
390 @type QPointF
391 @return the intersection point
392 @rtype QPointF
381 """ 393 """
382 rect = self.__mapRectFromItem(item) 394 rect = self.__mapRectFromItem(item)
383 lines = [ 395 lines = [
384 QLineF(rect.topLeft(), rect.topRight()), 396 QLineF(rect.topLeft(), rect.topRight()),
385 QLineF(rect.topLeft(), rect.bottomLeft()), 397 QLineF(rect.topLeft(), rect.bottomLeft()),
417 </pre> 429 </pre>
418 430
419 In order for the linear function calculations to work in this method 431 In order for the linear function calculations to work in this method
420 we must switch x and y values (x values become y values and viceversa) 432 we must switch x and y values (x values become y values and viceversa)
421 433
422 @param p1 first point of first line (QPointF) 434 @param p1 first point of first line
423 @param p2 second point of first line (QPointF) 435 @type QPointF
424 @param p3 first point of second line (QPointF) 436 @param p2 second point of first line
425 @param p4 second point of second line (QPointF) 437 @type QPointF
426 @return the intersection point (QPointF) 438 @param p3 first point of second line
439 @type QPointF
440 @param p4 second point of second line
441 @type QPointF
442 @return the intersection point
443 @rtype QPointF
427 """ 444 """
428 x1 = p1.y() 445 x1 = p1.y()
429 y1 = p1.x() 446 y1 = p1.x()
430 x2 = p2.y() 447 x2 = p2.y()
431 y2 = p2.x() 448 y2 = p2.x()
543 Public method to build a string to persist the specific item data. 560 Public method to build a string to persist the specific item data.
544 561
545 This string should be built like "attribute=value" with pairs separated 562 This string should be built like "attribute=value" with pairs separated
546 by ", ". value must not contain ", " or newlines. 563 by ", ". value must not contain ", " or newlines.
547 564
548 @return persistence data (string) 565 @return persistence data
566 @rtype str
549 """ 567 """
550 entries = [ 568 entries = [
551 "src={0}".format(self.itemA.getId()), 569 "src={0}".format(self.itemA.getId()),
552 "dst={0}".format(self.itemB.getId()), 570 "dst={0}".format(self.itemB.getId()),
553 "type={0}".format(self.assocType.value), 571 "type={0}".format(self.assocType.value),
558 @classmethod 576 @classmethod
559 def parseAssociationItemDataString(cls, data): 577 def parseAssociationItemDataString(cls, data):
560 """ 578 """
561 Class method to parse the given persistence data. 579 Class method to parse the given persistence data.
562 580
563 @param data persisted data to be parsed (string) 581 @param data persisted data to be parsed
582 @type str
564 @return tuple with the IDs of the source and destination items, 583 @return tuple with the IDs of the source and destination items,
565 the association type and a flag indicating to associate from top 584 the association type and a flag indicating to associate from top
566 to bottom (integer, integer, integer, boolean) 585 to bottom
586 @rtype tuple of (int, int, int, bool)
567 """ 587 """
568 src = -1 588 src = -1
569 dst = -1 589 dst = -1
570 assocType = AssociationType.NORMAL 590 assocType = AssociationType.NORMAL
571 topToBottom = False 591 topToBottom = False

eric ide

mercurial