From 972f0bef438dec38bede2e9a93cde6eafdce230f Mon Sep 17 00:00:00 2001 From: Diego Prado Gesto Date: Fri, 14 Sep 2018 10:51:56 +0200 Subject: [PATCH] WIP Fix an error in which the current selected material was not correctly selected when there is more than one brand (stupid mistake). Also fix problems when the user changes some material information. Contributes to CURA-5682. --- .../Materials/MaterialsDetailsPanel.qml | 15 +++--- .../Preferences/Materials/MaterialsList.qml | 51 +++++++++++++++---- .../Preferences/Materials/MaterialsView.qml | 12 ++--- 3 files changed, 53 insertions(+), 25 deletions(-) diff --git a/resources/qml/Preferences/Materials/MaterialsDetailsPanel.qml b/resources/qml/Preferences/Materials/MaterialsDetailsPanel.qml index ec5f694c18..43e98d63a6 100644 --- a/resources/qml/Preferences/Materials/MaterialsDetailsPanel.qml +++ b/resources/qml/Preferences/Materials/MaterialsDetailsPanel.qml @@ -13,16 +13,17 @@ Item { id: detailsPanel - property var currentItem: base.currentItem + property var currentItem: null - onCurrentItemChanged: updateMaterialPropertiesObject() + onCurrentItemChanged: + { + // When the current item changes, the detail view needs to be updated + updateMaterialPropertiesObject() + materialDetailsView.currentMaterialNode = currentItem.container_node + } function updateMaterialPropertiesObject() { - if (currentItem === null) - { - return - } materialProperties.name = currentItem.name || "Unknown" materialProperties.guid = currentItem.GUID materialProperties.container_id = currentItem.id @@ -71,8 +72,6 @@ Item properties: materialProperties containerId: currentItem != null ? currentItem.id : "" currentMaterialNode: currentItem.container_node - - } QtObject diff --git a/resources/qml/Preferences/Materials/MaterialsList.qml b/resources/qml/Preferences/Materials/MaterialsList.qml index 510d030445..0854371655 100644 --- a/resources/qml/Preferences/Materials/MaterialsList.qml +++ b/resources/qml/Preferences/Materials/MaterialsList.qml @@ -37,6 +37,13 @@ Item // Expand the list of materials in order to select the current material function expandActiveMaterial(search_root_id) { + if (search_root_id == "") + { + // When this happens it means that the information of one of the materials has changed, so the model + // was updated and the list has to highlight the current item. + var currentItemId = base.currentItem == null ? "" : base.currentItem.root_material_id + search_root_id = currentItemId + } for (var material_idx = 0; material_idx < genericMaterialsModel.rowCount(); material_idx++) { var material = genericMaterialsModel.getItem(material_idx) @@ -44,9 +51,9 @@ Item { if (materialList.expandedBrands.indexOf("Generic") == -1) { - materialList.expandedBrands.push("Generic"); - materialList.currentBrand = "Generic" + materialList.expandedBrands.push("Generic") } + materialList.currentBrand = "Generic" base.currentItem = material persistExpandedCategories() return true @@ -67,22 +74,22 @@ Item { if (materialList.expandedBrands.indexOf(brand.name) == -1) { - materialList.expandedBrands.push(brand.name); - materialList.currentBrand = brand.name + materialList.expandedBrands.push(brand.name) } + materialList.currentBrand = brand.name if (materialList.expandedTypes.indexOf(brand.name + "_" + type.name) == -1) { materialList.expandedTypes.push(brand.name + "_" + type.name) - materialList.currentType = brand.name + "_" + type.name } + materialList.currentType = brand.name + "_" + type.name base.currentItem = material persistExpandedCategories() return true } } } - return false } + return false } Connections @@ -91,13 +98,35 @@ Item onItemsChanged: { var correctlyExpanded = materialList.expandActiveMaterial(base.newRootMaterialIdToSwitchTo) - if (base.toActivateNewMaterial) + if (correctlyExpanded) { - var position = Cura.ExtruderManager.activeExtruderIndex - Cura.MachineManager.setMaterial(position, base.currentItem.container_node) + if (base.toActivateNewMaterial) + { + var position = Cura.ExtruderManager.activeExtruderIndex + Cura.MachineManager.setMaterial(position, base.currentItem.container_node) + } + base.newRootMaterialIdToSwitchTo = "" + base.toActivateNewMaterial = false + } + } + } + + Connections + { + target: genericMaterialsModel + onItemsChanged: + { + var correctlyExpanded = materialList.expandActiveMaterial(base.newRootMaterialIdToSwitchTo) + if (correctlyExpanded) + { + if (base.toActivateNewMaterial) + { + var position = Cura.ExtruderManager.activeExtruderIndex + Cura.MachineManager.setMaterial(position, base.currentItem.container_node) + } + base.newRootMaterialIdToSwitchTo = "" + base.toActivateNewMaterial = false } - base.newRootMaterialIdToSwitchTo = "" - base.toActivateNewMaterial = false } } diff --git a/resources/qml/Preferences/Materials/MaterialsView.qml b/resources/qml/Preferences/Materials/MaterialsView.qml index b1eb787cd2..56fa12877f 100644 --- a/resources/qml/Preferences/Materials/MaterialsView.qml +++ b/resources/qml/Preferences/Materials/MaterialsView.qml @@ -572,21 +572,21 @@ TabView } // update the values - base.materialManager.setMaterialName(base.currentMaterialNode, new_name); - materialProperties.name = new_name; + base.materialManager.setMaterialName(base.currentMaterialNode, new_name) + properties.name = new_name } // update the type of the material function updateMaterialType(old_type, new_type) { - base.setMetaDataEntry("material", old_type, new_type); - materialProperties.material = new_type; + base.setMetaDataEntry("material", old_type, new_type) + properties.material = new_type } // update the brand of the material function updateMaterialBrand(old_brand, new_brand) { - base.setMetaDataEntry("brand", old_brand, new_brand); - materialProperties.brand = new_brand; + base.setMetaDataEntry("brand", old_brand, new_brand) + properties.brand = new_brand } }