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

Add editingTimeout signal to Qgs(Double)SpinBox #59787

Merged
merged 2 commits into from
Dec 12, 2024

Conversation

nyalldawson
Copy link
Collaborator

Emitted when either:

  1. 2 seconds has elapsed since the last value change in the widget (eg last key press or scroll wheel event)
  2. or, immediately after the widget has lost focus after its value was changed.

This signal can be used to respond semi-instantly to changes in the spin box, without responding too quickly
while the user in the middle of setting the value.

Emitted when either:
1. 2 seconds has elapsed since the last value change in the widget
  (eg last key press or scroll wheel event)
2. or, immediately after the widget has lost focus after its value
  was changed.

This signal can be used to respond semi-instantly to changes in
the spin box, without responding too quickly
while the user in the middle of setting the value.
@nyalldawson nyalldawson added the API API improvement only, no visible user interface changes label Dec 9, 2024
@nyalldawson
Copy link
Collaborator Author

For motivation see #59398 (comment)

Copy link

github-actions bot commented Dec 9, 2024

🪟 Windows builds

Download Windows builds of this PR for testing.
Debug symbols for this build are available here.
(Built from commit b489454)

🪟 Windows Qt6 builds

Download Windows Qt6 builds of this PR for testing.
(Built from commit b489454)

@nicogodet
Copy link
Member

Very! Very nice!
Many thanks!

Is it possible to change the timeout delay ? 2 sec can be quite long sometimes

@uclaros
Copy link
Contributor

uclaros commented Dec 9, 2024

Is it possible to change the timeout delay ? 2 sec can be quite long sometimes

It would make sense to add a setTimeout( int msec );
There are cases that could benefit from a small delay.

@nyalldawson
Copy link
Collaborator Author

@nicogodet @uclaros do you think the timeout should be a qsettings value? Or set via API per widget?

@nicogodet
Copy link
Member

I'm in favor for an API method

@YoannQDQ
Copy link
Contributor

YoannQDQ commented Dec 9, 2024

Maybe both? A default QSettings timeout which can be overriden per widget?

@uclaros
Copy link
Contributor

uclaros commented Dec 9, 2024

I'd say API. This is more of a helper instead of manually creating the qtimers.
This would also make sense to have in other widgets that quickly change values, like the QgsFilterLineEdit

@nyalldawson
Copy link
Collaborator Author

I guess I'm just confused why we'd want different timeout behaviour across different widgets. Wont that be inconsistent and feel "odd" for users?

@@ -3,8 +3,8 @@
QgsDoubleSpinBox.MaximumValue = QgsDoubleSpinBox.ClearValueMode.MaximumValue
QgsDoubleSpinBox.CustomValue = QgsDoubleSpinBox.ClearValueMode.CustomValue
try:
QgsDoubleSpinBox.__attribute_docs__ = {'returnPressed': 'Emitted when the Return or Enter key is used in the line edit.\n\n.. versionadded:: 3.40\n', 'textEdited': 'Emitted when the the value has been manually edited via line edit.\n\n.. versionadded:: 3.40\n'}
QgsDoubleSpinBox.__signal_arguments__ = {'textEdited': ['text: str']}
QgsDoubleSpinBox.__attribute_docs__ = {'returnPressed': 'Emitted when the Return or Enter key is used in the line edit.\n\n.. versionadded:: 3.40\n', 'textEdited': 'Emitted when the the value has been manually edited via line edit.\n\n.. versionadded:: 3.40\n', 'editingTimeout': 'Emitted when either:\n\n1. 2 seconds has elapsed since the last value change in the widget (eg last key press or scroll wheel event)\n2. or, immediately after the widget has lost focus after its value was changed.\n\nThis signal can be used to respond semi-instantly to changes in the spin box, without responding too quickly\nwhile the user in the middle of setting the value.\n\n.. versionadded:: 3.42\n'}
Copy link
Contributor

Choose a reason for hiding this comment

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

While at it, removing the duplicate "the"?

Suggested change
QgsDoubleSpinBox.__attribute_docs__ = {'returnPressed': 'Emitted when the Return or Enter key is used in the line edit.\n\n.. versionadded:: 3.40\n', 'textEdited': 'Emitted when the the value has been manually edited via line edit.\n\n.. versionadded:: 3.40\n', 'editingTimeout': 'Emitted when either:\n\n1. 2 seconds has elapsed since the last value change in the widget (eg last key press or scroll wheel event)\n2. or, immediately after the widget has lost focus after its value was changed.\n\nThis signal can be used to respond semi-instantly to changes in the spin box, without responding too quickly\nwhile the user in the middle of setting the value.\n\n.. versionadded:: 3.42\n'}
QgsDoubleSpinBox.__attribute_docs__ = {'returnPressed': 'Emitted when the Return or Enter key is used in the line edit.\n\n.. versionadded:: 3.40\n', 'textEdited': 'Emitted when the value has been manually edited via line edit.\n\n.. versionadded:: 3.40\n', 'editingTimeout': 'Emitted when either:\n\n1. 2 seconds has elapsed since the last value change in the widget (eg last key press or scroll wheel event)\n2. or, immediately after the widget has lost focus after its value was changed.\n\nThis signal can be used to respond semi-instantly to changes in the spin box, without responding too quickly\nwhile the user in the middle of setting the value.\n\n.. versionadded:: 3.42\n'}

sorry for having only such basic suggestions...

@nicogodet
Copy link
Member

@nyalldawson Thinking on what would be my use case:

  • If heavy function is connected to this signal I would set a long delay
  • If value is crucial, user may think twice but start typing before thinking and it would trigger unwanted update while he is still thinking
  • On layout PR, a smaller delay (eg. 0.5sec would be enough)

I'm not a UX expert, just my thought

@uclaros
Copy link
Contributor

uclaros commented Dec 9, 2024

I would not use this for the case of typing values like the #59398 case. I really think that the editingFinished which was used is a better fit for expensive actions as the triggering is explicit.
I see this more as a way to limit the total number of signals for example when using the mouse wheel. Similar to the auto apply timer in QgsLayerStylingWidget. For this use case 2 sec is too much!

@nyalldawson
Copy link
Collaborator Author

Ok, API added for setting the timeout interval now. I've also decreased the default timeout interval to 1 second.

@nyalldawson nyalldawson merged commit 2f2e900 into qgis:master Dec 12, 2024
30 checks passed
@nyalldawson nyalldawson deleted the spin_box_editing_timeout branch December 12, 2024 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API API improvement only, no visible user interface changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants