Skip to content

Commit

Permalink
core: exporters: graphol_iri: use explicit int cast for coordinates a…
Browse files Browse the repository at this point in the history
…nd dimensions

Starting with python 3.10 implicit integer cast with loss is no longer
permitted. This change affects the way invocations to overloaded Qt
methods are bound in PyQt.
Previous to this change an invocation to the overloaded
QDomElement.setAttribute() method with a numeric type as argument
would always result in the integer version being invoked, even
with a floating-point number as argument. When running under
python 3.10 or later instead, a call to the QDomElement.setAttribute()
with a floating-point number would result in the float version of
the method to be called, resulting in the XML attribute getting serialized
with the floating-point value, which would then fail to be loaded
by the loader since we assume to be always using integer sizes
and coordinates in graphol.
This commit adds an explicit integer cast in the graphol exporter
whenever such situation might occur.
  • Loading branch information
mnamici committed Dec 21, 2022
1 parent 0f16a15 commit 66ffee2
Showing 1 changed file with 16 additions and 23 deletions.
39 changes: 16 additions & 23 deletions eddy/core/exporters/graphol_iri.py
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,8 @@ def getDiagramsDomElement(self):
def getDiagramDomElement(self,diagram):
diagramEl = self.getDomElement('diagram')
diagramEl.setAttribute('name', diagram.name)
diagramEl.setAttribute('width', diagram.width())
diagramEl.setAttribute('height', diagram.height())
diagramEl.setAttribute('width', int(diagram.width()))
diagramEl.setAttribute('height', int(diagram.height()))
for node in sorted(diagram.nodes(), key=lambda n:n.id):
func = self.exportFuncForItem[node.type()]
diagramEl.appendChild(func(node))
Expand Down Expand Up @@ -472,10 +472,10 @@ def exportFacetNode(self, node):

position = node.mapToScene(node.textPos())
label = self.document.createElement('label')
label.setAttribute('height', node.labelA.height())
label.setAttribute('width', node.labelA.width() + node.labelB.width())
label.setAttribute('x', position.x())
label.setAttribute('y', position.y())
label.setAttribute('height', int(node.labelA.height()))
label.setAttribute('width', int(node.labelA.width() + node.labelB.width()))
label.setAttribute('x', int(position.x()))
label.setAttribute('y', int(position.y()))
label.appendChild(self.document.createTextNode(node.text()))
nodeEl.appendChild(label)
element = self.getFacetDomElement(node)
Expand Down Expand Up @@ -677,19 +677,12 @@ def getLabelDomElement(self, node, labelText=False):
:type node: AbstractNode
:rtype: QDomElement
"""
#TODO position arriva sbagliata molte volte (Dopo che si è spostata label da posizione di default)!
position = node.mapToScene(node.textPos())
label = self.document.createElement('label')
label.setAttribute('height', node.label.height())
label.setAttribute('width', node.label.width())
'''
if isinstance(node, ConceptNode):
label.setAttribute('x', position.x()-30)
else:
label.setAttribute('x', position.x())
'''
label.setAttribute('x', position.x())
label.setAttribute('y', position.y())
label.setAttribute('height', int(node.label.height()))
label.setAttribute('width', int(node.label.width()))
label.setAttribute('x', int(position.x()))
label.setAttribute('y', int(position.y()))
label.setAttribute('customSize', 1 if node.label.customFont else 0)
label.setAttribute('size', node.label.font().pixelSize())
if labelText:
Expand All @@ -710,8 +703,8 @@ def exportGenericEdge(self, edge):

for p in [edge.source.anchor(edge)] + edge.breakpoints + [edge.target.anchor(edge)]:
point = self.document.createElement('point')
point.setAttribute('x', p.x())
point.setAttribute('y', p.y())
point.setAttribute('x', int(p.x()))
point.setAttribute('y', int(p.y()))
element.appendChild(point)
return element

Expand Down Expand Up @@ -741,10 +734,10 @@ def getNodeDomElement(self, node):
element.setAttribute('type', self.itemToXml[node.type()])
element.setAttribute('color', node.brush().color().name())
geometry = self.document.createElement('geometry')
geometry.setAttribute('height', node.height())
geometry.setAttribute('width', node.width())
geometry.setAttribute('x', node.pos().x())
geometry.setAttribute('y', node.pos().y())
geometry.setAttribute('height', int(node.height()))
geometry.setAttribute('width', int(node.width()))
geometry.setAttribute('x', int(node.pos().x()))
geometry.setAttribute('y', int(node.pos().y()))
element.appendChild(geometry)
return element

Expand Down

0 comments on commit 66ffee2

Please sign in to comment.