From: vsr Date: Mon, 14 Apr 2014 06:58:30 +0000 (+0400) Subject: Process properly visibility state (eye icon) for 'light' modules X-Git-Tag: V7_4_0b1^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=5aaafc7f5aedb15fa641c436917c1b2915b7471b;p=modules%2Fgui.git Process properly visibility state (eye icon) for 'light' modules --- diff --git a/src/LightApp/LightApp_Application.cxx b/src/LightApp/LightApp_Application.cxx index 6038e048e..15c0e9aa4 100644 --- a/src/LightApp/LightApp_Application.cxx +++ b/src/LightApp/LightApp_Application.cxx @@ -43,6 +43,7 @@ #include "LightApp_Module.h" #include "LightApp_DataModel.h" #include "LightApp_DataOwner.h" +#include "LightApp_Displayer.h" #include "LightApp_Study.h" #include "LightApp_Preferences.h" #include "LightApp_PreferencesDlg.h" @@ -378,6 +379,11 @@ LightApp_Application::LightApp_Application() #endif connect( mySelMgr, SIGNAL( selectionChanged() ), this, SLOT( onSelection() ) ); + connect( desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ), + this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ), Qt::UniqueConnection ); + connect( this, SIGNAL( viewManagerRemoved( SUIT_ViewManager* ) ), + this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ), Qt::UniqueConnection ); + // Set existing font for the python console in resources if( !aResMgr->hasValue( "PyConsole", "font" ) ) @@ -1688,6 +1694,11 @@ void LightApp_Application::onStudySaved( SUIT_Study* s ) /*!Protected SLOT. On study closed.*/ void LightApp_Application::onStudyClosed( SUIT_Study* s ) { + /* + disconnect( this, SIGNAL( viewManagerRemoved( SUIT_ViewManager* ) ), + this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ) ); + */ + // stop auto-save timer myAutoSaveTimer->stop(); @@ -3586,6 +3597,8 @@ void LightApp_Application::setDesktop( SUIT_Desktop* desk ) if ( desk ) { connect( desk, SIGNAL( message( const QString& ) ), this, SLOT( onDesktopMessage( const QString& ) ), Qt::UniqueConnection ); + connect( desk, SIGNAL( windowActivated( SUIT_ViewWindow* ) ), + this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ), Qt::UniqueConnection ); } } @@ -4335,3 +4348,73 @@ void LightApp_Application::emitOperationFinished( const QString& theModuleName, { emit operationFinished( theModuleName, theOperationName, theEntryList ); } + +/*! + Update visibility state of given objects +*/ +void LightApp_Application::updateVisibilityState( DataObjectList& theList, + SUIT_ViewModel* theViewModel ) +{ + if ( !theViewModel || theList.isEmpty() ) return; + + LightApp_Study* aStudy = dynamic_cast(activeStudy()); + if ( !aStudy ) return; + + SALOME_View* aView = dynamic_cast( theViewModel ); + + for ( DataObjectList::iterator itr = theList.begin(); itr != theList.end(); ++itr ) { + LightApp_DataObject* obj = dynamic_cast(*itr); + + if ( !obj || aStudy->isComponent( obj->entry() ) ) + continue; + + LightApp_Module* anObjModule = dynamic_cast(obj->module()); + if ( anObjModule ) { + LightApp_Displayer* aDisplayer = anObjModule->displayer(); + if ( aDisplayer ) { + Qtx::VisibilityState anObjState = Qtx::UnpresentableState; + if ( aDisplayer->canBeDisplayed( obj->entry(), theViewModel->getType() ) ) { + if ( aView && aDisplayer->IsDisplayed( obj->entry(), aView ) ) + anObjState = Qtx::ShownState; + else + anObjState = Qtx::HiddenState; + } + aStudy->setVisibilityState( obj->entry(), anObjState ); + } + } + } +} + +/*! + * Called when window activated + */ +void LightApp_Application::onWindowActivated( SUIT_ViewWindow* theViewWindow ) +{ + SUIT_DataBrowser* anOB = objectBrowser(); + if ( !anOB ) + return; + SUIT_DataObject* rootObj = anOB->root(); + if ( !rootObj ) + return; + + DataObjectList listObj = rootObj->children( true ); + + SUIT_ViewModel* vmod = 0; + if ( SUIT_ViewManager* vman = theViewWindow->getViewManager() ) + vmod = vman->getViewModel(); + updateVisibilityState( listObj, vmod ); +} + +/*! + Called then view manager removed +*/ +void LightApp_Application::onViewManagerRemoved( SUIT_ViewManager* ) +{ + ViewManagerList lst; + viewManagers( lst ); + if ( lst.count() == 1) { // in case if closed last view window + LightApp_Study* aStudy = dynamic_cast( activeStudy() ); + if ( aStudy ) + aStudy->setVisibilityStateForAll( Qtx::UnpresentableState ); + } +} diff --git a/src/LightApp/LightApp_Application.h b/src/LightApp/LightApp_Application.h index f017b06e3..1fcef083d 100644 --- a/src/LightApp/LightApp_Application.h +++ b/src/LightApp/LightApp_Application.h @@ -33,6 +33,7 @@ #include "LightApp.h" #include +#include #include #include @@ -50,6 +51,7 @@ class LightApp_DataObject; class SUIT_DataBrowser; class SUIT_Study; class SUIT_Accel; +class SUIT_ViewModel; class CAM_Module; class QString; @@ -174,6 +176,9 @@ public: void emitOperationFinished( const QString&, const QString&, const QStringList& ); + void updateVisibilityState( DataObjectList& theList, + SUIT_ViewModel* theViewModel ); + signals: void studyOpened(); void studySaved(); @@ -223,15 +228,17 @@ protected: protected slots: virtual void onDesktopActivated(); + virtual void onViewManagerRemoved( SUIT_ViewManager* ); + virtual void onWindowActivated( SUIT_ViewWindow* theViewWindow ); void onNewWindow(); void onModuleActivation( const QString& ); void onCloseView( SUIT_ViewManager* ); - void onStudyCreated( SUIT_Study* ); - void onStudyOpened( SUIT_Study* ); - void onStudySaved( SUIT_Study* ); - void onStudyClosed( SUIT_Study* ); + virtual void onStudyCreated( SUIT_Study* ); + virtual void onStudyOpened( SUIT_Study* ); + virtual void onStudySaved( SUIT_Study* ); + virtual void onStudyClosed( SUIT_Study* ); void onWCDestroyed( QObject* ); diff --git a/src/LightApp/LightApp_Module.cxx b/src/LightApp/LightApp_Module.cxx index 41e803fab..2127f0208 100644 --- a/src/LightApp/LightApp_Module.cxx +++ b/src/LightApp/LightApp_Module.cxx @@ -49,6 +49,7 @@ #include #include #include +#include #ifndef DISABLE_SALOMEOBJECT #include @@ -104,7 +105,8 @@ LightApp_Module::LightApp_Module( const QString& name ) myDisplay( -1 ), myErase( -1 ), myDisplayOnly( -1 ), - myEraseAll( -1 ) + myEraseAll( -1 ), + myIsFirstActivate( true ) { } @@ -243,6 +245,12 @@ bool LightApp_Module::activateModule( SUIT_Study* study ) m->registerColumn( getApp()->objectBrowser(), EntryCol, LightApp_DataObject::EntryId ); treeModel->setAppropriate( EntryCol, Qtx::Toggled ); }*/ + + if ( myIsFirstActivate ) { + updateModuleVisibilityState(); + myIsFirstActivate = false; + } + return res; } @@ -285,6 +293,22 @@ bool LightApp_Module::deactivateModule( SUIT_Study* study ) return CAM_Module::deactivateModule( study ); } +/*! Redefined to reset internal flags valid for study instance */ +void LightApp_Module::studyClosed( SUIT_Study* theStudy ) +{ + CAM_Module::studyClosed( theStudy ); + + myIsFirstActivate = true; + + LightApp_Application* app = dynamic_cast(application()); + if ( app ) { + SUIT_DataBrowser* ob = app->objectBrowser(); + if ( ob && ob->model() ) + disconnect( ob->model(), SIGNAL( clicked( SUIT_DataObject*, int ) ), + this, SLOT( onObjectClicked( SUIT_DataObject*, int ) ) ); + } +} + /*!NOT IMPLEMENTED*/ void LightApp_Module::MenuItem() { @@ -756,3 +780,61 @@ bool LightApp_Module::renameObject( const QString& /*entry*/, const QString& /*n { return false; } + +/*! + Update visibility state for data objects +*/ +void LightApp_Module::updateModuleVisibilityState() +{ + // update visibility state of objects + LightApp_Application* app = dynamic_cast(SUIT_Session::session()->activeApplication()); + if ( !app ) return; + + SUIT_DataBrowser* ob = app->objectBrowser(); + if ( !ob || !ob->model() ) return; + + // connect to click on item + connect( ob->model(), SIGNAL( clicked( SUIT_DataObject*, int ) ), + this, SLOT( onObjectClicked( SUIT_DataObject*, int ) ), Qt::UniqueConnection ); + + SUIT_DataObject* rootObj = ob->root(); + if ( !rootObj ) return; + + DataObjectList listObj = rootObj->children( true ); + + SUIT_ViewModel* vmod = 0; + if ( SUIT_ViewManager* vman = app->activeViewManager() ) + vmod = vman->getViewModel(); + app->updateVisibilityState( listObj, vmod ); +} + +/*! + * \brief Virtual public slot + * + * This method is called after the object inserted into data view to update their visibility state + * This is default implementation + */ +void LightApp_Module::onObjectClicked( SUIT_DataObject* theObject, int theColumn ) +{ + if ( !isActiveModule() ) return; + + // change visibility of object + if ( !theObject || theColumn != SUIT_DataObject::VisibilityId ) return; + + LightApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); + if ( !study ) return; + + LightApp_DataObject* lo = dynamic_cast( theObject ); + if ( !lo ) return; + + // detect action index (from LightApp level) + int id = -1; + + if ( study->visibilityState( lo->entry() ) == Qtx::ShownState ) + id = myErase; + else if ( study->visibilityState( lo->entry() ) == Qtx::HiddenState ) + id = myDisplay; + + if ( id != -1 ) + startOperation( id ); +} diff --git a/src/LightApp/LightApp_Module.h b/src/LightApp/LightApp_Module.h index 49729b95e..6572aef1d 100644 --- a/src/LightApp/LightApp_Module.h +++ b/src/LightApp/LightApp_Module.h @@ -106,9 +106,13 @@ public: virtual bool renameAllowed( const QString& ) const; virtual bool renameObject( const QString&, const QString& ); + virtual void updateModuleVisibilityState(); + public slots: virtual bool activateModule( SUIT_Study* ); virtual bool deactivateModule( SUIT_Study* ); + virtual void studyClosed( SUIT_Study* ); + virtual void onObjectClicked( SUIT_DataObject*, int ); void MenuItem(); @@ -165,6 +169,7 @@ private: protected: int myDisplay, myErase, myDisplayOnly, myEraseAll; + bool myIsFirstActivate; }; #ifdef WIN32 diff --git a/src/SUIT/SUIT_TreeModel.cxx b/src/SUIT/SUIT_TreeModel.cxx index 5fcd23c17..6ac1d67b3 100755 --- a/src/SUIT/SUIT_TreeModel.cxx +++ b/src/SUIT/SUIT_TreeModel.cxx @@ -711,34 +711,8 @@ void SUIT_TreeModel::setVisibilityState( const QString& id, Qtx::VisibilityState */ void SUIT_TreeModel::setVisibilityStateForAll( Qtx::VisibilityState state ) { - if ( state != Qtx::UnpresentableState ) { - VisibilityMap::ConstIterator it = myVisibilityMap.begin(); - while ( it != myVisibilityMap.end() ) { - if ( it.value() != state ) - setVisibilityState( it.key(), state ); - it++; - } - } - else { - QList anIds = myVisibilityMap.keys(); - myVisibilityMap.clear(); - QList::ConstIterator it = anIds.begin(); - while ( it != anIds.end() ) { - QModelIndexList lst; - if ( searcher() ) { - SUIT_DataObject* o = searcher()->findObject( *it ); - if ( o ) lst << index( o ); - } - else { - lst = match( index( 0, root()->customData( Qtx::IdType ).toInt() ), DisplayRole, (*it), 1, Qt::MatchExactly | Qt::MatchRecursive ); - } - if ( !lst.isEmpty() ) { - QModelIndex idx = index( lst.first().row(), SUIT_DataObject::VisibilityId ,lst.first().parent() ); - emit dataChanged( idx, idx ); - } - it++; - } - } + foreach( QString id, myVisibilityMap.keys() ) + setVisibilityState( id, state ); } /*! diff --git a/src/SalomeApp/SalomeApp_Application.cxx b/src/SalomeApp/SalomeApp_Application.cxx index 2dfa32ca9..0ae89d09d 100644 --- a/src/SalomeApp/SalomeApp_Application.cxx +++ b/src/SalomeApp/SalomeApp_Application.cxx @@ -54,7 +54,6 @@ #include #include #include -#include #include @@ -165,8 +164,6 @@ extern "C" SALOMEAPP_EXPORT SUIT_Application* createApplication() SalomeApp_Application::SalomeApp_Application() : LightApp_Application() { - connect( desktop(), SIGNAL( windowActivated( SUIT_ViewWindow* ) ), - this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ), Qt::UniqueConnection ); connect( desktop(), SIGNAL( message( const QString& ) ), this, SLOT( onLoadDocMessage( const QString& ) ), Qt::UniqueConnection ); myIsSiman = false; // default @@ -396,8 +393,6 @@ void SalomeApp_Application::setDesktop( SUIT_Desktop* desk ) LightApp_Application::setDesktop( desk ); if ( desk ) { - connect( desk, SIGNAL( windowActivated( SUIT_ViewWindow* ) ), - this, SLOT( onWindowActivated( SUIT_ViewWindow* ) ), Qt::UniqueConnection ); connect( desk, SIGNAL( message( const QString& ) ), this, SLOT( onLoadDocMessage( const QString& ) ), Qt::UniqueConnection ); } @@ -1576,25 +1571,9 @@ void SalomeApp_Application::onStudyCreated( SUIT_Study* study ) loadDockWindowsState(); - connect( this, SIGNAL( viewManagerRemoved( SUIT_ViewManager* ) ), - this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ), Qt::UniqueConnection ); - - objectBrowserColumnsVisibility(); } -/*!Called on Save study operation*/ -void SalomeApp_Application::onStudySaved( SUIT_Study* study ) -{ - LightApp_Application::onStudySaved( study ); - - // temporary commented - /*if ( objectBrowser() ) { - updateSavePointDataObjects( dynamic_cast( study ) ); - objectBrowser()->updateTree( study->root() ); - }*/ -} - /*!Called on Open study operation*/ void SalomeApp_Application::onStudyOpened( SUIT_Study* study ) { @@ -1607,9 +1586,6 @@ void SalomeApp_Application::onStudyOpened( SUIT_Study* study ) loadDockWindowsState(); - connect( this, SIGNAL( viewManagerRemoved( SUIT_ViewManager* ) ), - this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ), Qt::UniqueConnection ); - objectBrowserColumnsVisibility(); // temporary commented @@ -1842,80 +1818,6 @@ void SalomeApp_Application::onExtAction() printf("Error: Can't Invoke method %s\n", qPrintable(aDataList[1])); } -/*! - * Called when window activated - */ -void SalomeApp_Application::onWindowActivated( SUIT_ViewWindow* theViewWindow ) -{ - SUIT_DataBrowser* anOB = objectBrowser(); - if( !anOB ) - return; - SUIT_DataObject* rootObj = anOB->root(); - if( !rootObj ) - return; - - DataObjectList listObj = rootObj->children( true ); - - SUIT_ViewModel* vmod = 0; - if ( SUIT_ViewManager* vman = theViewWindow->getViewManager() ) - vmod = vman->getViewModel(); - updateVisibilityState( listObj, vmod ); -} - -/*! - Update visibility state of given objects - */ -void SalomeApp_Application::updateVisibilityState( DataObjectList& theList, - SUIT_ViewModel* theViewModel ) -{ - LightApp_Study* aStudy = dynamic_cast(activeStudy()); - - if(!theViewModel) - return; - - SALOME_View* aView = dynamic_cast( theViewModel ); - - if (theList.isEmpty() || !aStudy) - return; - - for ( DataObjectList::iterator itr = theList.begin(); itr != theList.end(); ++itr ) { - LightApp_DataObject* obj = dynamic_cast(*itr); - - if (!obj || aStudy->isComponent(obj->entry())) - continue; - - LightApp_Module* anObjModule = dynamic_cast(obj->module()); - Qtx::VisibilityState anObjState = Qtx::UnpresentableState; - - if(anObjModule) { - LightApp_Displayer* aDisplayer = anObjModule->displayer(); - if(aDisplayer) { - if( aDisplayer->canBeDisplayed(obj->entry(), theViewModel->getType()) ) { - if(aView && aDisplayer->IsDisplayed(obj->entry(),aView)) - anObjState = Qtx::ShownState; - else - anObjState = Qtx::HiddenState; - } - aStudy->setVisibilityState( obj->entry(), anObjState ); - } - } - } -} - -/*! - Called then view manager removed -*/ -void SalomeApp_Application::onViewManagerRemoved( SUIT_ViewManager* ) -{ - ViewManagerList lst; - viewManagers(lst); - if( lst.count() == 1) { // in case if closed last view window - LightApp_Study* aStudy = dynamic_cast(activeStudy()); - if(aStudy) - aStudy->setVisibilityStateForAll(Qtx::UnpresentableState); - } -} - /*! Checks that an object can be renamed. \param entry entry of the object diff --git a/src/SalomeApp/SalomeApp_Application.h b/src/SalomeApp/SalomeApp_Application.h index 88f577dcc..f38b410a4 100644 --- a/src/SalomeApp/SalomeApp_Application.h +++ b/src/SalomeApp/SalomeApp_Application.h @@ -34,8 +34,6 @@ #include "SalomeApp.h" #include -#include - #include //#include @@ -49,11 +47,9 @@ class LightApp_Preferences; class SalomeApp_Study; #ifndef DISABLE_PYCONSOLE - class SalomeApp_NoteBook; +class SalomeApp_NoteBook; #endif class SUIT_Desktop; - -class SUIT_ViewModel; class SALOME_LifeCycleCORBA; @@ -118,10 +114,6 @@ public: virtual SalomeApp_NoteBook* getNoteBook() const; #endif - //! update visibility state of objects - void updateVisibilityState( DataObjectList& theList, - SUIT_ViewModel* theViewModel ); - virtual bool renameAllowed( const QString& ) const; virtual bool renameObject( const QString&, const QString& ); @@ -148,12 +140,8 @@ public slots: protected slots: void onStudyCreated( SUIT_Study* ); - void onStudySaved( SUIT_Study* ); void onStudyOpened( SUIT_Study* ); - void onStudyClosed( SUIT_Study* ); - void onViewManagerRemoved( SUIT_ViewManager* ); - protected: virtual void createActions(); virtual SUIT_Study* createNewStudy(); @@ -198,8 +186,6 @@ private slots: void onOpenWith(); void onExtAction(); - void onWindowActivated( SUIT_ViewWindow* theViewWindow ); - private: void createExtraActions(); diff --git a/src/SalomeApp/SalomeApp_Module.cxx b/src/SalomeApp/SalomeApp_Module.cxx index 21e27eb0d..2b8fb0ae9 100644 --- a/src/SalomeApp/SalomeApp_Module.cxx +++ b/src/SalomeApp/SalomeApp_Module.cxx @@ -53,8 +53,7 @@ /*!Constructor.*/ SalomeApp_Module::SalomeApp_Module( const QString& name ) - : LightApp_Module( name ), - myIsFirstActivate( true ) + : LightApp_Module( name ) { } @@ -141,22 +140,6 @@ void SalomeApp_Module::storeVisualParameters(int savePoint) { } - -/*!Activate module.*/ -bool SalomeApp_Module::activateModule( SUIT_Study* theStudy ) -{ - bool state = LightApp_Module::activateModule( theStudy ); - - if (!myIsFirstActivate) - return state; - - updateModuleVisibilityState(); - - myIsFirstActivate = false; - - return state; -} - /*! * \brief Virtual public * @@ -166,94 +149,3 @@ bool SalomeApp_Module::activateModule( SUIT_Study* theStudy ) void SalomeApp_Module::restoreVisualParameters(int savePoint) { } - -/*! Redefined to reset internal flags valid for study instance */ -void SalomeApp_Module::studyClosed( SUIT_Study* theStudy ) -{ - LightApp_Module::studyClosed( theStudy ); - - myIsFirstActivate = true; - - LightApp_Application* app = dynamic_cast(application()); - if (!app) - return; - - SUIT_DataBrowser* ob = app->objectBrowser(); - if (ob && ob->model()) - disconnect( ob->model(), SIGNAL( clicked( SUIT_DataObject*, int ) ), - this, SLOT( onObjectClicked( SUIT_DataObject*, int ) ) ); -} - - -/*! - * \brief Virtual public slot - * - * This method is called after the object inserted into data view to update their visibility state - * This is default implementation - */ -void SalomeApp_Module::onObjectClicked( SUIT_DataObject* theObject, int theColumn ) -{ - if (!isActiveModule()) - return; - // change visibility of object - if (!theObject || theColumn != SUIT_DataObject::VisibilityId ) - return; - - SalomeApp_Study* study = dynamic_cast( SUIT_Session::session()->activeApplication()->activeStudy() ); - if( !study ) - return; - - LightApp_DataObject* lo = dynamic_cast(theObject); - if(!lo) - return; - - // detect action index (from LightApp level) - int id = -1; - - if ( study->visibilityState(lo->entry()) == Qtx::ShownState ) - id = myErase; - else if ( study->visibilityState(lo->entry()) == Qtx::HiddenState ) - id = myDisplay; - - if ( id != -1 ) - startOperation( id ); -} - - -/*! - Called then study closed -*/ -void SalomeApp_Application::onStudyClosed( SUIT_Study* theStudy){ - LightApp_Application::onStudyClosed(theStudy); - - disconnect( this, SIGNAL( viewManagerRemoved( SUIT_ViewManager* ) ), - this, SLOT( onViewManagerRemoved( SUIT_ViewManager* ) ) ); -} - - -void SalomeApp_Module::updateModuleVisibilityState() { - - // update visibility state of objects - SalomeApp_Application* app = dynamic_cast(SUIT_Session::session()->activeApplication()); - if (!app) - return; - - SUIT_DataBrowser* ob = app->objectBrowser(); - if (!ob || !ob->model()) - return; - - // connect to click on item - connect( ob->model(), SIGNAL( clicked( SUIT_DataObject*, int ) ), - this, SLOT( onObjectClicked( SUIT_DataObject*, int ) ), Qt::UniqueConnection ); - - SUIT_DataObject* rootObj = ob->root(); - if( !rootObj ) - return; - - DataObjectList listObj = rootObj->children( true ); - - SUIT_ViewModel* vmod = 0; - if ( SUIT_ViewManager* vman = app->activeViewManager() ) - vmod = vman->getViewModel(); - app->updateVisibilityState( listObj, vmod ); -} diff --git a/src/SalomeApp/SalomeApp_Module.h b/src/SalomeApp/SalomeApp_Module.h index d9c0852b2..2f4c7feea 100644 --- a/src/SalomeApp/SalomeApp_Module.h +++ b/src/SalomeApp/SalomeApp_Module.h @@ -64,20 +64,9 @@ public: virtual void restoreVisualParameters(int savePoint); virtual LightApp_Selection* createSelection() const; - public slots: - virtual bool activateModule( SUIT_Study* ); - virtual void studyClosed( SUIT_Study* ); - virtual void onObjectClicked( SUIT_DataObject*, int ); - - virtual void updateModuleVisibilityState(); - protected: virtual CAM_DataModel* createDataModel(); virtual void extractContainers( const SALOME_ListIO&, SALOME_ListIO& ) const; - - - protected: - bool myIsFirstActivate; }; #endif