Skip to content

Fix empty nested class properties not being cleaned up (#3998)#4415

Open
Oval17 wants to merge 1 commit intomapeditor:masterfrom
Oval17:fix/3998-cleanup-empty-nested-classes
Open

Fix empty nested class properties not being cleaned up (#3998)#4415
Oval17 wants to merge 1 commit intomapeditor:masterfrom
Oval17:fix/3998-cleanup-empty-nested-classes

Conversation

@Oval17
Copy link
Contributor

@Oval17 Oval17 commented Mar 10, 2026

1 -> When all members of a top-level class property are reset, the empty class container is now automatically removed but only when that property is defined in the object's assigned class.

2 -> Previously, the cleanup in setClassPropertyValue was intentionally skipped at depth 1 (allowReset = false) to avoid removing manually-added class properties. This fix threads an allowTopLevelReset flag through from Object::setProperty , which sets it to true only when the top-level key exists in classType()->members. Manually added properties (not defined in the object's class) are still preserved.

Fixes #3998

Ready for Review and Inputs @bjorn

When resetting the last member of a top-level class property that is
defined in the object's assigned class, the empty class container is
now automatically removed, consistent with how deeper nesting levels
already behave.

Manually added class properties (not defined in the object's class)
are still preserved when empty, to avoid accidentally losing them.
@kody-ai

This comment has been minimized.

@bjorn
Copy link
Member

bjorn commented Mar 18, 2026

Hmm, it seems this patch really only changes the behavior of Object::setProperty, but that function is only used in EditableObject::setPropertyImpl (scripting API), and then only when an object does not have an undo stack associated with it. It makes me wonder how you tested this?

For the new behavior to work from the UI, we probably need to change Document::setPropertyMember, which is what the SetProperty undo command uses. We probably also need to change VariantMapProperty::setMemberValue accordingly because it applies the change to the local mValue (a copy of the properties of the object) before emitting its signals (based on which CustomProperties::setPropertyValue creates the undo command).

I realize the whole setup is a little involved.

There is another problematic aspect. We don't want to automatically reset a top-level class value when the class value inherited from the object's class is not an empty value. Because when we reset the top-level value when it's empty, it would revert back to inheriting the non-empty value. So at least in that case, the user needs to explicitly reset the top-level value if that it what they want.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cleaning up empty nested classes

2 participants