mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-14 02:07:51 -06:00
Add a property to temporarily disable the material models from updating.
This allows the QMl to stop the updating when it's not even visible
This commit is contained in:
parent
7754b8a447
commit
41f2a0e222
3 changed files with 20 additions and 1 deletions
|
@ -16,6 +16,7 @@ from cura.Machines.MaterialNode import MaterialNode
|
|||
class BaseMaterialsModel(ListModel):
|
||||
|
||||
extruderPositionChanged = pyqtSignal()
|
||||
enabledChanged = pyqtSignal()
|
||||
|
||||
def __init__(self, parent = None):
|
||||
super().__init__(parent)
|
||||
|
@ -59,6 +60,7 @@ class BaseMaterialsModel(ListModel):
|
|||
|
||||
self._available_materials = None # type: Optional[Dict[str, MaterialNode]]
|
||||
self._favorite_ids = set() # type: Set[str]
|
||||
self._enabled = True
|
||||
|
||||
def _updateExtruderStack(self):
|
||||
global_stack = self._machine_manager.activeMachine
|
||||
|
@ -85,6 +87,18 @@ class BaseMaterialsModel(ListModel):
|
|||
def extruderPosition(self) -> int:
|
||||
return self._extruder_position
|
||||
|
||||
def setEnabled(self, enabled):
|
||||
if self._enabled != enabled:
|
||||
self._enabled = enabled
|
||||
if self._enabled:
|
||||
# ensure the data is there again.
|
||||
self._update()
|
||||
self.enabledChanged.emit()
|
||||
|
||||
@pyqtProperty(bool, fset=setEnabled, notify=enabledChanged)
|
||||
def enabled(self):
|
||||
return self._enabled
|
||||
|
||||
## This is an abstract method that needs to be implemented by the specific
|
||||
# models themselves.
|
||||
def _update(self):
|
||||
|
@ -96,7 +110,7 @@ class BaseMaterialsModel(ListModel):
|
|||
def _canUpdate(self):
|
||||
global_stack = self._machine_manager.activeMachine
|
||||
|
||||
if global_stack is None:
|
||||
if global_stack is None or not self._enabled:
|
||||
return False
|
||||
|
||||
extruder_position = str(self._extruder_position)
|
||||
|
|
|
@ -265,6 +265,7 @@ Item
|
|||
menu: Cura.MaterialMenu
|
||||
{
|
||||
extruderIndex: Cura.ExtruderManager.activeExtruderIndex
|
||||
updateModels: materialSelection.visible
|
||||
}
|
||||
}
|
||||
Item
|
||||
|
|
|
@ -15,22 +15,26 @@ Menu
|
|||
property int extruderIndex: 0
|
||||
property string currentRootMaterialId: Cura.MachineManager.currentRootMaterialId[extruderIndex]
|
||||
property string activeMaterialId: Cura.MachineManager.allActiveMaterialIds[Cura.ExtruderManager.extruderIds[extruderIndex]]
|
||||
property bool updateModels: true
|
||||
Cura.FavoriteMaterialsModel
|
||||
{
|
||||
id: favoriteMaterialsModel
|
||||
extruderPosition: menu.extruderIndex
|
||||
enabled: updateModels
|
||||
}
|
||||
|
||||
Cura.GenericMaterialsModel
|
||||
{
|
||||
id: genericMaterialsModel
|
||||
extruderPosition: menu.extruderIndex
|
||||
enabled: updateModels
|
||||
}
|
||||
|
||||
Cura.MaterialBrandsModel
|
||||
{
|
||||
id: brandModel
|
||||
extruderPosition: menu.extruderIndex
|
||||
enabled: updateModels
|
||||
}
|
||||
|
||||
MenuItem
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue