Always update root material even if not in QML

Previously the _current_root_material_id and _current_root_material_name dictionaries were only updated if they are used anywhere in QML. This is unreliable. We're now directly connecting to the signal so that they are always updated, even when not in use by the GUI. This way we can rely on it in other places than the GUI.

Contributes to issue CURA-4606.
This commit is contained in:
Ghostkeeper 2018-03-13 09:09:21 +01:00
parent f40e9bffa9
commit a87db2d721
No known key found for this signature in database
GPG key ID: 5252B696FB5E7C7A

View file

@ -125,6 +125,7 @@ class MachineManager(QObject):
# When the materials lookup table gets updated, it can mean that a material has its name changed, which should
# be reflected on the GUI. This signal emission makes sure that it happens.
self._material_manager.materialsUpdated.connect(self.rootMaterialChanged)
self.rootMaterialChanged.connect(self._onRootMaterialChanged)
activeQualityGroupChanged = pyqtSignal()
activeQualityChangesGroupChanged = pyqtSignal()
@ -876,23 +877,26 @@ class MachineManager(QObject):
def currentExtruderPositions(self):
return sorted(list(self._global_container_stack.extruders.keys()))
@pyqtProperty("QVariant", notify = rootMaterialChanged)
def currentRootMaterialId(self):
# initial filling the current_root_material_id
## Update _current_root_material_id and _current_root_material_name when
# the current root material was changed.
def _onRootMaterialChanged(self):
self._current_root_material_id = {}
for position in self._global_container_stack.extruders:
self._current_root_material_id[position] = self._global_container_stack.extruders[position].material.getMetaDataEntry("base_file")
return self._current_root_material_id
@pyqtProperty("QVariant", notify = rootMaterialChanged)
def currentRootMaterialName(self):
# initial filling the current_root_material_name
if self._global_container_stack:
self._current_root_material_name = {}
for position in self._global_container_stack.extruders:
if position not in self._current_root_material_name:
material = self._global_container_stack.extruders[position].material
self._current_root_material_name[position] = material.getName()
@pyqtProperty("QVariant", notify = rootMaterialChanged)
def currentRootMaterialId(self):
return self._current_root_material_id
@pyqtProperty("QVariant", notify = rootMaterialChanged)
def currentRootMaterialName(self):
return self._current_root_material_name
## Return the variant names in the extruder stack(s).