Turn if-clause into simple input check

Makes the code more readable in my opinion.

Contributes to issue CURA-2006.
This commit is contained in:
Ghostkeeper 2016-08-23 16:37:58 +02:00
parent 35fedbdad6
commit 9ba9e90a8f
No known key found for this signature in database
GPG key ID: 701948C5954A7385

View file

@ -489,7 +489,10 @@ class MachineManager(QObject):
old_variant = self._active_container_stack.findContainer({"type": "variant"})
old_material = self._active_container_stack.findContainer({"type": "material"})
old_quality = self._active_container_stack.findContainer({"type": "quality"})
if old_material:
if not old_material:
Logger.log("w", "While trying to set the active material, no material was found to replace it.")
return
old_material.nameChanged.disconnect(self._onMaterialNameChanged)
material_index = self._active_container_stack.getContainerIndex(old_material)
@ -502,8 +505,6 @@ class MachineManager(QObject):
preferred_quality_name = old_quality.getName()
self.setActiveQuality(self._updateQualityContainer(self._global_container_stack.getBottom(), old_variant, containers[0], preferred_quality_name).id)
else:
Logger.log("w", "While trying to set the active material, no material was found to replace.")
@pyqtSlot(str)
def setActiveVariant(self, variant_id):
@ -827,6 +828,33 @@ class MachineManager(QObject):
return self._empty_quality_container
## Finds a quality-changes container to use if any other container
# changes.
#
# \param quality_type The quality type to find a quality-changes for.
# \param preferred_quality_changes_name The name of the quality-changes to
# pick, if any such quality-changes profile is available.
def _updateQualityChangesContainer(self, quality_type, preferred_quality_changes_name = None):
container_registry = UM.Settings.ContainerRegistry.getInstance() # Cache.
search_criteria = { "type": "quality_changes" }
search_criteria["quality"] = quality_type
if preferred_quality_changes_name:
search_criteria["name"] = preferred_quality_changes_name
# Try to search with the name in the criteria first, since we prefer to have the correct name.
containers = container_registry.findInstanceContainers(**search_criteria)
if containers: # Found one!
return containers[0]
if "name" in search_criteria:
del search_criteria["name"] # Not found, then drop the name requirement (if we had one) and search again.
containers = container_registry.findInstanceContainers(**search_criteria)
if containers:
return containers[0]
return self._empty_quality_changes_container # Didn't find anything with the required quality_type.
def _onMachineNameChanged(self):
self.globalContainerChanged.emit()