Commit 865f0c0a authored by Maxime Perrotin's avatar Maxime Perrotin

Improve support for condition boxes

parent 50944e65
...@@ -228,14 +228,15 @@ class MscGraphBasicMSCScene(QGraphicsScene): ...@@ -228,14 +228,15 @@ class MscGraphBasicMSCScene(QGraphicsScene):
self.removeItem(comment) self.removeItem(comment)
#--------------- Conditions #--------------- Conditions
def addCondition(self, instance, pos=None, label=''): def addCondition(self, instance, y=None, label=''):
u""" u"""
Add new "condition" to the scene and position it in "pos" if any Add new "condition" to the scene and position it in y pos if any
""" """
condition = MscGraphCondition(label=label, parent=self.bmsc()) condition = MscGraphCondition(label=label, y=y,
parent=self.bmsc(), instance=instance)
instance.addEvent(condition) instance.addEvent(condition)
if pos is not None: if y is not None:
condition.setPos(pos) condition.setY(instance.mapFromScene(0, y).y())
condition.itemSelected.connect(self.itemSelected) condition.itemSelected.connect(self.itemSelected)
self.itemInserted.emit(condition) self.itemInserted.emit(condition)
return condition return condition
......
...@@ -41,12 +41,10 @@ class MscGraphCondition(MscGraphItem): ...@@ -41,12 +41,10 @@ class MscGraphCondition(MscGraphItem):
DefaultWidth = 150 DefaultWidth = 150
DefaultHeight = 30 DefaultHeight = 30
def __init__(self, data=None, y=0, label=None, parent=None): def __init__(self, data=None, y=0, label=None, parent=None, instance=None):
u"""
Initize
"""
super(MscGraphCondition, self).__init__(parent) super(MscGraphCondition, self).__init__(parent)
self.setFlag(super(MscGraphCondition, self).ItemIsMovable, True) self.setFlag(super(MscGraphCondition, self).ItemIsMovable, True)
self.instance = instance
if label is None: if label is None:
label = "Condition" label = "Condition"
...@@ -63,6 +61,7 @@ class MscGraphCondition(MscGraphItem): ...@@ -63,6 +61,7 @@ class MscGraphCondition(MscGraphItem):
# Create Path # Create Path
self.createPath() self.createPath()
self.setPos(self.pos().x(), y or 0)
#************************************************************************** #**************************************************************************
# Data Functions # Data Functions
...@@ -100,30 +99,27 @@ class MscGraphCondition(MscGraphItem): ...@@ -100,30 +99,27 @@ class MscGraphCondition(MscGraphItem):
def updateLabelPosition(self): def updateLabelPosition(self):
self.label.setCenterPos(QPointF(0, 15)) self.label.setCenterPos(QPointF(0, 15))
#self.label.setPos(self.x() + 10,
# -self.label.boundingRect().height() / 2)
#************************************************************************** #**************************************************************************
# Item Change # Item Change
#************************************************************************** #**************************************************************************
def limitsOfItem(self, value): def limitsOfItem(self, value):
u""" Check the limits of the event area of parent """ u""" Check the limits of the event area of parent """
parent = self.parentItem() parent = self.instance
if parent == None: if parent == None:
return value return value
upperY = parent.upperLimit().y() upperY = parent.upperLimit().y()
bottomY = parent.bottomLimit().y() #bottomY = parent.bottomLimit().y()
valueY = value.y() valueY = value.y()
if valueY < upperY: if valueY < upperY:
valueY = upperY valueY = upperY
new_pos = QPointF(self.pos().x(), valueY)
value.setX(self.pos().x()) return new_pos
value.setY(valueY)
return value
def itemChange(self, change, value): def itemChange(self, change, value):
''' On position change, check that item stays in an allowed area '''
if (change == super(MscGraphCondition, self).ItemPositionChange): if (change == super(MscGraphCondition, self).ItemPositionChange):
value = self.limitsOfItem(value) value = self.limitsOfItem(value)
...@@ -131,7 +127,7 @@ class MscGraphCondition(MscGraphItem): ...@@ -131,7 +127,7 @@ class MscGraphCondition(MscGraphItem):
self.mscData().setAbsPos(self.mapToScene(0, 0).y()) self.mscData().setAbsPos(self.mapToScene(0, 0).y())
self.yHasChanged.emit(self) self.yHasChanged.emit(self)
return MscGraphItem.itemChange(self, change, value) return value #MscGraphItem.itemChange(self, change, value)
#************************************************************************** #**************************************************************************
# Paint Functions # Paint Functions
......
...@@ -206,11 +206,6 @@ class MscGraphMessage(MscGraphItem): ...@@ -206,11 +206,6 @@ class MscGraphMessage(MscGraphItem):
if value.y() < recvStart.y(): if value.y() < recvStart.y():
value.setY(recvStart.y()) value.setY(recvStart.y())
# # Message are not below the instances
# if value.y() > sendEnd.y():
# value.setY(sendEnd.y())
# if value.y() > recvEnd.y():
# value.setY(recvEnd.y())
value.setX(self.pos().x()) value.setX(self.pos().x())
return value return value
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment