mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-04-22 21:59:37 +08:00
Wait with updating active stack variant and material until dialog was closed - CURA-4447
This commit is contained in:
parent
09ed53b4ec
commit
2361e96e29
@ -407,6 +407,8 @@ class CuraApplication(QtApplication):
|
||||
has_user_interaction = True
|
||||
return has_user_interaction
|
||||
|
||||
onDiscardOrKeepProfileChangesClosed = pyqtSignal() # Used to notify other managers that the dialog was closed
|
||||
|
||||
@pyqtSlot(str)
|
||||
def discardOrKeepProfileChangesClosed(self, option):
|
||||
if option == "discard":
|
||||
@ -429,6 +431,7 @@ class CuraApplication(QtApplication):
|
||||
user_global_container.update()
|
||||
|
||||
# notify listeners that quality has changed (after user selected discard or keep)
|
||||
self.onDiscardOrKeepProfileChangesClosed.emit()
|
||||
self.getMachineManager().activeQualityChanged.emit()
|
||||
|
||||
@pyqtSlot(int)
|
||||
|
@ -47,6 +47,10 @@ class MachineManager(QObject):
|
||||
self._active_container_stack = None # type: CuraContainerStack
|
||||
self._global_container_stack = None # type: GlobalStack
|
||||
|
||||
# Used to store the new containers until after confirming the dialog
|
||||
self._new_variant_container = None
|
||||
self._new_material_container = None
|
||||
|
||||
self._error_check_timer = QTimer()
|
||||
self._error_check_timer.setInterval(250)
|
||||
self._error_check_timer.setSingleShot(True)
|
||||
@ -58,6 +62,7 @@ class MachineManager(QObject):
|
||||
self._instance_container_timer.timeout.connect(self.__onInstanceContainersChanged)
|
||||
|
||||
Application.getInstance().globalContainerStackChanged.connect(self._onGlobalContainerChanged)
|
||||
|
||||
## When the global container is changed, active material probably needs to be updated.
|
||||
self.globalContainerChanged.connect(self.activeMaterialChanged)
|
||||
self.globalContainerChanged.connect(self.activeVariantChanged)
|
||||
@ -84,6 +89,9 @@ class MachineManager(QObject):
|
||||
ExtruderManager.getInstance().activeExtruderChanged.connect(self.activeStackChanged)
|
||||
self.activeStackChanged.connect(self.activeStackValueChanged)
|
||||
|
||||
# when a user closed dialog check if any delayed material or variant changes need to be applied
|
||||
Application.getInstance().onDiscardOrKeepProfileChangesClosed.connect(self._executeDelayedActiveContainerStackChanges)
|
||||
|
||||
Preferences.getInstance().addPreference("cura/active_machine", "")
|
||||
|
||||
self._global_event_keys = set()
|
||||
@ -747,7 +755,7 @@ class MachineManager(QObject):
|
||||
self.blurSettings.emit()
|
||||
old_material.nameChanged.disconnect(self._onMaterialNameChanged)
|
||||
|
||||
self._active_container_stack.material = material_container
|
||||
self._new_material_container = material_container # self._active_container_stack will be updated with a delay
|
||||
Logger.log("d", "Active material changed")
|
||||
|
||||
material_container.nameChanged.connect(self._onMaterialNameChanged)
|
||||
@ -801,13 +809,13 @@ class MachineManager(QObject):
|
||||
old_material = self._active_container_stack.material
|
||||
if old_variant:
|
||||
self.blurSettings.emit()
|
||||
self._active_container_stack.variant = containers[0]
|
||||
self._new_variant_container = containers[0] # self._active_container_stack will be updated with a delay
|
||||
Logger.log("d", "Active variant changed to {active_variant_id}".format(active_variant_id = containers[0].getId()))
|
||||
preferred_material_name = None
|
||||
if old_material:
|
||||
preferred_material_name = old_material.getName()
|
||||
|
||||
self.setActiveMaterial(self._updateMaterialContainer(self._global_container_stack.getBottom(), self._global_container_stack, containers[0], preferred_material_name).id)
|
||||
preferred_material_id = self._updateMaterialContainer(self._global_container_stack.getBottom(), self._global_container_stack, containers[0], preferred_material_name).id
|
||||
self.setActiveMaterial(preferred_material_id)
|
||||
else:
|
||||
Logger.log("w", "While trying to set the active variant, no variant was found to replace.")
|
||||
|
||||
@ -873,6 +881,19 @@ class MachineManager(QObject):
|
||||
if not has_user_interaction:
|
||||
self.activeQualityChanged.emit()
|
||||
|
||||
## Used to update material and variant in the active container stack with a delay.
|
||||
# This delay prevents the stack from triggering a lot of signals (eventually resulting in slicing)
|
||||
# before the user decided to keep or discard any of their changes using the dialog.
|
||||
# The activeQualityChanged signal triggers this method.
|
||||
def _executeDelayedActiveContainerStackChanges(self):
|
||||
if self._new_material_container is not None:
|
||||
self._active_container_stack.material = self._new_material_container
|
||||
self._new_material_container = None
|
||||
|
||||
if self._new_variant_container is not None:
|
||||
self._active_container_stack.variant = self._new_variant_container
|
||||
self._new_variant_container = None
|
||||
|
||||
## Determine the quality and quality changes settings for the current machine for a quality name.
|
||||
#
|
||||
# \param quality_name \type{str} the name of the quality.
|
||||
|
Loading…
x
Reference in New Issue
Block a user