From b85a8ca404a59e09def6b0e901b7b6374a221308 Mon Sep 17 00:00:00 2001 From: fieldOfView Date: Thu, 9 Jun 2016 07:54:13 +0200 Subject: [PATCH] Update ContainerSettingsModel when its containers have property changes CURA-1668 --- cura/ContainerSettingsModel.py | 52 ++++++++++++---------------------- 1 file changed, 18 insertions(+), 34 deletions(-) diff --git a/cura/ContainerSettingsModel.py b/cura/ContainerSettingsModel.py index 23d20cd6e2..1dea88cac3 100644 --- a/cura/ContainerSettingsModel.py +++ b/cura/ContainerSettingsModel.py @@ -22,31 +22,10 @@ class ContainerSettingsModel(ListModel): self._container_ids = [] self._container = None - self._global_container_stack = None - Application.getInstance().globalContainerStackChanged.connect(self._onGlobalContainerChanged) - self._update() - - def _onGlobalContainerChanged(self): - if self._global_container_stack: - self._global_container_stack.containersChanged.disconnect(self._onInstanceContainersChanged) - self._global_container_stack.propertyChanged.disconnect(self._onGlobalPropertyChanged) - - self._global_container_stack = Application.getInstance().getGlobalContainerStack() - - if self._global_container_stack: - Preferences.getInstance().setValue("cura/active_machine", self._global_container_stack.getId()) - self._global_container_stack.containersChanged.connect(self._onInstanceContainersChanged) - self._global_container_stack.propertyChanged.connect(self._onGlobalPropertyChanged) - - self._update() - - def _onGlobalPropertyChanged(self, key, property_name): + def _onPropertyChanged(self, key, property_name): if property_name == "value": self._update() - def _onInstanceContainersChanged(self, container): - self._update() - def _update(self): self.clear() @@ -54,24 +33,17 @@ class ContainerSettingsModel(ListModel): return keys = [] - containers = [] - for container_id in self._container_ids: - container = ContainerRegistry.getInstance().findContainers(id = container_id) - if not container: - return + for container in self._containers: + keys = keys + list(container.getAllKeys()) - keys = keys + list(container[0].getAllKeys()) - containers.append(container[0]) - - keys = list(set(keys)) + keys = list(set(keys)) # remove duplicate keys keys.sort() for key in keys: definition = None category = None values = [] - for container in containers: - + for container in self._containers: instance = container.getInstance(key) if instance: definition = instance.definition @@ -93,9 +65,21 @@ class ContainerSettingsModel(ListModel): "category": category.label }) - ## Set the id of the container which has the settings this model should list. + ## Set the ids of the containers which have the settings this model should list. + # Also makes sure the model updates when the containers have property changes def setContainers(self, container_ids): + for container in self._containers: + container.propertyChanged.disconnect(self._onPropertyChanged) + self._container_ids = container_ids + self._containers = [] + + for container_id in self._container_ids: + containers = ContainerRegistry.getInstance().findContainers(id = container_id) + if containers: + containers[0].propertyChanged.connect(self._onPropertyChanged) + self._containers.append(containers[0]) + self._update() containersChanged = pyqtSignal()