eric7/Graphics/AssociationItem.py

branch
eric7
changeset 8348
f4775ae8f441
parent 8318
962bce857696
child 8366
2a9f5153c438
equal deleted inserted replaced
8347:ca9ef7600df7 8348:f4775ae8f441
10 import enum 10 import enum
11 11
12 from PyQt6.QtCore import QPointF, QRectF, QLineF 12 from PyQt6.QtCore import QPointF, QRectF, QLineF
13 from PyQt6.QtWidgets import QGraphicsItem 13 from PyQt6.QtWidgets import QGraphicsItem
14 14
15 from E5Graphics.E5ArrowItem import E5ArrowItem, E5ArrowType 15 from EricGraphics.EricArrowItem import EricArrowItem, EricArrowType
16 16
17 import Utilities 17 import Utilities
18 18
19 19
20 class AssociationType(enum.Enum): 20 class AssociationType(enum.Enum):
40 SOUTH_EAST = 7 40 SOUTH_EAST = 7
41 SOUTH_WEST = 8 41 SOUTH_WEST = 8
42 CENTER = 9 42 CENTER = 9
43 43
44 44
45 class AssociationItem(E5ArrowItem): 45 class AssociationItem(EricArrowItem):
46 """ 46 """
47 Class implementing a graphics item for an association between two items. 47 Class implementing a graphics item for an association between two items.
48 48
49 The association is drawn as an arrow starting at the first items and 49 The association is drawn as an arrow starting at the first items and
50 ending at the second. 50 ending at the second.
67 @type tuple of (QColor, QColor) 67 @type tuple of (QColor, QColor)
68 @param parent reference to the parent object 68 @param parent reference to the parent object
69 @type QGraphicsItem 69 @type QGraphicsItem
70 """ 70 """
71 if assocType in (AssociationType.NORMAL, AssociationType.IMPORTS): 71 if assocType in (AssociationType.NORMAL, AssociationType.IMPORTS):
72 arrowType = E5ArrowType.NORMAL 72 arrowType = EricArrowType.NORMAL
73 arrowFilled = True 73 arrowFilled = True
74 elif assocType == AssociationType.GENERALISATION: 74 elif assocType == AssociationType.GENERALISATION:
75 arrowType = E5ArrowType.WIDE 75 arrowType = EricArrowType.WIDE
76 arrowFilled = False 76 arrowFilled = False
77 77
78 E5ArrowItem.__init__(self, QPointF(0, 0), QPointF(100, 100), 78 EricArrowItem.__init__(self, QPointF(0, 0), QPointF(100, 100),
79 arrowFilled, arrowType, colors, parent) 79 arrowFilled, arrowType, colors, parent)
80 80
81 self.setFlag(QGraphicsItem.GraphicsItemFlag.ItemIsMovable, False) 81 self.setFlag(QGraphicsItem.GraphicsItemFlag.ItemIsMovable, False)
82 self.setFlag(QGraphicsItem.GraphicsItemFlag.ItemIsSelectable, False) 82 self.setFlag(QGraphicsItem.GraphicsItemFlag.ItemIsSelectable, False)
83 83
553 Public method to unassociate from the widgets. 553 Public method to unassociate from the widgets.
554 """ 554 """
555 self.itemA.removeAssociation(self) 555 self.itemA.removeAssociation(self)
556 self.itemB.removeAssociation(self) 556 self.itemB.removeAssociation(self)
557 557
558 def buildAssociationItemDataString(self):
559 """
560 Public method to build a string to persist the specific item data.
561
562 This string should be built like "attribute=value" with pairs separated
563 by ", ". value must not contain ", " or newlines.
564
565 @return persistence data
566 @rtype str
567 """
568 entries = [
569 "src={0}".format(self.itemA.getId()),
570 "dst={0}".format(self.itemB.getId()),
571 "type={0}".format(self.assocType.value),
572 "topToBottom={0}".format(self.topToBottom)
573 ]
574 return ", ".join(entries)
575
576 @classmethod 558 @classmethod
577 def parseAssociationItemDataString(cls, data): 559 def parseAssociationItemDataString(cls, data):
578 """ 560 """
579 Class method to parse the given persistence data. 561 Class method to parse the given persistence data.
580 562

eric ide

mercurial