Emit metaDataChanged when changing properties

Properties is a dictionary inside the metadata dictionary. If you change one of the properties, it'll check afterwards if the dictionary is different from what it was before, but since the dictionary is passed by reference all the time, it'll think that the dictionary didn't change: The reference is still the same, so the thing it checks against is updated along.
This solution is a bit ugly but it does notice when the metadata changed inside the properties and then emits a change signal.

Contributes to issue CURA-2822.
This commit is contained in:
Ghostkeeper 2017-06-29 15:03:49 +02:00
parent c7120dddda
commit 8ae49c317c
No known key found for this signature in database
GPG key ID: C5F96EE2BC0F7E75

View file

@ -218,6 +218,7 @@ class ContainerManager(QObject):
entries = entry_name.split("/") entries = entry_name.split("/")
entry_name = entries.pop() entry_name = entries.pop()
sub_item_changed = False
if entries: if entries:
root_name = entries.pop(0) root_name = entries.pop(0)
root = container.getMetaDataEntry(root_name) root = container.getMetaDataEntry(root_name)
@ -226,12 +227,16 @@ class ContainerManager(QObject):
for entry in entries: for entry in entries:
item = item.get(entries.pop(0), { }) item = item.get(entries.pop(0), { })
if item[entry_name] != entry_value:
sub_item_changed = True
item[entry_name] = entry_value item[entry_name] = entry_value
entry_name = root_name entry_name = root_name
entry_value = root entry_value = root
container.setMetaDataEntry(entry_name, entry_value) container.setMetaDataEntry(entry_name, entry_value)
if sub_item_changed: #If it was only a sub-item that has changed then the setMetaDataEntry won't correctly notice that something changed, and we must manually signal that the metadata changed.
container.metaDataChanged.emit(container)
return True return True