OpenEditorsWindow: Fix crash when entries are removed

behind the back of the window.

The open editors window (that appears on ctrl+tab / opt+tab) keeps
pointers to Entry items from the DocumentModel. Usually that is no
problem, because the editor manager hides the open editors window before
closing editors. But there was an issue with suspended entries, that can
be reproduced with some effort, e.g.

- Give e.g. "Unload/Close Project" a shortcut that you can trigger while
  the popup is open, like Opt+K on macOS, or Ctrl+Shift+J on Lin/Win
- Open a project and a few files from the project
- Switch the document switcher of the editor view to "<no document>"
- Close & reopen QtC, reload the session

- You should now have a few "suspended" documents, and *only* suspended
  documents, since the editor view doesn't show anything
- Open the open editors window with ctrl+tab / opt+tab and trigger the
  "close project" shortcut without closing the popup
- The documents and the project close, but the popup is open and shows
  the old items
- The moment you press e.g. tab again to interact with the popup, it
  crashes

Just close the popup if items are removed from the document model
"behind its back". Also clear all items whenever it is set invisible so
we don't have references to broken items hanging around.

Change-Id: I70853838f292235efea0561755b35c20aaa8473d
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Eike Ziller
2024-12-09 14:40:04 +01:00
parent 1a781f9295
commit f6d57999d8

View File

@@ -146,6 +146,11 @@ OpenEditorsWindow::OpenEditorsWindow(QWidget *parent)
auto layout = new QVBoxLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->addWidget(m_editorView);
// Close the popup and clear it if documents are closed behind the back of the view
connect(DocumentModel::model(), &QAbstractItemModel::rowsAboutToBeRemoved, this, [this] {
setVisible(false);
});
}
void OpenEditorsWindow::selectAndHide()
@@ -159,6 +164,8 @@ void OpenEditorsWindow::setVisible(bool visible)
QWidget::setVisible(visible);
if (visible)
setFocus();
else
m_editorView->m_model.clear();
}
bool OpenEditorsWindow::eventFilter(QObject *obj, QEvent *e)