mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-05-11 16:19:00 +08:00
Update ContainerSettingsModel when its containers have property changes
CURA-1668
This commit is contained in:
parent
e702fef44b
commit
b85a8ca404
@ -22,31 +22,10 @@ class ContainerSettingsModel(ListModel):
|
|||||||
self._container_ids = []
|
self._container_ids = []
|
||||||
self._container = None
|
self._container = None
|
||||||
|
|
||||||
self._global_container_stack = None
|
def _onPropertyChanged(self, key, property_name):
|
||||||
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):
|
|
||||||
if property_name == "value":
|
if property_name == "value":
|
||||||
self._update()
|
self._update()
|
||||||
|
|
||||||
def _onInstanceContainersChanged(self, container):
|
|
||||||
self._update()
|
|
||||||
|
|
||||||
def _update(self):
|
def _update(self):
|
||||||
self.clear()
|
self.clear()
|
||||||
|
|
||||||
@ -54,24 +33,17 @@ class ContainerSettingsModel(ListModel):
|
|||||||
return
|
return
|
||||||
|
|
||||||
keys = []
|
keys = []
|
||||||
containers = []
|
for container in self._containers:
|
||||||
for container_id in self._container_ids:
|
keys = keys + list(container.getAllKeys())
|
||||||
container = ContainerRegistry.getInstance().findContainers(id = container_id)
|
|
||||||
if not container:
|
|
||||||
return
|
|
||||||
|
|
||||||
keys = keys + list(container[0].getAllKeys())
|
keys = list(set(keys)) # remove duplicate keys
|
||||||
containers.append(container[0])
|
|
||||||
|
|
||||||
keys = list(set(keys))
|
|
||||||
keys.sort()
|
keys.sort()
|
||||||
|
|
||||||
for key in keys:
|
for key in keys:
|
||||||
definition = None
|
definition = None
|
||||||
category = None
|
category = None
|
||||||
values = []
|
values = []
|
||||||
for container in containers:
|
for container in self._containers:
|
||||||
|
|
||||||
instance = container.getInstance(key)
|
instance = container.getInstance(key)
|
||||||
if instance:
|
if instance:
|
||||||
definition = instance.definition
|
definition = instance.definition
|
||||||
@ -93,9 +65,21 @@ class ContainerSettingsModel(ListModel):
|
|||||||
"category": category.label
|
"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):
|
def setContainers(self, container_ids):
|
||||||
|
for container in self._containers:
|
||||||
|
container.propertyChanged.disconnect(self._onPropertyChanged)
|
||||||
|
|
||||||
self._container_ids = container_ids
|
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()
|
self._update()
|
||||||
|
|
||||||
containersChanged = pyqtSignal()
|
containersChanged = pyqtSignal()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user