diff --git a/sources/diagram.cpp b/sources/diagram.cpp index 496956121..be3995dc6 100644 --- a/sources/diagram.cpp +++ b/sources/diagram.cpp @@ -377,8 +377,6 @@ void Diagram::keyReleaseEvent(QKeyEvent *e) * Diagram become the ownership of event_interface * If there is a previous interface, they will be delete before * and call init() to the new interface. - * The derivated class of DiagramEventInterface need to emit the signal "finish" when the job is done, - * diagram use this signal to delete the interface. If the signal isn't send, the interface will never be deleted. * @param event_interface */ void Diagram::setEventInterface(DiagramEventInterface *event_interface) @@ -391,6 +389,19 @@ void Diagram::setEventInterface(DiagramEventInterface *event_interface) m_event_interface = event_interface; } +/** + * @brief Diagram::clearEventInterface + * Clear the current event interface. + */ +void Diagram::clearEventInterface() +{ + if(m_event_interface) + { + delete m_event_interface; + m_event_interface = nullptr; + } +} + /** * @brief Diagram::conductorsAutonumName * @return the name of autonum to use. diff --git a/sources/diagram.h b/sources/diagram.h index c2a68d357..4c54ccaef 100644 --- a/sources/diagram.h +++ b/sources/diagram.h @@ -129,6 +129,7 @@ class Diagram : public QGraphicsScene public: void setEventInterface (DiagramEventInterface *event_interface); + void clearEventInterface(); //methods related to autonum QString conductorsAutonumName() const; diff --git a/sources/projectview.cpp b/sources/projectview.cpp index 2cf7b62ef..ba9924d89 100644 --- a/sources/projectview.cpp +++ b/sources/projectview.cpp @@ -989,15 +989,22 @@ void ProjectView::rebuildDiagramsMap() { * we display the fallback widget. * @param tab_id */ -void ProjectView::tabChanged(int tab_id) { +void ProjectView::tabChanged(int tab_id) +{ if (tab_id == -1) setDisplayFallbackWidget(true); else if(m_tab->count() == 1) setDisplayFallbackWidget(false); - + emit(diagramActivated(m_diagram_ids[tab_id])); + if (m_diagram_ids[tab_id] != nullptr) m_diagram_ids[tab_id]->diagram()->diagramActivated(); + + //Clear the event interface of the previous diagram + if (DiagramView *dv = m_diagram_ids[m_previous_tab_index]) + dv->diagram()->clearEventInterface(); + m_previous_tab_index = tab_id; } /** diff --git a/sources/projectview.h b/sources/projectview.h index 8dd788e22..e8ccdefc6 100644 --- a/sources/projectview.h +++ b/sources/projectview.h @@ -133,6 +133,7 @@ class ProjectView : public QWidget QLabel *fallback_label_; QTabWidget *m_tab; QMap m_diagram_ids; + int m_previous_tab_index = -1; QList m_diagram_view_list; };