Graphics/AssociationItem.py

changeset 2030
db11a2fe9bbc
parent 2024
717b72b32420
child 2034
8de0fc1f7fef
equal deleted inserted replaced
2028:30247d523fdb 2030:db11a2fe9bbc
10 from PyQt4.QtCore import QPointF, QRectF, QLineF 10 from PyQt4.QtCore import QPointF, QRectF, QLineF
11 from PyQt4.QtGui import QGraphicsItem 11 from PyQt4.QtGui import QGraphicsItem
12 12
13 from E5Graphics.E5ArrowItem import E5ArrowItem, NormalArrow, WideArrow 13 from E5Graphics.E5ArrowItem import E5ArrowItem, NormalArrow, WideArrow
14 14
15 import Utilities
16
17
15 Normal = 0 18 Normal = 0
16 Generalisation = 1 19 Generalisation = 1
17 Imports = 2 20 Imports = 2
21
18 22
19 NoRegion = 0 23 NoRegion = 0
20 West = 1 24 West = 1
21 North = 2 25 North = 2
22 East = 3 26 East = 3
75 self.calculateEndingPoints = self.__calculateEndingPoints_rectangle 79 self.calculateEndingPoints = self.__calculateEndingPoints_rectangle
76 80
77 self.itemA = itemA 81 self.itemA = itemA
78 self.itemB = itemB 82 self.itemB = itemB
79 self.assocType = type 83 self.assocType = type
84 self.topToBottom = topToBottom
80 85
81 self.regionA = NoRegion 86 self.regionA = NoRegion
82 self.regionB = NoRegion 87 self.regionB = NoRegion
83 88
84 self.calculateEndingPoints() 89 self.calculateEndingPoints()
502 """ 507 """
503 Public method to unassociate from the widgets. 508 Public method to unassociate from the widgets.
504 """ 509 """
505 self.itemA.removeAssociation(self) 510 self.itemA.removeAssociation(self)
506 self.itemB.removeAssociation(self) 511 self.itemB.removeAssociation(self)
512
513 def buildAssociationItemDataString(self):
514 """
515 Public method to build a string to persist the specific item data.
516
517 This string should be built like "attribute=value" with pairs separated
518 by ", ". value must not contain ", " or newlines.
519
520 @return persistence data (string)
521 """
522 entries = [
523 "src={0}".format(self.itemA.getId()),
524 "dst={0}".format(self.itemB.getId()),
525 "type={0}".format(self.assocType),
526 "topToBottom={0}".format(self.topToBottom)
527 ]
528 return ", ".join(entries)
529
530 @classmethod
531 def parseAssociationItemDataString(cls, data):
532 """
533 Class method to parse the given persistence data.
534
535 @param data persisted data to be parsed (string)
536 @return tuple with the IDs of the source and destination items,
537 the association type and a flag indicating to associate from top
538 to bottom (integer, integer, integer, boolean)
539 """
540 src = -1
541 dst = -1
542 assocType = Normal
543 topToBottom = False
544 for entry in data.split(", "):
545 if "=" in entry:
546 key, value = entry.split("=", 1)
547 if key == "src":
548 src = int(value)
549 elif key == "dst":
550 dst = int(value)
551 elif key == "type":
552 assocType = value
553 elif key == "topToBottom":
554 topToBottom = Utilities.toBool(value)
555
556 return src, dst, assocType, topToBottom

eric ide

mercurial