QmlDesigner: Fix some Qml null warnings

Remove some warnings that appear on launch and shut down

Change-Id: I0eb58eadd9e975f0cfc7ec74636f540c26042589
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Mahmoud Badri
2023-03-10 16:08:57 +02:00
parent d7c57bef32
commit f4f13d0bf4
6 changed files with 24 additions and 59 deletions

View File

@@ -9,20 +9,11 @@ QtObject {
property variant backendValue property variant backendValue
property color textColor: StudioTheme.Values.themeTextColor property color textColor: StudioTheme.Values.themeTextColor
property variant valueFromBackend: root.backendValue === undefined ? 0 : root.backendValue.value property variant valueFromBackend: root.backendValue?.value ?? 0
property bool baseStateFlag: isBaseState property bool baseStateFlag: isBaseState
property bool isInModel: { property bool isInModel: root.backendValue?.isInModel ?? false
if (root.backendValue !== undefined && root.backendValue.isInModel !== undefined) property bool isInSubState: root.backendValue?.isInSubState ?? false
return root.backendValue.isInModel
return false
}
property bool isInSubState: {
if (root.backendValue !== undefined && root.backendValue.isInSubState !== undefined)
return root.backendValue.isInSubState
return false
}
property bool highlight: root.textColor === root.__changedTextColor property bool highlight: root.textColor === root.__changedTextColor
property bool errorState: false property bool errorState: false
@@ -38,7 +29,7 @@ QtObject {
onErrorStateChanged: root.evaluate() onErrorStateChanged: root.evaluate()
function evaluate() { function evaluate() {
if (root.backendValue === undefined) if (!root.backendValue)
return return
if (root.errorState) { if (root.errorState) {
@@ -47,15 +38,11 @@ QtObject {
} }
if (root.baseStateFlag) { if (root.baseStateFlag) {
if (root.backendValue.isInModel) root.textColor = root.backendValue.isInModel ? root.__changedTextColor
root.textColor = root.__changedTextColor : root.__defaultTextColor
else
root.textColor = root.__defaultTextColor
} else { } else {
if (root.backendValue.isInSubState) root.textColor = root.backendValue.isInSubState ? StudioTheme.Values.themeChangedStateText
root.textColor = StudioTheme.Values.themeChangedStateText : root.__defaultTextColor
else
root.textColor = root.__defaultTextColor
} }
} }
} }

View File

@@ -19,7 +19,7 @@ StudioControls.ComboBox {
onModelChanged: colorLogic.invalidate() onModelChanged: colorLogic.invalidate()
hasActiveDrag: comboBox.backendValue !== undefined && comboBox.backendValue.hasActiveDrag hasActiveDrag: comboBox.backendValue?.hasActiveDrag ?? false
// This is available in all editors. // This is available in all editors.
@@ -120,7 +120,7 @@ StudioControls.ComboBox {
break break
case ComboBox.ValueType.Enum: case ComboBox.ValueType.Enum:
default: default:
if (comboBox.backendValue === undefined) if (!comboBox.backendValue)
break break
var enumString = comboBox.backendValue.enumeration var enumString = comboBox.backendValue.enumeration

View File

@@ -11,18 +11,8 @@ Item {
id: extendedFunctionButton id: extendedFunctionButton
property variant backendValue property variant backendValue
property bool isBoundBackend: { property bool isBoundBackend: backendValue?.isBound ?? false
if (backendValue !== undefined && backendValue.isBound !== undefined) property string backendExpression: backendValue?.expression ?? ""
return backendValue.isBound
return false
}
property string backendExpression: {
if (backendValue !== undefined && backendValue.expression !== undefined)
return backendValue.expression
return ""
}
property string glyph: StudioTheme.Constants.actionIcon property string glyph: StudioTheme.Constants.actionIcon
property string color: StudioTheme.Values.themeTextColor property string color: StudioTheme.Values.themeTextColor
@@ -38,7 +28,7 @@ Item {
function setIcon() { function setIcon() {
extendedFunctionButton.color = StudioTheme.Values.themeTextColor extendedFunctionButton.color = StudioTheme.Values.themeTextColor
if (backendValue === undefined) { if (!backendValue) {
extendedFunctionButton.glyph = StudioTheme.Constants.actionIcon extendedFunctionButton.glyph = StudioTheme.Constants.actionIcon
} else if (backendValue.isBound) { } else if (backendValue.isBound) {
if (backendValue.isTranslated) { if (backendValue.isTranslated) {
@@ -49,12 +39,8 @@ Item {
extendedFunctionButton.color = StudioTheme.Values.themeInteraction extendedFunctionButton.color = StudioTheme.Values.themeInteraction
} }
} else { } else {
if (backendValue.complexNode !== undefined if (!backendValue.complexNode || !backendValue.complexNode.exists)
&& backendValue.complexNode.exists) {
} else {
extendedFunctionButton.glyph = StudioTheme.Constants.actionIcon extendedFunctionButton.glyph = StudioTheme.Constants.actionIcon
}
} }
} }
@@ -77,8 +63,8 @@ Item {
id: menu id: menu
onAboutToShow: { onAboutToShow: {
exportMenuItem.checked = backendValue.hasPropertyAlias() exportMenuItem.checked = backendValue?.hasPropertyAlias() ?? false
exportMenuItem.enabled = !backendValue.isAttachedProperty() exportMenuItem.enabled = !(backendValue?.isAttachedProperty() ?? false)
extendedFunctionButton.menuVisible = true extendedFunctionButton.menuVisible = true
} }
onAboutToHide: extendedFunctionButton.menuVisible = false onAboutToHide: extendedFunctionButton.menuVisible = false

View File

@@ -111,8 +111,7 @@ StudioControls.TextField {
lineEdit.__dirty = false lineEdit.__dirty = false
} }
property bool isTranslated: colorLogic.backendValue === undefined ? false property bool isTranslated: colorLogic.backendValue?.isTranslated ?? false
: colorLogic.backendValue.isTranslated
translationIndicator.onClicked: { translationIndicator.onClicked: {
if (lineEdit.translationIndicator.checked) { if (lineEdit.translationIndicator.checked) {
@@ -124,19 +123,12 @@ StudioControls.TextField {
colorLogic.evaluate() colorLogic.evaluate()
} }
property variant backendValueValueInternal: lineEdit.backendValue === undefined ? 0 property variant backendValueValueInternal: lineEdit.backendValue?.value ?? 0
: lineEdit.backendValue.value
onBackendValueValueInternalChanged: { onBackendValueValueInternalChanged: {
if (lineEdit.backendValue === undefined) lineEdit.translationIndicator.checked = lineEdit.backendValue?.isTranslated ?? false
lineEdit.translationIndicator.checked = false
else
lineEdit.translationIndicator.checked = lineEdit.backendValue.isTranslated
} }
onIsTranslatedChanged: { onIsTranslatedChanged: {
if (lineEdit.backendValue === undefined) lineEdit.translationIndicator.checked = lineEdit.backendValue?.isTranslated ?? false
lineEdit.translationIndicator.checked = false
else
lineEdit.translationIndicator.checked = lineEdit.backendValue.isTranslated
} }
} }

View File

@@ -31,18 +31,18 @@ Item {
} }
Component.onCompleted: { Component.onCompleted: {
spinBox.enabled = backendValue === undefined ? false : !isBlocked(backendValue.name) spinBox.enabled = backendValue ? !isBlocked(backendValue.name) : false
} }
Connections { Connections {
target: modelNodeBackend target: modelNodeBackend
function onSelectionChanged() { function onSelectionChanged() {
spinBox.enabled = backendValue === undefined ? false : !isBlocked(backendValue.name) spinBox.enabled = backendValue ? !isBlocked(backendValue.name) : false
} }
} }
onBackendValueChanged: { onBackendValueChanged: {
spinBox.enabled = backendValue === undefined ? false : !isBlocked(backendValue.name) spinBox.enabled = backendValue ? !isBlocked(backendValue.name) : false
} }
StudioControls.RealSpinBox { StudioControls.RealSpinBox {

View File

@@ -88,7 +88,7 @@ Row {
ToolTip { ToolTip {
id: toolTip id: toolTip
visible: comboBox.hover && toolTip.text !== "" visible: comboBox.hover && toolTip.text !== ""
text: root.backendValue.valueToString text: root.backendValue?.valueToString ?? ""
delay: StudioTheme.Values.toolTipDelay delay: StudioTheme.Values.toolTipDelay
background: Rectangle { background: Rectangle {