From: asl Date: Thu, 7 Jul 2005 08:49:12 +0000 (+0000) Subject: Now the module stores operations in map and can to start operation by id X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c1955cf30cfa70dcbca3e21de5a64192fe031894;p=modules%2Fgui.git Now the module stores operations in map and can to start operation by id --- diff --git a/src/SalomeApp/SalomeApp_Module.cxx b/src/SalomeApp/SalomeApp_Module.cxx index caa39a156..c1728e3f4 100644 --- a/src/SalomeApp/SalomeApp_Module.cxx +++ b/src/SalomeApp/SalomeApp_Module.cxx @@ -10,6 +10,7 @@ #include "SalomeApp_Application.h" #include "SalomeApp_Preferences.h" #include "SalomeApp_UpdateFlags.h" +#include "SalomeApp_Operation.h" #include @@ -217,19 +218,49 @@ void SalomeApp_Module::updateControls() { } +void SalomeApp_Module::startOperation( const int id ) +{ + SalomeApp_Operation* op = 0; + if( myOperations.contains( id ) ) + op = myOperations[ id ]; + else + { + op = createOperation( id ); + if( op ) + { + myOperations.insert( id, op ); + op->setModule( this ); + connect( op, SIGNAL( stopped( SUIT_Operation* ) ), this, SLOT( onOperationStopped( SUIT_Operation* ) ) ); + connect( op, SIGNAL( destroyed() ), this, SLOT( onOperationDestroyed() ) ); + } + } + if( op ) + op->start(); +} +SalomeApp_Operation* SalomeApp_Module::createOperation( const int ) const +{ + return 0; +} +void SalomeApp_Module::onOperationStopped( SUIT_Operation* ) +{ +} - - - - - - - - - - - - +void SalomeApp_Module::onOperationDestroyed() +{ + const QObject* s = sender(); + if( s && s->inherits( "SalomeApp_Operation" ) ) + { + const SalomeApp_Operation* op = ( SalomeApp_Operation* )s; + MapOfOperation::const_iterator anIt = myOperations.begin(), + aLast = myOperations.end(); + for( ; anIt!=aLast; anIt++ ) + if( anIt.data()==op ) + { + myOperations.remove( anIt.key() ); + break; + } + } +} diff --git a/src/SalomeApp/SalomeApp_Module.h b/src/SalomeApp/SalomeApp_Module.h index 4ae6bea4c..abbce5b97 100644 --- a/src/SalomeApp/SalomeApp_Module.h +++ b/src/SalomeApp/SalomeApp_Module.h @@ -28,6 +28,7 @@ class SalomeApp_DataModel; class SalomeApp_Application; class SalomeApp_Preferences; class SalomeApp_SelectionManager; +class SalomeApp_Operation; /* Class : SalomeApp_Module @@ -86,6 +87,8 @@ protected slots: virtual void onModelSaved(); virtual void onModelOpened(); virtual void onModelClosed(); + virtual void onOperationStopped( SUIT_Operation* ); + virtual void onOperationDestroyed(); protected: QtxPopupMgr* popupMgr(); @@ -95,6 +98,17 @@ protected: virtual SalomeApp_Selection* createSelection() const; virtual void updateControls(); + /*! Module stores operations in map. This method starts operation by id. + * If operation isn't in map, then it will be created by createOperation method + * and will be inserted to map + */ + void startOperation( const int ); + + /*! Create operation by its id. You must not call this method, it will be called automatically + * by startOperation. Please redefine this method in current module + */ + virtual SalomeApp_Operation* createOperation( const int ) const; + int addPreference( const QString& label ); int addPreference( const QString& label, const int pId, const int = -1, const QString& section = QString::null, @@ -103,7 +117,11 @@ protected: void setPreferenceProperty( const int, const QString&, const QVariant& ); private: - QtxPopupMgr* myPopupMgr; + typedef QMap MapOfOperation; + +private: + QtxPopupMgr* myPopupMgr; + MapOfOperation myOperations; }; #endif