Gui: ActiveObject: remove upon delete
Squashed with: Gui: MDIView: connection bug. Gui: MDIView: forgot disconnect.
This commit is contained in:
parent
c161ffaf44
commit
ae3916229d
|
@ -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<std::string, App::DocumentObject*>::iterator it;
|
||||
for (it = _ObjectMap.begin(); it != _ObjectMap.end(); ++it)
|
||||
{
|
||||
if (it->second == object)
|
||||
{
|
||||
_ObjectMap.erase(it);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<std::string, App::DocumentObject*> _ObjectMap;
|
||||
|
||||
|
|
|
@ -24,6 +24,8 @@
|
|||
#include "PreCompiled.h"
|
||||
|
||||
#ifndef _PreComp_
|
||||
# include <boost/signals.hpp>
|
||||
# include <boost/bind.hpp>
|
||||
# include <qapplication.h>
|
||||
# include <qregexp.h>
|
||||
# include <QEvent>
|
||||
|
@ -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()
|
||||
|
|
|
@ -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:
|
||||
|
@ -149,6 +150,8 @@ private:
|
|||
Qt::WindowStates wstate;
|
||||
// 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
|
||||
|
|
Loading…
Reference in New Issue
Block a user