mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-08 23:46:22 -06:00
Add model to represent packages and export information to QML
We'll construct a bunch of these when we receive information from the API. Contributes to issue CURA-8556.
This commit is contained in:
parent
cf2b0d2777
commit
0f5c923d93
2 changed files with 37 additions and 4 deletions
|
@ -2,9 +2,14 @@
|
||||||
# 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 Qt
|
from PyQt5.QtCore import Qt
|
||||||
|
from typing import List, TYPE_CHECKING
|
||||||
from UM.Qt.ListModel import ListModel
|
from UM.Qt.ListModel import ListModel
|
||||||
|
|
||||||
|
from .PackageModel import PackageModel # This list is a list of PackageModels.
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from PyQt5.QtCore import QObject
|
||||||
|
|
||||||
class PackageList(ListModel):
|
class PackageList(ListModel):
|
||||||
"""
|
"""
|
||||||
Represents a list of packages to be displayed in the interface.
|
Represents a list of packages to be displayed in the interface.
|
||||||
|
@ -13,9 +18,12 @@ class PackageList(ListModel):
|
||||||
paginated.
|
paginated.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
PackageIDRole = Qt.UserRole + 1
|
PackageRole = Qt.UserRole + 1
|
||||||
DisplayNameRole = Qt.UserRole + 2
|
|
||||||
# TODO: Add more roles here when we need to display more information about packages.
|
def __init__(self, parent: "QObject" = None):
|
||||||
|
super().__init__(parent)
|
||||||
|
|
||||||
|
self._packages: List[PackageModel] = []
|
||||||
|
|
||||||
def _update(self) -> None:
|
def _update(self) -> None:
|
||||||
# TODO: Get list of packages from Marketplace class.
|
# TODO: Get list of packages from Marketplace class.
|
||||||
|
|
25
plugins/Marketplace/PackageModel.py
Normal file
25
plugins/Marketplace/PackageModel.py
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
# Copyright (c) 2021 Ultimaker B.V.
|
||||||
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
|
from PyQt5.QtCore import pyqtProperty, QObject
|
||||||
|
|
||||||
|
class PackageModel(QObject):
|
||||||
|
"""
|
||||||
|
Represents a package, containing all the relevant information to be displayed about a package.
|
||||||
|
|
||||||
|
Effectively this behaves like a glorified named tuple, but as a QObject so that its properties can be obtained from
|
||||||
|
QML.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, package_id: str, display_name: str, parent: QObject = None):
|
||||||
|
super().__init__(parent)
|
||||||
|
self._package_id = package_id
|
||||||
|
self._display_name = display_name
|
||||||
|
|
||||||
|
@pyqtProperty(str, constant = True)
|
||||||
|
def packageId(self) -> str:
|
||||||
|
return self._package_id
|
||||||
|
|
||||||
|
@pyqtProperty(str, constant = True)
|
||||||
|
def displayName(self) -> str:
|
||||||
|
return self._display_name
|
Loading…
Add table
Add a link
Reference in a new issue