Clean up the code by removing duplicate code. Also try to unify the

MaterialsBrandSection to use the same component for favorites, generic
and branded materials.

Contributes to CURA-5682.
This commit is contained in:
Diego Prado Gesto 2018-09-14 14:46:33 +02:00
parent 972f0bef43
commit f871a89825
3 changed files with 158 additions and 137 deletions

View file

@ -15,7 +15,7 @@ Rectangle
id: brand_section
property var sectionName: ""
property var elements // This can be a MaterialTypesModel or GenericMaterialsModel
property var elementsModel // This can be a MaterialTypesModel or GenericMaterialsModel or FavoriteMaterialsModel
property var hasMaterialTypes: true // It indicates wheather it has material types or not
property var expanded: materialList.expandedBrands.indexOf(sectionName) > -1
@ -109,22 +109,44 @@ Rectangle
Repeater
{
model: elements
delegate: MaterialsTypeSection
model: elementsModel
delegate: Item
{
visible: hasMaterialTypes
materialType: model
Loader
{
id: loader
property var element: model
sourceComponent: hasMaterialTypes ? materialsTypeSection : materialSlot
}
}
}
// In case there are no types, we create a material slot
Repeater
// Repeater
// {
// model: elementsModel
// delegate: MaterialsSlot
// {
// visible: !hasMaterialTypes
// material: model
// }
// }
}
Component
{
id: materialsTypeSection
MaterialsTypeSection
{
model: elements
delegate: MaterialsSlot
{
visible: !hasMaterialTypes
material: model
}
materialType: element
}
}
Component
{
id: materialSlot
MaterialsSlot
{
material: element
}
}