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.
This commit is contained in:
Diego Prado Gesto 2018-09-14 10:51:56 +02:00
parent 6dc53cc60a
commit 972f0bef43
3 changed files with 53 additions and 25 deletions

View File

@ -13,16 +13,17 @@ Item
{ {
id: detailsPanel 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() function updateMaterialPropertiesObject()
{ {
if (currentItem === null)
{
return
}
materialProperties.name = currentItem.name || "Unknown" materialProperties.name = currentItem.name || "Unknown"
materialProperties.guid = currentItem.GUID materialProperties.guid = currentItem.GUID
materialProperties.container_id = currentItem.id materialProperties.container_id = currentItem.id
@ -71,8 +72,6 @@ Item
properties: materialProperties properties: materialProperties
containerId: currentItem != null ? currentItem.id : "" containerId: currentItem != null ? currentItem.id : ""
currentMaterialNode: currentItem.container_node currentMaterialNode: currentItem.container_node
} }
QtObject QtObject

View File

@ -37,6 +37,13 @@ Item
// Expand the list of materials in order to select the current material // Expand the list of materials in order to select the current material
function expandActiveMaterial(search_root_id) 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++) for (var material_idx = 0; material_idx < genericMaterialsModel.rowCount(); material_idx++)
{ {
var material = genericMaterialsModel.getItem(material_idx) var material = genericMaterialsModel.getItem(material_idx)
@ -44,9 +51,9 @@ Item
{ {
if (materialList.expandedBrands.indexOf("Generic") == -1) if (materialList.expandedBrands.indexOf("Generic") == -1)
{ {
materialList.expandedBrands.push("Generic"); materialList.expandedBrands.push("Generic")
materialList.currentBrand = "Generic"
} }
materialList.currentBrand = "Generic"
base.currentItem = material base.currentItem = material
persistExpandedCategories() persistExpandedCategories()
return true return true
@ -67,22 +74,22 @@ Item
{ {
if (materialList.expandedBrands.indexOf(brand.name) == -1) if (materialList.expandedBrands.indexOf(brand.name) == -1)
{ {
materialList.expandedBrands.push(brand.name); materialList.expandedBrands.push(brand.name)
materialList.currentBrand = brand.name
} }
materialList.currentBrand = brand.name
if (materialList.expandedTypes.indexOf(brand.name + "_" + type.name) == -1) if (materialList.expandedTypes.indexOf(brand.name + "_" + type.name) == -1)
{ {
materialList.expandedTypes.push(brand.name + "_" + type.name) materialList.expandedTypes.push(brand.name + "_" + type.name)
materialList.currentType = brand.name + "_" + type.name
} }
materialList.currentType = brand.name + "_" + type.name
base.currentItem = material base.currentItem = material
persistExpandedCategories() persistExpandedCategories()
return true return true
} }
} }
} }
return false
} }
return false
} }
Connections Connections
@ -91,6 +98,8 @@ Item
onItemsChanged: onItemsChanged:
{ {
var correctlyExpanded = materialList.expandActiveMaterial(base.newRootMaterialIdToSwitchTo) var correctlyExpanded = materialList.expandActiveMaterial(base.newRootMaterialIdToSwitchTo)
if (correctlyExpanded)
{
if (base.toActivateNewMaterial) if (base.toActivateNewMaterial)
{ {
var position = Cura.ExtruderManager.activeExtruderIndex var position = Cura.ExtruderManager.activeExtruderIndex
@ -100,6 +109,26 @@ Item
base.toActivateNewMaterial = false 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
}
}
}
Column Column
{ {

View File

@ -572,21 +572,21 @@ TabView
} }
// update the values // update the values
base.materialManager.setMaterialName(base.currentMaterialNode, new_name); base.materialManager.setMaterialName(base.currentMaterialNode, new_name)
materialProperties.name = new_name; properties.name = new_name
} }
// update the type of the material // update the type of the material
function updateMaterialType(old_type, new_type) function updateMaterialType(old_type, new_type)
{ {
base.setMetaDataEntry("material", old_type, new_type); base.setMetaDataEntry("material", old_type, new_type)
materialProperties.material = new_type; properties.material = new_type
} }
// update the brand of the material // update the brand of the material
function updateMaterialBrand(old_brand, new_brand) function updateMaterialBrand(old_brand, new_brand)
{ {
base.setMetaDataEntry("brand", old_brand, new_brand); base.setMetaDataEntry("brand", old_brand, new_brand)
materialProperties.brand = new_brand; properties.brand = new_brand
} }
} }