Commit 6db01ee9 authored by Maxime Perrotin's avatar Maxime Perrotin
Browse files

Proper rendering of statechars with aggregations

parent cdbaeee2
......@@ -499,7 +499,7 @@ class Edge(Connection):
''' On a mouse click, display the control points '''
self.bezier_set_visible(True)
# pylint: disable=R0914
# pylint: disable=R0914
def reshape(self):
''' Update the shape of the edge (redefined function) '''
path = QPainterPath()
......@@ -536,19 +536,20 @@ class Edge(Connection):
if not self.text_label:
self.text_label = QGraphicsTextItem(
self.edge.get('label', ''), parent=self)
self.text_label.setX(pos.x() - width / 2)
self.text_label.setY(pos.y() - height / 2)
self.text_label.setFont(font)
# Make horizontal center alignment, as dot does
self.text_label.setTextWidth(self.text_label.boundingRect().width())
fmt = QTextBlockFormat()
fmt.setAlignment(Qt.AlignHCenter)
cursor = self.text_label.textCursor()
cursor.select(QTextCursor.Document)
cursor.mergeBlockFormat(fmt)
cursor.clearSelection()
self.text_label.setTextCursor(cursor)
self.text_label.show()
self.text_label.setX(pos.x() - width / 2)
self.text_label.setY(pos.y() - height / 2)
self.text_label.setFont(font)
# Make horizontal center alignment, as dot does
self.text_label.setTextWidth(
self.text_label.boundingRect().width())
fmt = QTextBlockFormat()
fmt.setAlignment(Qt.AlignHCenter)
cursor = self.text_label.textCursor()
cursor.select(QTextCursor.Document)
cursor.mergeBlockFormat(fmt)
cursor.clearSelection()
self.text_label.setTextCursor(cursor)
self.text_label.show()
except KeyError:
# no label
pass
......
......@@ -57,7 +57,7 @@ class Record(genericSymbols.HorizontalSymbol, object):
super(Record, self).__init__(x=node['pos'][0],
y=node['pos'][1], text=self.name)
self.set_shape(node['width'], node['height'])
#self.setBrush(QtGui.QBrush(QtGui.QColor(255, 255, 202)))
self.setBrush(QtGui.QBrush(QtGui.QColor(255, 255, 202)))
self.graph = graph
if 'properties' in node:
property_box = QtGui.QGraphicsTextItem(self)
......@@ -365,12 +365,11 @@ def render_statechart(scene, graphtree=None, keep_pos=False, dump_gfx=''):
# in order to resize the parent node accordingly
temp_scene = type(scene)()
render_statechart(temp_scene, agraph, keep_pos, dump_gfx)
print 'rendering', aname
for node in graphtree['graph'].iternodes():
if node == aname:
size = temp_scene.itemsBoundingRect()
node.attr['width'] = size.width() / 72.0
node.attr['height'] = size.height() / 72.0
node.attr['width'] = (temp_scene.width() + 30) / 72.0
node.attr['height'] = (temp_scene.height() + 30) / 72.0
graphtree['children'][aname]['scene'] = temp_scene
break
# Statechart symbols lookup table
......@@ -422,7 +421,6 @@ def render_statechart(scene, graphtree=None, keep_pos=False, dump_gfx=''):
nodes = preprocess_nodes(graph, bounding_rect, dot_dpi)
node_symbols = []
for node in nodes:
#print node
shape = node.get('shape')
try:
node_symbol = lookup[shape](node, graph)
......@@ -441,11 +439,16 @@ def render_statechart(scene, graphtree=None, keep_pos=False, dump_gfx=''):
# in the symbol by moving them from their temporary scene
for symb in scene.visible_symb:
if unicode(symb) == aname:
deltapos = symb.scenePos() + QtCore.QPointF(30.0, 30.0)
for each in agraph['scene'].floating_symb:
print 'changing scene of', unicode(each)
each.setParent(symb)
# In principle we should change the parentItem to make sure
# that all children items are moved together with their
# parent. Unfortunately calls to setParentItem provoke
# a segfault. To be tried again when PySide is fixed...
#each.setParent(symb)
scene.addItem(each)
each.position += symb.scenePos()
each.position += deltapos
each.setZValue(each.zValue() + symb.zValue() + 1)
def create_dot_graph(root_ast, basic=False):
......
......@@ -142,6 +142,7 @@ class EditableText(QGraphicsTextItem, object):
def __init__(self, parent, text='...', hyperlink=None):
super(EditableText, self).__init__(parent)
self.parent = parent
self.setFont(QFont('Ubuntu', 10))
self.completer = Completer(self)
self.completer.widget().itemActivated.connect(
......@@ -177,7 +178,7 @@ class EditableText(QGraphicsTextItem, object):
def set_text_alignment(self):
''' Apply the required text alignment within the text box '''
alignment = self.parentItem().text_alignment
alignment = self.parent.text_alignment
self.setTextWidth(self.boundingRect().width())
fmt = QTextBlockFormat()
fmt.setAlignment(alignment)
......@@ -189,11 +190,11 @@ class EditableText(QGraphicsTextItem, object):
def set_textbox_position(self):
''' Compute the textbox position '''
parent_rect = self.parentItem().boundingRect()
parent_rect = self.parent.boundingRect()
rect = self.boundingRect()
# Use parent symbol alignment requirement
# Does not support right nor bottom alignment
alignment = self.parentItem().textbox_alignment
alignment = self.parent.textbox_alignment
rect_center = parent_rect.center() - rect.center()
if alignment & Qt.AlignLeft:
x_pos = 0
......@@ -215,14 +216,14 @@ class EditableText(QGraphicsTextItem, object):
If needed, request a resizing of the parent item
(when text size expands)
'''
if self.parentItem().auto_expand:
if self.parent.auto_expand:
self.setTextWidth(-1)
parent_rect = self.parentItem().boundingRect()
parent_rect = self.parent.boundingRect()
rect = self.boundingRect()
if rect.width() + 30 > parent_rect.width():
parent_rect.setWidth(rect.width() + 30)
parent_rect.setHeight(max(rect.height(), parent_rect.height()))
self.parentItem().resize_item(parent_rect)
self.parent.resize_item(parent_rect)
@Slot(QListWidgetItem)
def completion_selected(self, item):
......@@ -317,7 +318,7 @@ class EditableText(QGraphicsTextItem, object):
self.completer.show()
# Make sure parent item has higher visibility than its siblings
# (useful in decision branches)
self.parentItem().setZValue(1)
self.parent.setZValue(1)
self.completer.setFocusProxy(self)
self.setTabChangesFocus(True)
else:
......@@ -342,7 +343,7 @@ class EditableText(QGraphicsTextItem, object):
if not self.completer or not self.completer.isVisible():
# Trigger a select - side effect makes the toolbar update
try:
self.parentItem().select(True)
self.parent.select(True)
except AttributeError:
# Some parents may not be selectable (e.g. Signalroute)
pass
......@@ -352,21 +353,21 @@ class EditableText(QGraphicsTextItem, object):
text_cursor.clearSelection()
self.setTextCursor(text_cursor)
# If something has changed, check syntax and create undo command
if(self.oldSize != self.parentItem().boundingRect() or
if(self.oldSize != self.parent.boundingRect() or
self.oldText != unicode(self)):
# Call syntax checker from item containing the text (if any)
self.scene().check_syntax(self.parentItem())
self.scene().check_syntax(self.parent)
# Update class completion list
self.scene().update_completion_list(self.parentItem())
# Create undo command, including possible CAM
with undoCommands.UndoMacro(self.scene().undo_stack, 'Text'):
undo_cmd = undoCommands.ResizeSymbol(
self.parentItem(), self.oldSize,
self.parentItem().boundingRect())
self.parent, self.oldSize,
self.parent.boundingRect())
self.scene().undo_stack.push(undo_cmd)
try:
self.parentItem().cam(self.parentItem().pos(),
self.parentItem().pos())
self.parent.cam(self.parent.pos(),
self.parent.pos())
except AttributeError:
# Some parents may not have CAM function (e.g. Channel)
pass
......@@ -376,10 +377,9 @@ class EditableText(QGraphicsTextItem, object):
self.scene().undo_stack.push(undo_cmd)
self.set_text_alignment()
# Reset Z-Values that were increased when getting focus
parent = self.parentItem()
top_level = parent.top_level()
top_level = self.parent.top_level()
top_level.setZValue(top_level.zValue() - 1)
parent.setZValue(parent.zValue() - 1)
self.parent.setZValue(self.parent.zValue() - 1)
super(EditableText, self).focusOutEvent(event)
# pylint: disable=C0103
......@@ -388,14 +388,13 @@ class EditableText(QGraphicsTextItem, object):
super(EditableText, self).focusInEvent(event)
# Change the Z-value of items to make sure the
# completer is always be on top of other symbols
parent = self.parentItem()
top_level = parent.top_level()
top_level = self.parent.top_level()
top_level.setZValue(top_level.zValue() + 1)
parent.setZValue(parent.zValue() + 1)
self.parent.setZValue(self.parent.zValue() + 1)
# Trigger a select - side effect makes the toolbar update
try:
parent.select(True)
self.parent.select(True)
except AttributeError:
# Some parents may not be selectable (e.g. Signalroute)
pass
......@@ -408,7 +407,7 @@ class EditableText(QGraphicsTextItem, object):
self.setTextWidth(-1)
if not self.editing:
self.oldText = unicode(self)
self.oldSize = parent.boundingRect()
self.oldSize = self.parent.boundingRect()
self.editing = True
def __str__(self):
......
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