Extruders can be undefined, not null

This happens when the printer is changed, such as when changing the Machine Width in the machine settings dialogue. It updates these menus then and if not all extruders are defined it'll give the following errors:
2020-03-20 16:56:57,839 - WARNING - [MainThread] UM.Qt.QtApplication.__onQmlWarning [406]: file:///home/trin/Gedeeld/Projects/Cura/resources/qml/Menus/SettingsMenu.qml:51: TypeError: Cannot read property 'isEnabled' of undefined
2020-03-20 16:56:57,840 - WARNING - [MainThread] UM.Qt.QtApplication.__onQmlWarning [406]: file:///home/trin/Gedeeld/Projects/Cura/resources/qml/Menus/SettingsMenu.qml:44: TypeError: Cannot read property 'isEnabled' of undefined
2020-03-20 16:56:57,841 - WARNING - [MainThread] UM.Qt.QtApplication.__onQmlWarning [406]: file:///home/trin/Gedeeld/Projects/Cura/resources/qml/Menus/MaterialMenu.qml:26: TypeError: Cannot read property 'isEnabled' of undefined
2020-03-20 16:56:57,841 - WARNING - [MainThread] UM.Qt.QtApplication.__onQmlWarning [406]: file:///home/trin/Gedeeld/Projects/Cura/resources/qml/Menus/MaterialMenu.qml:28: TypeError: Cannot read property 'material' of undefined

Done during Turbo Testing and Tooling.
This commit is contained in:
Ghostkeeper 2020-03-20 17:03:08 +01:00
parent 2f3462203c
commit 485e37e7f5
No known key found for this signature in database
GPG key ID: D2A8871EE34EC59A
2 changed files with 8 additions and 8 deletions

View file

@ -1,4 +1,4 @@
// Copyright (c) 2018 Ultimaker B.V. //Copyright (c) 2020 Ultimaker B.V.
//Cura is released under the terms of the LGPLv3 or higher. //Cura is released under the terms of the LGPLv3 or higher.
import QtQuick 2.7 import QtQuick 2.7
@ -23,9 +23,9 @@ Menu
var activeMachine = Cura.MachineManager.activeMachine var activeMachine = Cura.MachineManager.activeMachine
return (activeMachine === null) ? null : activeMachine.extruderList[extruderIndex] return (activeMachine === null) ? null : activeMachine.extruderList[extruderIndex]
} }
property bool isActiveExtruderEnabled: activeExtruder === null ? false : activeExtruder.isEnabled property bool isActiveExtruderEnabled: (activeExtruder === null || activeExtruder === undefined) ? false : activeExtruder.isEnabled
property string activeMaterialId: activeExtruder === null ? false : activeExtruder.material.id property string activeMaterialId: (activeExtruder === null || activeExtruder === undefined) ? false : activeExtruder.material.id
property bool updateModels: true property bool updateModels: true
Cura.FavoriteMaterialsModel Cura.FavoriteMaterialsModel

View file

@ -1,4 +1,4 @@
// Copyright (c) 2018 Ultimaker B.V. //Copyright (c) 2020 Ultimaker B.V.
//Cura is released under the terms of the LGPLv3 or higher. //Cura is released under the terms of the LGPLv3 or higher.
import QtQuick 2.2 import QtQuick 2.2
@ -41,14 +41,14 @@ Menu
{ {
text: catalog.i18nc("@action:inmenu", "Enable Extruder") text: catalog.i18nc("@action:inmenu", "Enable Extruder")
onTriggered: Cura.MachineManager.setExtruderEnabled(model.index, true) onTriggered: Cura.MachineManager.setExtruderEnabled(model.index, true)
visible: extruder === null ? false : !extruder.isEnabled visible: (extruder === null || extruder === undefined) ? false : !extruder.isEnabled
} }
MenuItem MenuItem
{ {
text: catalog.i18nc("@action:inmenu", "Disable Extruder") text: catalog.i18nc("@action:inmenu", "Disable Extruder")
onTriggered: Cura.MachineManager.setExtruderEnabled(index, false) onTriggered: Cura.MachineManager.setExtruderEnabled(index, false)
visible: extruder === null ? false : extruder.isEnabled visible: (extruder === null || extruder === undefined) ? false : extruder.isEnabled
enabled: Cura.MachineManager.numberExtrudersEnabled > 1 enabled: Cura.MachineManager.numberExtrudersEnabled > 1
} }