1 // Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 #include "CAM_Module.h"
25 #include "CAM_DataModel.h"
26 #include "CAM_Application.h"
27 #include "CAM_Study.h"
29 #include <QtxAction.h>
30 #include <QtxActionGroup.h>
31 #include <QtxActionMenuMgr.h>
32 #include <QtxActionToolMgr.h>
34 #include <SUIT_Desktop.h>
35 #include <SUIT_Session.h>
36 #include <SUIT_ResourceMgr.h>
42 \brief Base implementation of the module in the CAM application architecture.
44 Provides support of menu/toolbars management.
50 ActionMgrLocker( QtxActionMgr* m, bool use ) : myMgr( m ), myUseLock( use )
53 myUpdEnabled = myMgr->isUpdatesEnabled();
54 myMgr->setUpdatesEnabled( false );
60 myMgr->setUpdatesEnabled( myUpdEnabled );
71 \brief Default constructor.
73 Creates unnamed module.
75 CAM_Module::CAM_Module()
85 Creates module with the specified \a name.
87 \param name module name
89 CAM_Module::CAM_Module( const QString& name )
96 myActionLoggingEnabled( false )
105 CAM_Module::~CAM_Module()
112 \brief Initialize module.
114 This method is usually called when the module is created (for example,
115 on the module library loading).
116 Successor classes can use this method to create menu/toolbar actions
117 and perform other module initialization.
119 \param app parent application object
120 \sa activateModule(), deactivateModule()
122 void CAM_Module::initialize( CAM_Application* app )
127 SUIT_Session* aSession = SUIT_Session::session();
128 connect( aSession, SIGNAL( applicationClosed( SUIT_Application* ) ),
129 this, SLOT( onApplicationClosed( SUIT_Application* ) ) );
131 connect( myApp, SIGNAL( infoChanged( QString ) ), this, SLOT( onInfoChanged( QString ) ) );
136 \brief Get module icon.
137 \return module icon pixmap
140 QPixmap CAM_Module::moduleIcon() const
142 if ( myIcon.isNull() ) {
143 QString iname = iconName();
144 if ( !iname.isEmpty() ) {
145 CAM_Module* that = (CAM_Module*)this;
146 that->myIcon = application()->resourceMgr()->loadPixmap( name(), iname, false );
153 \brief Get module icon's name.
155 This function is used to get module icon's file name.
156 Default implementation returns empty string.
158 \return module icon's name.
161 QString CAM_Module::iconName() const
163 return application()->moduleIcon( name() );
167 \brief Get module (internal) name
169 \sa setName(), moduleName(), setModuleName()
171 QString CAM_Module::name() const
177 \brief Get module title (user name)
179 \sa setModuleName(), name(), setName()
181 QString CAM_Module::moduleName() const
187 \brief Get data model.
189 Creates data model, if it is not yet created.
191 \return data model pointer
192 \sa createDataModel()
194 CAM_DataModel* CAM_Module::dataModel() const
198 CAM_Module* that = (CAM_Module*)this;
199 that->myDataModel = that->createDataModel();
200 that->myDataModel->initialize();
206 \brief Get application.
207 \return application pointer
209 CAM_Application* CAM_Module::application() const
215 \brief If return false, selection will be cleared at module activation
217 bool CAM_Module::isSelectionCompatible()
223 \brief Activate module.
225 This method is called when the user activates module.
226 Successor classes can use this method to customize module activation process,
227 for example, to show own menus, toolbars, etc.
229 Default implementation always returns \c true.
231 \return \c true if module is activated successfully.
232 \sa initialize(), deactivateModule()
234 bool CAM_Module::activateModule( SUIT_Study* /*study*/ )
236 // IMN 05/03/2015: we copied myActionMap for reset/unset actions accelerator keys
237 // after activate/deactivate modules
238 for ( QMap<QAction*, QKeySequence>::Iterator it = myActionShortcutMap.begin(); it != myActionShortcutMap.end(); ++it )
240 // Reset actions accelerator keys
241 it.key()->setShortcut( it.value() );
243 myActionShortcutMap.clear();
248 \brief Deactivate module.
250 This method is called when the user deactivates module.
251 Successor classes can use this method to customize module deactivation process,
252 for example, to hide own menus, toolbars, etc.
254 Default implementation always returns \c true.
256 \return \c true if module is deactivated successfully.
257 \sa initialize(), activateModule()
259 bool CAM_Module::deactivateModule( SUIT_Study* )
261 // IMN 05/03/2015: we copied myActionMap for reset/unset actions accelerator keys
262 // after activate/deactivate modules
263 myActionShortcutMap.clear();
264 for ( QMap<int, QAction*>::Iterator it = myActionMap.begin(); it != myActionMap.end(); ++it )
266 myActionShortcutMap.insert( it.value(), it.value()->shortcut() );
267 it.value()->setShortcut( QKeySequence() );
273 \brief Called when study is closed.
275 Removes data model from the \a study.
277 \param study study being closed
279 void CAM_Module::studyClosed( SUIT_Study* study )
281 CAM_Study* camDoc = dynamic_cast<CAM_Study*>( study );
285 CAM_DataModel* dm = dataModel();
286 if ( dm && camDoc->containsDataModel( dm ) ) {
288 camDoc->removeDataModel( dm );
293 \brief Called when study is changed (obsolete).
295 Default implementation does nothing.
297 \param oldStudy old study
298 \param newStudy new study
300 void CAM_Module::studyChanged( SUIT_Study* /*oldStudy*/, SUIT_Study* /*newStudy*/ )
305 \brief Check if the module is active.
306 \return \c true if module is active.
308 bool CAM_Module::isActiveModule() const
310 return application() ? application()->activeModule() == this : false;
314 \brief Put the text message into the status bar of the application main window.
316 If \a msec > 0, the message will be shown \a msec milliseconds.
317 If \a msec < 0, the message will be constantly displayed until module is active.
319 \param msg text message
320 \param msec message displaying duration in milliseconds
322 void CAM_Module::putInfo( const QString& msg, const int msec )
325 application()->putInfo( msg, msec );
332 \brief Shows the notifications with spectified text, title and automatic close timeout.
333 Notification will be automatically closed after specified timeout in msec. If
334 timeout is zero then automatic closing doesn't performed.
335 \param text - Notification text
336 \param title - Notification title
337 \param timeout - Notification close timeout in msec
338 \return notification identifier
340 int CAM_Module::showNotification( const QString& message, const QString& title, int timeout )
344 res = application()->showNotification( message, title, timeout );
349 \brief Closes the notifications with spectified text.
350 \param text - Notification text
352 void CAM_Module::hideNotification( const QString& message )
355 application()->hideNotification( message );
359 \brief Closes the notifications with spectified identifier.
360 \param text - Notification text
362 void CAM_Module::hideNotification( int id )
365 application()->hideNotification( id );
369 \brief Restore message info.
371 Restores constant text message when previous information status message is removed.
373 \param txt previous message (being removed)
376 void CAM_Module::onInfoChanged( QString txt )
378 if ( txt.isEmpty() && isActiveModule() && !myInfo.isEmpty() && application() )
379 application()->putInfo( myInfo );
383 \brief Called when application is closed.
385 Nullify application pointer if the application is being closed.
387 \param theApp application
389 void CAM_Module::onApplicationClosed( SUIT_Application* theApp )
396 \brief Create data model.
397 \return created data model object or 0 if it could not be created
399 CAM_DataModel* CAM_Module::createDataModel()
401 return new CAM_DataModel( this );
405 \brief Set module (internal) name
406 \param name new module name
407 \sa name(), moduleName(), setModuleName()
409 void CAM_Module::setName( const QString& name )
411 setObjectName( name );
415 \brief Set module title (user name)
416 \param name new module title
417 \sa moduleName(), name(), setName()
419 void CAM_Module::setModuleName( const QString& name )
425 \brief Get menu manager.
426 \return menu manager pointer
428 QtxActionMenuMgr* CAM_Module::menuMgr() const
430 QtxActionMenuMgr* mgr = 0;
431 if ( application() && application()->desktop() )
432 mgr = application()->desktop()->menuMgr();
437 \brief Get toolbar manager.
438 \return toolbar manager pointer
440 QtxActionToolMgr* CAM_Module::toolMgr() const
442 QtxActionToolMgr* mgr = 0;
443 if ( application() && application()->desktop() )
444 mgr = application()->desktop()->toolMgr();
449 \brief Create toolbar with speicifed \a name.
451 If the toolbar has been already created, its ID is just returned.
453 \param title toolbar title
454 \param name toolbar name (identifier)
455 \return toolbar ID or -1 if toolbar could not be created
457 int CAM_Module::createTool( const QString& title, const QString& name )
462 ActionMgrLocker lock( toolMgr(), !myToolShown );
464 return toolMgr()->createToolBar( title, name );
468 \brief Add toolbar item.
470 Insert action \a to the toolbar manager and register it with specified \a id.
471 Resulting action ID may differ from the requested one. This can happen if
472 requested ID is already in use.
474 If action has been already added previously, its ID is just returned.
476 If \a id < 0, the action ID is generated automatically.
478 If \a idx < 0, the action is added to the end of the toolbar.
481 \param tBar toolbar ID
482 \param id requested action ID
483 \param idx action index (desired position in the toolbar)
484 \return action ID or -1 if toolbar item could not be added
486 int CAM_Module::createTool( QAction* a, const int tBar, const int id, const int idx )
491 ActionMgrLocker lock( toolMgr(), !myToolShown );
493 int regId = registerAction( id, a );
494 int intId = toolMgr()->insert( a, tBar, idx );
497 setToolShown( a, false );
499 return intId != -1 ? regId : -1;
503 \brief Add toolbar item.
505 Insert action \a to the toolbar manager and register it with specified \a id.
506 Resulting action ID may differ from the requested one. This can happen if
507 requested ID is already in use.
509 If action has been already added previously, its ID is just returned.
511 If \a id < 0, the action ID is generated automatically.
513 If \a idx < 0, the action is added to the end of the toolbar.
516 \param tBar toolbar name
517 \param id requested action ID
518 \param idx action index (desired position in the toolbar)
519 \return action ID or -1 if toolbar item could not be added
521 int CAM_Module::createTool( QAction* a, const QString& tBar, const int id, const int idx )
526 ActionMgrLocker lock( toolMgr(), !myToolShown );
528 int regId = registerAction( id, a );
529 int intId = toolMgr()->insert( a, tBar, idx );
532 setToolShown( a, false );
534 return intId != -1 ? regId : -1;
538 \brief Add toolbar item.
540 Insert action with \a id identifier to the toolbar manager.
541 It is assumed that action has been already registered.
543 Resulting action ID may differ from the requested one. This can happen if
544 requested ID is already in use.
546 If action has been already added previously, its ID is just returned.
548 If \a idx < 0, the action is added to the end of the toolbar.
551 \param tBar toolbar ID
552 \param idx action index (desired position in the toolbar)
553 \return action ID or -1 if toolbar item could not be added
555 int CAM_Module::createTool( const int id, const int tBar, const int idx )
560 ActionMgrLocker lock( toolMgr(), !myToolShown );
562 int intId = toolMgr()->insert( action( id ), tBar, idx );
565 setToolShown( action( id ), false );
567 return intId != -1 ? id : -1;
571 \brief Add toolbar item.
573 Insert action with \a id identifier to the toolbar manager.
574 It is assumed that action has been already registered.
576 Resulting action ID may differ from the requested one. This can happen if
577 requested ID is already in use.
579 If action has been already added previously, its ID is just returned.
581 If \a idx < 0, the action is added to the end of the toolbar.
584 \param tBar toolbar name
585 \param idx action index (desired position in the toolbar)
586 \return action ID or -1 if toolbar item could not be added
588 int CAM_Module::createTool( const int id, const QString& tBar, const int idx )
593 ActionMgrLocker lock( toolMgr(), !myToolShown );
595 int intId = toolMgr()->insert( action( id ), tBar, idx );
598 setToolShown( action( id ), false );
600 return intId != -1 ? id : -1;
604 Clears given toolbar.
605 \param title - title of toolbar
607 void CAM_Module::clearTool( const QString& title )
610 toolMgr()->clear( title );
614 \brief Create menu or submenu.
616 Create main menu or popup submenu and register it with specified \a id.
617 Resulting action ID may differ from the requested one. This can happen if
618 requested ID is already in use.
620 If \a id < 0, the menu ID is generated automatically.
621 If menu has been already created previously, its ID is just returned.
623 The \a menu parameter represents the menu name - it could be a sequence
624 of strings, separated by '|' symbol. For example, "File|Edit" means
625 File->Edit submenu. If menu doesn't exist, it is created automatically.
627 Parameter \a idx defines the index of the menu item in the menu group which
628 is defined by the \a group. If \a idx < 0, the menu/submenu is added to the
629 end of the menu group.
631 \param subMenu subMenu name
632 \param menu parent menu ID
633 \param id requested menu ID
634 \param group menu group ID
635 \param idx menu item index (desired position in the menu group)
636 \return menu item ID or -1 if menu item could not be added
638 int CAM_Module::createMenu( const QString& subMenu, const int menu,
639 const int id, const int group, const int idx, QMenu * menuObj )
644 return menuMgr()->insert( subMenu, menu, group, id, idx, menuObj );
648 \brief Create menu or submenu.
650 Create main menu or popup submenu and register it with specified \a id.
651 Resulting action ID may differ from the requested one. This can happen if
652 requested ID is already in use.
654 If \a id < 0, the menu ID is generated automatically.
655 If menu has been already created previously, its ID is just returned.
657 The \a menu parameter represents the menu name - it could be a sequence
658 of strings, separated by '|' symbol. For example, "File|Edit" means
659 File->Edit submenu. If menu doesn't exist, it is created automatically.
661 Parameter \a idx defines the index of the menu item in the menu group which
662 is defined by the \a group. If \a idx < 0, the menu/submenu is added to the
663 end of the menu group.
665 \param subMenu subMenu name
666 \param menu parent menu name(s)
667 \param id requested menu ID
668 \param group menu group ID
669 \param idx menu item index (desired position in the menu group)
670 \return menu item ID or -1 if menu item could not be added
672 int CAM_Module::createMenu( const QString& subMenu, const QString& menu,
673 const int id, const int group, const int idx )
678 return menuMgr()->insert( subMenu, menu, group, id, idx );
682 \brief Add menu item.
684 Insert action \a to the menu manager and register it with specified \a id.
685 Resulting action ID may differ from the requested one. This can happen if
686 requested ID is already in use.
688 If \a id < 0, the action ID is generated automatically.
690 If action has been already added previously, its ID is just returned.
692 Parameter \a idx defines the index of the menu item in the menu group which
693 is defined by the \a group. If \a idx < 0, the action is added to the
694 end of the menu group.
698 \param id requested action ID
699 \param group menu group ID
700 \param idx action index (desired position in the menu group)
701 \return action ID or -1 if menu item could not be added
703 int CAM_Module::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
705 if ( !a || !menuMgr() )
708 ActionMgrLocker lock( menuMgr(), !myMenuShown );
710 int regId = registerAction( id, a );
711 int intId = menuMgr()->insert( a, menu, group, idx );
714 setMenuShown( a, false );
716 return intId != -1 ? regId : -1;
720 \brief Add menu item.
722 Insert action \a to the menu manager and register it with specified \a id.
723 Resulting action ID may differ from the requested one. This can happen if
724 requested ID is already in use.
726 If \a id < 0, the action ID is generated automatically.
728 If action has been already added previously, its ID is just returned.
730 The \a menu parameter represents the menu name - it could be a sequence
731 of strings, separated by '|' symbol. For example, "File|Edit" means
732 File->Edit submenu. If menu doesn't exist, it is created automatically.
734 Parameter \a idx defines the index of the menu item in the menu group which
735 is defined by the \a group. If \a idx < 0, the action is added to the
736 end of the menu group.
739 \param menu menu name(s)
740 \param id requested action ID
741 \param group menu group ID
742 \param idx action index (desired position in the menu group)
743 \return action ID or -1 if menu item could not be added
745 int CAM_Module::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
747 if ( !a || !menuMgr() )
750 ActionMgrLocker lock( menuMgr(), !myMenuShown );
752 int regId = registerAction( id, a );
753 int intId = menuMgr()->insert( a, menu, group, idx );
756 setMenuShown( a, false );
758 return intId != -1 ? regId : -1;
762 \brief Add menu item.
764 Insert action with \a id identifier to the menu manager.
765 It is assumed that action has been already registered.
767 Resulting action ID may differ from the requested one. This can happen if
768 requested ID is already in use.
770 If action has been already added previously, its ID is just returned.
772 Parameter \a idx defines the index of the menu item in the menu group which
773 is defined by the \a group. If \a idx < 0, the action is added to the
774 end of the menu group.
778 \param group menu group ID
779 \param idx action index (desired position in the menu group)
780 \return action ID or -1 if menu item could not be added
782 int CAM_Module::createMenu( const int id, const int menu, const int group, const int idx )
787 ActionMgrLocker lock( menuMgr(), !myMenuShown );
789 int intId = menuMgr()->insert( action( id ), menu, group, idx );
792 setMenuShown( action( id ), false );
794 return intId != -1 ? id : -1;
798 \brief Add menu item.
800 Insert action with \a id identifier to the menu manager.
801 It is assumed that action has been already registered.
803 Resulting action ID may differ from the requested one. This can happen if
804 requested ID is already in use.
806 If action has been already added previously, its ID is just returned.
808 The \a menu parameter represents the menu name - it could be a sequence
809 of strings, separated by '|' symbol. For example, "File|Edit" means
810 File->Edit submenu. If menu doesn't exist, it is created automatically.
812 Parameter \a idx defines the index of the menu item in the menu group which
813 is defined by the \a group. If \a idx < 0, the action is added to the
814 end of the menu group.
817 \param menu menu name(s)
818 \param group menu group ID
819 \param idx action index (desired position in the menu group)
820 \return action ID or -1 if menu item could not be added
822 int CAM_Module::createMenu( const int id, const QString& menu, const int group, const int idx )
827 ActionMgrLocker lock( menuMgr(), !myMenuShown );
829 int intId = menuMgr()->insert( action( id ), menu, group, idx );
832 setMenuShown( action( id ), false );
834 return intId != -1 ? id : -1;
838 \brief Show/hide all module's menus.
839 \param on if \c true, show menus, otherwise, hide all menus
842 void CAM_Module::setMenuShown( const bool on )
846 QtxActionMenuMgr* mMgr = menuMgr();
850 bool upd = mMgr->isUpdatesEnabled();
851 mMgr->setUpdatesEnabled( false );
853 QAction* sep = separator();
854 for ( QMap<int, QAction*>::Iterator it = myActionMap.begin(); it != myActionMap.end(); ++it )
856 if ( it.value() != sep )
857 mMgr->setShown( mMgr->actionId( it.value() ), on );
860 mMgr->setUpdatesEnabled( upd );
866 \brief Show/hide specified menu item.
868 \param on if \c true, show menu item, otherwise, hide it
870 void CAM_Module::setMenuShown( QAction* a, const bool on )
873 menuMgr()->setShown( menuMgr()->actionId( a ), on );
877 \brief Show/hide specified menu item.
878 \param id menu item ID
879 \param on if \c true, show menu item, otherwise, hide it
881 void CAM_Module::setMenuShown( const int id, const bool on )
883 setMenuShown( action( id ), on );
887 \brief Show/hide all module's toolbars.
888 \param on if \c true, show toolbars, otherwise, hide all toolbars
891 void CAM_Module::setToolShown( const bool on )
895 QtxActionToolMgr* tMgr = toolMgr();
899 bool upd = tMgr->isUpdatesEnabled();
900 tMgr->setUpdatesEnabled( false );
902 QAction* sep = separator();
903 for ( QMap<int, QAction*>::Iterator it = myActionMap.begin(); it != myActionMap.end(); ++it )
905 if ( it.value() != sep )
906 tMgr->setShown( tMgr->actionId( it.value() ), on );
909 tMgr->setUpdatesEnabled( upd );
915 \brief Show/hide specified toolbar item.
917 \param on if \c true, show toolbar item, otherwise, hide it
919 void CAM_Module::setToolShown( QAction* a, const bool on )
922 toolMgr()->setShown( toolMgr()->actionId( a ), on );
926 \brief Show/hide specified toolbar item.
927 \param id toolbar item ID
928 \param on if \c true, show toolbar item, otherwise, hide it
930 void CAM_Module::setToolShown( const int id, const bool on )
932 setToolShown( action( id ), on );
936 \brief Get action by specified \a id.
938 \return action or 0 if not found
940 QAction* CAM_Module::action( const int id ) const
943 if ( myActionMap.contains( id ) )
945 else if ( menuMgr() ) {
946 QMenu* m = menuMgr()->findMenu( id );
947 if ( m ) a = m->menuAction();
953 \brief Get action ID.
955 \return action ID or -1 if not found
957 int CAM_Module::actionId( const QAction* a ) const
960 for ( QMap<int, QAction*>::ConstIterator it = myActionMap.begin(); it != myActionMap.end() && id == -1; ++it )
962 if ( it.value() == a )
969 \brief Create new instance of QtxAction and register action with specified \a id.
971 Resulting action ID may differ from the requested one. This can happen if
972 requested ID is already in use.
974 If \a id < 0, the action ID is generated automatically.
976 \param id required action ID
977 \param text tooltip text
978 \param icon action icon
979 \param menu menu text
980 \param tip status bar tip
981 \param key keyboard accelerator
982 \param parent parent object
983 \param toggle if \c true, the action will be toggled
984 \param reciever action activation signal receiver object
985 \param member action activation signal receiver slot
987 QAction* CAM_Module::createAction( const int id, const QString& text, const QIcon& icon,
988 const QString& menu, const QString& tip, const int key,
989 QObject* parent, const bool toggle, QObject* reciever,
990 const char* member, const QString& shortcutAction )
992 return createAction( id, text, icon, menu, tip, QKeySequence(key), parent, toggle, reciever, member, shortcutAction );
996 \brief Create new instance of QtxAction and register action with specified \a id.
998 Resulting action ID may differ from the requested one. This can happen if
999 requested ID is already in use.
1001 If \a id < 0, the action ID is generated automatically.
1003 \param id required action ID
1004 \param text tooltip text
1005 \param icon action icon
1006 \param menu menu text
1007 \param tip status bar tip
1008 \param key keyboard accelerator
1009 \param parent parent object
1010 \param toggle if \c true, the action will be toggled
1011 \param reciever action activation signal receiver object
1012 \param member action activation signal receiver slot
1014 QAction* CAM_Module::createAction( const int id, const QString& text, const QIcon& icon,
1015 const QString& menu, const QString& tip, const QKeySequence& key,
1016 QObject* parent, const bool toggle, QObject* reciever,
1017 const char* member, const QString& shortcutAction )
1019 QtxAction* a = new QtxAction( text, icon, menu, key, parent, toggle, shortcutAction );
1020 a->setStatusTip( tip );
1022 connect( a, SIGNAL( triggered( bool ) ), this, SLOT( moduleActionActivated() ), Qt::UniqueConnection );
1024 if ( reciever && member )
1025 connect( a, SIGNAL( triggered( bool ) ), reciever, member );
1027 registerAction( id, a );
1033 \brief Create new action group.
1034 \param id action group ID
1035 \param exclusive \c true for exclusive action group
1036 \return created action group
1038 QtxActionGroup* CAM_Module::createActionGroup( const int id, const bool exclusive )
1040 QtxActionGroup* a = qobject_cast<QtxActionGroup*>( action( id ) );
1042 a = new QtxActionGroup( this );
1043 registerAction( id, a );
1045 a->setExclusive( exclusive );
1050 \brief Register action in the internal action map.
1052 If action has been already added previously, its ID is just returned.
1053 If \a id < 0, the action ID is generated automatically.
1055 \param id action required ID
1059 int CAM_Module::registerAction( const int id, QAction* a )
1062 for ( QMap<int, QAction*>::ConstIterator it = myActionMap.begin(); it != myActionMap.end() && ident == -1; ++it )
1063 if ( it.value() == a )
1069 static int generatedId = -1;
1070 ident = id < 0 ? --generatedId : id;
1072 myActionMap.insert( ident, a );
1075 menuMgr()->registerAction( a );
1078 toolMgr()->registerAction( a );
1080 if ( application() && application()->desktop() &&
1081 a->shortcutContext() != Qt::WidgetShortcut &&
1082 a->shortcutContext() != Qt::WidgetWithChildrenShortcut )
1083 application()->desktop()->addAction( a );
1089 \brief Unregister action from the internal action map.
1092 \return \c true on success or \c false if action is in use
1094 bool CAM_Module::unregisterAction( const int id )
1096 return unregisterAction( action( id ) );
1100 \brief Unregister action from the internal action map.
1103 \return \c true on success or \c false if action is in use
1105 bool CAM_Module::unregisterAction( QAction* a )
1110 int id = menuMgr()->actionId( a );
1111 if ( id != -1 && menuMgr()->containsMenu( id, -1 ) )
1115 int id = toolMgr()->actionId( a );
1116 if ( id != -1 && toolMgr()->containsAction( id ) )
1120 menuMgr()->unRegisterAction( menuMgr()->actionId( a ) );
1122 toolMgr()->unRegisterAction( toolMgr()->actionId( a ) );
1127 \brief Create separator action.
1129 Separator action can be used in menus or toolbars.
1131 \return new separator action
1133 QAction* CAM_Module::separator()
1135 return QtxActionMgr::separator();
1139 \brief Update visibility state of the module objects.
1141 void CAM_Module::updateModuleVisibilityState() {
1146 \brief Activate GUI operation of module by its ID.
1147 This method is called from CAM_Application::startOperation().
1148 \param actionId is a numerical unique operation id.
1150 bool CAM_Module::activateOperation( int /*actionId*/ )
1156 \brief Activate GUI operation of module by its ID.
1157 This method is called from CAM_Application::startOperation().
1158 \param actionId is a string unique operation id.
1160 bool CAM_Module::activateOperation( const QString& /*actionId*/ )
1166 \brief Activate GUI operation of module by its ID and \a pluginName.
1167 This method is called from CAM_Application::startOperation().
1168 \param actionId is a string unique operation id.
1169 \param pluginName is a name of a plugin where the operation is implemented.
1171 bool CAM_Module::activateOperation( const QString& /*actionId*/, const QString& /*pluginName*/ )
1178 \brief Connect data model of the module to the active study
1179 \param camStudy CAM study object
1181 void CAM_Module::connectToStudy( CAM_Study* camStudy )
1183 CAM_Application* app = camStudy ? dynamic_cast<CAM_Application*>( camStudy->application() ) : 0;
1187 CAM_DataModel* prev = 0;
1188 CAM_Application::ModuleList mods = app->modules();
1189 for( QList<CAM_Module*>::const_iterator it = mods.begin(); it != mods.end(); ++it )
1191 CAM_DataModel* dm = (*it)->dataModel();
1192 if( (*it) == this && !camStudy->containsDataModel( dm ) )
1195 camStudy->insertDataModel( (*it)->dataModel(), prev );
1197 camStudy->insertDataModel( (*it)->dataModel(), 0 );
1204 \fn void CAM_Module::contextMenuPopup( const QString& type, QMenu* menu, QString& title );
1205 \brief Create context popup menu.
1206 \param type popup menu context
1207 \param menu popup menu
1208 \param title popup menu title, which can be set by the module if required
1212 \fn void CAM_Module::updateCommandsStatus();
1213 \brief Update menu/toolbar actions.
1217 bool CAM_Module::abortAllOperations()
1223 \brief Called when an action is triggered
1225 void CAM_Module::moduleActionActivated()
1227 QAction* action = qobject_cast<QAction*>( sender() );
1228 if ( action && !action->isSeparator() && isActionLoggingEnabled() )
1229 logAction( action );
1233 \brief Log given action.
1234 \param action GUI action being logged.
1236 Default implementation just forwards to CAM_Applicaion::logAction();
1238 void CAM_Module::logAction( QAction* action )
1240 CAM_Application::logAction( action, moduleName() );
1244 \brief Return \c true if action logging is enabled.
1246 bool CAM_Module::isActionLoggingEnabled() const
1248 return myActionLoggingEnabled;
1252 \brief Enable / disable action logging.
1253 \param enabled \c true to enable logging, or \c false to disable it.
1255 void CAM_Module::setActionLoggingEnabled( bool enabled )
1257 myActionLoggingEnabled = enabled;