Fix QObject segfaults in QML

CURA-6599
This commit is contained in:
Lipu Fei 2019-09-25 14:38:27 +02:00
parent d1330e5ffa
commit 9ced5e9205
4 changed files with 37 additions and 6 deletions

View file

@ -15,6 +15,14 @@ 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

View file

@ -26,8 +26,17 @@ from cura.Machines.ContainerNode import ContainerNode
#
class QualityGroup(QObject):
def __init__(self, name: str, quality_type: str, parent = None) -> None:
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]

View file

@ -1599,12 +1599,17 @@ class MachineManager(QObject):
@pyqtProperty(QObject, fset = setQualityChangesGroup, notify = activeQualityChangesGroupChanged)
def activeQualityChangesGroup(self) -> Optional["QualityChangesGroup"]:
global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
if not global_stack or global_stack.qualityChanges == empty_quality_changes_container:
if global_stack is None or global_stack.qualityChanges == empty_quality_changes_container:
return None
for group in ContainerTree.getInstance().getCurrentQualityChangesGroups(): # Match on the container ID of the global stack to find the quality changes group belonging to the active configuration.
all_group_list = ContainerTree.getInstance().getCurrentQualityChangesGroups()
the_group = None
for group in all_group_list: # Match on the container ID of the global stack to find the quality changes group belonging to the active configuration.
if group.metadata_for_global and group.metadata_for_global["id"] == global_stack.qualityChanges.getId():
return group
return None
the_group = group
break
return the_group
@pyqtProperty(bool, notify = activeQualityChangesGroupChanged)
def hasCustomQuality(self) -> bool:

View file

@ -172,7 +172,16 @@ Popup
checkable: true
visible: model.available
text: model.name
checked: Cura.MachineManager.activeQualityChangesGroup.getName() == model.quality_changes_group.getName()
checked:
{
var active_quality_group = Cura.MachineManager.activeQualityChangesGroup
if (active_quality_group != null)
{
return active_quality_group.getName() == model.quality_changes_group.getName()
}
return false
}
ButtonGroup.group: buttonGroup
}
}