mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 15:37:27 -06:00
Build models using reserved tags
Contributes to CURA-5670
This commit is contained in:
parent
6cceebb117
commit
dec76a19ed
2 changed files with 70 additions and 16 deletions
|
@ -30,7 +30,7 @@ ScrollView
|
||||||
id: allPlugins
|
id: allPlugins
|
||||||
width: parent.width
|
width: parent.width
|
||||||
heading: toolbox.viewCategory == "material" ? catalog.i18nc("@label", "Community Contributions") : catalog.i18nc("@label", "Community Plugins")
|
heading: toolbox.viewCategory == "material" ? catalog.i18nc("@label", "Community Contributions") : catalog.i18nc("@label", "Community Plugins")
|
||||||
model: toolbox.viewCategory == "material" ? toolbox.authorsModel : toolbox.packagesModel
|
model: toolbox.viewCategory == "material" ? toolbox.materialsAvailableModel : toolbox.pluginsAvailableModel
|
||||||
}
|
}
|
||||||
|
|
||||||
ToolboxDownloadsGrid
|
ToolboxDownloadsGrid
|
||||||
|
|
|
@ -83,7 +83,7 @@ class Toolbox(QObject, Extension):
|
||||||
"plugins_available": PackagesModel(self),
|
"plugins_available": PackagesModel(self),
|
||||||
"plugins_installed": PackagesModel(self),
|
"plugins_installed": PackagesModel(self),
|
||||||
"materials_showcase": AuthorsModel(self),
|
"materials_showcase": AuthorsModel(self),
|
||||||
"materials_available": PackagesModel(self),
|
"materials_available": AuthorsModel(self),
|
||||||
"materials_installed": PackagesModel(self),
|
"materials_installed": PackagesModel(self),
|
||||||
"materials_generic": PackagesModel(self)
|
"materials_generic": PackagesModel(self)
|
||||||
} # type: Dict[str, ListModel]
|
} # type: Dict[str, ListModel]
|
||||||
|
@ -517,7 +517,7 @@ class Toolbox(QObject, Extension):
|
||||||
@pyqtSlot(str, result = int)
|
@pyqtSlot(str, result = int)
|
||||||
def getTotalNumberOfPackagesByAuthor(self, author_id: str) -> int:
|
def getTotalNumberOfPackagesByAuthor(self, author_id: str) -> int:
|
||||||
count = 0
|
count = 0
|
||||||
for package in self._metadata["materials_available"]:
|
for package in self._metadata["packages"]:
|
||||||
if package["author"]["author_id"] == author_id:
|
if package["author"]["author_id"] == author_id:
|
||||||
count += 1
|
count += 1
|
||||||
return count
|
return count
|
||||||
|
@ -624,24 +624,27 @@ class Toolbox(QObject, Extension):
|
||||||
Logger.log("e", "Could not find the %s model.", type)
|
Logger.log("e", "Could not find the %s model.", type)
|
||||||
break
|
break
|
||||||
|
|
||||||
# HACK: Eventually get rid of the code from here...
|
# HACK
|
||||||
if type is "plugins_showcase" or type is "materials_showcase":
|
do_not_handle = [
|
||||||
self._metadata["plugins_showcase"] = json_data["data"]["plugin"]["packages"]
|
"materials_available",
|
||||||
self._models["plugins_showcase"].setMetadata(self._metadata["plugins_showcase"])
|
"materials_showcase",
|
||||||
self._metadata["materials_showcase"] = json_data["data"]["material"]["authors"]
|
"plugins_available",
|
||||||
self._models["materials_showcase"].setMetadata(self._metadata["materials_showcase"])
|
"plugins_showcase",
|
||||||
else:
|
]
|
||||||
# ...until here.
|
|
||||||
# This hack arises for multiple reasons but the main
|
# Do nothing because we'll handle these from the "packages" call
|
||||||
# one is because there are not separate API calls
|
if type in do_not_handle:
|
||||||
# for different kinds of showcases.
|
return
|
||||||
self._metadata[type] = json_data["data"]
|
|
||||||
self._models[type].setMetadata(self._metadata[type])
|
self._metadata[type] = json_data["data"]
|
||||||
|
self._models[type].setMetadata(self._metadata[type])
|
||||||
|
|
||||||
# Do some auto filtering
|
# Do some auto filtering
|
||||||
# TODO: Make multiple API calls in the future to handle this
|
# TODO: Make multiple API calls in the future to handle this
|
||||||
if type is "packages":
|
if type is "packages":
|
||||||
self._models[type].setFilter({"type": "plugin"})
|
self._models[type].setFilter({"type": "plugin"})
|
||||||
|
self.buildMaterialsModels()
|
||||||
|
self.buildPluginsModels()
|
||||||
if type is "authors":
|
if type is "authors":
|
||||||
self._models[type].setFilter({"package_types": "material"})
|
self._models[type].setFilter({"package_types": "material"})
|
||||||
if type is "materials_generic":
|
if type is "materials_generic":
|
||||||
|
@ -755,6 +758,10 @@ class Toolbox(QObject, Extension):
|
||||||
def pluginsShowcaseModel(self) -> PackagesModel:
|
def pluginsShowcaseModel(self) -> PackagesModel:
|
||||||
return cast(PackagesModel, self._models["plugins_showcase"])
|
return cast(PackagesModel, self._models["plugins_showcase"])
|
||||||
|
|
||||||
|
@pyqtProperty(QObject, notify = metadataChanged)
|
||||||
|
def pluginsAvailableModel(self) -> PackagesModel:
|
||||||
|
return cast(PackagesModel, self._models["plugins_available"])
|
||||||
|
|
||||||
@pyqtProperty(QObject, notify = metadataChanged)
|
@pyqtProperty(QObject, notify = metadataChanged)
|
||||||
def pluginsInstalledModel(self) -> PackagesModel:
|
def pluginsInstalledModel(self) -> PackagesModel:
|
||||||
return cast(PackagesModel, self._models["plugins_installed"])
|
return cast(PackagesModel, self._models["plugins_installed"])
|
||||||
|
@ -763,6 +770,10 @@ class Toolbox(QObject, Extension):
|
||||||
def materialsShowcaseModel(self) -> AuthorsModel:
|
def materialsShowcaseModel(self) -> AuthorsModel:
|
||||||
return cast(AuthorsModel, self._models["materials_showcase"])
|
return cast(AuthorsModel, self._models["materials_showcase"])
|
||||||
|
|
||||||
|
@pyqtProperty(QObject, notify = metadataChanged)
|
||||||
|
def materialsAvailableModel(self) -> AuthorsModel:
|
||||||
|
return cast(AuthorsModel, self._models["materials_available"])
|
||||||
|
|
||||||
@pyqtProperty(QObject, notify = metadataChanged)
|
@pyqtProperty(QObject, notify = metadataChanged)
|
||||||
def materialsInstalledModel(self) -> PackagesModel:
|
def materialsInstalledModel(self) -> PackagesModel:
|
||||||
return cast(PackagesModel, self._models["materials_installed"])
|
return cast(PackagesModel, self._models["materials_installed"])
|
||||||
|
@ -798,3 +809,46 @@ class Toolbox(QObject, Extension):
|
||||||
return
|
return
|
||||||
self._models[model_type].setFilter({})
|
self._models[model_type].setFilter({})
|
||||||
self.filterChanged.emit()
|
self.filterChanged.emit()
|
||||||
|
|
||||||
|
|
||||||
|
# HACK(S):
|
||||||
|
# --------------------------------------------------------------------------
|
||||||
|
def buildMaterialsModels(self) -> None:
|
||||||
|
|
||||||
|
self._metadata["materials_showcase"] = []
|
||||||
|
self._metadata["materials_available"] = []
|
||||||
|
|
||||||
|
processed_authors = []
|
||||||
|
|
||||||
|
for item in self._metadata["packages"]:
|
||||||
|
if item["package_type"] == "material":
|
||||||
|
|
||||||
|
author = item["author"]
|
||||||
|
if author["author_id"] in processed_authors:
|
||||||
|
continue
|
||||||
|
|
||||||
|
if "showcase" in item["tags"]:
|
||||||
|
self._metadata["materials_showcase"].append(author)
|
||||||
|
else:
|
||||||
|
self._metadata["materials_available"].append(author)
|
||||||
|
|
||||||
|
processed_authors.append(author["author_id"])
|
||||||
|
|
||||||
|
self._models["materials_showcase"].setMetadata(self._metadata["materials_showcase"])
|
||||||
|
self._models["materials_available"].setMetadata(self._metadata["materials_available"])
|
||||||
|
|
||||||
|
def buildPluginsModels(self) -> None:
|
||||||
|
|
||||||
|
self._metadata["plugins_showcase"] = []
|
||||||
|
self._metadata["plugins_available"] = []
|
||||||
|
|
||||||
|
for item in self._metadata["packages"]:
|
||||||
|
if item["package_type"] == "plugin":
|
||||||
|
|
||||||
|
if "showcase" in item["tags"]:
|
||||||
|
self._metadata["plugins_showcase"].append(item)
|
||||||
|
else:
|
||||||
|
self._metadata["plugins_available"].append(item)
|
||||||
|
|
||||||
|
self._models["plugins_showcase"].setMetadata(self._metadata["plugins_showcase"])
|
||||||
|
self._models["plugins_available"].setMetadata(self._metadata["plugins_available"])
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue