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

View file

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

View file

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