Ensure that each intent gets it's own bar in recommended

CURA-6598
This commit is contained in:
Jaime van Kessel 2019-07-30 15:28:22 +02:00
parent 24d6d5b102
commit 5401a4db15
3 changed files with 60 additions and 34 deletions

View file

@ -19,6 +19,7 @@ class IntentModel(ListModel):
QualityTypeRole = Qt.UserRole + 2
LayerHeightRole = Qt.UserRole + 3
AvailableRole = Qt.UserRole + 4
IntentRole = Qt.UserRole + 5
def __init__(self, parent: Optional[QObject] = None) -> None:
super().__init__(parent)
@ -27,6 +28,7 @@ class IntentModel(ListModel):
self.addRoleName(self.QualityTypeRole, "quality_type")
self.addRoleName(self.LayerHeightRole, "layer_height")
self.addRoleName(self.AvailableRole, "available")
self.addRoleName(self.IntentRole, "intent_category")
self._intent_category = "engineering"
@ -59,12 +61,32 @@ class IntentModel(ListModel):
return
quality_groups = ContainerTree.getInstance().getCurrentQualityGroups()
layer_heights_added = []
for quality_tuple, quality_group in quality_groups.items():
new_items.append({"name": quality_group.name,
# Add the intents that are of the correct category
if quality_tuple[0] == self._intent_category:
layer_height = self._fetchLayerHeight(quality_group)
new_items.append({"name": quality_group.name,
"quality_type": quality_tuple[1],
"layer_height": self._fetchLayerHeight(quality_group),
"available": True
"layer_height": layer_height,
"available": quality_group.is_available,
"intent_category": self._intent_category
})
layer_heights_added.append(layer_height)
# Now that we added all intents that we found something for, ensure that we set add ticks (and layer_heights)
# for all groups that we don't have anything for (and set it to not available)
for quality_tuple, quality_group in quality_groups.items():
# Add the intents that are of the correct category
if quality_tuple[0] != self._intent_category:
layer_height = self._fetchLayerHeight(quality_group)
if layer_height not in layer_heights_added:
new_items.append({"name": "Unavailable",
"quality_type": "",
"layer_height": layer_height,
"intent_category": self._intent_category,
"available": False})
layer_heights_added.append(layer_height)
new_items = sorted(new_items, key=lambda x: x["layer_height"])
self.setItems(new_items)
@ -98,3 +120,6 @@ class IntentModel(ListModel):
layer_height = layer_height(global_stack)
return float(layer_height)
def __repr__(self):
return str(self.items)