[Viewer] ImageMetadataView: Check that value is set before assigning it

This commit fixes the following errors:
- "<Unknown File>: Can't assign to existing role 'value' of different
type [VariantMap -> String]" which occurs whenever the metadata view is
enabled and appears if at least one of the metadata keys has an empty
value;
- "Unable to assign [undefined] to QString" which occurs whenever the
search bar is cleared.
This commit is contained in:
Candice Bentéjac 2023-10-17 11:15:20 +02:00
parent b916a923e1
commit 9249615baf

View file

@ -94,7 +94,13 @@ FloatingPane {
entry["group"] = "-"
entry["key"] = key
}
entry["value"] = metadata[key]
// If a key has an empty corresponding value, set it as an empty string.
// Otherwise it will be considered as a Variant Map.
if (typeof(metadata[key]) != "string")
entry["value"] = ""
else
entry["value"] = metadata[key]
entry["raw"] = entry["group"] + ":" + entry["key"] + "=" + entry["value"]
entries.push(entry)
}
@ -199,7 +205,7 @@ FloatingPane {
elide: Text.ElideRight
}
Label {
text: value
text: value != undefined ? value : ""
Layout.fillWidth: true
wrapMode: Label.WrapAtWordBoundaryOrAnywhere
}