mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-22 14:13:55 -06:00
Fix material menu model extruder binding and initial update
This commit is contained in:
parent
68b1a374e0
commit
8dfa52f15c
3 changed files with 36 additions and 11 deletions
|
@ -955,8 +955,6 @@ class CuraApplication(QtApplication):
|
||||||
qmlRegisterType(GenericMaterialsModel, "Cura", 1, 0, "GenericMaterialsModel")
|
qmlRegisterType(GenericMaterialsModel, "Cura", 1, 0, "GenericMaterialsModel")
|
||||||
qmlRegisterType(BrandMaterialsModel, "Cura", 1, 0, "BrandMaterialsModel")
|
qmlRegisterType(BrandMaterialsModel, "Cura", 1, 0, "BrandMaterialsModel")
|
||||||
qmlRegisterType(MaterialsModel, "Cura", 1, 0, "MaterialsModel")
|
qmlRegisterType(MaterialsModel, "Cura", 1, 0, "MaterialsModel")
|
||||||
|
|
||||||
# TODO: make this singleton?
|
|
||||||
qmlRegisterType(QualityManagementModel, "Cura", 1, 0, "QualityManagementModel")
|
qmlRegisterType(QualityManagementModel, "Cura", 1, 0, "QualityManagementModel")
|
||||||
|
|
||||||
qmlRegisterSingletonType(QualityProfilesModel, "Cura", 1, 0, "QualityProfilesModel", self.getQualityProfileModel)
|
qmlRegisterSingletonType(QualityProfilesModel, "Cura", 1, 0, "QualityProfilesModel", self.getQualityProfileModel)
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
# Copyright (c) 2017 Ultimaker B.V.
|
# Copyright (c) 2018 Ultimaker B.V.
|
||||||
# Cura is released under the terms of the LGPLv3 or higher.
|
# Cura is released under the terms of the LGPLv3 or higher.
|
||||||
|
|
||||||
from typing import Any, List, Optional
|
from typing import Optional
|
||||||
from PyQt5.QtCore import Qt
|
from PyQt5.QtCore import Qt, pyqtSignal, pyqtProperty
|
||||||
|
|
||||||
from UM.Logger import Logger
|
from UM.Logger import Logger
|
||||||
from UM.Qt.ListModel import ListModel
|
from UM.Qt.ListModel import ListModel
|
||||||
from UM.Settings.ContainerRegistry import ContainerRegistry
|
|
||||||
from UM.Settings.Models.InstanceContainersModel import InstanceContainersModel
|
|
||||||
|
|
||||||
|
|
||||||
def getAvailableMaterials(extruder_position: Optional[int] = None):
|
def getAvailableMaterials(extruder_position: Optional[int] = None):
|
||||||
|
@ -48,6 +46,8 @@ class BaseMaterialsModel(ListModel):
|
||||||
ColorRole = Qt.UserRole + 6
|
ColorRole = Qt.UserRole + 6
|
||||||
ContainerNodeRole = Qt.UserRole + 7
|
ContainerNodeRole = Qt.UserRole + 7
|
||||||
|
|
||||||
|
extruderPositionChanged = pyqtSignal()
|
||||||
|
|
||||||
def __init__(self, parent = None):
|
def __init__(self, parent = None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
|
||||||
|
@ -59,6 +59,17 @@ class BaseMaterialsModel(ListModel):
|
||||||
self.addRoleName(self.ColorRole, "color_name")
|
self.addRoleName(self.ColorRole, "color_name")
|
||||||
self.addRoleName(self.ContainerNodeRole, "container_node")
|
self.addRoleName(self.ContainerNodeRole, "container_node")
|
||||||
|
|
||||||
|
self._extruder_position = 0
|
||||||
|
|
||||||
|
def setExtruderPosition(self, position: int):
|
||||||
|
if self._extruder_position != position:
|
||||||
|
self._extruder_position = position
|
||||||
|
self.extruderPositionChanged.emit()
|
||||||
|
|
||||||
|
@pyqtProperty(int, fset = setExtruderPosition, notify = extruderPositionChanged)
|
||||||
|
def extruderPosition(self) -> int:
|
||||||
|
return self._extruder_positoin
|
||||||
|
|
||||||
|
|
||||||
class GenericMaterialsModel(BaseMaterialsModel):
|
class GenericMaterialsModel(BaseMaterialsModel):
|
||||||
|
|
||||||
|
@ -82,7 +93,7 @@ class GenericMaterialsModel(BaseMaterialsModel):
|
||||||
self.setItems([])
|
self.setItems([])
|
||||||
return
|
return
|
||||||
|
|
||||||
result_dict = getAvailableMaterials()
|
result_dict = getAvailableMaterials(self._extruder_position)
|
||||||
if result_dict is None:
|
if result_dict is None:
|
||||||
self.setItems([])
|
self.setItems([])
|
||||||
return
|
return
|
||||||
|
@ -126,12 +137,16 @@ class BrandMaterialsModel(ListModel):
|
||||||
NameRole = Qt.UserRole + 1
|
NameRole = Qt.UserRole + 1
|
||||||
MaterialsRole = Qt.UserRole + 2
|
MaterialsRole = Qt.UserRole + 2
|
||||||
|
|
||||||
|
extruderPositionChanged = pyqtSignal()
|
||||||
|
|
||||||
def __init__(self, parent = None):
|
def __init__(self, parent = None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
|
|
||||||
self.addRoleName(self.NameRole, "name")
|
self.addRoleName(self.NameRole, "name")
|
||||||
self.addRoleName(self.MaterialsRole, "materials")
|
self.addRoleName(self.MaterialsRole, "materials")
|
||||||
|
|
||||||
|
self._extruder_position = 0
|
||||||
|
|
||||||
from cura.CuraApplication import CuraApplication
|
from cura.CuraApplication import CuraApplication
|
||||||
self._machine_manager = CuraApplication.getInstance().getMachineManager()
|
self._machine_manager = CuraApplication.getInstance().getMachineManager()
|
||||||
extruder_manager = CuraApplication.getInstance().getExtruderManager()
|
extruder_manager = CuraApplication.getInstance().getExtruderManager()
|
||||||
|
@ -141,13 +156,24 @@ class BrandMaterialsModel(ListModel):
|
||||||
extruder_manager.activeExtruderChanged.connect(self._update)
|
extruder_manager.activeExtruderChanged.connect(self._update)
|
||||||
material_manager.materialsUpdated.connect(self._update)
|
material_manager.materialsUpdated.connect(self._update)
|
||||||
|
|
||||||
|
self._update()
|
||||||
|
|
||||||
|
def setExtruderPosition(self, position: int):
|
||||||
|
if self._extruder_position != position:
|
||||||
|
self._extruder_position = position
|
||||||
|
self.extruderPositionChanged.emit()
|
||||||
|
|
||||||
|
@pyqtProperty(int, fset = setExtruderPosition, notify = extruderPositionChanged)
|
||||||
|
def extruderPosition(self) -> int:
|
||||||
|
return self._extruder_position
|
||||||
|
|
||||||
def _update(self):
|
def _update(self):
|
||||||
global_stack = self._machine_manager.activeMachine
|
global_stack = self._machine_manager.activeMachine
|
||||||
if global_stack is None:
|
if global_stack is None:
|
||||||
self.setItems([])
|
self.setItems([])
|
||||||
return
|
return
|
||||||
|
|
||||||
result_dict = getAvailableMaterials()
|
result_dict = getAvailableMaterials(self._extruder_position)
|
||||||
if result_dict is None:
|
if result_dict is None:
|
||||||
self.setItems([])
|
self.setItems([])
|
||||||
return
|
return
|
||||||
|
@ -180,7 +206,7 @@ class BrandMaterialsModel(ListModel):
|
||||||
|
|
||||||
for brand, material_dict in brand_group_dict.items():
|
for brand, material_dict in brand_group_dict.items():
|
||||||
brand_item = {"name": brand,
|
brand_item = {"name": brand,
|
||||||
"materials": MaterialsModelGroupedByType(self)} # TODO
|
"materials": MaterialsModelGroupedByType(self)}
|
||||||
|
|
||||||
material_type_item_list = []
|
material_type_item_list = []
|
||||||
for material_type, material_list in material_dict.items():
|
for material_type, material_list in material_dict.items():
|
||||||
|
|
|
@ -82,12 +82,13 @@ Menu
|
||||||
Cura.GenericMaterialsModel
|
Cura.GenericMaterialsModel
|
||||||
{
|
{
|
||||||
id: genericMaterialsModel
|
id: genericMaterialsModel
|
||||||
//Component.onCompleted: populateMenuModels()
|
extruderPosition: menu.extruderIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
Cura.BrandMaterialsModel
|
Cura.BrandMaterialsModel
|
||||||
{
|
{
|
||||||
id: brandModel
|
id: brandModel
|
||||||
|
extruderPosition: menu.extruderIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
ExclusiveGroup { id: group }
|
ExclusiveGroup { id: group }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue