Fix some issues in the material preference page.

Now the generic section collapses and expands correctly. Some qml error
was also fixed.

Contributes to CURA-5682.
This commit is contained in:
Diego Prado Gesto 2018-09-10 15:57:19 +02:00
parent 51b0497f84
commit fe256b3562
3 changed files with 37 additions and 24 deletions

View File

@ -15,19 +15,23 @@ Item
property var currentItem: base.currentItem property var currentItem: base.currentItem
onCurrentItemChanged: { updateMaterialPropertiesObject(currentItem) } onCurrentItemChanged: { updateMaterialPropertiesObject() }
function updateMaterialPropertiesObject( currentItem ) 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
materialProperties.brand = currentItem.brand || "Unknown" materialProperties.brand = currentItem.brand || "Unknown"
materialProperties.material = currentItem.material || "Unknown" materialProperties.material = currentItem.material || "Unknown"
materialProperties.color_name = currentItem.color_name || "Yellow" materialProperties.color_name = currentItem.color_name || "Yellow"
materialProperties.color_code = currentItem.color_code || "yellow" materialProperties.color_code = currentItem.color_code || "yellow"
materialProperties.description = currentItem.description || "" materialProperties.description = currentItem.description || ""
materialProperties.adhesion_info = currentItem.adhesion_info || ""; materialProperties.adhesion_info = currentItem.adhesion_info || ""
materialProperties.density = currentItem.density || 0.0 materialProperties.density = currentItem.density || 0.0
materialProperties.diameter = currentItem.diameter || 0.0 materialProperties.diameter = currentItem.diameter || 0.0
materialProperties.approximate_diameter = currentItem.approximate_diameter || "0" materialProperties.approximate_diameter = currentItem.approximate_diameter || "0"
@ -62,11 +66,11 @@ Item
bottom: parent.bottom bottom: parent.bottom
} }
editingEnabled: base.currentItem != null && !base.currentItem.is_read_only editingEnabled: currentItem != null && !currentItem.is_read_only
properties: materialProperties properties: materialProperties
containerId: base.currentItem != null ? base.currentItem.id : "" containerId: currentItem != null ? currentItem.id : ""
currentMaterialNode: base.currentItem.container_node currentMaterialNode: currentItem.container_node
} }

View File

@ -181,10 +181,12 @@ Item
anchors.left: parent.left anchors.left: parent.left
height: generic_section.expanded ? childrenRect.height : 0 height: generic_section.expanded ? childrenRect.height : 0
visible: generic_section.expanded visible: generic_section.expanded
Repeater Repeater
{ {
model: genericMaterialsModel model: genericMaterialsModel
delegate: MaterialsSlot { delegate: MaterialsSlot
{
material: model material: model
} }
} }

View File

@ -19,6 +19,8 @@ Item
property var currentItem: null property var currentItem: null
property var current_type: null property var current_type: null
property var current_brand: null property var current_brand: null
property var hasCurrentItem: base.currentItem != null
property var isCurrentItemActivated: property var isCurrentItemActivated:
{ {
const extruder_position = Cura.ExtruderManager.activeExtruderIndex; const extruder_position = Cura.ExtruderManager.activeExtruderIndex;
@ -89,47 +91,48 @@ Item
} }
Component.onCompleted: { expandActiveMaterial(active_root_material_id) } Component.onCompleted: { expandActiveMaterial(active_root_material_id) }
onCurrentItemChanged: { MaterialsDetailsPanel.currentItem = currentItem } onCurrentItemChanged: { materialDetailsPanel.currentItem = currentItem }
Connections Connections
{ {
target: materials_model target: materials_model
onItemsChanged: onItemsChanged:
{ {
var currentItemId = base.currentItem == null ? "" : base.currentItem.root_material_id; var currentItemId = hasCurrentItem ? base.currentItem.root_material_id : ""
var position = Cura.ExtruderManager.activeExtruderIndex; var position = Cura.ExtruderManager.activeExtruderIndex
// try to pick the currently selected item; it may have been moved // try to pick the currently selected item; it may have been moved
if (base.newRootMaterialIdToSwitchTo == "") if (base.newRootMaterialIdToSwitchTo == "")
{ {
base.newRootMaterialIdToSwitchTo = currentItemId; base.newRootMaterialIdToSwitchTo = currentItemId
} }
for (var idx = 0; idx < materials_model.rowCount(); ++idx) for (var idx = 0; idx < materials_model.rowCount(); ++idx)
{ {
var item = materials_model.getItem(idx); var item = materials_model.getItem(idx)
if (item.root_material_id == base.newRootMaterialIdToSwitchTo) if (item.root_material_id == base.newRootMaterialIdToSwitchTo)
{ {
// Switch to the newly created profile if needed // Switch to the newly created profile if needed
materialListView.currentIndex = idx; materialDetailsPanel.currentIndex = idx
materialListView.activateDetailsWithIndex(materialListView.currentIndex); materialDetailsPanel.activateDetailsWithIndex(materialListView.currentIndex)
if (base.toActivateNewMaterial) if (base.toActivateNewMaterial)
{ {
Cura.MachineManager.setMaterial(position, item.container_node); Cura.MachineManager.setMaterial(position, item.container_node)
} }
base.newRootMaterialIdToSwitchTo = ""; base.newRootMaterialIdToSwitchTo = ""
base.toActivateNewMaterial = false; base.toActivateNewMaterial = false
return return
} }
} }
materialListView.currentIndex = 0; materialListView.currentIndex = 0
materialListView.activateDetailsWithIndex(materialListView.currentIndex); materialListView.activateDetailsWithIndex(materialListView.currentIndex)
if (base.toActivateNewMaterial) if (base.toActivateNewMaterial)
{ {
Cura.MachineManager.setMaterial(position, materials_model.getItem(0).container_node); Cura.MachineManager.setMaterial(position, materials_model.getItem(0).container_node)
} }
base.newRootMaterialIdToSwitchTo = ""; base.newRootMaterialIdToSwitchTo = ""
base.toActivateNewMaterial = false; base.toActivateNewMaterial = false
} }
} }
@ -313,11 +316,15 @@ Item
frameVisible: true frameVisible: true
verticalScrollBarPolicy: Qt.ScrollBarAlwaysOn verticalScrollBarPolicy: Qt.ScrollBarAlwaysOn
MaterialsList {} MaterialsList
{
id: materialListView
}
} }
MaterialsDetailsPanel MaterialsDetailsPanel
{ {
id: materialDetailsPanel
anchors anchors
{ {
left: materialScrollView.right left: materialScrollView.right