1 #include "CAM_Module.h"
3 #include "CAM_DataModel.h"
4 #include "CAM_Application.h"
8 #include <QtxActionMenuMgr.h>
9 #include <QtxActionToolMgr.h>
12 static const char* ModuleIcon[] = {
19 " .................. ",
28 " .................. ",
32 " .. .. .. .. .. .. ",
34 " .. .. .. .. .. .. ",
37 QPixmap MYPixmap( ModuleIcon );
40 CAM_Module::CAM_Module()
48 /*!Constructor. initialize \a name.*/
49 CAM_Module::CAM_Module( const QString& name )
58 /*!Destructor. Remove data model.*/
59 CAM_Module::~CAM_Module()
65 /*!Initialize application.*/
66 void CAM_Module::initialize( CAM_Application* app )
71 /*!\retval Module icon.*/
72 QPixmap CAM_Module::moduleIcon() const
77 /*!\retval Module icon name.*/
78 QString CAM_Module::iconName() const
83 /*!\retval Module name.*/
84 QString CAM_Module::moduleName() const
89 /*! \brief Return data model.
90 * Create data model, if it was't created before.
92 CAM_DataModel* CAM_Module::dataModel() const
96 CAM_Module* that = (CAM_Module*)this;
97 that->myDataModel = that->createDataModel();
98 that->myDataModel->initialize();
103 /*!\retval CAM_Application pointer - application.*/
104 CAM_Application* CAM_Module::application() const
112 bool CAM_Module::activateModule( SUIT_Study* study )
120 bool CAM_Module::deactivateModule( SUIT_Study* )
125 /*!Public slot, remove data model from \a study.*/
126 void CAM_Module::studyClosed( SUIT_Study* study )
128 CAM_Study* camDoc = dynamic_cast<CAM_Study*>( study );
132 CAM_DataModel* dm = dataModel();
133 if ( dm && camDoc->containsDataModel( dm ) ) {
135 camDoc->removeDataModel( dm );
139 /*!Public slot, do nothing.*/
140 void CAM_Module::studyChanged( SUIT_Study* , SUIT_Study* )
144 /*!Create and return new instance of CAM_DataModel.*/
145 CAM_DataModel* CAM_Module::createDataModel()
147 return new CAM_DataModel( this );
150 /*!Sets module name to \a name.
151 * \param name - new name for module.
153 void CAM_Module::setModuleName( const QString& name )
158 /*!Sets module icon to \a icon.
159 * \param icon - new icon for module.
161 void CAM_Module::setModuleIcon( const QPixmap& icon )
166 /*! Return menu manager pointer.
167 * \retval QtxActionMenuMgr pointer - menu manager.
169 QtxActionMenuMgr* CAM_Module::menuMgr() const
171 QtxActionMenuMgr* mgr = 0;
172 if ( application() && application()->desktop() )
173 mgr = application()->desktop()->menuMgr();
177 /*! Return tool manager pointer.
178 * \retval QtxActionToolMgr pointer - tool manager.
180 QtxActionToolMgr* CAM_Module::toolMgr() const
182 QtxActionToolMgr* mgr = 0;
183 if ( application() && application()->desktop() )
184 mgr = application()->desktop()->toolMgr();
188 /*! Create tool bar with name \a name, if it was't created before.
189 * \retval -1 - if tool manager was't be created.
191 int CAM_Module::createTool( const QString& name )
196 return toolMgr()->createToolBar( name );
199 /*! Create tool. Register action \a a with id \a id.
200 * Insert QAction to tool manager.
202 *\param tBar - integer
204 *\param idx - integer
205 *\retval integer id of new action in tool manager.
206 *\retval Return -1 if something wrong.
208 int CAM_Module::createTool( QAction* a, const int tBar, const int id, const int idx )
213 int regId = registerAction( id, a );
214 int intId = toolMgr()->insert( a, tBar, idx );
215 return intId != -1 ? regId : -1;
218 /*! Create tool. Register action \a a with id \a id.
219 * Insert QAction to tool manager.
221 *\param tBar - QString&
223 *\param idx - integer
224 *\retval integer id of new action in tool manager.
225 *\retval Return -1 if something wrong.
227 int CAM_Module::createTool( QAction* a, const QString& tBar, const int id, const int idx )
232 int regId = registerAction( id, a );
233 int intId = toolMgr()->insert( a, tBar, idx );
234 return intId != -1 ? regId : -1;
238 * Insert QAction with id \a id from action map(myActionMap) to tool manager.
240 *\param tBar - integer
242 *\param idx - integer
243 *\retval integer id of new action in tool manager.
244 *\retval Return -1 if something wrong.
246 int CAM_Module::createTool( const int id, const int tBar, const int idx )
251 int intId = toolMgr()->insert( action( id ), tBar, idx );
252 return intId != -1 ? id : -1;
256 * Insert QAction with id \a id from action map(myActionMap) to tool manager.
258 *\param tBar - QString&
260 *\param idx - integer
261 *\retval integer id of new action in tool manager.
262 *\retval Return -1 if something wrong.
264 int CAM_Module::createTool( const int id, const QString& tBar, const int idx )
269 int intId = toolMgr()->insert( action( id ), tBar, idx );
270 return intId != -1 ? id : -1;
274 * Insert submenu \a subMenu to menu manager.
275 *\param subMenu - QString&
276 *\param menu - integer
278 *\param group - integer
279 *\param index - integer
280 *\retval integer id of new menu in tool manager.
281 *\retval Return -1 if something wrong.
283 int CAM_Module::createMenu( const QString& subMenu, const int menu,
284 const int id, const int group, const int index )
289 return menuMgr()->insert( subMenu, menu, group, index );
293 * Insert submenu \a subMenu to menu manager.
294 *\param subMenu - QString&
295 *\param menu - QString&
297 *\param group - integer
298 *\param index - integer
299 *\retval integer id of new menu in tool manager.
300 *\retval Return -1 if something wrong.
302 int CAM_Module::createMenu( const QString& subMenu, const QString& menu,
303 const int id, const int group, const int index )
308 return menuMgr()->insert( subMenu, menu, group, index );
312 /*! Create menu. Register action \a a with id \a id.
313 * Insert QAction to menu manager.
315 *\param menu - integer
317 *\param group - integer
318 *\param index - integer
319 *\retval integer id of new menu in tool manager.
320 *\retval Return -1 if something wrong.
322 int CAM_Module::createMenu( QAction* a, const int menu, const int id, const int group, const int index )
324 if ( !a || !menuMgr() )
327 int regId = registerAction( id, a );
328 int intId = menuMgr()->insert( a, menu, group, index );
329 return intId != -1 ? regId : -1;
332 /*! Create menu. Register action \a a with id \a id.
333 * Insert QAction to menu manager.
335 *\param menu - QString&
337 *\param group - integer
338 *\param index - integer
339 *\retval integer id of new menu in tool manager.
340 *\retval Return -1 if something wrong.
342 int CAM_Module::createMenu( QAction* a, const QString& menu, const int id, const int group, const int index )
344 if ( !a || !menuMgr() )
347 int regId = registerAction( id, a );
348 int intId = menuMgr()->insert( a, menu, group, index );
349 return intId != -1 ? regId : -1;
353 * Insert QAction with id \a id from action map(myActionMap) to menu manager.
354 *\param menu - integer
356 *\param group - integer
357 *\param index - integer
358 *\retval integer id of new menu in tool manager.
359 *\retval Return -1 if something wrong.
361 int CAM_Module::createMenu( const int id, const int menu, const int group, const int index )
366 int intId = menuMgr()->insert( action( id ), menu, group, index );
367 return intId != -1 ? id : -1;
371 * Insert QAction with id \a id from action map(myActionMap) to menu manager.
372 *\param menu - QString&
374 *\param group - integer
375 *\param index - integer
376 *\retval integer id of new menu in tool manager.
377 *\retval Return -1 if something wrong.
379 int CAM_Module::createMenu( const int id, const QString& menu, const int group, const int index )
384 int intId = menuMgr()->insert( action( id ), menu, group, index );
385 return intId != -1 ? id : -1;
388 /*!Sets menus shown to \a on floag.
391 void CAM_Module::setMenuShown( const bool on )
393 QtxActionMenuMgr* mMgr = menuMgr();
397 bool upd = mMgr->isUpdatesEnabled();
398 mMgr->setUpdatesEnabled( false );
400 QAction* sep = separator();
401 for ( QMap<int, QAction*>::Iterator it = myActionMap.begin(); it != myActionMap.end(); ++it )
403 if ( it.data() != sep )
404 mMgr->setShown( mMgr->actionId( it.data() ), on );
407 mMgr->setUpdatesEnabled( upd );
412 /*!Sets menu shown for QAction \a a to \a on flag.
416 void CAM_Module::setMenuShown( QAction* a, const bool on )
419 menuMgr()->setShown( menuMgr()->actionId( a ), on );
422 /*!Sets menu shown for action with id=\a id to \a on flag.
423 * \param id - id of action
426 void CAM_Module::setMenuShown( const int id, const bool on )
428 setMenuShown( action( id ), on );
431 /*!Set tools shown to \a on flag.
432 *\param on - boolean flag.
434 void CAM_Module::setToolShown( const bool on )
436 QtxActionToolMgr* tMgr = toolMgr();
440 bool upd = tMgr->isUpdatesEnabled();
441 tMgr->setUpdatesEnabled( false );
443 QAction* sep = separator();
444 for ( QMap<int, QAction*>::Iterator it = myActionMap.begin(); it != myActionMap.end(); ++it )
446 if ( it.data() != sep )
447 tMgr->setShown( tMgr->actionId( it.data() ), on );
450 tMgr->setUpdatesEnabled( upd );
455 /*!Set tools shown for QAction \a a to \a on flag.
457 * \param on - boolean flag
459 void CAM_Module::setToolShown( QAction* a, const bool on )
462 toolMgr()->setShown( toolMgr()->actionId( a ), on );
465 /*!Set tools shown for action with id=\a id to \a on flag.
466 * \param id - integer action id
467 * \param on - boolean flag
469 void CAM_Module::setToolShown( const int id, const bool on )
471 setToolShown( action( id ), on );
474 /*! Return action by id.
475 * \param id - id of action.
478 QAction* CAM_Module::action( const int id ) const
481 if ( myActionMap.contains( id ) )
486 /*! Return id by action.
487 * \param a - QAction.
488 * \retval id of action.
490 int CAM_Module::actionId( const QAction* a ) const
493 for ( QMap<int, QAction*>::ConstIterator it = myActionMap.begin(); it != myActionMap.end() && id == -1; ++it )
495 if ( it.data() == a )
501 /*! Create new instance of QtxAction and register action with \a id.
502 * \param id - id for new action.
503 * \param text - parameter for creation QtxAction
504 * \param icon - parameter for creation QtxAction
505 * \param menu - parameter for creation QtxAction
506 * \param tip - tip status for QtxAction action.
507 * \param key - parameter for creation QtxAction
508 * \param parent - parent for action
509 * \param toggle - parameter for creation QtxAction
513 QAction* CAM_Module::createAction( const int id, const QString& text, const QIconSet& icon,
514 const QString& menu, const QString& tip, const int key,
515 QObject* parent, const bool toggle, QObject* reciever, const char* member )
517 QtxAction* a = new QtxAction( text, icon, menu, key, parent, 0, toggle );
518 a->setStatusTip( tip );
520 if ( reciever && member )
521 connect( a, SIGNAL( activated() ), reciever, member );
523 registerAction( id, a );
528 /*! Register action in action map.
529 * \param id - id for action.
531 * \retval new id for action.
533 int CAM_Module::registerAction( const int id, QAction* a )
536 for ( QMap<int, QAction*>::ConstIterator it = myActionMap.begin(); it != myActionMap.end() && ident == -1; ++it )
537 if ( it.data() == a )
543 static int generatedId = -1;
544 ident = id < 0 ? --generatedId : id;
546 myActionMap.insert( ident, a );
549 menuMgr()->registerAction( a );
552 toolMgr()->registerAction( a );
557 /*! Return qt action manager separator.*/
558 QAction* CAM_Module::separator()
560 return QtxActionMgr::separator();
563 /*! Connect data model of module with active study */
564 void CAM_Module::connectToStudy( CAM_Study* camStudy )
566 CAM_Application* app = camStudy ? dynamic_cast<CAM_Application*>( camStudy->application() ) : 0;
570 CAM_DataModel* prev = 0;
571 for( CAM_Application::ModuleListIterator it = app->modules(); it.current(); ++it )
573 CAM_DataModel* dm = it.current()->dataModel();
574 if( it.current() == this && !camStudy->containsDataModel( dm ) )
577 camStudy->insertDataModel( it.current()->dataModel(), prev );
579 camStudy->insertDataModel( it.current()->dataModel(), 0 );