Import a scene from an .mg file into the current graph

Add an "Import Scene" (Ctrl+Shift+I) option in the File menu
that allows to select an existing .mg file and import it in the
current graph.

The imported scene will automatically be placed below the lowest
existing node along the Y axis.
This commit is contained in:
Candice Bentéjac 2022-08-31 10:50:35 +02:00
parent ede24713d0
commit a33f79e4d7
4 changed files with 159 additions and 3 deletions

View file

@ -353,6 +353,19 @@ class UIGraph(QObject):
self.setGraph(g)
return status
@Slot(QUrl, result=bool)
def importScene(self, filepath):
if isinstance(filepath, (QUrl)):
# depending how the QUrl has been initialized,
# toLocalFile() may return the local path or an empty string
localFile = filepath.toLocalFile()
if not localFile:
localFile = filepath.toString()
else:
localFile = filepath
yOffset = self.layout.gridSpacing + self.layout.nodeHeight
return self.push(commands.ImportSceneCommand(self._graph, localFile, yOffset=yOffset))
@Slot(QUrl)
def saveAs(self, url):
if isinstance(url, (str)):