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 name.*/
78 QString CAM_Module::moduleName() const
83 /*! \brief Return data model.
84 * Create data model, if it was't created before.
86 CAM_DataModel* CAM_Module::dataModel() const
90 CAM_Module* that = (CAM_Module*)this;
91 that->myDataModel = that->createDataModel();
92 that->myDataModel->initialize();
97 /*!\retval CAM_Application pointer - application.*/
98 CAM_Application* CAM_Module::application() const
106 bool CAM_Module::activateModule( SUIT_Study* study )
114 bool CAM_Module::deactivateModule( SUIT_Study* )
119 /*!Public slot, remove data model from \a study.*/
120 void CAM_Module::studyClosed( SUIT_Study* study )
122 CAM_Study* camDoc = dynamic_cast<CAM_Study*>( study );
126 if ( camDoc->containsDataModel( dataModel() ) )
127 camDoc->removeDataModel( dataModel() );
130 /*!Public slot, do nothing.*/
131 void CAM_Module::studyChanged( SUIT_Study* , SUIT_Study* )
135 /*!Create and return new instance of CAM_DataModel.*/
136 CAM_DataModel* CAM_Module::createDataModel()
138 return new CAM_DataModel( this );
141 /*!Sets module name to \a name.
142 * \param name - new name for module.
144 void CAM_Module::setModuleName( const QString& name )
149 /*!Sets module icon to \a icon.
150 * \param icon - new icon for module.
152 void CAM_Module::setModuleIcon( const QPixmap& icon )
157 /*! Return menu manager pointer.
158 * \retval QtxActionMenuMgr pointer - menu manager.
160 QtxActionMenuMgr* CAM_Module::menuMgr() const
162 QtxActionMenuMgr* mgr = 0;
163 if ( application() && application()->desktop() )
164 mgr = application()->desktop()->menuMgr();
168 /*! Return tool manager pointer.
169 * \retval QtxActionToolMgr pointer - tool manager.
171 QtxActionToolMgr* CAM_Module::toolMgr() const
173 QtxActionToolMgr* mgr = 0;
174 if ( application() && application()->desktop() )
175 mgr = application()->desktop()->toolMgr();
179 /*! Create tool bar with name \a name, if it was't created before.
180 * \retval -1 - if tool manager was't be created.
182 int CAM_Module::createTool( const QString& name )
187 return toolMgr()->createToolBar( name );
190 /*! Create tool. Register action \a a with id \a id.
191 * Insert QAction to tool manager.
193 *\param tBar - integer
195 *\param idx - integer
196 *\retval integer id of new action in tool manager.
197 *\retval Return -1 if something wrong.
199 int CAM_Module::createTool( QAction* a, const int tBar, const int id, const int idx )
204 int regId = registerAction( id, a );
205 int intId = toolMgr()->insert( a, tBar, idx );
206 return intId != -1 ? regId : -1;
209 /*! Create tool. Register action \a a with id \a id.
210 * Insert QAction to tool manager.
212 *\param tBar - QString&
214 *\param idx - integer
215 *\retval integer id of new action in tool manager.
216 *\retval Return -1 if something wrong.
218 int CAM_Module::createTool( QAction* a, const QString& tBar, const int id, const int idx )
223 int regId = registerAction( id, a );
224 int intId = toolMgr()->insert( a, tBar, idx );
225 return intId != -1 ? regId : -1;
229 * Insert QAction with id \a id from action map(myActionMap) to tool manager.
231 *\param tBar - integer
233 *\param idx - integer
234 *\retval integer id of new action in tool manager.
235 *\retval Return -1 if something wrong.
237 int CAM_Module::createTool( const int id, const int tBar, const int idx )
242 int intId = toolMgr()->insert( action( id ), tBar, idx );
243 return intId != -1 ? id : -1;
247 * Insert QAction with id \a id from action map(myActionMap) to tool manager.
249 *\param tBar - QString&
251 *\param idx - integer
252 *\retval integer id of new action in tool manager.
253 *\retval Return -1 if something wrong.
255 int CAM_Module::createTool( const int id, const QString& tBar, const int idx )
260 int intId = toolMgr()->insert( action( id ), tBar, idx );
261 return intId != -1 ? id : -1;
265 * Insert submenu \a subMenu to menu manager.
266 *\param subMenu - QString&
267 *\param menu - integer
269 *\param group - integer
270 *\param index - integer
271 *\retval integer id of new menu in tool manager.
272 *\retval Return -1 if something wrong.
274 int CAM_Module::createMenu( const QString& subMenu, const int menu,
275 const int id, const int group, const int index )
280 return menuMgr()->insert( subMenu, menu, group, index );
284 * Insert submenu \a subMenu to menu manager.
285 *\param subMenu - QString&
286 *\param menu - QString&
288 *\param group - integer
289 *\param index - integer
290 *\retval integer id of new menu in tool manager.
291 *\retval Return -1 if something wrong.
293 int CAM_Module::createMenu( const QString& subMenu, const QString& menu,
294 const int id, const int group, const int index )
299 return menuMgr()->insert( subMenu, menu, group, index );
303 /*! Create menu. Register action \a a with id \a id.
304 * Insert QAction to menu manager.
306 *\param menu - integer
308 *\param group - integer
309 *\param index - integer
310 *\retval integer id of new menu in tool manager.
311 *\retval Return -1 if something wrong.
313 int CAM_Module::createMenu( QAction* a, const int menu, const int id, const int group, const int index )
315 if ( !a || !menuMgr() )
318 int regId = registerAction( id, a );
319 int intId = menuMgr()->insert( a, menu, group, index );
320 return intId != -1 ? regId : -1;
323 /*! Create menu. Register action \a a with id \a id.
324 * Insert QAction to menu manager.
326 *\param menu - QString&
328 *\param group - integer
329 *\param index - integer
330 *\retval integer id of new menu in tool manager.
331 *\retval Return -1 if something wrong.
333 int CAM_Module::createMenu( QAction* a, const QString& menu, const int id, const int group, const int index )
335 if ( !a || !menuMgr() )
338 int regId = registerAction( id, a );
339 int intId = menuMgr()->insert( a, menu, group, index );
340 return intId != -1 ? regId : -1;
344 * Insert QAction with id \a id from action map(myActionMap) to menu manager.
345 *\param menu - integer
347 *\param group - integer
348 *\param index - integer
349 *\retval integer id of new menu in tool manager.
350 *\retval Return -1 if something wrong.
352 int CAM_Module::createMenu( const int id, const int menu, const int group, const int index )
357 int intId = menuMgr()->insert( action( id ), menu, group, index );
358 return intId != -1 ? id : -1;
362 * Insert QAction with id \a id from action map(myActionMap) to menu manager.
363 *\param menu - QString&
365 *\param group - integer
366 *\param index - integer
367 *\retval integer id of new menu in tool manager.
368 *\retval Return -1 if something wrong.
370 int CAM_Module::createMenu( const int id, const QString& menu, const int group, const int index )
375 int intId = menuMgr()->insert( action( id ), menu, group, index );
376 return intId != -1 ? id : -1;
379 /*!Sets menus shown to \a on floag.
382 void CAM_Module::setMenuShown( const bool on )
384 QtxActionMenuMgr* mMgr = menuMgr();
388 bool upd = mMgr->isUpdatesEnabled();
389 mMgr->setUpdatesEnabled( false );
391 QAction* sep = separator();
392 for ( QMap<int, QAction*>::Iterator it = myActionMap.begin(); it != myActionMap.end(); ++it )
394 if ( it.data() != sep )
395 mMgr->setShown( mMgr->actionId( it.data() ), on );
398 mMgr->setUpdatesEnabled( upd );
403 /*!Sets menu shown for QAction \a a to \a on flag.
407 void CAM_Module::setMenuShown( QAction* a, const bool on )
410 menuMgr()->setShown( menuMgr()->actionId( a ), on );
413 /*!Sets menu shown for action with id=\a id to \a on flag.
414 * \param id - id of action
417 void CAM_Module::setMenuShown( const int id, const bool on )
419 setMenuShown( action( id ), on );
422 /*!Set tools shown to \a on flag.
423 *\param on - boolean flag.
425 void CAM_Module::setToolShown( const bool on )
427 QtxActionToolMgr* tMgr = toolMgr();
431 bool upd = tMgr->isUpdatesEnabled();
432 tMgr->setUpdatesEnabled( false );
434 QAction* sep = separator();
435 for ( QMap<int, QAction*>::Iterator it = myActionMap.begin(); it != myActionMap.end(); ++it )
437 if ( it.data() != sep )
438 tMgr->setShown( tMgr->actionId( it.data() ), on );
441 tMgr->setUpdatesEnabled( upd );
446 /*!Set tools shown for QAction \a a to \a on flag.
448 * \param on - boolean flag
450 void CAM_Module::setToolShown( QAction* a, const bool on )
453 toolMgr()->setShown( toolMgr()->actionId( a ), on );
456 /*!Set tools shown for action with id=\a id to \a on flag.
457 * \param id - integer action id
458 * \param on - boolean flag
460 void CAM_Module::setToolShown( const int id, const bool on )
462 setToolShown( action( id ), on );
465 /*! Return action by id.
466 * \param id - id of action.
469 QAction* CAM_Module::action( const int id ) const
472 if ( myActionMap.contains( id ) )
477 /*! Return id by action.
478 * \param a - QAction.
479 * \retval id of action.
481 int CAM_Module::actionId( const QAction* a ) const
484 for ( QMap<int, QAction*>::ConstIterator it = myActionMap.begin(); it != myActionMap.end() && id == -1; ++it )
486 if ( it.data() == a )
492 /*! Create new instance of QtxAction and register action with \a id.
493 * \param id - id for new action.
494 * \param text - parameter for creation QtxAction
495 * \param icon - parameter for creation QtxAction
496 * \param menu - parameter for creation QtxAction
497 * \param tip - tip status for QtxAction action.
498 * \param key - parameter for creation QtxAction
499 * \param parent - parent for action
500 * \param toggle - parameter for creation QtxAction
504 QAction* CAM_Module::createAction( const int id, const QString& text, const QIconSet& icon,
505 const QString& menu, const QString& tip, const int key,
506 QObject* parent, const bool toggle, QObject* reciever, const char* member )
508 QtxAction* a = new QtxAction( text, icon, menu, key, parent, 0, toggle );
509 a->setStatusTip( tip );
511 if ( reciever && member )
512 connect( a, SIGNAL( activated() ), reciever, member );
514 registerAction( id, a );
519 /*! Register action in action map.
520 * \param id - id for action.
522 * \retval new id for action.
524 int CAM_Module::registerAction( const int id, QAction* a )
527 for ( QMap<int, QAction*>::ConstIterator it = myActionMap.begin(); it != myActionMap.end() && ident == -1; ++it )
528 if ( it.data() == a )
534 static int generatedId = -1;
535 ident = id < 0 ? --generatedId : id;
537 myActionMap.insert( ident, a );
540 menuMgr()->registerAction( a );
543 toolMgr()->registerAction( a );
548 /*! Return qt action manager separator.*/
549 QAction* CAM_Module::separator()
551 return QtxActionMgr::separator();