diff --git a/cura/Machines/Models/IntentModel.py b/cura/Machines/Models/IntentModel.py index b310ec47a6..666786e26a 100644 --- a/cura/Machines/Models/IntentModel.py +++ b/cura/Machines/Models/IntentModel.py @@ -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) diff --git a/resources/qml/PrintSetupSelector/Recommended/RecommendedQualityProfileSelector.qml b/resources/qml/PrintSetupSelector/Recommended/RecommendedQualityProfileSelector.qml index 7ad3493dca..2c8843122d 100644 --- a/resources/qml/PrintSetupSelector/Recommended/RecommendedQualityProfileSelector.qml +++ b/resources/qml/PrintSetupSelector/Recommended/RecommendedQualityProfileSelector.qml @@ -7,7 +7,7 @@ import QtQuick.Controls 2.3 as Controls2 import QtQuick.Controls.Styles 1.4 import UM 1.2 as UM -import Cura 1.0 as Cura +import Cura 1.6 as Cura // @@ -98,7 +98,8 @@ Item { id: activeProfileButtonGroup exclusive: true - onClicked: Cura.MachineManager.activeQualityGroup = button.identifier + onClicked: Cura.IntentManager.selectIntent(button.modelData.intent_category, button.modelData.quality_type) + } Cura.LabelBar @@ -114,29 +115,32 @@ Item modelKey: "layer_height" } - Cura.RadioCheckbar + Repeater { - anchors + model: Cura.IntentCategoryModel{} + Cura.RadioCheckbar { - left: parent.left - right: parent.right - } - - model: Cura.QualityProfilesDropDownMenuModel - buttonGroup: activeProfileButtonGroup - modelKey: "quality_group" - - function checkedFunction(modelItem) - { - if(Cura.MachineManager.hasCustomQuality) + anchors { - // When user created profile is active, no quality tickbox should be active. - return false + left: parent.left + right: parent.right } - return Cura.MachineManager.activeQualityType == modelItem.quality_type + dataModel: model["qualities"] + buttonGroup: activeProfileButtonGroup + + function checkedFunction(modelItem) + { + if(Cura.MachineManager.hasCustomQuality) + { + // When user created profile is active, no quality tickbox should be active. + return false + } + return Cura.MachineManager.activeQualityType == modelItem.quality_type && Cura.MachineManager.activeIntentCategory == modelItem.intent_category + } + + isCheckedFunction: checkedFunction } - isCheckedFunction: checkedFunction } } } \ No newline at end of file diff --git a/resources/qml/RadioCheckbar.qml b/resources/qml/RadioCheckbar.qml index 3044fedb86..1bc1c135f6 100644 --- a/resources/qml/RadioCheckbar.qml +++ b/resources/qml/RadioCheckbar.qml @@ -18,12 +18,7 @@ Item implicitWidth: 200 implicitHeight: checkboxSize - property var model: null - - // What key of the model should be used to set the identifier of the checkbox. - // This is used to figure out what checkbox just got toggled. Set a buttonGroup and listen to it's clicked signal. - // You can use button.identifier to figure out which button was clicked. - property string modelKey: "name" + property var dataModel: null // The horizontal inactive bar that sits behind the buttons Rectangle @@ -45,6 +40,7 @@ Item } } + RowLayout { id: buttonBar @@ -56,7 +52,7 @@ Item Repeater { id: repeater - model: base.model + model: base.dataModel height: checkboxSize Item { @@ -75,7 +71,9 @@ Item height: barSize width: buttonBar.width / (repeater.count - 1) - activeComponent.width - 2 color: defaultItemColor - + // This can (and should) be done wiht a verticalCenter. For some reason it does work in QtCreator + // but not when using the exact same QML in Cura. + y: 0.5 * checkboxSize anchors { right: activeComponent.left @@ -87,9 +85,7 @@ Item id: activeComponent sourceComponent: isEnabled? checkboxComponent : disabledComponent width: checkboxSize - // This can (and should) be done wiht a verticalCenter. For some reason it does work in QtCreator - // but not when using the exact same QML in Cura. - y: -0.5 * checkboxSize + property var modelItem: model } } @@ -127,7 +123,8 @@ Item ButtonGroup.group: buttonGroup width: checkboxSize height: checkboxSize - property var identifier: modelItem[base.modelKey] + property var modelData: modelItem + checked: isCheckedFunction(modelItem) indicator: Rectangle {