Fix a closed project staying in the element collection panel

A project opened before the element collection panel's first load is
queued until the load starts; one opened during a load goes into the
model being loaded. ElementsCollectionWidget::removeProject() only
removed the project from the model already shown, so a project closed
in either window stayed in the collection, and the next reload read the
freed project (crash in XmlElementCollection::root()).

removeProject() now also takes the project out of the queue and out of
the model being loaded. That model waits for its loading threads, which
read the project, and drops the project's items from the list applied
when the loading ends.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ispyisail
2026-10-19 18:27:38 +13:00
parent 31730678c5
commit 46d8588113
4 changed files with 97 additions and 0 deletions
@@ -526,6 +526,13 @@ void ElementsCollectionModel::removeProject(QETProject *project)
if (!m_project_list.contains(project))
return;
//A loading may be setting up this project's items on worker
//threads: let it end, and keep the items about to be deleted out of
//the list applied when it is finished.
m_future.waitForFinished();
for (ElementCollectionItem *eci : projectItems(project))
m_items_list_to_setUp.removeOne(eci);
int row = m_project_list.indexOf(project);
if (removeRows(row, 1, QModelIndex())) {
m_project_list.removeOne(project);
@@ -141,6 +141,11 @@ void ElementsCollectionWidget::addProject(QETProject *project)
}
void ElementsCollectionWidget::removeProject(QETProject *project) {
//Before the first load and during a load, the project is also
//waiting to be loaded, or in the model being loaded
m_waiting_project.removeAll(project);
if (m_new_model)
m_new_model->removeProject(project);
if (m_model)
m_model->removeProject(project);
}