[ui] GraphEditor: Import pipeline on the mouse's position with the node menu

If a pipeline is imported with the node menu instead of the "Import
Project" action from the File menu, the top-left "corner" of the graph
should be placed on the mouse's position.
The position of pipelines imported with the "Import Project" menu
remains unchanged: they are automatically placed below the lowest
node in the current graph.
This commit is contained in:
Candice Bentéjac 2022-12-02 18:13:17 +01:00
parent 04ab813cef
commit c2570ca0fb
3 changed files with 12 additions and 5 deletions

View file

@ -354,7 +354,8 @@ class UIGraph(QObject):
return status
@Slot(QUrl, result=bool)
def importProject(self, filepath):
@Slot(QUrl, QPoint, result=bool)
def importProject(self, filepath, position=None):
if isinstance(filepath, (QUrl)):
# depending how the QUrl has been initialized,
# toLocalFile() may return the local path or an empty string
@ -363,8 +364,10 @@ class UIGraph(QObject):
localFile = filepath.toString()
else:
localFile = filepath
if isinstance(position, QPoint):
position = Position(position.x(), position.y())
yOffset = self.layout.gridSpacing + self.layout.nodeHeight
return self.push(commands.ImportProjectCommand(self._graph, localFile, yOffset=yOffset))
return self.push(commands.ImportProjectCommand(self._graph, localFile, position=position, yOffset=yOffset))
@Slot(QUrl)
def saveAs(self, url):