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
This commit is contained in:
c.lamboo 2022-11-25 16:09:55 +01:00
parent e8f6786e97
commit 52ee149edc
3 changed files with 46 additions and 71 deletions

View file

@ -1631,33 +1631,49 @@ class MachineManager(QObject):
# Examples: # Examples:
# - "my_profile - Fine" (only based on a default quality, no intent involved) # - "my_profile - Fine" (only based on a default quality, no intent involved)
# - "my_profile - Engineering - Fine" (based on an intent) # - "my_profile - Engineering - Fine" (based on an intent)
@pyqtProperty("QList<QString>", 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) @pyqtProperty("QVariantMap", notify = activeQualityDisplayNameChanged)
def activeQualityDisplayNameMap(self) -> Dict[str, str]: def activeQualityDisplayNameMap(self) -> Dict[str, Any]:
global_stack = self._application.getGlobalContainerStack() global_stack = self._application.getGlobalContainerStack()
if global_stack is None: if global_stack is None:
return {"main": "", return {
"suffix": ""} "profile": "",
"intent_category": "",
"intent": "",
"custom_profile": None,
"is_experimental": False
}
display_name = global_stack.quality.getName() return {
"profile": global_stack.quality.getName(),
intent_category = self.activeIntentCategory "intent_category": self.activeIntentCategory,
if intent_category != "default": "intent_name": IntentCategoryModel.translation(self.activeIntentCategory, "name", self.activeIntentCategory.title()),
intent_display_name = IntentCategoryModel.translation(intent_category, "custom_profile": self.activeQualityOrQualityChangesName \
"name", if global_stack.qualityChanges is not empty_quality_changes_container \
intent_category.title()) else None,
display_name = "{intent_name} - {the_rest}".format(intent_name = intent_display_name, "layer_height": self.activeQualityLayerHeight if self.isActiveQualitySupported else None,
the_rest = display_name) "is_experimental": self.isActiveQualityExperimental and self.isActiveQualitySupported,
}
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}
@pyqtSlot(str) @pyqtSlot(str)
def setIntentByCategory(self, intent_category: str) -> None: def setIntentByCategory(self, intent_category: str) -> None:
@ -1776,7 +1792,9 @@ class MachineManager(QObject):
@pyqtProperty(bool, notify = activeQualityGroupChanged) @pyqtProperty(bool, notify = activeQualityGroupChanged)
def hasNotSupportedQuality(self) -> bool: def hasNotSupportedQuality(self) -> bool:
global_container_stack = self._application.getGlobalContainerStack() 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) @pyqtProperty(bool, notify = activeQualityGroupChanged)
def isActiveQualityCustom(self) -> bool: def isActiveQualityCustom(self) -> bool:

View file

@ -67,7 +67,7 @@ Item
UM.Label UM.Label
{ {
id: textLabel id: textLabel
text: Cura.MachineManager.activeQualityDisplayNameMap["main"] text: Cura.MachineManager.activeQualityDisplayNameStringParts[0]
Layout.margins: 0 Layout.margins: 0
Layout.maximumWidth: Math.floor(parent.width * 0.7) // Always leave >= 30% for the rest of the row. Layout.maximumWidth: Math.floor(parent.width * 0.7) // Always leave >= 30% for the rest of the row.
height: contentHeight height: contentHeight
@ -77,7 +77,8 @@ Item
UM.Label UM.Label
{ {
text: activeQualityDetailText() text: Cura.MachineManager.activeQualityDisplayNameStringParts.slice(1).join(" - ")
color: UM.Theme.getColor("text_detail") color: UM.Theme.getColor("text_detail")
Layout.margins: 0 Layout.margins: 0
Layout.fillWidth: true Layout.fillWidth: true
@ -85,32 +86,6 @@ Item
height: contentHeight height: contentHeight
elide: Text.ElideRight elide: Text.ElideRight
wrapMode: Text.NoWrap 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
}
} }
} }

View file

@ -17,26 +17,8 @@ RowLayout
{ {
source: UM.Theme.getIcon("Sliders", "medium") source: UM.Theme.getIcon("Sliders", "medium")
iconSize: UM.Theme.getSize("button_icon").width 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: Cura.MachineManager.activeQualityDisplayNameStringParts.join(" - ")
{
text += " - " + layerHeight.properties.value + "mm"
text += Cura.MachineManager.isActiveQualityExperimental ? " - " + catalog.i18nc("@label", "Experimental") : ""
}
return text
}
return ""
}
font: UM.Theme.getFont("medium") font: UM.Theme.getFont("medium")
elide: Text.ElideMiddle elide: Text.ElideMiddle
wrapMode: Text.NoWrap wrapMode: Text.NoWrap