diff --git a/src/Mod/Drawing/Gui/DrawingView.cpp b/src/Mod/Drawing/Gui/DrawingView.cpp
index 3cd5c5e61..df4485358 100644
--- a/src/Mod/Drawing/Gui/DrawingView.cpp
+++ b/src/Mod/Drawing/Gui/DrawingView.cpp
@@ -58,7 +58,9 @@
#include
#include
#include
+#include
#include
+#include
#include
#include
@@ -249,6 +251,10 @@ DrawingView::DrawingView(Gui::Document* doc, QWidget* parent)
//setWindowTitle(tr("SVG Viewer"));
}
+DrawingView::~DrawingView()
+{
+}
+
void DrawingView::load (const QString & fileName)
{
if (!fileName.isEmpty()) {
@@ -274,6 +280,27 @@ void DrawingView::load (const QString & fileName)
}
}
+void DrawingView::setDocumentObject(const std::string& name)
+{
+ m_objectName = name;
+}
+
+void DrawingView::closeEvent(QCloseEvent* ev)
+{
+ ev->accept();
+
+ // when closing the view from GUI notify the view provider to mark it invisible
+ if (_pcDocument && !m_objectName.empty()) {
+ App::Document* doc = _pcDocument->getDocument();
+ if (doc) {
+ App::DocumentObject* obj = doc->getObject(m_objectName.c_str());
+ Gui::ViewProvider* vp = _pcDocument->getViewProvider(obj);
+ if (vp)
+ vp->hide();
+ }
+ }
+}
+
void DrawingView::contextMenuEvent(QContextMenuEvent *event)
{
QMenu menu;
diff --git a/src/Mod/Drawing/Gui/DrawingView.h b/src/Mod/Drawing/Gui/DrawingView.h
index b3fe5e27e..f4e53abcf 100644
--- a/src/Mod/Drawing/Gui/DrawingView.h
+++ b/src/Mod/Drawing/Gui/DrawingView.h
@@ -80,6 +80,7 @@ class DrawingGuiExport DrawingView : public Gui::MDIView
public:
DrawingView(Gui::Document* doc, QWidget* parent = 0);
+ virtual ~DrawingView();
public Q_SLOTS:
void load(const QString &path = QString());
@@ -94,10 +95,12 @@ public:
void printPdf();
void printPreview();
void print(QPrinter* printer);
+ void setDocumentObject(const std::string&);
PyObject* getPyObject();
protected:
void contextMenuEvent(QContextMenuEvent *event);
+ void closeEvent(QCloseEvent*);
private:
QAction *m_nativeAction;
@@ -108,6 +111,7 @@ private:
QAction *m_outlineAction;
SvgView *m_view;
+ std::string m_objectName;
QString m_currentPath;
};
diff --git a/src/Mod/Drawing/Gui/ViewProviderPage.cpp b/src/Mod/Drawing/Gui/ViewProviderPage.cpp
index 60ab900fe..2d3d4bcc2 100644
--- a/src/Mod/Drawing/Gui/ViewProviderPage.cpp
+++ b/src/Mod/Drawing/Gui/ViewProviderPage.cpp
@@ -66,6 +66,10 @@ ViewProviderDrawingPage::ViewProviderDrawingPage()
ADD_PROPERTY(HintScale,(10.0));
ADD_PROPERTY(HintOffsetX,(10.0));
ADD_PROPERTY(HintOffsetY,(10.0));
+
+ // do not show this in the property editor
+ Visibility.StatusBits.set(3, true);
+ DisplayMode.StatusBits.set(3, true);
}
ViewProviderDrawingPage::~ViewProviderDrawingPage()
@@ -91,17 +95,40 @@ std::vector ViewProviderDrawingPage::getDisplayModes(void) const
return StrList;
}
+void ViewProviderDrawingPage::show(void)
+{
+ // showing the drawing page should not affect its children but opens the MDI view
+ // therefore do not call the method of its direct base class
+ ViewProviderDocumentObject::show();
+ if (!this->view) {
+ showDrawingView();
+ this->view->load(QString::fromUtf8(getPageObject()->PageResult.getValue()));
+ view->viewAll();
+ }
+}
+
+void ViewProviderDrawingPage::hide(void)
+{
+ // hiding the drawing page should not affect its children but closes the MDI view
+ // therefore do not call the method of its direct base class
+ ViewProviderDocumentObject::hide();
+ if (view) {
+ view->parentWidget()->deleteLater();
+ }
+}
+
void ViewProviderDrawingPage::updateData(const App::Property* prop)
{
Gui::ViewProviderDocumentObjectGroup::updateData(prop);
if (prop->getTypeId() == App::PropertyFileIncluded::getClassTypeId()) {
if (std::string(getPageObject()->PageResult.getValue()) != "") {
- DrawingView* view = showDrawingView();
- view->load(QString::fromUtf8(getPageObject()->PageResult.getValue()));
- if (view->isHidden())
- QTimer::singleShot(300, view, SLOT(viewAll()));
- else
- view->viewAll();
+ if (view) {
+ view->load(QString::fromUtf8(getPageObject()->PageResult.getValue()));
+ if (view->isHidden())
+ QTimer::singleShot(300, view, SLOT(viewAll()));
+ else
+ view->viewAll();
+ }
}
}
else if (pcObject && prop == &pcObject->Label) {
@@ -129,11 +156,7 @@ bool ViewProviderDrawingPage::setEdit(int ModNum)
bool ViewProviderDrawingPage::doubleClicked(void)
{
- if (!this->view) {
- showDrawingView();
- this->view->load(QString::fromUtf8(getPageObject()->PageResult.getValue()));
- view->viewAll();
- }
+ show();
Gui::getMainWindow()->setActiveWindow(this->view);
return true;
}
@@ -149,6 +172,7 @@ DrawingView* ViewProviderDrawingPage::showDrawingView()
const char* objname = pcObject->Label.getValue();
view->setObjectName(QString::fromUtf8(objname));
view->onRelabel(doc);
+ view->setDocumentObject(pcObject->getNameInDocument());
Gui::getMainWindow()->addWindow(view);
}
diff --git a/src/Mod/Drawing/Gui/ViewProviderPage.h b/src/Mod/Drawing/Gui/ViewProviderPage.h
index 350471652..6a73f8088 100644
--- a/src/Mod/Drawing/Gui/ViewProviderPage.h
+++ b/src/Mod/Drawing/Gui/ViewProviderPage.h
@@ -56,6 +56,10 @@ public:
virtual bool useNewSelectionModel(void) const {return false;}
/// returns a list of all possible modes
virtual std::vector getDisplayModes(void) const;
+ /// Hides the view provider
+ virtual void hide(void);
+ /// Shows the view provider
+ virtual void show(void);
/// Is called by the tree if the user double click on the object
virtual bool doubleClicked(void);