mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-25 07:33:57 -06:00
Expanded states preserved when updating models
Did this so that models can be updated more often fixing bugs where when a material is set as "not favorite" in the favorites section, its updated accordingly in its "normal" section. It's also the ground work for saving material section expansion to preferences. Contributes to CURA-5378
This commit is contained in:
parent
13069a2f99
commit
2304aeaceb
6 changed files with 74 additions and 28 deletions
|
@ -35,6 +35,9 @@ class BaseMaterialsModel(ListModel):
|
|||
# Update this model when list of materials changes
|
||||
self._material_manager.materialsUpdated.connect(self._update)
|
||||
|
||||
# Update this model when list of favorites changes
|
||||
self._material_manager.favoritesUpdated.connect(self._update)
|
||||
|
||||
self.addRoleName(Qt.UserRole + 1, "root_material_id")
|
||||
self.addRoleName(Qt.UserRole + 2, "id")
|
||||
self.addRoleName(Qt.UserRole + 3, "GUID")
|
||||
|
|
|
@ -8,7 +8,6 @@ class FavoriteMaterialsModel(BaseMaterialsModel):
|
|||
|
||||
def __init__(self, parent = None):
|
||||
super().__init__(parent)
|
||||
self._material_manager.favoritesUpdated.connect(self._update) # Update when favorites are changed
|
||||
self._update()
|
||||
|
||||
def _update(self):
|
||||
|
|
|
@ -13,7 +13,7 @@ import Cura 1.0 as Cura
|
|||
Rectangle
|
||||
{
|
||||
id: brand_section
|
||||
property var expanded: true
|
||||
property var expanded: base.collapsed_brands.indexOf(model.name) > -1
|
||||
property var types_model: model.material_types
|
||||
height: childrenRect.height
|
||||
width: parent.width
|
||||
|
@ -69,7 +69,19 @@ Rectangle
|
|||
anchors.fill: brand_header
|
||||
onPressed:
|
||||
{
|
||||
brand_section.expanded = !brand_section.expanded
|
||||
const i = base.collapsed_brands.indexOf(model.name)
|
||||
if (i > -1)
|
||||
{
|
||||
// Remove it
|
||||
base.collapsed_brands.splice(i, 1)
|
||||
brand_section.expanded = false
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add it
|
||||
base.collapsed_brands.push(model.name)
|
||||
brand_section.expanded = true
|
||||
}
|
||||
}
|
||||
}
|
||||
Column
|
||||
|
|
|
@ -102,7 +102,7 @@ Item
|
|||
}
|
||||
Rectangle
|
||||
{
|
||||
property var expanded: true
|
||||
property var expanded: base.collapsed_brands.indexOf("Generic") > -1
|
||||
|
||||
id: generic_section
|
||||
height: childrenRect.height
|
||||
|
@ -158,7 +158,19 @@ Item
|
|||
anchors.fill: generic_header
|
||||
onPressed:
|
||||
{
|
||||
generic_section.expanded = !generic_section.expanded
|
||||
const i = base.collapsed_brands.indexOf("Generic")
|
||||
if (i > -1)
|
||||
{
|
||||
// Remove it
|
||||
base.collapsed_brands.splice(i, 1)
|
||||
generic_section.expanded = false
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add it
|
||||
base.collapsed_brands.push("Generic")
|
||||
generic_section.expanded = true
|
||||
}
|
||||
}
|
||||
}
|
||||
Column
|
||||
|
|
|
@ -26,36 +26,44 @@ Item
|
|||
property string newRootMaterialIdToSwitchTo: ""
|
||||
property bool toActivateNewMaterial: false
|
||||
|
||||
// TODO: Save these to preferences
|
||||
property var collapsed_brands: []
|
||||
property var collapsed_types: []
|
||||
|
||||
UM.I18nCatalog
|
||||
{
|
||||
id: catalog
|
||||
name: "cura"
|
||||
}
|
||||
Cura.MaterialBrandsModel
|
||||
Cura.MaterialBrandsModel { id: materialsModel }
|
||||
|
||||
function findModelByRootId( search_root_id )
|
||||
{
|
||||
id: materialsModel
|
||||
}
|
||||
Cura.GenericMaterialsModel
|
||||
for (var i = 0; i < materialsModel.rowCount(); i++)
|
||||
{
|
||||
id: genericMaterialsModel
|
||||
var types_model = materialsModel.getItem(i).material_types;
|
||||
for (var j = 0; j < types_model.rowCount(); j++)
|
||||
{
|
||||
var colors_model = types_model.getItem(j).colors;
|
||||
for (var k = 0; k < colors_model.rowCount(); k++)
|
||||
{
|
||||
var material = colors_model.getItem(k);
|
||||
if (material.root_material_id == search_root_id)
|
||||
{
|
||||
return material
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Component.onCompleted:
|
||||
{
|
||||
// Select the activated material when this page shows up
|
||||
const extruder_position = Cura.ExtruderManager.activeExtruderIndex;
|
||||
const active_root_material_id = Cura.MachineManager.currentRootMaterialId[extruder_position];
|
||||
console.log("goign to search for", active_root_material_id)
|
||||
base.currentItem = findModelByRootId(active_root_material_id)
|
||||
}
|
||||
// Component.onCompleted:
|
||||
// {
|
||||
// // Select the activated material when this page shows up
|
||||
// const extruder_position = Cura.ExtruderManager.activeExtruderIndex;
|
||||
// const active_root_material_id = Cura.MachineManager.currentRootMaterialId[extruder_position];
|
||||
// var itemIndex = -1;
|
||||
// for (var i = 0; i < materialsModel.rowCount(); ++i)
|
||||
// {
|
||||
// var item = materialsModel.getItem(i);
|
||||
// if (item.root_material_id == active_root_material_id)
|
||||
// {
|
||||
// itemIndex = i;
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// materialListView.currentIndex = itemIndex;
|
||||
// }
|
||||
|
||||
onCurrentItemChanged: { MaterialsDetailsPanel.currentItem = currentItem }
|
||||
Connections
|
||||
|
|
|
@ -13,7 +13,7 @@ import Cura 1.0 as Cura
|
|||
Rectangle
|
||||
{
|
||||
id: material_type_section
|
||||
property var expanded: true
|
||||
property var expanded: base.collapsed_types.indexOf(model.brand + "_" + model.name) > -1
|
||||
property var colors_model: model.colors
|
||||
height: childrenRect.height
|
||||
width: parent.width
|
||||
|
@ -76,7 +76,19 @@ Rectangle
|
|||
anchors.fill: material_type_header
|
||||
onPressed:
|
||||
{
|
||||
material_type_section.expanded = !material_type_section.expanded
|
||||
const i = base.collapsed_types.indexOf(model.brand + "_" + model.name)
|
||||
if (i > -1)
|
||||
{
|
||||
// Remove it
|
||||
base.collapsed_types.splice(i, 1)
|
||||
material_type_section.expanded = false
|
||||
}
|
||||
else
|
||||
{
|
||||
// Add it
|
||||
base.collapsed_types.push(model.brand + "_" + model.name)
|
||||
material_type_section.expanded = true
|
||||
}
|
||||
}
|
||||
}
|
||||
Column
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue