1 #include "CAM_Module.h"
3 #include "CAM_DataModel.h"
4 #include "CAM_Application.h"
8 #include <QtxActionMenuMgr.h>
9 #include <QtxActionToolMgr.h>
11 static const char* ModuleIcon[] = {
18 " .................. ",
27 " .................. ",
31 " .. .. .. .. .. .. ",
33 " .. .. .. .. .. .. ",
36 QPixmap MYPixmap( ModuleIcon );
39 CAM_Module::CAM_Module()
47 /*!Constructor. initialize \a name.*/
48 CAM_Module::CAM_Module( const QString& name )
57 /*!Destructor. Remove data model.*/
58 CAM_Module::~CAM_Module()
64 /*!Initialize application.*/
65 void CAM_Module::initialize( CAM_Application* app )
70 /*!\retval Module icon.*/
71 QPixmap CAM_Module::moduleIcon() const
76 /*!\retval Module name.*/
77 QString CAM_Module::moduleName() const
82 /*! \brief Return data model.
83 * Create data model, if it was't created before.
85 CAM_DataModel* CAM_Module::dataModel() const
89 CAM_Module* that = (CAM_Module*)this;
90 that->myDataModel = that->createDataModel();
91 that->myDataModel->initialize();
96 /*!\retval CAM_Application pointer - application.*/
97 CAM_Application* CAM_Module::application() const
105 bool CAM_Module::activateModule( SUIT_Study* study )
113 bool CAM_Module::deactivateModule( SUIT_Study* )
118 /*!Public slot, remove data model from \a study.*/
119 void CAM_Module::studyClosed( SUIT_Study* study )
121 CAM_Study* camDoc = dynamic_cast<CAM_Study*>( study );
125 if ( camDoc->containsDataModel( dataModel() ) )
126 camDoc->removeDataModel( dataModel() );
129 /*!Public slot, do nothing.*/
130 void CAM_Module::studyChanged( SUIT_Study* , SUIT_Study* )
134 /*!Create and return new instance of CAM_DataModel.*/
135 CAM_DataModel* CAM_Module::createDataModel()
137 return new CAM_DataModel( this );
140 /*!Sets module name to \a name.
141 * \param name - new name for module.
143 void CAM_Module::setModuleName( const QString& name )
148 /*!Sets module icon to \a icon.
149 * \param icon - new icon for module.
151 void CAM_Module::setModuleIcon( const QPixmap& icon )
156 /*! Return menu manager pointer.
157 * \retval QtxActionMenuMgr pointer - menu manager.
159 QtxActionMenuMgr* CAM_Module::menuMgr() const
161 QtxActionMenuMgr* mgr = 0;
162 if ( application() && application()->desktop() )
163 mgr = application()->desktop()->menuMgr();
167 /*! Return tool manager pointer.
168 * \retval QtxActionToolMgr pointer - tool manager.
170 QtxActionToolMgr* CAM_Module::toolMgr() const
172 QtxActionToolMgr* mgr = 0;
173 if ( application() && application()->desktop() )
174 mgr = application()->desktop()->toolMgr();
178 /*! Create tool bar with name \a name, if it was't created before.
179 * \retval -1 - if tool manager was't be created.
181 int CAM_Module::createTool( const QString& name )
186 return toolMgr()->createToolBar( name );
190 int CAM_Module::createTool( QAction* a, const int tBar, const int id, const int idx )
195 int regId = registerAction( id, a );
196 int intId = toolMgr()->insert( a, tBar, idx );
197 return intId != -1 ? regId : -1;
200 int CAM_Module::createTool( QAction* a, const QString& tBar, const int id, const int idx )
205 int regId = registerAction( id, a );
206 int intId = toolMgr()->insert( a, tBar, idx );
207 return intId != -1 ? regId : -1;
210 int CAM_Module::createTool( const int id, const int tBar, const int idx )
215 int intId = toolMgr()->insert( action( id ), tBar, idx );
216 return intId != -1 ? id : -1;
219 int CAM_Module::createTool( const int id, const QString& tBar, const int idx )
224 int intId = toolMgr()->insert( action( id ), tBar, idx );
225 return intId != -1 ? id : -1;
228 int CAM_Module::createMenu( const QString& subMenu, const int menu,
229 const int id, const int group, const int index )
234 return menuMgr()->insert( subMenu, menu, group, index );
237 int CAM_Module::createMenu( const QString& subMenu, const QString& menu,
238 const int id, const int group, const int index )
243 return menuMgr()->insert( subMenu, menu, group, index );
246 int CAM_Module::createMenu( QAction* a, const int menu, const int id, const int group, const int index )
248 if ( !a || !menuMgr() )
251 int regId = registerAction( id, a );
252 int intId = menuMgr()->insert( a, menu, group, index );
253 return intId != -1 ? regId : -1;
256 int CAM_Module::createMenu( QAction* a, const QString& menu, const int id, const int group, const int index )
258 if ( !a || !menuMgr() )
261 int regId = registerAction( id, a );
262 int intId = menuMgr()->insert( a, menu, group, index );
263 return intId != -1 ? regId : -1;
266 int CAM_Module::createMenu( const int id, const int menu, const int group, const int index )
271 int intId = menuMgr()->insert( action( id ), menu, group, index );
272 return intId != -1 ? id : -1;
275 int CAM_Module::createMenu( const int id, const QString& menu, const int group, const int index )
280 int intId = menuMgr()->insert( action( id ), menu, group, index );
281 return intId != -1 ? id : -1;
284 /*!Sets menus shown to \a on floag.
287 void CAM_Module::setMenuShown( const bool on )
289 QtxActionMenuMgr* mMgr = menuMgr();
293 bool upd = mMgr->isUpdatesEnabled();
294 mMgr->setUpdatesEnabled( false );
296 QAction* sep = separator();
297 for ( QMap<int, QAction*>::Iterator it = myActionMap.begin(); it != myActionMap.end(); ++it )
299 if ( it.data() != sep )
300 mMgr->setShown( mMgr->actionId( it.data() ), on );
303 mMgr->setUpdatesEnabled( upd );
308 /*!Sets menu shown for QAction \a a to \a on flag.
312 void CAM_Module::setMenuShown( QAction* a, const bool on )
315 menuMgr()->setShown( menuMgr()->actionId( a ), on );
318 /*!Sets menu shown for action with id=\a id to \a on flag.
319 * \param id - id of action
322 void CAM_Module::setMenuShown( const int id, const bool on )
324 setMenuShown( action( id ), on );
327 /*!Set tools shown to \a on flag.
328 *\param on - boolean flag.
330 void CAM_Module::setToolShown( const bool on )
332 QtxActionToolMgr* tMgr = toolMgr();
336 bool upd = tMgr->isUpdatesEnabled();
337 tMgr->setUpdatesEnabled( false );
339 QAction* sep = separator();
340 for ( QMap<int, QAction*>::Iterator it = myActionMap.begin(); it != myActionMap.end(); ++it )
342 if ( it.data() != sep )
343 tMgr->setShown( tMgr->actionId( it.data() ), on );
346 tMgr->setUpdatesEnabled( upd );
351 /*!Set tools shown for QAction \a a to \a on flag.
353 * \param on - boolean flag
355 void CAM_Module::setToolShown( QAction* a, const bool on )
358 toolMgr()->setShown( toolMgr()->actionId( a ), on );
361 /*!Set tools shown for action with id=\a id to \a on flag.
362 * \param id - integer action id
363 * \param on - boolean flag
365 void CAM_Module::setToolShown( const int id, const bool on )
367 setToolShown( action( id ), on );
370 /*! Return action by id.
371 * \param id - id of action.
374 QAction* CAM_Module::action( const int id ) const
377 if ( myActionMap.contains( id ) )
382 /*! Return id by action.
383 * \param a - QAction.
384 * \retval id of action.
386 int CAM_Module::actionId( const QAction* a ) const
389 for ( QMap<int, QAction*>::ConstIterator it = myActionMap.begin(); it != myActionMap.end() && id == -1; ++it )
391 if ( it.data() == a )
397 /*! Create new instance of QtxAction and register action with \a id.
398 * \param id - id for new action.
399 * \param text - parameter for creation QtxAction
400 * \param icon - parameter for creation QtxAction
401 * \param menu - parameter for creation QtxAction
402 * \param tip - tip status for QtxAction action.
403 * \param key - parameter for creation QtxAction
404 * \param parent - parent for action
405 * \param toggle - parameter for creation QtxAction
409 QAction* CAM_Module::createAction( const int id, const QString& text, const QIconSet& icon,
410 const QString& menu, const QString& tip, const int key,
411 QObject* parent, const bool toggle, QObject* reciever, const char* member )
413 QtxAction* a = new QtxAction( text, icon, menu, key, parent, 0, toggle );
414 a->setStatusTip( tip );
416 if ( reciever && member )
417 connect( a, SIGNAL( activated() ), reciever, member );
419 registerAction( id, a );
424 /*! Register action in action map.
425 * \param id - id for action.
427 * \retval new id for action.
429 int CAM_Module::registerAction( const int id, QAction* a )
432 for ( QMap<int, QAction*>::ConstIterator it = myActionMap.begin(); it != myActionMap.end() && ident == -1; ++it )
433 if ( it.data() == a )
439 static int generatedId = -1;
440 ident = id < 0 ? --generatedId : id;
442 myActionMap.insert( ident, a );
445 menuMgr()->registerAction( a );
448 toolMgr()->registerAction( a );
453 /*! Return qt action manager separator.*/
454 QAction* CAM_Module::separator()
456 return QtxActionMgr::separator();