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

New properties framework #4045

Draft
wants to merge 78 commits into
base: master
Choose a base branch
from

Conversation

bjorn
Copy link
Member

@bjorn bjorn commented Aug 30, 2024

I've started implementing a new properties framework in an attempt to improve some existing usability issues as well as to make it easier to add support for list properties (#4002).

This is a work-in-progress! It its current state the Properties view can only edit a few built-in map properties.

I'm sharing this here for the curious and to gather feedback.

@bjorn
Copy link
Member Author

bjorn commented Aug 30, 2024

Here's a preview of what it looked like at some point, when it wasn't actually functional but had all Map properties represented:

image

And here's a video of the current state, with only three properties, but they are fully implemented:

resize-map-button.mp4

Main advantages are currently:

  • The widgets can be directly interacted with.
  • They can respond to layout (W/H presented horizontally or vertically based on width of view).
  • Easy to add buttons like "Resize Map" that are not hidden.
  • Huge reduction in complexity / code size compared to existing properties framework (but still lacking features, like nested properties, selection, etc.).

@dogboydog
Copy link
Contributor

I got a chance to try this out and look at the code. I like it. It's nice to have the resize map button more accessible on the map properties.

As far as the code, I'm definitely less equipped than you to judge it but I had a few thoughts.

At first I wondered if there might be a way to define these editable properties and the widgets that would be produced on the edited objects themselves (worlds, maps, etc.) but I guess that's really only used in this property editor component, so there's no need.

The properties have to take the editor factory in as a constructor argument, and currently you are creating a subclass for each type of property. I'm wondering about if there's a way to make it so that only the PropertiesWidget would even need to know about the factory. I feel like the factory could just be a way to generate editor widgets for well-known types of properties that don't need customization. Or maybe the factory just becomes a parameter to addProperty() instead and you only need to provide one if you need to customize the produced widget.

Also, it might be nice if there was a lighter syntax for adding a property that didn't entail creating a class for each property. Part of what makes me think this is the current need to store the editor factory in each property which creates a little more boilerplate for each property, while classes that customize the widget like MapSizeProperty don't actually need the factory at all from what I can see. Being able to just pass in lambdas or something for getting/setting the value to addProperty() could be nice. I would think there would be a lot of properties where you would just be calling existing getters and setters, but maybe I'm wrong.

Feel free to disregard any of this, though, just some initial thoughts that may be misinformed

@bjorn
Copy link
Member Author

bjorn commented Sep 2, 2024

@dogboydog Thanks for writing down your thoughts on the new properties implementation! They've been the exact things I'm also wondering about / struggling with. There may not be one simple solution for everything, but indeed this "factory" argument is quite annoying, especially when passing in that "default factory" most of the time anyway.

I've thought about creating the properties through the factory instead. So far there are ValueTypeEditorFactory::createProperty (to create a ValueProperty) and createQObjectProperty. But for now both have remained unused because they didn't quite fit either:

  • The ValueProperty keeps a local value, which I thought would be a good way to avoid subclassing. Of course, then signals need to be connected to keep that value updated and respond to changes. I still need to try this approach.

  • The QObjectProperty could be even more automatic, since it wraps Qt's meta object system to directly work on a declared Q_PROPERTY. However, currently none of the relevant properties are exposed as a Q_PROPERTY. The closest are those on the EditableMap class, but they're lacking a NOTIFY signal which means the widget's value can't update when needed. I'm also not entirely sure about using EditableMap since it's the scripting API, but it could work out and some people could use the change signals in the API too anyway.

When not using QObjectProperty, another thing I'm not happy about is that each property needs to do its own change signal handling. Hence I'm looking into introducing a kind of MapProperties class, which would own all the map's properties and connect to the relevant change signals instead.

src/tiled/propertieswidget.cpp Outdated Show resolved Hide resolved
@bjorn bjorn force-pushed the new-properties-framework branch from f40314a to f13fd5c Compare September 4, 2024 06:29
@bjorn
Copy link
Member Author

bjorn commented Sep 11, 2024

Small update on the current state. Last week I've finished implementing the built-in properties for all data types, minus a few that will need a custom widget:

image

In the above we see a lacking widget for setting "Allowed Transformations" as well as for changing tileset parameters (which will use a button for now, similar to "Resize Map").

In the past days I've addressed many loose ends, like setting minimum/maximum values, step sizes and file dialog filters. I've also improved the widget for setting up the font of text objects, so it takes up less vertical space:

image

The biggest task remaining is to add support for editing, adding and removing Custom Properties, and also to make the headers collapsible. Other open tasks are restoring support for changing the properties of multiple objects at once and displaying "inherited" values like the class set on a tile when a tile object is selected.

@bjorn bjorn force-pushed the new-properties-framework branch from 036f68c to 68d84af Compare September 19, 2024 06:41
@bjorn
Copy link
Member Author

bjorn commented Sep 27, 2024

Screenshot showing some of the recent changes:

image

  • Collapsible headers.
  • Support for editing custom properties, including support for expandable custom classes.
  • Boolean properties showing their name on the right side of the checkbox rather than in the left column (test).
  • Color properties displaying the "Unset" state again (as in old properties framework).
  • "Remove" buttons to remove top-level properties.
  • "Reset" buttons to reset class members to their default value, and indicating whether a class value is set with bold font.

@bjorn bjorn force-pushed the new-properties-framework branch from 50abb67 to 99dcb30 Compare October 9, 2024 12:08
@bjorn
Copy link
Member Author

bjorn commented Oct 10, 2024

After the above change, inherited properties are now shown in disabled state, with a '+' button that allows adding those properties:

image

One issue that remains to be addressed is when the removal of a property exposes an inherited property with the same name, but with a different type. The relevant property will need to be re-created in this case.

@bjorn bjorn force-pushed the new-properties-framework branch from bf0c1cf to 6b23c51 Compare October 10, 2024 19:55
@bjorn
Copy link
Member Author

bjorn commented Oct 14, 2024

Latest changes address various features that already existed with the old properties solution:

  • Handling changes in the custom property type definitions.
  • Showing suggested properties from all selected objects.
  • Applying changes to all selected objects or layers

Also there is now a custom widget for the tile object flipping states:

image

And there is a tool tip showing the type of each custom property, including the type for class members:

image

@bjorn bjorn force-pushed the new-properties-framework branch from 1385a01 to b1d79f7 Compare October 15, 2024 10:17
@bjorn
Copy link
Member Author

bjorn commented Oct 17, 2024

Today I've added a context menu with some useful actions:

image

Also, the expanded state is now remembered (by property name, so it applies to that property regardless of which object is selected).

@bjorn bjorn force-pushed the new-properties-framework branch from 5e872ea to 2177a6e Compare October 18, 2024 16:25
@bjorn
Copy link
Member Author

bjorn commented Oct 20, 2024

Reported feedback so far:

  • Icons for the add/remove/reset buttons are lacking a fallback so they only work with a system icon theme.
  • Scroll wheel on some edit widgets triggers focus and value change (affects spin boxes and combo boxes at least).
  • Undo shortcut is eaten by local widget's undo support, but expected is generally the global undo.
  • Consider moving "Output Chunk Size" together with "Infinite" because the latter determines whether the former is enabled.
  • Consider moving "Compression Level" together with "Layer Data Format", for same reason.
  • It's hard to unfocus an editor (previously could be done by clicking anywhere outside of it).
  • Repeated changes to Map properties are not grouped together.
  • Collapsed state of headers isn't remembered.
  • If Map/Tileset/Layer/etc Properties are collapsed and one tries to access them through the menu, they should expand (see also Nothing happens when I click [Map > Map Properties...] #3806).
  • Consider adding Map/Tileset Properties buttons to the bottom of the properties panel (and to the document tab context menu) (see Tileset and Map Properties could be easier to access #3101)
  • The Add/Remove/Reset buttons take up a lot of space in a narrow view. Would be good to add an option to hide them (the actions are also available from the context menu, anyway).
  • Boolean labels True/False may be preferred to On/Off.

Many thanks to @eishiya for all their feedback!

bjorn added 14 commits October 24, 2024 17:09
The new property editor will be based on a widget hierarchy instead of a
QTreeView. This will allow better customization and direct widget
interaction.

This first step implements various property edit widgets which are
instantiated based on the type of QVariant values.

* DoubleSpinBox, with precision logic from existing property editor
* Custom spin boxes and combo boxes which shrink horizontally
* Property names elide when there isn't enough space
* QPointF and QColor editor factories
* Includes a test with all built-in map properties
* Supports headers (not collapsible for now)
* Supports separators
* EnumEditorFactory, with support for non-consecutive enums
* Name and editor widgets are stretched by a fixed 2:3 ratio and ignore
  their size hint
* Includes some start on possible API for setting/getting the value
It adjusts the layout based on its width.

Also made a few other visual tweaks.
Introduced Property class and changed from using editor factories to
having the property itself create its widget.
* Map size is read-only but features a "Resize Map" button that triggers
  the resize dialog.

* Both map size and tile size are implemented based on the new
  "ValueTypeEditorFactory" which selects an editor based on the value
  type. This functionality is moved out of the VariantEditor.

* Introduced AbstractProperty, ValueProperty and QObjectProperty in an
  attempt to provide some convenience on top of the Property interface.

I'm not entirely convinced it was a good idea to put the "createEditor"
function on the Property. It makes it easy to do custom widgets for a
property, but annoying to have it use a type-based editor.
* Introduced MapProperties class to make it easier to emit valueChanged
  for all the map's properties, as well to move their creation out of
  PropertiesWidget::currentObjectChanged.

* Added GetSetProperty that makes it easier to define a property in
  terms of a given getter and setter function, since it avoids the need
  for a specific Property subclass.

* Finished implementation of the BoolEditorFactory (signals connected).

* Moved property edit widgets to their own file.
* Introduced a few helper functions to reduce code duplication, like
  MapProperties::push.

* Disabled properties when they are irrelevant.

* Finished connecting the signals for the remaining editor factories:
  StringEditorFactory, IntEditorFactory, FloatEditorFactory,
  PointEditorFactory, PointFEditorFactory, RectFEditorFactory and
  ColorEditorFactory.
This property uses an editable combo box with the valid classes set up for
the given object type.
Still needs special handling for:

* Color (requires handling invalid/unset values)
* Widget for editing allowed transformations
* Widget for showing tileset parameters (and trigger edit dialog)
* Specifying 1 as minimum value for column count
Some details remain to be done:

* Changes made to layer properties should apply to all selected layers
* Opacity should probably be a slider now and have appropriate limits
* Step size for opacity and parallax factor is too big
Added support for editing QUrl values using UrlEditorFactory that
creates a FileEdit.
Also in this change:

* Made SpinBox and DoubleSpinBox don't respond to changing from
  keyboard typing immediately.

* Share a single implementation of wrapping label/widget pairs for
  SizeEdit, SizeFEdit, PointEdit, PointFEdit and RectFEdit.

* Added widget factories for QFont, QSizeF and Qt::Alignment.

* Allow setting suffix on custom FloatEditorFactory, used for adding
  degree symbol to rotation values.

A few things remain to be done:

* Custom widget for editing tile object flipping flags
* Try reducing size of font editor with style toggle buttons
Now all built-in properties are present, apart from some loose ends.

* Added RectEdit / RectEditorFactory (QRect values)
* Added Property::toolTip (set on label and editor, but currently not
  functional on label due to the eliding tool tip logic)
* Added change events to fix updating of WangSet and WangColor properties
  (was already broken with old framework)
Instead there are now typed Property subclasses similar to the generic
GetSetProperty.
@bjorn bjorn force-pushed the new-properties-framework branch from cf7f163 to 85ef006 Compare November 14, 2024 12:49
A bit of a hacky solution to hiding the "Custom Properties" header in
this context, because it is now inside a group box with that title.
These have been replaced by the new property framework.
The QtPropertyBrowser solution has served us well for over 10 years. Now
it has been replaced by a new widget-based solution with a more
convenient API.
@bjorn bjorn force-pushed the new-properties-framework branch from 2568cb4 to 1a7abf8 Compare November 21, 2024 11:54
@bjorn bjorn force-pushed the new-properties-framework branch from 58db1d0 to 2990619 Compare November 29, 2024 16:07
bjorn added 14 commits December 5, 2024 11:48
A lot of places were still relying on the mapChanged signal, but they
should use mapResized or the MapChangeEvent since
2177fac.
When adding custom class properties, they are expanded with the first
member focused.
Use a special property that creates a name edit as label and a type
combo box as editor, instead of a modal Add Property dialog.

VariantEditorView::focusProperty now makes sure that the focused
property widget is visible.

The "add value" property is automatically removed when it loses focus.
To achieve this, each property now gets its own parent widget rather
than just having its widgets added to a nested horizontal layout. This
way, we can check whether the focus remains within the same parent
widget.

The Add button has Qt::StrongFocus policy now, otherwise the focus would
be lost to the properties view when clicking it.
When changed by other means (scripting, undo/redo, Layers view), the
name wasn't updating due to a missing valueChanged call.
We don't really need to put it in a QWidget with a vertical layout.
- Top-level properties can be selected by clicking.
- Holding Ctrl or Shift allows selecting multiple.
- Keyboard handling for selection implemented.
- Remove and Rename actions on tool bar now functional.
- Copy/paste shortcuts work.

As part of implementing this, the VariantEditor and VariantEditorView
have been merged into a single PropertiesView class.

ToDo:

- selectedPropertiesChanged may not get emitted when a selected property
  is removed.
- Add Copy/Paste actions to context menu.
To match the rename in the last commit.

The term "VariantEditor" referred to the initial approach of using
QVariant for all properties. Now "PropertiesView" is more appropriate,
since it is a view based on the type-agnostic "Property" hierarchy.
Now they both scale vertically to cover the minimum size of both.
Better to not touch the clipboard at all in this case.
When pasting custom properties, we now make sure that the Custom
Properties group is expanded and select the pasted properties for some
additional feedback. Also focus the first pasted property, which makes
sure at least one of them is visible.
This change also disables Enter for opening the combo box popup, fixing
the rather broken behavior (at least on Linux) that pressing Enter to
select a type will immediately re-open the popup. That only applies to
combo boxes in the Properties view, though.
@bjorn bjorn force-pushed the new-properties-framework branch from ee2d01d to 73e6373 Compare December 5, 2024 10:49
@dganzella
Copy link

hmm seems that the new system you cand copy-paste properties anymore :(

@bjorn
Copy link
Member Author

bjorn commented Dec 5, 2024

hmm seems that the new system you cand copy-paste properties anymore :(

You can, though for now only with shortcuts Ctrl+X/C/V. I still need to add those actions back to the context menu.

This makes the property-specific actions like "Go to Object" and "Open
Containing Folder" available again, as well as the Cut, Copy and Paste
actions.

For now, the Custom Types Editor has no context menu anymore...

Property widgets are now removed before their property is deleted to
avoid a crash when right-clicking the AddValueProperty, since that
caused the focus to be lost and thus the removal of the property while
at the same time triggering a context menu for it.
The QCommonStyle always uses the WindowText role when rendering a
checkbox label, so change the palette so that is picks up the
HighlightedText role when the property is selected.
@bjorn bjorn force-pushed the new-properties-framework branch from 55b83d3 to 754b2a5 Compare December 13, 2024 09:06
@HeadClot
Copy link

Got a question - Will this PR be a breaking change for existing exporters for other engines?

@bjorn
Copy link
Member Author

bjorn commented Dec 13, 2024

Got a question - Will this PR be a breaking change for existing exporters for other engines?

No, this change is purely related to improving the UI of the Properties view the related view on class members in the Custom Types Editor.

When this change is done I will resume work on #4002, which will be a new feature to support in exporters and other engines. It's not expected to be a breaking change either though, unless array properties are actually used.

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.

5 participants