Skip to content

Commit

Permalink
+ fixes #1698: All drawing pages are opened automatically when openin…
Browse files Browse the repository at this point in the history
…g a project file
  • Loading branch information
wwmayer committed Jan 3, 2015
1 parent c47eea6 commit 3614a08
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 11 deletions.
27 changes: 27 additions & 0 deletions src/Mod/Drawing/Gui/DrawingView.cpp
Expand Up @@ -58,7 +58,9 @@
#include <Base/Stream.h>
#include <Base/gzstream.h>
#include <Base/PyObjectBase.h>
#include <App/Document.h>
#include <Gui/Document.h>
#include <Gui/ViewProvider.h>
#include <Gui/FileDialog.h>
#include <Gui/WaitCursor.h>

Expand Down Expand Up @@ -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()) {
Expand All @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/Mod/Drawing/Gui/DrawingView.h
Expand Up @@ -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());
Expand All @@ -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;
Expand All @@ -108,6 +111,7 @@ public Q_SLOTS:
QAction *m_outlineAction;

SvgView *m_view;
std::string m_objectName;

QString m_currentPath;
};
Expand Down
46 changes: 35 additions & 11 deletions src/Mod/Drawing/Gui/ViewProviderPage.cpp
Expand Up @@ -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()
Expand All @@ -91,17 +95,40 @@ std::vector<std::string> 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) {
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}

Expand Down
4 changes: 4 additions & 0 deletions src/Mod/Drawing/Gui/ViewProviderPage.h
Expand Up @@ -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<std::string> 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);
Expand Down

0 comments on commit 3614a08

Please sign in to comment.