mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-16 11:17:49 -06:00
Add generic material packages to materials page
Contributes to CURA-5510
This commit is contained in:
parent
e3a193d6a6
commit
0bde1487e7
5 changed files with 47 additions and 11 deletions
|
@ -9,6 +9,9 @@ import UM 1.1 as UM
|
||||||
|
|
||||||
Column
|
Column
|
||||||
{
|
{
|
||||||
|
property var heading: ""
|
||||||
|
property var model
|
||||||
|
id: gridArea
|
||||||
height: childrenRect.height + 2 * padding
|
height: childrenRect.height + 2 * padding
|
||||||
width: parent.width
|
width: parent.width
|
||||||
spacing: UM.Theme.getSize("default_margin").height
|
spacing: UM.Theme.getSize("default_margin").height
|
||||||
|
@ -16,7 +19,7 @@ Column
|
||||||
Label
|
Label
|
||||||
{
|
{
|
||||||
id: heading
|
id: heading
|
||||||
text: toolbox.viewCategory == "material" ? catalog.i18nc("@label", "Community contributions") : catalog.i18nc("@label", "Community plugins")
|
text: gridArea.heading
|
||||||
width: parent.width
|
width: parent.width
|
||||||
color: UM.Theme.getColor("text_medium")
|
color: UM.Theme.getColor("text_medium")
|
||||||
font: UM.Theme.getFont("medium")
|
font: UM.Theme.getFont("medium")
|
||||||
|
@ -24,14 +27,13 @@ Column
|
||||||
GridLayout
|
GridLayout
|
||||||
{
|
{
|
||||||
id: grid
|
id: grid
|
||||||
property var model: toolbox.viewCategory == "material" ? toolbox.authorsModel : toolbox.packagesModel
|
|
||||||
width: parent.width - 2 * parent.padding
|
width: parent.width - 2 * parent.padding
|
||||||
columns: 2
|
columns: 2
|
||||||
columnSpacing: UM.Theme.getSize("default_margin").height
|
columnSpacing: UM.Theme.getSize("default_margin").height
|
||||||
rowSpacing: UM.Theme.getSize("default_margin").width
|
rowSpacing: UM.Theme.getSize("default_margin").width
|
||||||
Repeater
|
Repeater
|
||||||
{
|
{
|
||||||
model: grid.model
|
model: gridArea.model
|
||||||
delegate: ToolboxDownloadsGridTile
|
delegate: ToolboxDownloadsGridTile
|
||||||
{
|
{
|
||||||
Layout.preferredWidth: (grid.width - (grid.columns - 1) * grid.columnSpacing) / grid.columns
|
Layout.preferredWidth: (grid.width - (grid.columns - 1) * grid.columnSpacing) / grid.columns
|
||||||
|
|
|
@ -104,8 +104,18 @@ Item
|
||||||
switch(toolbox.viewCategory)
|
switch(toolbox.viewCategory)
|
||||||
{
|
{
|
||||||
case "material":
|
case "material":
|
||||||
|
|
||||||
|
// If model has a type, it must be a package
|
||||||
|
if (model.type)
|
||||||
|
{
|
||||||
|
toolbox.viewPage = "detail"
|
||||||
|
toolbox.filterModelByProp("packages", "id", model.id)
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
toolbox.viewPage = "author"
|
toolbox.viewPage = "author"
|
||||||
toolbox.filterModelByProp("packages", "author_id", model.id)
|
toolbox.filterModelByProp("packages", "author_id", model.id)
|
||||||
|
}
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
toolbox.viewPage = "detail"
|
toolbox.viewPage = "detail"
|
||||||
|
|
|
@ -29,6 +29,17 @@ 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")
|
||||||
|
model: toolbox.viewCategory == "material" ? toolbox.authorsModel : toolbox.packagesModel
|
||||||
|
}
|
||||||
|
|
||||||
|
ToolboxDownloadsGrid
|
||||||
|
{
|
||||||
|
id: genericMaterials
|
||||||
|
visible: toolbox.viewCategory == "material"
|
||||||
|
width: parent.width
|
||||||
|
heading: catalog.i18nc("@label", "Generic Materials")
|
||||||
|
model: toolbox.materialsGenericModel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,7 @@ class PackagesModel(ListModel):
|
||||||
self.addRoleName(Qt.UserRole + 16, "has_configs")
|
self.addRoleName(Qt.UserRole + 16, "has_configs")
|
||||||
self.addRoleName(Qt.UserRole + 17, "supported_configs")
|
self.addRoleName(Qt.UserRole + 17, "supported_configs")
|
||||||
self.addRoleName(Qt.UserRole + 18, "download_count")
|
self.addRoleName(Qt.UserRole + 18, "download_count")
|
||||||
|
self.addRoleName(Qt.UserRole + 19, "tags")
|
||||||
|
|
||||||
# List of filters for queries. The result is the union of the each list of results.
|
# List of filters for queries. The result is the union of the each list of results.
|
||||||
self._filter = {} # type: Dict[str, str]
|
self._filter = {} # type: Dict[str, str]
|
||||||
|
@ -78,13 +79,15 @@ class PackagesModel(ListModel):
|
||||||
"is_installed": package["is_installed"] if "is_installed" in package else False,
|
"is_installed": package["is_installed"] if "is_installed" in package else False,
|
||||||
"has_configs": has_configs,
|
"has_configs": has_configs,
|
||||||
"supported_configs": configs_model,
|
"supported_configs": configs_model,
|
||||||
"download_count": package["download_count"] if "download_count" in package else 0
|
"download_count": package["download_count"] if "download_count" in package else 0,
|
||||||
|
"tags": package["tags"] if "tags" in package else []
|
||||||
})
|
})
|
||||||
|
|
||||||
# Filter on all the key-word arguments.
|
# Filter on all the key-word arguments.
|
||||||
for key, value in self._filter.items():
|
for key, value in self._filter.items():
|
||||||
if "*" in value:
|
if key is "tags":
|
||||||
|
key_filter = lambda item, value = value: value in item["tags"]
|
||||||
|
elif "*" in value:
|
||||||
key_filter = lambda candidate, key = key, value = value: self._matchRegExp(candidate, key, value)
|
key_filter = lambda candidate, key = key, value = value: self._matchRegExp(candidate, key, value)
|
||||||
else:
|
else:
|
||||||
key_filter = lambda candidate, key = key, value = value: self._matchString(candidate, key, value)
|
key_filter = lambda candidate, key = key, value = value: self._matchString(candidate, key, value)
|
||||||
|
|
|
@ -71,7 +71,8 @@ class Toolbox(QObject, Extension):
|
||||||
"plugins_installed": [],
|
"plugins_installed": [],
|
||||||
"materials_showcase": [],
|
"materials_showcase": [],
|
||||||
"materials_available": [],
|
"materials_available": [],
|
||||||
"materials_installed": []
|
"materials_installed": [],
|
||||||
|
"materials_generic": []
|
||||||
} # type: Dict[str, List[Any]]
|
} # type: Dict[str, List[Any]]
|
||||||
|
|
||||||
# Models:
|
# Models:
|
||||||
|
@ -83,7 +84,8 @@ class Toolbox(QObject, Extension):
|
||||||
"plugins_installed": PackagesModel(self),
|
"plugins_installed": PackagesModel(self),
|
||||||
"materials_showcase": AuthorsModel(self),
|
"materials_showcase": AuthorsModel(self),
|
||||||
"materials_available": PackagesModel(self),
|
"materials_available": PackagesModel(self),
|
||||||
"materials_installed": PackagesModel(self)
|
"materials_installed": PackagesModel(self),
|
||||||
|
"materials_generic": PackagesModel(self)
|
||||||
} # type: Dict[str, ListModel]
|
} # type: Dict[str, ListModel]
|
||||||
|
|
||||||
# These properties are for keeping track of the UI state:
|
# These properties are for keeping track of the UI state:
|
||||||
|
@ -178,7 +180,8 @@ class Toolbox(QObject, Extension):
|
||||||
"plugins_showcase": QUrl("{base_url}/showcase".format(base_url=self._api_url)),
|
"plugins_showcase": QUrl("{base_url}/showcase".format(base_url=self._api_url)),
|
||||||
"plugins_available": QUrl("{base_url}/packages?package_type=plugin".format(base_url=self._api_url)),
|
"plugins_available": QUrl("{base_url}/packages?package_type=plugin".format(base_url=self._api_url)),
|
||||||
"materials_showcase": QUrl("{base_url}/showcase".format(base_url=self._api_url)),
|
"materials_showcase": QUrl("{base_url}/showcase".format(base_url=self._api_url)),
|
||||||
"materials_available": QUrl("{base_url}/packages?package_type=material".format(base_url=self._api_url))
|
"materials_available": QUrl("{base_url}/packages?package_type=material".format(base_url=self._api_url)),
|
||||||
|
"materials_generic": QUrl("{base_url}/packages?package_type=material&tags=generic".format(base_url=self._api_url))
|
||||||
}
|
}
|
||||||
|
|
||||||
# Get the API root for the packages API depending on Cura version settings.
|
# Get the API root for the packages API depending on Cura version settings.
|
||||||
|
@ -229,6 +232,7 @@ class Toolbox(QObject, Extension):
|
||||||
self._makeRequestByType("plugins_showcase")
|
self._makeRequestByType("plugins_showcase")
|
||||||
self._makeRequestByType("materials_showcase")
|
self._makeRequestByType("materials_showcase")
|
||||||
self._makeRequestByType("materials_available")
|
self._makeRequestByType("materials_available")
|
||||||
|
self._makeRequestByType("materials_generic")
|
||||||
|
|
||||||
# Gather installed packages:
|
# Gather installed packages:
|
||||||
self._updateInstalledModels()
|
self._updateInstalledModels()
|
||||||
|
@ -640,6 +644,8 @@ class Toolbox(QObject, Extension):
|
||||||
self._models[type].setFilter({"type": "plugin"})
|
self._models[type].setFilter({"type": "plugin"})
|
||||||
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":
|
||||||
|
self._models[type].setFilter({"tags": "generic"})
|
||||||
|
|
||||||
self.metadataChanged.emit()
|
self.metadataChanged.emit()
|
||||||
|
|
||||||
|
@ -761,6 +767,10 @@ class Toolbox(QObject, Extension):
|
||||||
def materialsInstalledModel(self) -> PackagesModel:
|
def materialsInstalledModel(self) -> PackagesModel:
|
||||||
return cast(PackagesModel, self._models["materials_installed"])
|
return cast(PackagesModel, self._models["materials_installed"])
|
||||||
|
|
||||||
|
@pyqtProperty(QObject, notify=metadataChanged)
|
||||||
|
def materialsGenericModel(self) -> PackagesModel:
|
||||||
|
return cast(PackagesModel, self._models["materials_generic"])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# Filter Models:
|
# Filter Models:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue