Update intent models to also house nested qualities

CURA-6598
This commit is contained in:
Jaime van Kessel 2019-07-30 14:20:58 +02:00
parent 8d53ee90b4
commit 24d6d5b102
2 changed files with 56 additions and 9 deletions

View file

@ -5,9 +5,11 @@ from PyQt5.QtCore import Qt
import collections
from typing import TYPE_CHECKING
from cura.Machines.Models.IntentModel import IntentModel
from cura.Settings.IntentManager import IntentManager
from UM.Qt.ListModel import ListModel
from UM.Settings.ContainerRegistry import ContainerRegistry #To update the list if anything changes.
from PyQt5.QtCore import pyqtProperty, pyqtSignal
if TYPE_CHECKING:
from UM.Settings.ContainerRegistry import ContainerInterface
@ -15,12 +17,14 @@ if TYPE_CHECKING:
from UM.i18n import i18nCatalog
catalog = i18nCatalog("cura")
## Lists the intent categories that are available for the current printer
# configuration.
class IntentCategoryModel(ListModel):
NameRole = Qt.UserRole + 1
IntentCategoryRole = Qt.UserRole + 2
WeightRole = Qt.UserRole + 3
QualitiesRole = Qt.UserRole + 4
#Translations to user-visible string. Ordered by weight.
#TODO: Create a solution for this name and weight to be used dynamically.
@ -29,6 +33,8 @@ class IntentCategoryModel(ListModel):
name_translation["engineering"] = catalog.i18nc("@label", "Engineering")
name_translation["smooth"] = catalog.i18nc("@label", "Smooth")
modelUpdated = pyqtSignal()
## Creates a new model for a certain intent category.
# \param The category to list the intent profiles for.
def __init__(self, intent_category: str) -> None:
@ -38,6 +44,7 @@ class IntentCategoryModel(ListModel):
self.addRoleName(self.NameRole, "name")
self.addRoleName(self.IntentCategoryRole, "intent_category")
self.addRoleName(self.WeightRole, "weight")
self.addRoleName(self.QualitiesRole, "qualities")
ContainerRegistry.getInstance().containerAdded.connect(self._onContainerChange)
ContainerRegistry.getInstance().containerRemoved.connect(self._onContainerChange)
@ -55,9 +62,13 @@ class IntentCategoryModel(ListModel):
available_categories = IntentManager.getInstance().currentAvailableIntentCategories()
result = []
for category in available_categories:
qualities = IntentModel()
qualities.setIntentCategory(category)
result.append({
"name": self.name_translation.get(category, catalog.i18nc("@label", "Unknown")),
"intent_category": category,
"weight": list(self.name_translation.keys()).index(category)
"weight": list(self.name_translation.keys()).index(category),
"qualities": qualities
})
self.setItems(result)
result.sort(key = lambda k: k["weight"])
self.setItems(result)