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

VectorDataWidget single value drop fix #6242

Merged

Conversation

ericmehl
Copy link
Collaborator

This fixes dropping a single value onto a VectorDataWidget / VectorDataPlugValueWidget. Previously, if you dropped a single value, the + and - buttons would not activate. This meant it reverted to the PlugValueWidget behavior, which attempts to convert the dropped data into the data type expected by the widget.

*VectorData objects can take a single value in their constructor. For IntVectorData, this creates a vector of length equal to the value being dropped. StringVectorData similarly turns a string constructor argument into a vector where each letter is an element.

So the data would convert and the drop would succeed but with unexpected values.

This PR handles those cases by converting to single-element vectors instead, for correct dropping onto VectorDataWidget, including the +, - and overall plug (effectively the plug name)`.

Checklist

  • I have read the contribution guidelines.
  • I have updated the documentation, if applicable.
  • I have tested my change(s) in the test suite, and added new test cases where necessary.
  • My code follows the Gaffer project's prevailing coding style and conventions.

Copy link
Member

@johnhaddon johnhaddon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Eric!

@@ -131,6 +131,17 @@ def __dataChanged( self, widget ) :
for plug, value in zip( self.__dataPlugs(), self.__dataWidget.getData() ) :
plug.setValue( value )

def _convertValue( self, value ) :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Am I right in thinking that we are overriding this for the case where the value is dropped onto the plug's label, and PlugValueWidget handles the drop rather than VectorDataWidget?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we move it up to live with the other protected overrides for PlugValueWidget methods? I find things easier to understand if they broadly follow a public/protected/private structure.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is for when the value is dropped onto the plug's label. PlugValueWidget is handling the drop, but it wasn't getting quite the right data type to drop, so this override course-corrects it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, makes sense to place it up with the other protecteds. Amended into the original, now 72c4bd1

@@ -664,7 +676,8 @@ def __drop( self, widget, event ) :
else :
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't a new thing, but in testing I realised that dragging onto the plug label acts differently to dragging onto the cells, although both use the same highlighting style. The label sets the entire value, and the cells act in the same was as a drop on the + button. Do you think there would be any merit in making them both act the same (setting the whole value)? Or maybe we should highlight the + button when the drag goes onto the cells?

Feel free to call this out of scope for this PR though.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found that a bit odd too. I'm not entirely sure what I'd want the behavior to be. I'm undecided between "I dragged this value onto the list, so that value should replace the list" and "I didn't mean to replace the whole list, just to add to it".

If we highlight the + button when dragging onto the list, does that entice users to want to use Shift / Ctrl + drop to add / remove from the list?

I'm inclined to leave it out of scope for this PR. At the least, would it be better done on the 1.5 branch?

@ericmehl ericmehl force-pushed the vectorDataWidgetIntDropFix branch from 3b191b3 to 72c4bd1 Compare January 30, 2025 14:37
Previously, we were letting `PlugValueWidget` attempt to convert dropped
data into something the target plug can support. When dropping a single
value such as `IntData` onto a `VectorDataPlugValueWidget`, this meant
converting `IntData` to `IntVectorData`. `*VectorData` supports
construction from an integer value, in which case it creates n elements
in the vector.

This commit instead converts a non-sequence value into a single item
sequence holding that value to use as drop data.
@ericmehl ericmehl force-pushed the vectorDataWidgetIntDropFix branch from 72c4bd1 to 5ee1b12 Compare January 30, 2025 14:51
@johnhaddon johnhaddon merged commit 18e0ff9 into GafferHQ:1.4_maintenance Jan 30, 2025
5 checks passed
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.

2 participants