From 3614a08911a9da3495af577666d657b040d7c889 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 3 Jan 2015 13:45:12 +0100 Subject: [PATCH] + fixes #0001698: All drawing pages are opened automatically when opening a project file --- src/Mod/Drawing/Gui/DrawingView.cpp | 27 ++++++++++++++ src/Mod/Drawing/Gui/DrawingView.h | 4 +++ src/Mod/Drawing/Gui/ViewProviderPage.cpp | 46 ++++++++++++++++++------ src/Mod/Drawing/Gui/ViewProviderPage.h | 4 +++ 4 files changed, 70 insertions(+), 11 deletions(-) diff --git a/src/Mod/Drawing/Gui/DrawingView.cpp b/src/Mod/Drawing/Gui/DrawingView.cpp index 3cd5c5e61e72..df448535891b 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 b3fe5e27e816..f4e53abcf23b 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 Q_SLOTS: 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 @@ public Q_SLOTS: 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 60ab900fefbe..2d3d4bcc22d6 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 3504716527c8..6a73f80888bf 100644 --- a/src/Mod/Drawing/Gui/ViewProviderPage.h +++ b/src/Mod/Drawing/Gui/ViewProviderPage.h @@ -56,6 +56,10 @@ class DrawingGuiExport ViewProviderDrawingPage : public Gui::ViewProviderDocumen 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);