From a69e39cd2fe4f3a8d6cbe493ebd7290b426cba0f Mon Sep 17 00:00:00 2001 From: blacksun Date: Wed, 26 Jul 2017 08:55:32 +0000 Subject: [PATCH] Fix crash: In Xref link widget, If there is an element being added (element pose mode), and this one is compatible with the type of Xref sought by the widget, then the widget show this element. When user finish the element pose mode, the element under the cursor is deleted, but continue to be show by the widget. So, click on this element in the widget cause a crash. This case come when user add element and go to another diagram without finish the pose mode, and open Xref link widget from an element in this other diagram. git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/trunk@4993 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/diagram.cpp | 15 +++++++++++++-- sources/diagram.h | 1 + sources/projectview.cpp | 11 +++++++++-- sources/projectview.h | 1 + 4 files changed, 24 insertions(+), 4 deletions(-) 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; };