def __init__(self, details, start, end, style, *args, **kwds): self.details = details # Start and end are the BlockRepresentation details for this line. self.start = start self.end = end self.name = None start.addConnection(self) end.addConnection(self) Line.__init__(self, 0, 0, 0, 0, None, style, details.style_role) if details.theDetails.Name: self.name = Text(details.theDetails.Name, style, self.full_role, self) self.updatePos()
def __init__(self, details, fp, anchor, style): if details.SequenceNr: text = '%s: %s'%(details.SequenceNr, fp.Name) else: text = fp.Name role = details.style_role self.anchor = anchor self.details = details self.fp = fp self.arrow = None Text.__init__(self, text, style, role, apply=False) self.setFlag(QtGui.QGraphicsItem.ItemIsSelectable) self.setFlag(QtGui.QGraphicsItem.ItemIsMovable) if isinstance(self.anchor, BlockItem): self.arrow = None else: # Add the arrow. length = style.getFloat('%s-arrow-%s-length'%(role, self.ROLE), 1.0) self.arrow = Line(-10*length, 0, 0, 0, self, style, (role, self.ROLE)) self.applyStyle()
class FunctionPoint(Text): ROLE = 'functionpoint' def __init__(self, details, fp, anchor, style): if details.SequenceNr: text = '%s: %s'%(details.SequenceNr, fp.Name) else: text = fp.Name role = details.style_role self.anchor = anchor self.details = details self.fp = fp self.arrow = None Text.__init__(self, text, style, role, apply=False) self.setFlag(QtGui.QGraphicsItem.ItemIsSelectable) self.setFlag(QtGui.QGraphicsItem.ItemIsMovable) if isinstance(self.anchor, BlockItem): self.arrow = None else: # Add the arrow. length = style.getFloat('%s-arrow-%s-length'%(role, self.ROLE), 1.0) self.arrow = Line(-10*length, 0, 0, 0, self, style, (role, self.ROLE)) self.applyStyle() def applyStyle(self): Text.applyStyle(self) if self.arrow: self.arrow.applyStyle() self.updatePos() def setRole(self, role): ''' Called by the style editing mechanism when the user changes the role. The role is here only the user-determined part, and does not include the hard-coded part from ROLE.''' self.details.style_role = role self.arrow.setRole(role) Text.setRole(self, role) self.applyStyle() def exportSvg(self): tmplt = ''' <g transform="translate($x,$y)"> $arrow $txt </g> ''' arrow=self.arrow.exportSvg() if self.arrow else '' txt = Text.exportSvg(self, NO_POS) # The text position is the position of the group. d = dict(text=str(self.text.toPlainText()), x=self.x(), y=self.y(), txt=txt, arrow = arrow) xml = string.Template(tmplt).substitute(d) return xml def anchorPos(self): x, y = self.anchor.fpPos() order = self.details.order_on_target x += 10*order y -= 20*order return x, y def updatePos(self): p = self.parentItem() if self.details.SequenceNr: text = '%s: %s'%(self.details.SequenceNr, self.fp.Name) else: text = self.fp.Name self.setText(text) x, y = self.anchorPos() x += self.details.Xoffset y += self.details.Yoffset self.setPos(x,y) #print 'background rect:', p.rect(), p.pos(), self.pos() if self.arrow: angle = -self.anchor.line().angle() if self.fp.isResponse: angle += 180.0 self.arrow.setRotation(angle) self.arrow.setPos(self.style.getOffset('%s-arrow-%s'%(self.role, self.ROLE), default=[-10,10])) def mouseReleaseEvent(self, event): Text.mouseReleaseEvent(self, event) self.scene().session.commit() def mouseMoveEvent(self, event): # Get the current position p = self.pos() Text.mouseMoveEvent(self, event) # If moved, make it permanent if self.pos() != p: np = self.pos() self.details.Xoffset += np.x() - p.x() self.details.Yoffset += np.y() - p.y() def menuFactory(self, view): ''' Factory function for creating a right-click menu. :param view: The view where the right-click menu is requested. :return: An instance of QtGui.QMenu ''' definition = list(view.standard_menu_def) return mkMenu(definition, view)
def applyStyle(self): Line.applyStyle(self) if self.name: self.name.applyStyle()
def setRole(self, role): """ Called by the style editing mechanism when the user changes the role. The role is here only the user-determined part, and does not include the hard-coded part from ROLE.""" self.details.style_role = role Line.setRole(self, role)