From bc524b2c149ea93c79b78a9178395a802a52f801 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Tue, 1 Oct 2019 11:20:24 +0200 Subject: [PATCH] Fix unit test due to QualityGroup parent changes --- cura/Machines/MachineNode.py | 23 ++++++++++++++++++++--- cura/Machines/QualityChangesGroup.py | 10 +--------- cura/Machines/QualityGroup.py | 8 -------- cura/Machines/QualityManager.py | 8 +++++++- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/cura/Machines/MachineNode.py b/cura/Machines/MachineNode.py index 8b45540723..56965b32a4 100644 --- a/cura/Machines/MachineNode.py +++ b/cura/Machines/MachineNode.py @@ -7,12 +7,14 @@ from UM.Logger import Logger from UM.Signal import Signal from UM.Util import parseBool from UM.Settings.ContainerRegistry import ContainerRegistry # To find all the variants for this machine. + 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.QualityGroup import QualityGroup # To construct groups of quality profiles that belong together. from cura.Machines.QualityNode import QualityNode from cura.Machines.VariantNode import VariantNode + ## This class represents a machine in the container tree. # # The subnodes of these nodes are variants. @@ -80,7 +82,15 @@ class MachineNode(ContainerNode): if not global_quality_node.container: Logger.log("w", "Node {0} doesn't have a container.".format(global_quality_node.container_id)) continue - quality_groups[quality_type] = QualityGroup(name = global_quality_node.container.getMetaDataEntry("name", "Unnamed profile"), quality_type = quality_type) + # CURA-6599 + # 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 for extruder, qualities_per_type in enumerate(qualities_per_type_per_extruder): if quality_type in qualities_per_type: @@ -123,7 +133,14 @@ class MachineNode(ContainerNode): for quality_changes in machine_quality_changes: name = quality_changes["name"] if name not in groups_by_name: - groups_by_name[name] = QualityChangesGroup(name, quality_type = quality_changes["quality_type"], intent_category = quality_changes.get("intent_category", "default")) + # CURA-6599 + # 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 + groups_by_name[name] = QualityChangesGroup(name, quality_type = quality_changes["quality_type"], + intent_category = quality_changes.get("intent_category", "default"), + parent = CuraApplication.getInstance()) elif groups_by_name[name].intent_category == "default": # Intent category should be stored as "default" if everything is default or as the intent if any of the extruder have an actual intent. groups_by_name[name].intent_category = quality_changes.get("intent_category", "default") if "position" in quality_changes: # An extruder profile. @@ -147,7 +164,7 @@ class MachineNode(ContainerNode): # If the preferred global quality is not in there, an arbitrary global # quality is taken. # If there are no global qualities, an empty quality is returned. - def preferredGlobalQuality(self) -> QualityNode: + def preferredGlobalQuality(self) -> "QualityNode": return self.global_qualities.get(self.preferred_quality_type, next(iter(self.global_qualities.values()))) ## (Re)loads all variants under this printer. diff --git a/cura/Machines/QualityChangesGroup.py b/cura/Machines/QualityChangesGroup.py index 0cb17f797a..4fb9706a0a 100644 --- a/cura/Machines/QualityChangesGroup.py +++ b/cura/Machines/QualityChangesGroup.py @@ -3,7 +3,7 @@ from typing import Any, Dict, Optional -from PyQt5.QtCore import QObject, pyqtSlot, pyqtProperty +from PyQt5.QtCore import QObject, pyqtProperty ## Data struct to group several quality changes instance containers together. @@ -15,14 +15,6 @@ class QualityChangesGroup(QObject): def __init__(self, name: str, quality_type: str, intent_category: str, parent: Optional["QObject"] = None) -> None: super().__init__(parent) - - # CURA-6599 - # 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 - self.setParent(CuraApplication.getInstance()) - self._name = name self.quality_type = quality_type self.intent_category = intent_category diff --git a/cura/Machines/QualityGroup.py b/cura/Machines/QualityGroup.py index 60f307555f..1ea7ef6903 100644 --- a/cura/Machines/QualityGroup.py +++ b/cura/Machines/QualityGroup.py @@ -29,14 +29,6 @@ class QualityGroup(QObject): def __init__(self, name: str, quality_type: str, parent: Optional["QObject"] = None) -> None: super().__init__(parent) - # CURA-6599 - # 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 - self.setParent(CuraApplication.getInstance()) - self.name = name self.node_for_global = None # type: Optional[ContainerNode] self.nodes_for_extruders = {} # type: Dict[int, ContainerNode] diff --git a/cura/Machines/QualityManager.py b/cura/Machines/QualityManager.py index 4aa88d6775..bf1ecc66a6 100644 --- a/cura/Machines/QualityManager.py +++ b/cura/Machines/QualityManager.py @@ -111,7 +111,13 @@ class QualityManager(QObject): quality_group_dict = dict() for node in nodes_to_check: if node and node.quality_type: - quality_group = QualityGroup(node.getMetaDataEntry("name", ""), node.quality_type) + # CURA-6599 + # 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. + quality_group = QualityGroup(node.getMetaDataEntry("name", ""), node.quality_type, + parent = CuraApplication.getInstance()) quality_group.setGlobalNode(node) quality_group_dict[node.quality_type] = quality_group