-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Adding support for list property types #4002
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
Conversation
Urgh, turned out the "Ability to add items to a list" is only mostly working. When just pressing the "+ Add" button instead of using the menu, it is not possible to add items of the same custom enum or class type. This is because the values are at that point converted to their "display value", which means a class is just a map and an enum is just a number, and only the |
6f0a900
to
334deed
Compare
Resuming work on this based on the new Properties framework introduced in #4045, I've just rebased the changes. The code for actually displaying the list will have to be re-written, so for now it just displays the amount of items: |
33b56d8
to
e4b619a
Compare
c4b403a
to
e3d0fd6
Compare
I believe lists are working quite fine now. There's at least the following remaining issues:
|
Above issues now resolved, but I've discovered a few more problems:
|
f03a94e
to
9cecfc4
Compare
Yeah, it used to show the object name and an icon depending on the type of the object, but we lost that functionality because it relied on the previous Properties view having two states: display and edit, whereas we now only have the edit state. Maybe we can somehow display that name and icon when the field is not focused. Of course that's unrelated to list properties but applies to object reference properties in general, so it can be a separate PR to improve the
Thanks for noticing that! Indeed I haven't finished this part of the updating logic, where |
* Added 'list' as option when adding properties, based on QVariantList. * Added support for saving and loading list properties to TMX and JSON formats.
The ListEdit features a button to add an item to the list (currently just adds "0" integer values).
* There is now menu alongside the menu to add new values: - Choosing from the menu adds a value of the selected type - Clicking the button now adds the same type as the last item, or spawns the menu (for empty lists) * Saving in JSON format now supports lists of lists (not yet supported for loading) * Some code moved around to share code between AddValueProperty and the new menu for adding list items.
* Introduced ClassProperty and VariantListProperty and share property creation code previously part of VariantMapProperty. * Support displaying list values, adding values to a list and removing values from a list. All edits affecting a list are currently treating the list as a single value. This causes some issues when undoing/redoing list changes. Multiple consecutive edits to the same list, even if they are add item, remove item or different items being changed, merge into a single undo command. This change breaks object reference properties for now, since the MapDocument context is lost that was previously provided by VariantMapProperty.
Made preparations for fixing undo command merging affecting list values.
Now only those changes are merged which affect the exact same value, using the PropertyPath introduced in 218561a. Also addressed some other issues related to out of date list values stored by VariantListProperty. Now the VariantListProperty no longer stores the actual list, similar to the ClassProperty not storing the class value. The ListEdit was similarly changed to avoid storing the list value.
Also fixed initial parent of children.
As fixed earlier for boolean properties in 791c462.
Create a new value based on the default value of their type.
We'll need to enable the removal of list values through the context menu somehow though.
Now the properties UI can display the object name again and provide the picking functionality.
* Support lists when resolving class members * Check for circular references caused by values in lists * Fix saving and loading lists in classes in the JSON and XML formats * Fix lists in classes for the Lua export
The contentMargins gets overridden by QFrame::setFrameRect if it results in an invalid contentsRect during.
Now canReuseProperty checks whether the Preferences is currently emitting propertyTypesChanged. This way list values are recreated when necessary in VariantListProperty::createOrUpdateProperty.
57ad70a
to
be3bf18
Compare
Now I think there's one remaining major issue:
|
When adding values to lists that are part of a custom class definition, it was possible to create a cyclic reference. Now the same mechanism that was used to prevent such references when adding members is also applied when adding list values. Since lists can be nested this was a little more involved. The PropertyTypesEditor now uses a custom PropertiesView subclass which the VariantListProperty and AddValueProperty now use to obtain the currently edited class type. To enable this, each Property which is shown in a PropertiesView now gets a reference to this view.
That's right, this is a desirable feature. However, the type is currently embedded in the value so a list with a type per value was the more natural fit to start with. I was thinking it might be alright if we add an option to class members to set them as arrays, though such an approach isn't without issues either especially for top-level values. It is definitely worth considering an approach towards this before the 1.12 release, though its implementation may be out of scope for now.
Wow, I didn't expect that to actually work, but it works because for the JSON format the value is converted directly from JSON to a It's a bit of a happy coincidence which unfortunately doesn't work for the XML format, which rather completely destroys the list values, replacing it with an empty string value. I'll definitely need add a warning in the news post and the docs regarding this.
I would personally think the "Property value" checkbox should suffice for now, but more fine-grained settings could be implemented later if that turns out to be sufficiently useful.
Thanks for bringing this up again! I've implemented that in #4265.
Maybe it would suffice to remove the expand interaction for "empty" classes. In addition I think it might be good to display the class name. I had implemented this as part of the name column and it seemed kind of busy, which is why it's only in the tool tip now, but especially for class values in lists there is such an odd waste of space. We could try showing the class name to the value column, but this should also be a new PR. Thanks for the thorough feedback! |
I don't think it would. I've seen that in other software and it always feels janky when there isn't an explicit indicator that a list is empty. A row saying "(empty)" when expanded, for example, or "(empty") in the list header. |
Ah, that's a good point regarding lists, but @dogboydog was talking about class values. Since you can't add anything to an empty class (except in the Custom Types Editor) I think hiding the expand arrow there is fine. For lists I wonder if it would be nice to show the "Add Value" thing into the list as the last element, since that's where it will actually add the value. That does mean you'd need to scroll to the bottom of the list to click it, but that might be better than the current behavior, where you need to scroll back to the top to add another element. |
Ah, whoops. +1 for having the add value widget at the bottom. Either way it's going to be an issue with long lists though, and a nice bit of polish would be to make it easy to add a new value even when a list is unwieldy. Perhaps a context menu "Add value" option that scrolls you to that widget if it's not visible and focuses it? |
Implementation so far:
QVariantList
.CustomPropertiesHelper
to create sub-properties that display the values in the list (maybe should rather be done by theVariantPropertyManager
).VariantPropertyManager
because it couldn't delegate class member creation back to theCustomPropertiesHelper
. IfVariantPropertyManager
should handle lists, then it would need to handle classes as well.ToDo:
Resolves #1493