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

DlgTrackInfo: apply pending changes also when saving via hotkey #4562

Merged
merged 2 commits into from
Dec 18, 2021

Conversation

ronso0
Copy link
Member

@ronso0 ronso0 commented Dec 10, 2021

This fixes a small usability regression introduced by #3906
It affects my personal workflow when mass-editing metadata (same metadata field for a few tracks in a row).
https://bugs.launchpad.net/mixxx/+bug/1954346

The issue is that the track record is only updated when changed QLineEdits send the editingFinished() signal -- which is not the case when I don't press Enter and Apply/saveTrack() is invoked via hotkey while the changed line is still focused.

I will definitely add this to my personal branch and I don't mind if it's rejected because "The user should simply hit Enter, let's not add this hack".

if (this == QApplication::activeWindow()) {
auto focusWidget = QApplication::focusWidget();
if (focusWidget) {
QLineEdit* focusedLineEdit = static_cast<QLineEdit*>(focusWidget);
Copy link
Contributor

Choose a reason for hiding this comment

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

This is undefined behavior if the focused widget is not of type QLineEdit.

Copy link
Member

Choose a reason for hiding this comment

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

See qobject_cast for the safe cast.

Copy link
Contributor

@uklotzde uklotzde Dec 11, 2021

Choose a reason for hiding this comment

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

Is it possible to switch focus to the Apply button and then process all subsequent events before continuing? This would be a more robust solution that is independent of the actual widgets that are used.

Copy link
Member Author

@ronso0 ronso0 Dec 11, 2021

Choose a reason for hiding this comment

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

See qobject_cast for the safe cast.

Yeah, thanks!
This also allows to remove the if (focusWidget) check because qobject_cast returns nullptr if focusWidget is a nullptr

Copy link
Member Author

Choose a reason for hiding this comment

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

Is it possible to switch focus to the Apply button and then process all subsequent events before continuing?

The benefit of using hotkeys is that the metadata field remains focused when switching tracks, see the mass-edit example I mentioned.

alternative hacks:

  • store focus widget, focus Apply button to fire editingFinished, re-focus previous widget, but this is a bit over the top to fix the behaviour
  • send a Return key event
    requires filtering for non-QPushButton widgets
  • sending Tab then Shift+Tab
    that's is even more of a hack
  • have a list of all used QLineEdits (they're hardcoded here anyway) and in saveTrack() iterate over that to emit editingFinished() for all of them
  • shortest widget-independent and most straight-forward hack:
auto focusWidget = QApplication::focusWidget();
if (focusWidget) {
    focusWidget->clearFocus();
    focusWidget->setFocus();
}

: )

Copy link
Member Author

Choose a reason for hiding this comment

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

It works, but still it's a hack -- and I thought we prefer 'official ways' over hacks.
I don't care as long as the bug is fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Leaving the focused widget is what is supposed to happen before hitting Apply. That's the regular flow. I don't like to introduce shortcuts that work differently.

Copy link
Contributor

Choose a reason for hiding this comment

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

The focus change variant works for me. Didn't notice that you introduced it here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Leaving the focused widget is what is supposed to happen before hitting Apply

...when you use the mouse, sure.

I don't like to introduce shortcuts that work differently

They do work differently: QShortcut makes its QPushButton emit clicked() but it does not force-focus the button.
FWIW #3906 broke the flow for hotkey users, or at least made it more complex by requiring to hit Return.
(no, that's no occassion to post that famous xkcb cartoon... ;)

Copy link
Member Author

Choose a reason for hiding this comment

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

The focus change variant works for me. Didn't notice that you introduced it here.

I just did after you asked for it.

@ronso0 ronso0 force-pushed the track-info-reset branch 2 times, most recently from 1a253fc to 234005a Compare December 11, 2021 19:38
Copy link
Contributor

@uklotzde uklotzde left a comment

Choose a reason for hiding this comment

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

This workaround is acceptable and unlikely to break when modifying the dialog widgets in the future. Thank you! LGTM

@uklotzde uklotzde merged commit 70bee44 into mixxxdj:main Dec 18, 2021
@ronso0 ronso0 deleted the track-info-reset branch December 18, 2021 13:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants