From 52ee149edc1960382595f71c30a8e98a37d93aa7 Mon Sep 17 00:00:00 2001 From: "c.lamboo" Date: Fri, 25 Nov 2022 16:09:55 +0100 Subject: [PATCH] Unify `activeQualityDisplayNameMap` string creation Generation quality display names in `CustomPrintSetup.qml` and `PrintSetupSelectorHeader.qml` were so similar that I decided to combine the logic. Cura-9773 --- cura/Settings/MachineManager.py | 66 ++++++++++++------- .../Custom/CustomPrintSetup.qml | 31 +-------- .../PrintSetupSelectorHeader.qml | 20 +----- 3 files changed, 46 insertions(+), 71 deletions(-) diff --git a/cura/Settings/MachineManager.py b/cura/Settings/MachineManager.py index 27d8fbbc78..6992ffc4e0 100755 --- a/cura/Settings/MachineManager.py +++ b/cura/Settings/MachineManager.py @@ -1631,33 +1631,49 @@ class MachineManager(QObject): # Examples: # - "my_profile - Fine" (only based on a default quality, no intent involved) # - "my_profile - Engineering - Fine" (based on an intent) + @pyqtProperty("QList", notify = activeQualityDisplayNameChanged) + def activeQualityDisplayNameStringParts(self) -> [str]: + result_map = self.activeQualityDisplayNameMap + string_parts = list() + + if result_map["custom_profile"] is not None: + string_parts.append(result_map["custom_profile"]) + + string_parts.append(result_map["profile"]) + + if result_map["intent_category"] is not "default": + string_parts.append(result_map["intent_name"]) + + if result_map["layer_height"]: + string_parts.append(f"""{result_map["layer_height"]}mm""") + + if result_map["is_experimental"]: + string_parts.append(catalog.i18nc("@label", "Experimental")) + + return string_parts + @pyqtProperty("QVariantMap", notify = activeQualityDisplayNameChanged) - def activeQualityDisplayNameMap(self) -> Dict[str, str]: + def activeQualityDisplayNameMap(self) -> Dict[str, Any]: global_stack = self._application.getGlobalContainerStack() if global_stack is None: - return {"main": "", - "suffix": ""} + return { + "profile": "", + "intent_category": "", + "intent": "", + "custom_profile": None, + "is_experimental": False + } - display_name = global_stack.quality.getName() - - intent_category = self.activeIntentCategory - if intent_category != "default": - intent_display_name = IntentCategoryModel.translation(intent_category, - "name", - intent_category.title()) - display_name = "{intent_name} - {the_rest}".format(intent_name = intent_display_name, - the_rest = display_name) - - main_part = display_name - suffix_part = "" - - # Not a custom quality - if global_stack.qualityChanges != empty_quality_changes_container: - main_part = self.activeQualityOrQualityChangesName - suffix_part = display_name - - return {"main": main_part, - "suffix": suffix_part} + return { + "profile": global_stack.quality.getName(), + "intent_category": self.activeIntentCategory, + "intent_name": IntentCategoryModel.translation(self.activeIntentCategory, "name", self.activeIntentCategory.title()), + "custom_profile": self.activeQualityOrQualityChangesName \ + if global_stack.qualityChanges is not empty_quality_changes_container \ + else None, + "layer_height": self.activeQualityLayerHeight if self.isActiveQualitySupported else None, + "is_experimental": self.isActiveQualityExperimental and self.isActiveQualitySupported, + } @pyqtSlot(str) def setIntentByCategory(self, intent_category: str) -> None: @@ -1776,7 +1792,9 @@ class MachineManager(QObject): @pyqtProperty(bool, notify = activeQualityGroupChanged) def hasNotSupportedQuality(self) -> bool: global_container_stack = self._application.getGlobalContainerStack() - return (not global_container_stack is None) and global_container_stack.quality == empty_quality_container and global_container_stack.qualityChanges == empty_quality_changes_container + return global_container_stack is not None\ + and global_container_stack.quality == empty_quality_container \ + and global_container_stack.qualityChanges == empty_quality_changes_container @pyqtProperty(bool, notify = activeQualityGroupChanged) def isActiveQualityCustom(self) -> bool: diff --git a/resources/qml/PrintSetupSelector/Custom/CustomPrintSetup.qml b/resources/qml/PrintSetupSelector/Custom/CustomPrintSetup.qml index 554b663a9b..6385d60c6a 100644 --- a/resources/qml/PrintSetupSelector/Custom/CustomPrintSetup.qml +++ b/resources/qml/PrintSetupSelector/Custom/CustomPrintSetup.qml @@ -67,7 +67,7 @@ Item UM.Label { id: textLabel - text: Cura.MachineManager.activeQualityDisplayNameMap["main"] + text: Cura.MachineManager.activeQualityDisplayNameStringParts[0] Layout.margins: 0 Layout.maximumWidth: Math.floor(parent.width * 0.7) // Always leave >= 30% for the rest of the row. height: contentHeight @@ -77,7 +77,8 @@ Item UM.Label { - text: activeQualityDetailText() + text: Cura.MachineManager.activeQualityDisplayNameStringParts.slice(1).join(" - ") + color: UM.Theme.getColor("text_detail") Layout.margins: 0 Layout.fillWidth: true @@ -85,32 +86,6 @@ Item height: contentHeight elide: Text.ElideRight wrapMode: Text.NoWrap - function activeQualityDetailText() - { - var resultMap = Cura.MachineManager.activeQualityDisplayNameMap - var resultSuffix = resultMap["suffix"] - var result = "" - - if (Cura.MachineManager.isActiveQualityExperimental) - { - resultSuffix += " (Experimental)" - } - - if (Cura.MachineManager.isActiveQualitySupported) - { - if (Cura.MachineManager.activeQualityLayerHeight > 0) - { - if (resultSuffix) - { - result += " - " + resultSuffix - } - result += " - " - result += Cura.MachineManager.activeQualityLayerHeight + "mm" - } - } - - return result - } } } diff --git a/resources/qml/PrintSetupSelector/PrintSetupSelectorHeader.qml b/resources/qml/PrintSetupSelector/PrintSetupSelectorHeader.qml index 41e913a2c1..8804e51bb2 100644 --- a/resources/qml/PrintSetupSelector/PrintSetupSelectorHeader.qml +++ b/resources/qml/PrintSetupSelector/PrintSetupSelectorHeader.qml @@ -17,26 +17,8 @@ RowLayout { source: UM.Theme.getIcon("Sliders", "medium") iconSize: UM.Theme.getSize("button_icon").width - text: - { - if (Cura.MachineManager.activeStack) - { - var resultMap = Cura.MachineManager.activeQualityDisplayNameMap - var text = resultMap["main"] - if (resultMap["suffix"]) - { - text += " - " + resultMap["suffix"] - } - if (!Cura.MachineManager.hasNotSupportedQuality) - { - text += " - " + layerHeight.properties.value + "mm" - text += Cura.MachineManager.isActiveQualityExperimental ? " - " + catalog.i18nc("@label", "Experimental") : "" - } - return text - } - return "" - } + text: Cura.MachineManager.activeQualityDisplayNameStringParts.join(" - ") font: UM.Theme.getFont("medium") elide: Text.ElideMiddle wrapMode: Text.NoWrap