From c6b8ca4137b966ea0b1e5a80b7d84a742a8ebc4d Mon Sep 17 00:00:00 2001 From: san Date: Mon, 8 Dec 2008 16:39:24 +0000 Subject: [PATCH] SHow/hide ParaView view manager Close a study and create a new one --- src/PVGUI/PVGUI_Module.cxx | 62 ++++++++++++++++++++-------------- src/PVGUI/PVGUI_Module_impl.h | 11 +----- src/PVGUI/PVGUI_ViewWindow.cxx | 24 ++++++------- src/PVGUI/PVGUI_ViewWindow.h | 3 -- 4 files changed, 47 insertions(+), 53 deletions(-) diff --git a/src/PVGUI/PVGUI_Module.cxx b/src/PVGUI/PVGUI_Module.cxx index c06baf2a..28cc1c4a 100644 --- a/src/PVGUI/PVGUI_Module.cxx +++ b/src/PVGUI/PVGUI_Module.cxx @@ -182,8 +182,27 @@ void PVGUI_Module::initialize( CAM_Application* app ) } */ + // Initialize ParaView client pvInit(); + // Create GUI elements (menus, toolbars, dock widgets) + if ( !Implementation ){ + LightApp_Application* anApp = getApp(); + + // Simulate ParaView client main window + Implementation = new pqImplementation( anApp->desktop() ); + + setupDockWidgets(); + + pvCreateActions(); + pvCreateMenus(); + pvCreateToolBars(); + + setupDockWidgetsContextMenu(); + + // Now that we're ready, initialize everything ... + Implementation->Core.initializeStates(); + } } /*! @@ -224,6 +243,7 @@ bool PVGUI_Module::pvInit() { if ( !pqImplementation::myPVMain ){ // Obtain command-line arguments + // Workaround to avoid pqOptions messages: pass only the executable path to vtkPVMain int argc = 0; QStringList args = QApplication::arguments(); char** argv = new char*[args.size()]; @@ -276,36 +296,22 @@ void PVGUI_Module::pvShutdown() */ void PVGUI_Module::showView( bool toShow ) { - // TODO: check if ParaView view already exists - if ( !Implementation ){ - LightApp_Application* anApp = getApp(); - SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); - PVGUI_ViewManager* viewMgr = new PVGUI_ViewManager( anApp->activeStudy(), anApp->desktop() ); + LightApp_Application* anApp = getApp(); + PVGUI_ViewManager* viewMgr = dynamic_cast( anApp->getViewManager( PVGUI_Viewer::Type(), false ) ); + if ( !viewMgr ) { + viewMgr = new PVGUI_ViewManager( anApp->activeStudy(), anApp->desktop() ); anApp->addViewManager( viewMgr ); connect( viewMgr, SIGNAL( lastViewClosed( SUIT_ViewManager* ) ), anApp, SLOT( onCloseView( SUIT_ViewManager* ) ) ); - //connect( viewMgr, SIGNAL( viewCreated( SUIT_ViewWindow* ) ), vm, SLOT( onViewCreated( SUIT_ViewWindow* ) ) ); - //connect( viewMgr, SIGNAL( deleteView( SUIT_ViewWindow* ) ), this, SLOT( onViewDeleted( SUIT_ViewWindow* ) ) ); - SUIT_ViewWindow* wnd = viewMgr->createViewWindow(); + } - // Simulate ParaView client main window - Implementation = new pqImplementation( anApp->desktop() ); - PVGUI_ViewWindow* pvWnd = dynamic_cast( wnd ); + PVGUI_ViewWindow* pvWnd = dynamic_cast( viewMgr->getActiveView() ); + if ( !pvWnd ) { + pvWnd = dynamic_cast( viewMgr->createViewWindow() ); pvWnd->setMultiViewManager( &Implementation->Core.multiViewManager() ); - - setupDockWidgets(); - - pvCreateActions(); - pvCreateMenus(); - pvCreateToolBars(); - - setupDockWidgetsContextMenu(); - - // Now that we're ready, initialize everything ... - Implementation->Core.initializeStates(); } - else - restoreDockWidgetsState(); + + pvWnd->setShown( toShow ); } /*! @@ -673,19 +679,21 @@ bool PVGUI_Module::activateModule( SUIT_Study* study ) bool isDone = LightApp_Module::activateModule( study ); if ( !isDone ) return false; + showView( true ); + if ( mySourcesMenuId != -1 ) menuMgr()->show(mySourcesMenuId); if ( myFiltersMenuId != -1 ) menuMgr()->show(myFiltersMenuId); setMenuShown( true ); setToolShown( true ); - showView( true ); - toolMgr()->toolBar(tr("TOOL_LOOKMARKS"))->installEventFilter(this); // Make default server connection if ( Implementation ) Implementation->Core.makeDefaultConnectionIfNoneExists(); + restoreDockWidgetsState(); + return isDone; } @@ -700,6 +708,8 @@ bool PVGUI_Module::deactivateModule( SUIT_Study* study ) { toolMgr()->toolBar(tr("TOOL_LOOKMARKS"))->removeEventFilter(this); + showView( false ); + // hide menus menuMgr()->hide(mySourcesMenuId); menuMgr()->hide(myFiltersMenuId); diff --git a/src/PVGUI/PVGUI_Module_impl.h b/src/PVGUI/PVGUI_Module_impl.h index 127a601a..55a01629 100644 --- a/src/PVGUI/PVGUI_Module_impl.h +++ b/src/PVGUI/PVGUI_Module_impl.h @@ -43,16 +43,12 @@ class PVGUI_Module::pqImplementation pqImplementation(QWidget* parent) : AssistantClient(0), Core(parent), - RecentFilesMenu(0)//, - //ViewMenu(0), - //ToolbarsMenu(0) + RecentFilesMenu(0) { } ~pqImplementation() { - //delete this->ViewMenu; - //delete this->ToolbarsMenu; if(this->AssistantClient) { this->AssistantClient->closeAssistant(); delete this->AssistantClient; @@ -60,13 +56,8 @@ class PVGUI_Module::pqImplementation } QPointer AssistantClient; - //Ui::MainWindow UI; pqMainWindowCore Core; pqRecentFilesMenu* RecentFilesMenu; - //pqViewMenu* ViewMenu; - //pqViewMenu* ToolbarsMenu; - //QLineEdit* CurrentTimeWidget; - //QSpinBox* CurrentTimeIndexWidget; QPointer ActiveServer; QString DocumentationDir; diff --git a/src/PVGUI/PVGUI_ViewWindow.cxx b/src/PVGUI/PVGUI_ViewWindow.cxx index 51ec369e..a8c03aaa 100644 --- a/src/PVGUI/PVGUI_ViewWindow.cxx +++ b/src/PVGUI/PVGUI_ViewWindow.cxx @@ -48,23 +48,20 @@ PVGUI_ViewWindow::PVGUI_ViewWindow( SUIT_Desktop* theDesktop, PVGUI_Viewer* theM /*! \brief Destructor. + As pqViewManager persists through the whole session, + the destructor first removes it from the children of this PVGUI_ViewWindow + to prevent its unexpected deletion. */ PVGUI_ViewWindow::~PVGUI_ViewWindow() { + if ( myPVMgr ) { + myPVMgr->setParent( 0 ); + myPVMgr->hide(); + myPVMgr = 0; + setCentralWidget( 0 ); + } } -/*! - \brief Custom event filter. - \param watched event receiver object - \param e event - \return \c true if further event processing should be stopped -*/ -bool PVGUI_ViewWindow::eventFilter( QObject* watched, QEvent* e ) -{ - return SUIT_ViewWindow::eventFilter( watched, e ); -} - - /*! \brief Get the visual parameters of the view window. \return visual parameters of this view window formatted to the string @@ -90,10 +87,9 @@ void PVGUI_ViewWindow::setMultiViewManager( pqViewManager* viewMgr ) { myPVMgr = viewMgr; myPVMgr->setParent( this ); - // This is mandatory, see setParent() documentation + // This is mandatory, see setParent() method in Qt 4 documentation myPVMgr->show(); setCentralWidget( myPVMgr ); - myPVMgr->installEventFilter( this ); } /*! diff --git a/src/PVGUI/PVGUI_ViewWindow.h b/src/PVGUI/PVGUI_ViewWindow.h index a18d5f51..df0b1af4 100644 --- a/src/PVGUI/PVGUI_ViewWindow.h +++ b/src/PVGUI/PVGUI_ViewWindow.h @@ -38,9 +38,6 @@ public: PVGUI_ViewWindow( SUIT_Desktop*, PVGUI_Viewer* ); virtual ~PVGUI_ViewWindow(); - - virtual bool eventFilter( QObject*, QEvent* ); - virtual QString getVisualParameters(); virtual void setVisualParameters( const QString& ); -- 2.39.2