Added sections to the packagelists

By providing a `section_title` with a string to the `package_data`
packages can be subdivided in sections, each with its own header.
For remote packages this will be `None` and therefore no sections are
created there.

Contributes to CURA-8558
This commit is contained in:
j.spijker@ultimaker.com 2021-11-02 14:31:12 +01:00 committed by Jelle Spijker
parent 397baebda4
commit c4c99f6657
No known key found for this signature in database
GPG key ID: 6662DC033BE6B99A
3 changed files with 33 additions and 2 deletions

View file

@ -41,8 +41,11 @@ class LocalPackageList(PackageList):
bundled = plugin_registry.getInstalledPlugins() bundled = plugin_registry.getInstalledPlugins()
for b in bundled: for b in bundled:
package = PackageModel({"package_id": b, "display_name": b}, parent = self) package = PackageModel({"package_id": b, "display_name": b, "section_title": "bundled"}, parent = self)
self.appendItem({"package": package}) self.appendItem({"package": package})
packages = package_manager.getInstalledPackageIDs() packages = package_manager.getInstalledPackageIDs()
for p in packages:
package = PackageModel({"package_id": p, "display_name": p, "section_title": "package"}, parent = self)
self.appendItem({"package": package})
self.setIsLoading(False) self.setIsLoading(False)
self.setHasMore(False) self.setHasMore(False)

View file

@ -2,7 +2,7 @@
# Cura is released under the terms of the LGPLv3 or higher. # Cura is released under the terms of the LGPLv3 or higher.
from PyQt5.QtCore import pyqtProperty, QObject from PyQt5.QtCore import pyqtProperty, QObject
from typing import Any, Dict from typing import Any, Dict, Optional
from UM.i18n import i18nCatalog # To translate placeholder names if data is not present. from UM.i18n import i18nCatalog # To translate placeholder names if data is not present.
@ -25,6 +25,7 @@ class PackageModel(QObject):
super().__init__(parent) super().__init__(parent)
self._package_id = package_data.get("package_id", "UnknownPackageId") self._package_id = package_data.get("package_id", "UnknownPackageId")
self._display_name = package_data.get("display_name", catalog.i18nc("@label:property", "Unknown Package")) self._display_name = package_data.get("display_name", catalog.i18nc("@label:property", "Unknown Package"))
self._section_title = package_data.get("section_title", None)
@pyqtProperty(str, constant = True) @pyqtProperty(str, constant = True)
def packageId(self) -> str: def packageId(self) -> str:
@ -33,3 +34,7 @@ class PackageModel(QObject):
@pyqtProperty(str, constant = True) @pyqtProperty(str, constant = True)
def displayName(self) -> str: def displayName(self) -> str:
return self._display_name return self._display_name
@pyqtProperty(str, constant = True)
def sectionTitle(self) -> Optional[str]:
return self._section_title

View file

@ -24,6 +24,29 @@ ScrollView
spacing: UM.Theme.getSize("default_margin").height spacing: UM.Theme.getSize("default_margin").height
section.property: "package.sectionTitle"
section.criteria: ViewSection.FullString
section.delegate: Rectangle
{
width: packagesListview.width
height: sectionHeaderText.implicitHeight + UM.Theme.getSize("default_margin").height
color: UM.Theme.getColor("detail_background")
required property string section
Label
{
id: sectionHeaderText
anchors.verticalCenter: parent.verticalCenter
anchors.left: parent.left
text: parent.section
font: UM.Theme.getFont("large")
color: UM.Theme.getColor("text")
}
}
delegate: Rectangle delegate: Rectangle
{ {
width: packagesListview.width width: packagesListview.width