mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-24 15:13:56 -06:00
Provide activeQualityGroupName instead of QualityGroup(QObject)
We don't need to inherit from QObject if we expose the name elsewhere. This prevents having workarounds for C++ vs QML ownership, and also allows us to test this while mocking out CuraApplication. Done during Turbo Testing and Tooling.
This commit is contained in:
parent
6f2f15c74f
commit
6c0772cd4a
3 changed files with 27 additions and 20 deletions
|
@ -8,6 +8,7 @@ from UM.Signal import Signal
|
||||||
from UM.Util import parseBool
|
from UM.Util import parseBool
|
||||||
from UM.Settings.ContainerRegistry import ContainerRegistry # To find all the variants for this machine.
|
from UM.Settings.ContainerRegistry import ContainerRegistry # To find all the variants for this machine.
|
||||||
|
|
||||||
|
import cura.CuraApplication # Imported like this to prevent circular dependencies.
|
||||||
from cura.Machines.ContainerNode import ContainerNode
|
from cura.Machines.ContainerNode import ContainerNode
|
||||||
from cura.Machines.QualityChangesGroup import QualityChangesGroup # To construct groups of quality changes profiles that belong together.
|
from cura.Machines.QualityChangesGroup import QualityChangesGroup # To construct groups of quality changes profiles that belong together.
|
||||||
from cura.Machines.QualityGroup import QualityGroup # To construct groups of quality profiles that belong together.
|
from cura.Machines.QualityGroup import QualityGroup # To construct groups of quality profiles that belong together.
|
||||||
|
@ -81,15 +82,7 @@ class MachineNode(ContainerNode):
|
||||||
if not global_quality_node.container:
|
if not global_quality_node.container:
|
||||||
Logger.log("w", "Node {0} doesn't have a container.".format(global_quality_node.container_id))
|
Logger.log("w", "Node {0} doesn't have a container.".format(global_quality_node.container_id))
|
||||||
continue
|
continue
|
||||||
# CURA-6599
|
quality_groups[quality_type] = QualityGroup(name = global_quality_node.container.getMetaDataEntry("name", "Unnamed profile"), quality_type = quality_type)
|
||||||
# Same as QualityChangesGroup.
|
|
||||||
# For some reason, QML will get null or fail to convert type for MachineManager.activeQualityChangesGroup() to
|
|
||||||
# a QObject. Setting the object ownership to QQmlEngine.CppOwnership doesn't work, but setting the object
|
|
||||||
# parent to application seems to work.
|
|
||||||
from cura.CuraApplication import CuraApplication
|
|
||||||
quality_groups[quality_type] = QualityGroup(name = global_quality_node.container.getMetaDataEntry("name", "Unnamed profile"),
|
|
||||||
quality_type = quality_type,
|
|
||||||
parent = CuraApplication.getInstance())
|
|
||||||
quality_groups[quality_type].node_for_global = global_quality_node
|
quality_groups[quality_type].node_for_global = global_quality_node
|
||||||
for extruder, qualities_per_type in enumerate(qualities_per_type_per_extruder):
|
for extruder, qualities_per_type in enumerate(qualities_per_type_per_extruder):
|
||||||
if quality_type in qualities_per_type:
|
if quality_type in qualities_per_type:
|
||||||
|
@ -168,7 +161,7 @@ class MachineNode(ContainerNode):
|
||||||
return self.global_qualities.get(self.preferred_quality_type, next(iter(self.global_qualities.values())))
|
return self.global_qualities.get(self.preferred_quality_type, next(iter(self.global_qualities.values())))
|
||||||
|
|
||||||
## (Re)loads all variants under this printer.
|
## (Re)loads all variants under this printer.
|
||||||
def _loadAll(self):
|
def _loadAll(self) -> None:
|
||||||
container_registry = ContainerRegistry.getInstance()
|
container_registry = ContainerRegistry.getInstance()
|
||||||
if not self.has_variants:
|
if not self.has_variants:
|
||||||
self.variants["empty"] = VariantNode("empty_variant", machine = self)
|
self.variants["empty"] = VariantNode("empty_variant", machine = self)
|
||||||
|
|
|
@ -27,11 +27,12 @@ from cura.Machines.ContainerNode import ContainerNode
|
||||||
# applied to a configuration, so that when a quality level is selected, the
|
# applied to a configuration, so that when a quality level is selected, the
|
||||||
# container can directly be applied to each stack instead of looking them up
|
# container can directly be applied to each stack instead of looking them up
|
||||||
# again.
|
# again.
|
||||||
class QualityGroup(QObject):
|
class QualityGroup:
|
||||||
|
## Constructs a new group.
|
||||||
def __init__(self, name: str, quality_type: str, parent: Optional["QObject"] = None) -> None:
|
# \param name The user-visible name for the group.
|
||||||
super().__init__(parent)
|
# \param quality_type The quality level that each profile in this group
|
||||||
|
# has.
|
||||||
|
def __init__(self, name: str, quality_type: str) -> None:
|
||||||
self.name = name
|
self.name = name
|
||||||
self.node_for_global = None # type: Optional[ContainerNode]
|
self.node_for_global = None # type: Optional[ContainerNode]
|
||||||
self.nodes_for_extruders = {} # type: Dict[int, ContainerNode]
|
self.nodes_for_extruders = {} # type: Dict[int, ContainerNode]
|
||||||
|
@ -39,7 +40,6 @@ class QualityGroup(QObject):
|
||||||
self.is_available = False
|
self.is_available = False
|
||||||
self.is_experimental = False
|
self.is_experimental = False
|
||||||
|
|
||||||
@pyqtSlot(result = str)
|
|
||||||
def getName(self) -> str:
|
def getName(self) -> str:
|
||||||
return self.name
|
return self.name
|
||||||
|
|
||||||
|
|
|
@ -613,9 +613,10 @@ class MachineManager(QObject):
|
||||||
global_container_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
|
global_container_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
|
||||||
if not global_container_stack:
|
if not global_container_stack:
|
||||||
return False
|
return False
|
||||||
if not self.activeQualityGroup:
|
active_quality_group = self.activeQualityGroup()
|
||||||
|
if active_quality_group is None:
|
||||||
return False
|
return False
|
||||||
return self.activeQualityGroup.is_available
|
return active_quality_group.is_available
|
||||||
|
|
||||||
@pyqtProperty(bool, notify = activeQualityGroupChanged)
|
@pyqtProperty(bool, notify = activeQualityGroupChanged)
|
||||||
def isActiveQualityExperimental(self) -> bool:
|
def isActiveQualityExperimental(self) -> bool:
|
||||||
|
@ -1646,13 +1647,26 @@ class MachineManager(QObject):
|
||||||
else: # No intent had the correct category.
|
else: # No intent had the correct category.
|
||||||
extruder.intent = empty_intent_container
|
extruder.intent = empty_intent_container
|
||||||
|
|
||||||
@pyqtProperty(QObject, fset = setQualityGroup, notify = activeQualityGroupChanged)
|
## Get the currently activated quality group.
|
||||||
|
#
|
||||||
|
# If no printer is added yet or the printer doesn't have quality profiles,
|
||||||
|
# this returns ``None``.
|
||||||
|
# \return The currently active quality group.
|
||||||
def activeQualityGroup(self) -> Optional["QualityGroup"]:
|
def activeQualityGroup(self) -> Optional["QualityGroup"]:
|
||||||
global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
|
global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
|
||||||
if not global_stack or global_stack.quality == empty_quality_container:
|
if not global_stack or global_stack.quality == empty_quality_container:
|
||||||
return None
|
return None
|
||||||
return ContainerTree.getInstance().getCurrentQualityGroups().get(self.activeQualityType)
|
return ContainerTree.getInstance().getCurrentQualityGroups().get(self.activeQualityType)
|
||||||
|
|
||||||
|
## Get the name of the active quality group.
|
||||||
|
# \return The name of the active quality group.
|
||||||
|
@pyqtProperty(str, notify = activeQualityGroupChanged)
|
||||||
|
def activeQualityGroupName(self) -> str:
|
||||||
|
quality_group = self.activeQualityGroup()
|
||||||
|
if quality_group is None:
|
||||||
|
return ""
|
||||||
|
return quality_group.getName()
|
||||||
|
|
||||||
@pyqtSlot(QObject)
|
@pyqtSlot(QObject)
|
||||||
def setQualityChangesGroup(self, quality_changes_group: "QualityChangesGroup", no_dialog: bool = False) -> None:
|
def setQualityChangesGroup(self, quality_changes_group: "QualityChangesGroup", no_dialog: bool = False) -> None:
|
||||||
self.blurSettings.emit()
|
self.blurSettings.emit()
|
||||||
|
@ -1668,7 +1682,7 @@ class MachineManager(QObject):
|
||||||
if self._global_container_stack is None:
|
if self._global_container_stack is None:
|
||||||
return
|
return
|
||||||
with postponeSignals(*self._getContainerChangedSignals(), compress = CompressTechnique.CompressPerParameterValue):
|
with postponeSignals(*self._getContainerChangedSignals(), compress = CompressTechnique.CompressPerParameterValue):
|
||||||
self._setQualityGroup(self.activeQualityGroup)
|
self._setQualityGroup(self.activeQualityGroup())
|
||||||
for stack in [self._global_container_stack] + list(self._global_container_stack.extruders.values()):
|
for stack in [self._global_container_stack] + list(self._global_container_stack.extruders.values()):
|
||||||
stack.userChanges.clear()
|
stack.userChanges.clear()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue