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

Fix empty editor windows #7515

Merged
merged 7 commits into from
Oct 7, 2024
Merged

Conversation

firewall1110
Copy link
Contributor

@firewall1110 firewall1110 commented Sep 21, 2024

(1) Bug affects not only Song Editor window, but also Piano Roll, Pattern Editor, Automation Editor windows (all are extending Editor class). Using MainWindow::refocus() makes closing event handling close to closing by shortcut (from MainWindow code)
(2) This is BugFix PR so I do not change coding convention violation ( variable _ce ).
[Edited: after some refactoring commits by LMMS member I decide to change _ce to event]

Reworks #7035
Fixes #7412

@firewall1110
Copy link
Contributor Author

@michaelgregorius wrote

... with an explanation of why you think this fixes the bug. ...
ensure that the solution does not break anything else what worked before

(1) I think that it fix the bug because I test my code.

(2) Bug is result of not proper another bug solution done by PR #7035

So I add another line
getGUI()->mainWindow()->refocus();

but restore

_ce->ignore();

as it was before.

I tested it against PR #7035 fixed bug steps:

1: place notes on the grid.
2: reduce the grid until at least one of the notes doesn't line up.
3: play the loop.
4: close the piano roll editor.
5: hit space to pause.

so line
getGUI()->mainWindow()->refocus();
is proper solution (and should be added in PR #7035 instead to change _ce->ignore();).

And this code is called, than windows are closed by Ctrl+1 , Ctrl+2, Ctrl+3, Ctrl+4 .
So calling it from here can not harm more than calling in Ctrl+1 , Ctrl+2, Ctrl+3, Ctrl+4 context.

(3)

Using _ce->ignore(); in such situation is also in Qt 5.12 documentation:

"The event handler QWidget::closeEvent() receives close events. The default implementation of this event handler accepts the close event. If you do not want your widget to be hidden, or want some special handling, you should reimplement the event handler and ignore() the event."

Copy link
Contributor

@irrenhaus3 irrenhaus3 left a comment

Choose a reason for hiding this comment

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

Fixes the bug. Might prefer a signal/slot channel instead of making the private refocus() public. Not a blocker in my eyes though.

@michaelgregorius
Copy link
Contributor

Can someone explain why and how it fixes the bug? What caused the bug in the first place?

@messmerd messmerd changed the title Fix Issue #7412 (After closing Song Editor new project loaded ends with empty song editor window) by redoing PR #7035 Fix empty editor windows Sep 24, 2024
Refactor `MainWindow::refocus` to make it more readable and
straight-forward. Replace the Qt collection with a vector so that we
can do a simple foreach loop. Also remove the local variable `found` by
returning early on success or setting the focus on the main window
otherwise.

Remove code repetition by fetching the GUI once via `getGUI`.
@michaelgregorius
Copy link
Contributor

I have checked the implementation of MainWindow::refocus and found that it could use some refactoring. Commit 4e78fb5 introduces modern C++ and slightly simplifies the logic. It's less cluttered now.

@firewall1110
Copy link
Contributor Author

how it fixes the bug?

Empty editors window bug is kind of bugs I call "mystical bugs":
empty not functional window should not be fixed simply by hiding + un - hiding , but it happens , so all inner structures are ok.
My guess is
that after accepting close event Qt library make some kind of optimization , resource release, ... assuming, that this widget will not be used. So if we do not follow Qt documentation we get some undefined thing.
But it is only my guess.

Might prefer a signal/slot channel instead of making the private refocus() public.

My opinion is, that signal/slot channel is "overkill".
Variant is use friend line in Editor.h but:

  • if once it needed, may be will be needed once more;
  • from my point off view friend is more complex and more "exotic".

Commit 4e78fb5 introduces modern C++ and slightly simplifies the logic.

It is better and is in LMMS style, so I accept this.

[ But I prefer old good (only for my taste illustration):

void MainWindow::refocus()
{
	QWidget* editor = getGUI()->songEditor()->parentWidget();
	if (!editor->isHidden()) { editor->setFocus(); return; }
	editor = getGUI()->patternEditor()->parentWidget();
	if (!editor->isHidden()) { editor->setFocus(); return; }
	editor = getGUI()->pianoRoll()->parentWidget();
	if (!editor->isHidden()) { editor->setFocus(); return; }
	editor = getGUI()->automationEditor()->parentWidget();
	if (!editor->isHidden()) { editor->setFocus(); return; }
	this->setFocus();
}

Modern compilers will make editor register variable, so it will be faster and more compact in result assembler code.

But such things not allowed here ...
]

src/gui/MainWindow.cpp Outdated Show resolved Hide resolved

for (auto editorParent : editorParents)
{
if(!editorParent->isHidden())
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if(!editorParent->isHidden())
if (!editorParent->isHidden())

style

src/gui/MainWindow.cpp Outdated Show resolved Hide resolved
firewall1110 and others added 3 commits September 25, 2024 08:22
Co-authored-by: Dalton Messmer <messmer.dalton@gmail.com>
Co-authored-by: Dalton Messmer <messmer.dalton@gmail.com>
@firewall1110
Copy link
Contributor Author

Now in refocus() refactoring context I have one question:

is MainWindow class is right place for refocus()?

What about GuiApplication class?

P.S.
But my opinion : not here (in this bug fix PR) such changes ...

Remove the local variable from `MainWindow::refocus` and add whitespace
to the if statement.
@firewall1110
Copy link
Contributor Author

firewall1110 commented Sep 25, 2024

Now MainWindow::refocus compiled with clang++ (ver. 14) with exported CXXFLAGS="-Oz" is little bit more compact, than my "old style variant", but assembler listing is near the same ...

Copy link
Contributor

@michaelgregorius michaelgregorius left a comment

Choose a reason for hiding this comment

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

Approving this PR as it seems to fix the problem.

@michaelgregorius michaelgregorius merged commit 639e122 into LMMS:master Oct 7, 2024
11 checks passed
@firewall1110
Copy link
Contributor Author

Thank You!
Not so long ... ~ 15 days
P.S.
Should I open new issue about:

is MainWindow class is right place for refocus()?
What about GuiApplication class?

May be I find more things in MainWindow and Editor context to refactor.
Or it is not actual?

@michaelgregorius
Copy link
Contributor

@firewall1110, I am currently not sure where to put it. I would have assumed that the other editors would be children of the MainWindow and in that case having refocus in MainWindow would be fitting as it would act on its children. However, in GuiApplication the editors seem to be parallel to MainWindow with regards to the hierarchy. It would be interesting to know if the windows are reparented at some point or what this all means.

So for now I'd rather keep the refocus method in MainWindow as it seems to make sense from an intuitive model.

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.

After closing Song Editor new project loaded ends with empty song editor window (must be closed and opened)
4 participants