Turn MaterialManagementModel into a singleton

Just like MaterialManager used to be. There can be only one instance of the page then.
This prevents a crash when Qt deletes the QObject because it's no longer used in the page when you close the preferences screen. But when you open it again it doesn't construct a new one. Now there is always one instance so that's not a problem any more. Also it allows other pages to access this item.

Contributes to issue CURA-6600.
This commit is contained in:
Ghostkeeper 2019-08-27 15:22:28 +02:00
parent b60b13e5bf
commit 8346e465f6
No known key found for this signature in database
GPG Key ID: 86BEF881AE2CF276
3 changed files with 11 additions and 9 deletions

View File

@ -222,6 +222,7 @@ class CuraApplication(QtApplication):
self._machine_error_checker = None self._machine_error_checker = None
self._machine_settings_manager = MachineSettingsManager(self, parent = self) self._machine_settings_manager = MachineSettingsManager(self, parent = self)
self._material_management_model = MaterialManagementModel()
self._discovered_printer_model = DiscoveredPrintersModel(self, parent = self) self._discovered_printer_model = DiscoveredPrintersModel(self, parent = self)
self._first_start_machine_actions_model = FirstStartMachineActionsModel(self, parent = self) self._first_start_machine_actions_model = FirstStartMachineActionsModel(self, parent = self)
@ -976,6 +977,10 @@ class CuraApplication(QtApplication):
def getMachineActionManager(self, *args): def getMachineActionManager(self, *args):
return self._machine_action_manager return self._machine_action_manager
@pyqtSlot(result = QObject)
def getMaterialManagementModel(self):
return self._material_management_model
def getSimpleModeSettingsManager(self, *args): def getSimpleModeSettingsManager(self, *args):
if self._simple_mode_settings_manager is None: if self._simple_mode_settings_manager is None:
self._simple_mode_settings_manager = SimpleModeSettingsManager() self._simple_mode_settings_manager = SimpleModeSettingsManager()
@ -1055,7 +1060,7 @@ class CuraApplication(QtApplication):
qmlRegisterType(GenericMaterialsModel, "Cura", 1, 0, "GenericMaterialsModel") qmlRegisterType(GenericMaterialsModel, "Cura", 1, 0, "GenericMaterialsModel")
qmlRegisterType(MaterialBrandsModel, "Cura", 1, 0, "MaterialBrandsModel") qmlRegisterType(MaterialBrandsModel, "Cura", 1, 0, "MaterialBrandsModel")
qmlRegisterType(QualityManagementModel, "Cura", 1, 0, "QualityManagementModel") qmlRegisterType(QualityManagementModel, "Cura", 1, 0, "QualityManagementModel")
qmlRegisterType(MaterialManagementModel, "Cura", 1, 5, "MaterialManagementModel") qmlRegisterSingletonType(MaterialManagementModel, "Cura", 1, 5, "MaterialManagementModel", self.getMaterialManagementModel)
qmlRegisterType(DiscoveredPrintersModel, "Cura", 1, 0, "DiscoveredPrintersModel") qmlRegisterType(DiscoveredPrintersModel, "Cura", 1, 0, "DiscoveredPrintersModel")

View File

@ -18,6 +18,7 @@ Item
property var currentItem: null property var currentItem: null
property var materialManager: CuraApplication.getMaterialManager() property var materialManager: CuraApplication.getMaterialManager()
property var materialManagementModel: CuraApplication.getMaterialManagementModel()
property var hasCurrentItem: base.currentItem != null property var hasCurrentItem: base.currentItem != null
property var isCurrentItemActivated: property var isCurrentItemActivated:
@ -42,11 +43,6 @@ Item
name: "cura" name: "cura"
} }
Cura.MaterialManagementModel
{
id: materialManagement
}
function resetExpandedActiveMaterial() function resetExpandedActiveMaterial()
{ {
materialListView.expandActiveMaterial(active_root_material_id) materialListView.expandActiveMaterial(active_root_material_id)
@ -152,7 +148,7 @@ Item
id: removeMenuButton id: removeMenuButton
text: catalog.i18nc("@action:button", "Remove") text: catalog.i18nc("@action:button", "Remove")
iconName: "list-remove" iconName: "list-remove"
enabled: base.hasCurrentItem && !base.currentItem.is_read_only && !base.isCurrentItemActivated && materialManagement.canMaterialBeRemoved(base.currentItem.container_node) enabled: base.hasCurrentItem && !base.currentItem.is_read_only && !base.isCurrentItemActivated && base.materialManagementModel.canMaterialBeRemoved(base.currentItem.container_node)
onClicked: onClicked:
{ {
@ -302,7 +298,7 @@ Item
{ {
// Set the active material as the fallback. It will be selected when the current material is deleted // Set the active material as the fallback. It will be selected when the current material is deleted
base.newRootMaterialIdToSwitchTo = base.active_root_material_id base.newRootMaterialIdToSwitchTo = base.active_root_material_id
base.materialManagement.removeMaterial(base.currentItem.container_node); base.materialManagementModel.removeMaterial(base.currentItem.container_node);
} }
} }

View File

@ -23,6 +23,7 @@ TabView
property real secondColumnWidth: (width * 0.40) | 0 property real secondColumnWidth: (width * 0.40) | 0
property string containerId: "" property string containerId: ""
property var materialPreferenceValues: UM.Preferences.getValue("cura/material_settings") ? JSON.parse(UM.Preferences.getValue("cura/material_settings")) : {} property var materialPreferenceValues: UM.Preferences.getValue("cura/material_settings") ? JSON.parse(UM.Preferences.getValue("cura/material_settings")) : {}
property var materialManagementModel: CuraApplication.getMaterialManagementModel()
property double spoolLength: calculateSpoolLength() property double spoolLength: calculateSpoolLength()
property real costPerMeter: calculateCostPerMeter() property real costPerMeter: calculateCostPerMeter()
@ -565,7 +566,7 @@ TabView
} }
// update the values // update the values
materialManagement.setMaterialName(base.currentMaterialNode, new_name) base.materialManagementModel.setMaterialName(base.currentMaterialNode, new_name)
properties.name = new_name properties.name = new_name
} }