Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleaning up empty nested classes #3998

Open
hnbdr opened this issue Jul 5, 2024 · 3 comments
Open

Cleaning up empty nested classes #3998

hnbdr opened this issue Jul 5, 2024 · 3 comments
Labels
feature It's a feature, not a bug.

Comments

@hnbdr
Copy link

hnbdr commented Jul 5, 2024

Nested class properties remain even if they do not have a single subproperty. They are visible in the interface and then saved in the json map. They appear if you clear all nested properties manually but forget to delete the nested class itself. They also remain after setProperty(path, undefined) is executed.

It would be convenient if they were cleaned automatically.

@hnbdr hnbdr added the feature It's a feature, not a bug. label Jul 5, 2024
@bjorn
Copy link
Member

bjorn commented Jul 5, 2024

Hmm, this is supposed to work. The clearing of "empty" class values is done in setClassPropertyMemberValue:

// Mark whole class as "unset" if it has no members left, unless at top level
if (!classMembers.isEmpty() || depth == 1) {
classPropertyValue.value = classMembers;
classValue = QVariant::fromValue(classPropertyValue);
} else {
classValue = QVariant();
}

SetProperty::redo calls this function via Document::setPropertyMember. So we need to find out why this isn't working as expected in your situation. Can you mention specific and ideally minimal steps to reproduce this issue?

@hnbdr
Copy link
Author

hnbdr commented Jul 5, 2024

Certainly.

  1. Create a new project.
  2. Create a class ParentClass
  3. Create a NestedClass
  4. In the NestedClass class, create a nestedProperty of any type
  5. In the ParentClass class, create a nestedClass property of type NestedClass
  6. Create a TestLayer on the map
  7. Assign the TestLayer a ParentClass
  8. Change the nestedProperty of TestLayer
  9. Clear the nestedProperty property of TestLayer manually by clicking on "Reset" or run item.setProperty(['nestedClass', 'nestedProperty'], undefined)
  10. The nestedClas property is still there. The text color is dark. The script api shows Tiled::PropertyValue(, 2, NestedClass) with an empty value object. The map file saved as json or xml also has a nestedClass property with an empty value.

@hnbdr
Copy link
Author

hnbdr commented Jul 5, 2024

It looks like the scheme works but only if the nesting depth is greater than one. So the property itself with depth 1 is not cleared, regardless of whether the class is assigned to the object on the map or not. If it is not assigned it makes sense, but if it is assigned then it is redundant to have an empty one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature It's a feature, not a bug.
Projects
None yet
Development

No branches or pull requests

2 participants