[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.
This commit is contained in:
Candice Bentéjac 2022-11-29 18:08:15 +01:00
parent c2570ca0fb
commit 2e5f471b7b
2 changed files with 9 additions and 18 deletions

View file

@ -198,6 +198,9 @@ class MeshroomApp(QApplication):
templates.append(variant) templates.append(variant)
return templates return templates
def _pipelineTemplateNames(self):
return [p["name"] for p in self.pipelineTemplateFiles]
@Slot() @Slot()
def reloadTemplateList(self): def reloadTemplateList(self):
for f in meshroom.core.pipelineTemplatesFolders: for f in meshroom.core.pipelineTemplatesFolders:
@ -352,5 +355,6 @@ class MeshroomApp(QApplication):
pipelineTemplateFilesChanged = Signal() pipelineTemplateFilesChanged = Signal()
recentProjectFilesChanged = Signal() recentProjectFilesChanged = Signal()
pipelineTemplateFiles = Property("QVariantList", _pipelineTemplateFiles, notify=pipelineTemplateFilesChanged) pipelineTemplateFiles = Property("QVariantList", _pipelineTemplateFiles, notify=pipelineTemplateFilesChanged)
pipelineTemplateNames = Property("QVariantList", _pipelineTemplateNames, notify=pipelineTemplateFilesChanged)
recentProjectFiles = Property("QVariantList", _recentProjectFiles, notify=recentProjectFilesChanged) recentProjectFiles = Property("QVariantList", _recentProjectFiles, notify=recentProjectFilesChanged)
default8bitViewerEnabled = Property(bool, _default8bitViewerEnabled, constant=True) default8bitViewerEnabled = Property(bool, _default8bitViewerEnabled, constant=True)

View file

@ -229,18 +229,9 @@ Item {
function importPipeline(pipeline) function importPipeline(pipeline)
{ {
var pipelineNames = [] if (MeshroomApp.pipelineTemplateNames.includes(pipeline)) {
var pipelinePaths = [] var url = MeshroomApp.pipelineTemplateFiles[MeshroomApp.pipelineTemplateNames.indexOf(pipeline)]["path"]
for (const [_, data] of Object.entries(MeshroomApp.pipelineTemplateFiles)) { uigraph.importProject(Filepath.stringToUrl(url), spawnPosition)
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)
return true return true
} }
return false return false
@ -259,12 +250,8 @@ Item {
categories[category].push(name) categories[category].push(name)
} }
// Add list of templates to create pipelines // Add a "Pipelines" category, filled with the list of templates to create pipelines from the menu
categories["Pipelines"] = []; categories["Pipelines"] = MeshroomApp.pipelineTemplateNames;
for (const [_, data] of Object.entries(MeshroomApp.pipelineTemplateFiles)) {
let pipeline = data["name"];
categories["Pipelines"].push(pipeline)
}
return categories return categories
} }