Fix crash when close project

At time of closing project, if a master element(may be every linkable
element) is selected and the editor dock display a lot of available
slave, qet crash.
This commit is contained in:
Claveau Joshua
2020-04-09 16:12:21 +02:00
parent 94aa5c0247
commit 017f78fb13
4 changed files with 18 additions and 15 deletions

View File

@@ -101,7 +101,6 @@ DiagramView::DiagramView(Diagram *diagram, QWidget *parent) :
} }
connect(m_diagram, SIGNAL(showDiagram(Diagram*)), this, SIGNAL(showDiagram(Diagram*))); connect(m_diagram, SIGNAL(showDiagram(Diagram*)), this, SIGNAL(showDiagram(Diagram*)));
connect(m_diagram, SIGNAL(selectionChanged()), this, SIGNAL(selectionChanged()));
connect(m_diagram, SIGNAL(sceneRectChanged(QRectF)), this, SLOT(adjustSceneRect())); connect(m_diagram, SIGNAL(sceneRectChanged(QRectF)), this, SLOT(adjustSceneRect()));
connect(&(m_diagram -> border_and_titleblock), SIGNAL(diagramTitleChanged(const QString &)), this, SLOT(updateWindowTitle())); connect(&(m_diagram -> border_and_titleblock), SIGNAL(diagramTitleChanged(const QString &)), this, SLOT(updateWindowTitle()));
connect(diagram, SIGNAL(editElementRequired(ElementsLocation)), this, SIGNAL(editElementRequired(ElementsLocation))); connect(diagram, SIGNAL(editElementRequired(ElementsLocation)), this, SIGNAL(editElementRequired(ElementsLocation)));

View File

@@ -1,4 +1,4 @@
/* /*
Copyright 2006-2019 The QElectroTech Team Copyright 2006-2019 The QElectroTech Team
This file is part of QElectroTech. This file is part of QElectroTech.
@@ -102,8 +102,6 @@ class DiagramView : public QGraphicsView
bool gestures() const; bool gestures() const;
signals: signals:
/// Signal emitted after the selection changed
void selectionChanged();
/// Signal emitted after the selection mode changed /// Signal emitted after the selection mode changed
void modeChanged(); void modeChanged();
/// Signal emitted after the diagram title changed /// Signal emitted after the diagram title changed

View File

@@ -56,11 +56,8 @@ ProjectView::ProjectView(QETProject *project, QWidget *parent) :
Supprime les DiagramView embarquees Supprime les DiagramView embarquees
*/ */
ProjectView::~ProjectView() { ProjectView::~ProjectView() {
// qDebug() << "Suppression du ProjectView" << ((void *)this); for (auto dv_ : m_diagram_ids.values())
foreach(int id, m_diagram_ids.keys()) { dv_->deleteLater();
DiagramView *diagram_view = m_diagram_ids.take(id);
delete diagram_view;
}
} }
/** /**

View File

@@ -1932,17 +1932,26 @@ void QETDiagramEditor::activateProject(ProjectView *project_view) {
} }
/** /**
Gere la fermeture d'une ProjectView * @brief QETDiagramEditor::projectWasClosed
@param project_view ProjectView fermee * Manage the close of a project.
*/ * @param project_view
void QETDiagramEditor::projectWasClosed(ProjectView *project_view) { */
void QETDiagramEditor::projectWasClosed(ProjectView *project_view)
{
QETProject *project = project_view -> project(); QETProject *project = project_view -> project();
if (project) { if (project)
{
pa -> elementsPanel().projectWasClosed(project); pa -> elementsPanel().projectWasClosed(project);
m_element_collection_widget->removeProject(project); m_element_collection_widget->removeProject(project);
undo_group.removeStack(project -> undoStack()); undo_group.removeStack(project -> undoStack());
QETApp::unregisterProject(project); QETApp::unregisterProject(project);
} }
//When project is closed, a lot of signal are emited, notably if there is an item selected in a diagram.
//In some special case, since signal/slot connection can be direct or queued, some signal are handled after QObject is deleted, and crash qet
//notably in the function Diagram::elements when she call items() (I don't know exactly why).
//set nullptr to "m_selection_properties_editor->setDiagram()" fix this crash
m_selection_properties_editor->setDiagram(nullptr);
project_view -> deleteLater(); project_view -> deleteLater();
project -> deleteLater(); project -> deleteLater();
} }
@@ -2147,7 +2156,7 @@ void QETDiagramEditor::removeDiagramFromProject() {
*/ */
void QETDiagramEditor::diagramWasAdded(DiagramView *dv) void QETDiagramEditor::diagramWasAdded(DiagramView *dv)
{ {
connect(dv, SIGNAL(selectionChanged()), this, SLOT(selectionChanged())); connect(dv->diagram(), &QGraphicsScene::selectionChanged, this, &QETDiagramEditor::selectionChanged, Qt::DirectConnection);
connect(dv, SIGNAL(modeChanged()), this, SLOT(slot_updateModeActions())); connect(dv, SIGNAL(modeChanged()), this, SLOT(slot_updateModeActions()));
} }