Skip to content

Commit

Permalink
Qt5: workaround for undocking of mdi view
Browse files Browse the repository at this point in the history
fix minor issues reported by clang static analyzer
  • Loading branch information
wwmayer committed May 3, 2017
1 parent 1a9c878 commit 378a1e4
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 10 deletions.
44 changes: 44 additions & 0 deletions src/Gui/CommandView.cpp
Expand Up @@ -1551,6 +1551,49 @@ void StdViewDockUndockFullscreen::activated(int iMsg)
MDIView* view = getMainWindow()->activeWindow();
if (!view) return; // no active view

#if defined(HAVE_QT5_OPENGL)
// nothing to do when the view is docked and 'Docked' is pressed
if (iMsg == 0 && view->currentViewMode() == MDIView::Child)
return;
// Change the view mode after an mdi view was already visible doesn't
// work well with Qt5 any more because of some strange OpenGL behaviour.
// A workaround is to clone the mdi view, set its view mode and delete
// the original view.
Gui::Document* doc = Gui::Application::Instance->activeDocument();
if (doc) {
Gui::MDIView* clone = doc->cloneView(view);
if (!clone)
return;

const char* ppReturn = 0;
if (view->onMsg("GetCamera", &ppReturn)) {
std::string sMsg = "SetCamera ";
sMsg += ppReturn;

const char** pReturnIgnore=0;
clone->onMsg(sMsg.c_str(), pReturnIgnore);
}

if (iMsg==0) {
getMainWindow()->addWindow(clone);
}
else if (iMsg==1) {
if (view->currentViewMode() == MDIView::TopLevel)
getMainWindow()->addWindow(clone);
else
clone->setCurrentViewMode(MDIView::TopLevel);
}
else if (iMsg==2) {
if (view->currentViewMode() == MDIView::FullScreen)
getMainWindow()->addWindow(clone);
else
clone->setCurrentViewMode(MDIView::FullScreen);
}

// destroy the old view
view->deleteSelf();
}
#else
if (iMsg==0) {
view->setCurrentViewMode(MDIView::Child);
}
Expand All @@ -1566,6 +1609,7 @@ void StdViewDockUndockFullscreen::activated(int iMsg)
else
view->setCurrentViewMode(MDIView::FullScreen);
}
#endif
}

bool StdViewDockUndockFullscreen::isActive(void)
Expand Down
27 changes: 27 additions & 0 deletions src/Gui/Document.cpp
Expand Up @@ -1093,6 +1093,33 @@ void Document::createView(const Base::Type& typeId)
}
}

Gui::MDIView* Document::cloneView(Gui::MDIView* oldview)
{
if (!oldview)
return 0;

if (oldview->getTypeId() == View3DInventor::getClassTypeId()) {
View3DInventor* view3D = new View3DInventor(this, getMainWindow());

// attach the viewprovider
std::map<const App::DocumentObject*,ViewProviderDocumentObject*>::const_iterator It1;
for (It1=d->_ViewProviderMap.begin();It1!=d->_ViewProviderMap.end();++It1)
view3D->getViewer()->addViewProvider(It1->second);
std::map<std::string,ViewProvider*>::const_iterator It2;
for (It2=d->_ViewProviderMapAnnotation.begin();It2!=d->_ViewProviderMapAnnotation.end();++It2)
view3D->getViewer()->addViewProvider(It2->second);

view3D->setWindowTitle(oldview->windowTitle());
view3D->setWindowModified(oldview->isWindowModified());
view3D->setWindowIcon(oldview->windowIcon());
view3D->resize(oldview->size());

return view3D;
}

return 0;
}

void Document::attachView(Gui::BaseView* pcView, bool bPassiv)
{
if (!bPassiv)
Expand Down
2 changes: 2 additions & 0 deletions src/Gui/Document.h
Expand Up @@ -162,6 +162,8 @@ class GuiExport Document : public Base::Persistence
Gui::MDIView* getViewOfNode(SoNode*) const;
/// Create a new view
void createView(const Base::Type& typeId);
/// Create a clone of the given view
Gui::MDIView* cloneView(Gui::MDIView*);
/** send messages to the active view
* Send a specific massage to the active view and is able to recive a
* return massage
Expand Down
8 changes: 4 additions & 4 deletions src/Gui/View3DInventor.cpp
Expand Up @@ -1010,10 +1010,10 @@ void View3DInventor::setCurrentViewMode(ViewMode newmode)
// Internally the QOpenGLWidget switches of the multi-sampling and there is no
// way to switch it on again. So as a workaround we just re-create a new viewport
// The method is private but defined as slot to avoid to call it by accident.
int index = _viewer->metaObject()->indexOfMethod("replaceViewport()");
if (index >= 0) {
_viewer->qt_metacall(QMetaObject::InvokeMetaMethod, index, 0);
}
//int index = _viewer->metaObject()->indexOfMethod("replaceViewport()");
//if (index >= 0) {
// _viewer->qt_metacall(QMetaObject::InvokeMetaMethod, index, 0);
//}
#endif

// This widget becomes the focus proxy of the embedded GL widget if we leave
Expand Down
2 changes: 1 addition & 1 deletion src/Mod/Image/Gui/OpenGLImageBox.cpp
Expand Up @@ -870,7 +870,7 @@ void GLImageBox::renderText(int x, int y, const QString& str, const QFont& fnt)

GLint view[4];
bool use_scissor_testing = f->glIsEnabled(GL_SCISSOR_TEST);
if (!use_scissor_testing)
//if (!use_scissor_testing)
f->glGetIntegerv(GL_VIEWPORT, &view[0]);


Expand Down
10 changes: 5 additions & 5 deletions src/Mod/Sketcher/Gui/SoDatumLabel.cpp
Expand Up @@ -337,11 +337,11 @@ void SoDatumLabel::generatePrimitives(SoAction * action)
} else if (this->datumtype.getValue() == SYMMETRIC) {

// Get the Scale. See GLRender function for details on the viewport width calculation
SoState *state = action->getState();
const SbViewVolume & vv = SoViewVolumeElement::get(state);
float scale = vv.getWorldToScreenScale(SbVec3f(0.f,0.f,0.f), 1.0f);
SbVec2s vp_size = SoViewportRegionElement::get(state).getViewportSizePixels();
scale /= float(vp_size[0]);
//SoState *state = action->getState();
//const SbViewVolume & vv = SoViewVolumeElement::get(state);
//float scale = vv.getWorldToScreenScale(SbVec3f(0.f,0.f,0.f), 1.0f);
//SbVec2s vp_size = SoViewportRegionElement::get(state).getViewportSizePixels();
//scale /= float(vp_size[0]);

SbVec3f dir = (p2-p1);
dir.normalize();
Expand Down

0 comments on commit 378a1e4

Please sign in to comment.