From ae3916229d9b055720b49bfac01f906376cbe13c Mon Sep 17 00:00:00 2001 From: blobfish Date: Sun, 3 May 2015 22:01:35 -0400 Subject: [PATCH] Gui: ActiveObject: remove upon delete Squashed with: Gui: MDIView: connection bug. Gui: MDIView: forgot disconnect. --- src/Gui/ActiveObjectList.cpp | 15 +++++++++++++++ src/Gui/ActiveObjectList.h | 2 ++ src/Gui/MDIView.cpp | 13 ++++++++++++- src/Gui/MDIView.h | 7 +++++-- 4 files changed, 34 insertions(+), 3 deletions(-) diff --git a/src/Gui/ActiveObjectList.cpp b/src/Gui/ActiveObjectList.cpp index c9ab78b36..03a0d208c 100644 --- a/src/Gui/ActiveObjectList.cpp +++ b/src/Gui/ActiveObjectList.cpp @@ -54,3 +54,18 @@ bool Gui::ActiveObjectList::hasObject(const char*name)const { return _ObjectMap.find(name) != _ObjectMap.end(); } + +void ActiveObjectList::objectDeleted(const ViewProviderDocumentObject& viewProviderIn) +{ + App::DocumentObject* object = viewProviderIn.getObject(); + //maybe boost::bimap or boost::multi_index + std::map::iterator it; + for (it = _ObjectMap.begin(); it != _ObjectMap.end(); ++it) + { + if (it->second == object) + { + _ObjectMap.erase(it); + return; + } + } +} diff --git a/src/Gui/ActiveObjectList.h b/src/Gui/ActiveObjectList.h index 8ef0baa01..fc53a5f73 100644 --- a/src/Gui/ActiveObjectList.h +++ b/src/Gui/ActiveObjectList.h @@ -36,6 +36,7 @@ namespace Gui { class Document; + class ViewProviderDocumentObject; /** List of active or special objects * This class holds a list of objects with a special name. @@ -56,6 +57,7 @@ namespace Gui } void setObject(App::DocumentObject*, const char*, const Gui::HighlightMode& m = Gui::LightBlue); bool hasObject(const char*)const; + void objectDeleted(const ViewProviderDocumentObject& viewProviderIn); protected: std::map _ObjectMap; diff --git a/src/Gui/MDIView.cpp b/src/Gui/MDIView.cpp index 68098b7db..5ea1ecafe 100644 --- a/src/Gui/MDIView.cpp +++ b/src/Gui/MDIView.cpp @@ -24,6 +24,8 @@ #include "PreCompiled.h" #ifndef _PreComp_ +# include +# include # include # include # include @@ -38,6 +40,7 @@ #include "Document.h" #include "Application.h" #include "MainWindow.h" +#include "ViewProviderDocumentObject.h" using namespace Gui; @@ -48,6 +51,13 @@ MDIView::MDIView(Gui::Document* pcDocument,QWidget* parent, Qt::WindowFlags wfla : QMainWindow(parent, wflags), BaseView(pcDocument),currentMode(Child), wstate(Qt::WindowNoState) { setAttribute(Qt::WA_DeleteOnClose); + + if (pcDocument) + { + connectDelObject = pcDocument->signalDeletedObject.connect + (boost::bind(&ActiveObjectList::objectDeleted, &ActiveObjects, _1)); + assert(connectDelObject.connected()); + } } MDIView::~MDIView() @@ -70,7 +80,8 @@ MDIView::~MDIView() } } } - + if (connectDelObject.connected()) + connectDelObject.disconnect(); } void MDIView::deleteSelf() diff --git a/src/Gui/MDIView.h b/src/Gui/MDIView.h index 29597c7bc..8faac4dfe 100644 --- a/src/Gui/MDIView.h +++ b/src/Gui/MDIView.h @@ -35,6 +35,7 @@ QT_END_NAMESPACE namespace Gui { class Document; +class ViewProviderDocumentObject; /** Base class of all windows belonging to a document. * There are two ways of belonging to a document: @@ -147,8 +148,10 @@ protected: private: ViewMode currentMode; Qt::WindowStates wstate; - // list of active objects of this view - ActiveObjectList ActiveObjects; + // list of active objects of this view + ActiveObjectList ActiveObjects; + typedef boost::BOOST_SIGNALS_NAMESPACE::connection Connection; + Connection connectDelObject; //remove active object upon delete. }; } // namespace Gui