From 2e5f471b7b9e00da1676536d0a0028f5cd60d20a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Candice=20Bent=C3=A9jac?= Date: Tue, 29 Nov 2022 18:08:15 +0100 Subject: [PATCH] [ui] Add a "pipelineTemplateNames" property This property simplifies and optimizes the addition of templates in the node menu and their import into the graph, as it prevents us from looping over the entire "pipelineTemplateFiles" dictionary to retrieve the information we need. --- meshroom/ui/app.py | 4 ++++ meshroom/ui/qml/GraphEditor/GraphEditor.qml | 23 +++++---------------- 2 files changed, 9 insertions(+), 18 deletions(-) diff --git a/meshroom/ui/app.py b/meshroom/ui/app.py index 3f9df1fa..1ab9a068 100644 --- a/meshroom/ui/app.py +++ b/meshroom/ui/app.py @@ -198,6 +198,9 @@ class MeshroomApp(QApplication): templates.append(variant) return templates + def _pipelineTemplateNames(self): + return [p["name"] for p in self.pipelineTemplateFiles] + @Slot() def reloadTemplateList(self): for f in meshroom.core.pipelineTemplatesFolders: @@ -352,5 +355,6 @@ class MeshroomApp(QApplication): pipelineTemplateFilesChanged = Signal() recentProjectFilesChanged = Signal() pipelineTemplateFiles = Property("QVariantList", _pipelineTemplateFiles, notify=pipelineTemplateFilesChanged) + pipelineTemplateNames = Property("QVariantList", _pipelineTemplateNames, notify=pipelineTemplateFilesChanged) recentProjectFiles = Property("QVariantList", _recentProjectFiles, notify=recentProjectFilesChanged) default8bitViewerEnabled = Property(bool, _default8bitViewerEnabled, constant=True) diff --git a/meshroom/ui/qml/GraphEditor/GraphEditor.qml b/meshroom/ui/qml/GraphEditor/GraphEditor.qml index 28265a86..d2c48a57 100755 --- a/meshroom/ui/qml/GraphEditor/GraphEditor.qml +++ b/meshroom/ui/qml/GraphEditor/GraphEditor.qml @@ -229,18 +229,9 @@ Item { function importPipeline(pipeline) { - var pipelineNames = [] - var pipelinePaths = [] - for (const [_, data] of Object.entries(MeshroomApp.pipelineTemplateFiles)) { - let name = data["name"] - let path = data["path"] - pipelineNames.push(name) - pipelinePaths.push(path) - } - - if (pipelineNames.includes(pipeline)) { - var url = Filepath.stringToUrl(pipelinePaths[pipelineNames.indexOf(pipeline)]) - uigraph.importProject(url, spawnPosition) + if (MeshroomApp.pipelineTemplateNames.includes(pipeline)) { + var url = MeshroomApp.pipelineTemplateFiles[MeshroomApp.pipelineTemplateNames.indexOf(pipeline)]["path"] + uigraph.importProject(Filepath.stringToUrl(url), spawnPosition) return true } return false @@ -259,12 +250,8 @@ Item { categories[category].push(name) } - // Add list of templates to create pipelines - categories["Pipelines"] = []; - for (const [_, data] of Object.entries(MeshroomApp.pipelineTemplateFiles)) { - let pipeline = data["name"]; - categories["Pipelines"].push(pipeline) - } + // Add a "Pipelines" category, filled with the list of templates to create pipelines from the menu + categories["Pipelines"] = MeshroomApp.pipelineTemplateNames; return categories }