mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-16 11:17:49 -06:00
Fix QObject segfaults in QML
CURA-6599
This commit is contained in:
parent
d1330e5ffa
commit
9ced5e9205
4 changed files with 37 additions and 6 deletions
|
@ -15,6 +15,14 @@ class QualityChangesGroup(QObject):
|
||||||
|
|
||||||
def __init__(self, name: str, quality_type: str, intent_category: str, parent: Optional["QObject"] = None) -> None:
|
def __init__(self, name: str, quality_type: str, intent_category: str, parent: Optional["QObject"] = None) -> None:
|
||||||
super().__init__(parent)
|
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.name = name
|
||||||
self.quality_type = quality_type
|
self.quality_type = quality_type
|
||||||
self.intent_category = intent_category
|
self.intent_category = intent_category
|
||||||
|
|
|
@ -26,8 +26,17 @@ from cura.Machines.ContainerNode import ContainerNode
|
||||||
#
|
#
|
||||||
class QualityGroup(QObject):
|
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)
|
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.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]
|
||||||
|
|
|
@ -1599,12 +1599,17 @@ class MachineManager(QObject):
|
||||||
@pyqtProperty(QObject, fset = setQualityChangesGroup, notify = activeQualityChangesGroupChanged)
|
@pyqtProperty(QObject, fset = setQualityChangesGroup, notify = activeQualityChangesGroupChanged)
|
||||||
def activeQualityChangesGroup(self) -> Optional["QualityChangesGroup"]:
|
def activeQualityChangesGroup(self) -> Optional["QualityChangesGroup"]:
|
||||||
global_stack = cura.CuraApplication.CuraApplication.getInstance().getGlobalContainerStack()
|
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
|
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():
|
if group.metadata_for_global and group.metadata_for_global["id"] == global_stack.qualityChanges.getId():
|
||||||
return group
|
the_group = group
|
||||||
return None
|
break
|
||||||
|
|
||||||
|
return the_group
|
||||||
|
|
||||||
@pyqtProperty(bool, notify = activeQualityChangesGroupChanged)
|
@pyqtProperty(bool, notify = activeQualityChangesGroupChanged)
|
||||||
def hasCustomQuality(self) -> bool:
|
def hasCustomQuality(self) -> bool:
|
||||||
|
|
|
@ -172,7 +172,16 @@ Popup
|
||||||
checkable: true
|
checkable: true
|
||||||
visible: model.available
|
visible: model.available
|
||||||
text: model.name
|
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
|
ButtonGroup.group: buttonGroup
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue