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

@ -7,6 +7,7 @@ from PyQt5.QtCore import Qt, QObject, pyqtProperty, pyqtSignal
from UM.Qt.ListModel import ListModel
from UM.Settings.ContainerRegistry import ContainerRegistry
from UM.Settings.SettingFunction import SettingFunction
from cura.Machines.ContainerTree import ContainerTree
from cura.Settings.IntentManager import IntentManager
@ -16,18 +17,22 @@ import cura.CuraApplication
class IntentModel(ListModel):
NameRole = Qt.UserRole + 1
QualityTypeRole = Qt.UserRole + 2
LayerHeightRole = Qt.UserRole + 3
AvailableRole = Qt.UserRole + 4
def __init__(self, parent: Optional[QObject] = None) -> None:
super().__init__(parent)
self.addRoleName(self.NameRole, "name")
self.addRoleName(self.QualityTypeRole, "quality_type")
self.addRoleName(self.LayerHeightRole, "layer_height")
self.addRoleName(self.AvailableRole, "available")
self._intent_category = "engineering"
ContainerRegistry.getInstance().containerAdded.connect(self._onChanged)
ContainerRegistry.getInstance().containerRemoved.connect(self._onChanged)
self._layer_height_unit = "" # This is cached
self._update()
intentCategoryChanged = pyqtSignal()
@ -54,11 +59,42 @@ class IntentModel(ListModel):
return
quality_groups = ContainerTree.getInstance().getCurrentQualityGroups()
for intent_category, quality_type in IntentManager.getInstance().getCurrentAvailableIntents():
if intent_category == self._intent_category:
new_items.append({"name": quality_groups[quality_type].name, "quality_type": quality_type})
if self._intent_category == "default": #For Default we always list all quality types. We can't filter on available profiles since the empty intent is not a specific quality type.
for quality_type in quality_groups.keys():
new_items.append({"name": quality_groups[quality_type].name, "quality_type": quality_type})
for quality_tuple, quality_group in quality_groups.items():
new_items.append({"name": quality_group.name,
"quality_type": quality_tuple[1],
"layer_height": self._fetchLayerHeight(quality_group),
"available": True
})
new_items = sorted(new_items, key=lambda x: x["layer_height"])
self.setItems(new_items)
#TODO: Copied this from QualityProfilesDropdownMenuModel for the moment. This code duplication should be fixed.
def _fetchLayerHeight(self, quality_group) -> float:
global_stack = cura.CuraApplication.CuraApplication.getInstance().getMachineManager().activeMachine
if not self._layer_height_unit:
unit = global_stack.definition.getProperty("layer_height", "unit")
if not unit:
unit = ""
self._layer_height_unit = unit
default_layer_height = global_stack.definition.getProperty("layer_height", "value")
# Get layer_height from the quality profile for the GlobalStack
if quality_group.node_for_global is None:
return float(default_layer_height)
container = quality_group.node_for_global.getContainer()
layer_height = default_layer_height
if container and container.hasProperty("layer_height", "value"):
layer_height = container.getProperty("layer_height", "value")
else:
# Look for layer_height in the GlobalStack from material -> definition
container = global_stack.definition
if container and container.hasProperty("layer_height", "value"):
layer_height = container.getProperty("layer_height", "value")
if isinstance(layer_height, SettingFunction):
layer_height = layer_height(global_stack)
return float(layer_height)