1 // Copyright (C) 2007-2024 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>
37 #include <SUIT_ShortcutMgr.h>
43 \brief Base implementation of the module in the CAM application architecture.
45 Provides support of menu/toolbars management.
51 ActionMgrLocker( QtxActionMgr* m, bool use ) : myMgr( m ), myUseLock( use )
54 myUpdEnabled = myMgr->isUpdatesEnabled();
55 myMgr->setUpdatesEnabled( false );
61 myMgr->setUpdatesEnabled( myUpdEnabled );
72 \brief Default constructor.
74 Creates unnamed module.
76 CAM_Module::CAM_Module()
86 Creates module with the specified \a name.
88 \param name module name
90 CAM_Module::CAM_Module( const QString& name )
97 myActionLoggingEnabled( false )
106 CAM_Module::~CAM_Module()
113 \brief Initialize module.
115 This method is usually called when the module is created (for example,
116 on the module library loading).
117 Successor classes can use this method to create menu/toolbar actions
118 and perform other module initialization.
120 \param app parent application object
121 \sa activateModule(), deactivateModule()
123 void CAM_Module::initialize( CAM_Application* app )
128 SUIT_Session* aSession = SUIT_Session::session();
129 connect( aSession, SIGNAL( applicationClosed( SUIT_Application* ) ),
130 this, SLOT( onApplicationClosed( SUIT_Application* ) ) );
132 connect( myApp, SIGNAL( infoChanged( QString ) ), this, SLOT( onInfoChanged( QString ) ) );
137 \brief Get module icon.
138 \return module icon pixmap
141 QPixmap CAM_Module::moduleIcon() const
143 if ( myIcon.isNull() ) {
144 QString iname = iconName();
145 if ( !iname.isEmpty() ) {
146 CAM_Module* that = (CAM_Module*)this;
147 that->myIcon = application()->resourceMgr()->loadPixmap( name(), iname, false );
154 \brief Get module icon's name.
156 This function is used to get module icon's file name.
157 Default implementation returns empty string.
159 \return module icon's name.
162 QString CAM_Module::iconName() const
164 return application()->moduleIcon( name() );
168 \brief Get module (internal) name
170 \sa setName(), moduleName(), setModuleName()
172 QString CAM_Module::name() const
178 \brief Get module title (user name)
180 \sa setModuleName(), name(), setName()
182 QString CAM_Module::moduleName() const
188 \brief Get data model.
190 Creates data model, if it is not yet created.
192 \return data model pointer
193 \sa createDataModel()
195 CAM_DataModel* CAM_Module::dataModel() const
199 CAM_Module* that = (CAM_Module*)this;
200 that->myDataModel = that->createDataModel();
201 that->myDataModel->initialize();
207 \brief Get application.
208 \return application pointer
210 CAM_Application* CAM_Module::application() const
216 \brief If return false, selection will be cleared at module activation
218 bool CAM_Module::isSelectionCompatible()
224 \brief Activate module.
226 This method is called when the user activates module.
227 Successor classes can use this method to customize module activation process,
228 for example, to show own menus, toolbars, etc.
230 Default implementation always returns \c true.
232 \return \c true if module is activated successfully.
233 \sa initialize(), deactivateModule()
235 bool CAM_Module::activateModule( SUIT_Study* /*study*/ )
237 // IMN 05/03/2015: we copied myActionMap for reset/unset actions accelerator keys
238 // after activate/deactivate modules
239 for ( QMap<QAction*, QKeySequence>::Iterator it = myActionShortcutMap.begin(); it != myActionShortcutMap.end(); ++it )
241 // Reset actions accelerator keys
242 it.key()->setShortcut( it.value() );
244 myActionShortcutMap.clear();
249 \brief Deactivate module.
251 This method is called when the user deactivates module.
252 Successor classes can use this method to customize module deactivation process,
253 for example, to hide own menus, toolbars, etc.
255 Default implementation always returns \c true.
257 \return \c true if module is deactivated successfully.
258 \sa initialize(), activateModule()
260 bool CAM_Module::deactivateModule( SUIT_Study* )
262 // IMN 05/03/2015: we copied myActionMap for reset/unset actions accelerator keys
263 // after activate/deactivate modules
264 myActionShortcutMap.clear();
265 for ( QMap<int, QAction*>::Iterator it = myActionMap.begin(); it != myActionMap.end(); ++it )
267 myActionShortcutMap.insert( it.value(), it.value()->shortcut() );
268 it.value()->setShortcut( QKeySequence() );
274 \brief Called when study is closed.
276 Removes data model from the \a study.
278 \param study study being closed
280 void CAM_Module::studyClosed( SUIT_Study* study )
282 CAM_Study* camDoc = dynamic_cast<CAM_Study*>( study );
286 CAM_DataModel* dm = dataModel();
287 if ( dm && camDoc->containsDataModel( dm ) ) {
289 camDoc->removeDataModel( dm );
294 \brief Called when study is changed (obsolete).
296 Default implementation does nothing.
298 \param oldStudy old study
299 \param newStudy new study
301 void CAM_Module::studyChanged( SUIT_Study* /*oldStudy*/, SUIT_Study* /*newStudy*/ )
306 \brief Check if the module is active.
307 \return \c true if module is active.
309 bool CAM_Module::isActiveModule() const
311 return application() ? application()->activeModule() == this : false;
315 \brief Put the text message into the status bar of the application main window.
317 If \a msec > 0, the message will be shown \a msec milliseconds.
318 If \a msec < 0, the message will be constantly displayed until module is active.
320 \param msg text message
321 \param msec message displaying duration in milliseconds
323 void CAM_Module::putInfo( const QString& msg, const int msec )
326 application()->putInfo( msg, msec );
333 \brief Shows the notifications with spectified text, title and automatic close timeout.
334 Notification will be automatically closed after specified timeout in msec. If
335 timeout is zero then automatic closing doesn't performed.
336 \param text - Notification text
337 \param title - Notification title
338 \param timeout - Notification close timeout in msec
339 \return notification identifier
341 int CAM_Module::showNotification( const QString& message, const QString& title, int timeout )
345 res = application()->showNotification( message, title, timeout );
350 \brief Closes the notifications with spectified text.
351 \param text - Notification text
353 void CAM_Module::hideNotification( const QString& message )
356 application()->hideNotification( message );
360 \brief Closes the notifications with spectified identifier.
361 \param text - Notification text
363 void CAM_Module::hideNotification( int id )
366 application()->hideNotification( id );
370 \brief Restore message info.
372 Restores constant text message when previous information status message is removed.
374 \param txt previous message (being removed)
377 void CAM_Module::onInfoChanged( QString txt )
379 if ( txt.isEmpty() && isActiveModule() && !myInfo.isEmpty() && application() )
380 application()->putInfo( myInfo );
384 \brief Called when application is closed.
386 Nullify application pointer if the application is being closed.
388 \param theApp application
390 void CAM_Module::onApplicationClosed( SUIT_Application* theApp )
397 \brief Create data model.
398 \return created data model object or 0 if it could not be created
400 CAM_DataModel* CAM_Module::createDataModel()
402 return new CAM_DataModel( this );
406 \brief Set module (internal) name
407 \param name new module name
408 \sa name(), moduleName(), setModuleName()
410 void CAM_Module::setName( const QString& name )
412 setObjectName( name );
416 \brief Set module title (user name)
417 \param name new module title
418 \sa moduleName(), name(), setName()
420 void CAM_Module::setModuleName( const QString& name )
426 \brief Get menu manager.
427 \return menu manager pointer
429 QtxActionMenuMgr* CAM_Module::menuMgr() const
431 QtxActionMenuMgr* mgr = 0;
432 if ( application() && application()->desktop() )
433 mgr = application()->desktop()->menuMgr();
438 \brief Get toolbar manager.
439 \return toolbar manager pointer
441 QtxActionToolMgr* CAM_Module::toolMgr() const
443 QtxActionToolMgr* mgr = 0;
444 if ( application() && application()->desktop() )
445 mgr = application()->desktop()->toolMgr();
450 \brief Create toolbar with speicifed \a name.
452 If the toolbar has been already created, its ID is just returned.
454 \param title toolbar title
455 \param name toolbar name (identifier)
456 \return toolbar ID or -1 if toolbar could not be created
458 int CAM_Module::createTool( const QString& title, const QString& name )
463 ActionMgrLocker lock( toolMgr(), !myToolShown );
465 return toolMgr()->createToolBar( title, name );
469 \brief Add toolbar item.
471 Insert action \a to the toolbar manager and register it with specified \a id.
472 Resulting action ID may differ from the requested one. This can happen if
473 requested ID is already in use.
475 If action has been already added previously, its ID is just returned.
477 If \a id < 0, the action ID is generated automatically.
479 If \a idx < 0, the action is added to the end of the toolbar.
482 \param tBar toolbar ID
483 \param id requested action ID
484 \param idx action index (desired position in the toolbar)
485 \return action ID or -1 if toolbar item could not be added
487 int CAM_Module::createTool( QAction* a, const int tBar, const int id, const int idx )
492 ActionMgrLocker lock( toolMgr(), !myToolShown );
494 int regId = registerAction( id, a );
495 int intId = toolMgr()->insert( a, tBar, idx );
498 setToolShown( a, false );
500 return intId != -1 ? regId : -1;
504 \brief Add toolbar item.
506 Insert action \a to the toolbar manager and register it with specified \a id.
507 Resulting action ID may differ from the requested one. This can happen if
508 requested ID is already in use.
510 If action has been already added previously, its ID is just returned.
512 If \a id < 0, the action ID is generated automatically.
514 If \a idx < 0, the action is added to the end of the toolbar.
517 \param tBar toolbar name
518 \param id requested action ID
519 \param idx action index (desired position in the toolbar)
520 \return action ID or -1 if toolbar item could not be added
522 int CAM_Module::createTool( QAction* a, const QString& tBar, const int id, const int idx )
527 ActionMgrLocker lock( toolMgr(), !myToolShown );
529 int regId = registerAction( id, a );
530 int intId = toolMgr()->insert( a, tBar, idx );
533 setToolShown( a, false );
535 return intId != -1 ? regId : -1;
539 \brief Add toolbar item.
541 Insert action with \a id identifier to the toolbar manager.
542 It is assumed that action has been already registered.
544 Resulting action ID may differ from the requested one. This can happen if
545 requested ID is already in use.
547 If action has been already added previously, its ID is just returned.
549 If \a idx < 0, the action is added to the end of the toolbar.
552 \param tBar toolbar ID
553 \param idx action index (desired position in the toolbar)
554 \return action ID or -1 if toolbar item could not be added
556 int CAM_Module::createTool( const int id, const int tBar, const int idx )
561 ActionMgrLocker lock( toolMgr(), !myToolShown );
563 int intId = toolMgr()->insert( action( id ), tBar, idx );
566 setToolShown( action( id ), false );
568 return intId != -1 ? id : -1;
572 \brief Add toolbar item.
574 Insert action with \a id identifier to the toolbar manager.
575 It is assumed that action has been already registered.
577 Resulting action ID may differ from the requested one. This can happen if
578 requested ID is already in use.
580 If action has been already added previously, its ID is just returned.
582 If \a idx < 0, the action is added to the end of the toolbar.
585 \param tBar toolbar name
586 \param idx action index (desired position in the toolbar)
587 \return action ID or -1 if toolbar item could not be added
589 int CAM_Module::createTool( const int id, const QString& tBar, const int idx )
594 ActionMgrLocker lock( toolMgr(), !myToolShown );
596 int intId = toolMgr()->insert( action( id ), tBar, idx );
599 setToolShown( action( id ), false );
601 return intId != -1 ? id : -1;
605 Clears given toolbar.
606 \param title - title of toolbar
608 void CAM_Module::clearTool( const QString& title )
611 toolMgr()->clear( title );
615 \brief Create menu or submenu.
617 Create main menu or popup submenu and register it with specified \a id.
618 Resulting action ID may differ from the requested one. This can happen if
619 requested ID is already in use.
621 If \a id < 0, the menu ID is generated automatically.
622 If menu has been already created previously, its ID is just returned.
624 The \a menu parameter represents the menu name - it could be a sequence
625 of strings, separated by '|' symbol. For example, "File|Edit" means
626 File->Edit submenu. If menu doesn't exist, it is created automatically.
628 Parameter \a idx defines the index of the menu item in the menu group which
629 is defined by the \a group. If \a idx < 0, the menu/submenu is added to the
630 end of the menu group.
632 \param subMenu subMenu name
633 \param menu parent menu ID
634 \param id requested menu ID
635 \param group menu group ID
636 \param idx menu item index (desired position in the menu group)
637 \return menu item ID or -1 if menu item could not be added
639 int CAM_Module::createMenu( const QString& subMenu, const int menu,
640 const int id, const int group, const int idx, QMenu * menuObj )
645 return menuMgr()->insert( subMenu, menu, group, id, idx, menuObj );
649 \brief Create menu or submenu.
651 Create main menu or popup submenu and register it with specified \a id.
652 Resulting action ID may differ from the requested one. This can happen if
653 requested ID is already in use.
655 If \a id < 0, the menu ID is generated automatically.
656 If menu has been already created previously, its ID is just returned.
658 The \a menu parameter represents the menu name - it could be a sequence
659 of strings, separated by '|' symbol. For example, "File|Edit" means
660 File->Edit submenu. If menu doesn't exist, it is created automatically.
662 Parameter \a idx defines the index of the menu item in the menu group which
663 is defined by the \a group. If \a idx < 0, the menu/submenu is added to the
664 end of the menu group.
666 \param subMenu subMenu name
667 \param menu parent menu name(s)
668 \param id requested menu ID
669 \param group menu group ID
670 \param idx menu item index (desired position in the menu group)
671 \return menu item ID or -1 if menu item could not be added
673 int CAM_Module::createMenu( const QString& subMenu, const QString& menu,
674 const int id, const int group, const int idx )
679 return menuMgr()->insert( subMenu, menu, group, id, idx );
683 \brief Add menu item.
685 Insert action \a to the menu manager and register it with specified \a id.
686 Resulting action ID may differ from the requested one. This can happen if
687 requested ID is already in use.
689 If \a id < 0, the action ID is generated automatically.
691 If action has been already added previously, its ID is just returned.
693 Parameter \a idx defines the index of the menu item in the menu group which
694 is defined by the \a group. If \a idx < 0, the action is added to the
695 end of the menu group.
699 \param id requested action ID
700 \param group menu group ID
701 \param idx action index (desired position in the menu group)
702 \return action ID or -1 if menu item could not be added
704 int CAM_Module::createMenu( QAction* a, const int menu, const int id, const int group, const int idx )
706 if ( !a || !menuMgr() )
709 ActionMgrLocker lock( menuMgr(), !myMenuShown );
711 int regId = registerAction( id, a );
712 int intId = menuMgr()->insert( a, menu, group, idx );
715 setMenuShown( a, false );
717 return intId != -1 ? regId : -1;
721 \brief Add menu item.
723 Insert action \a to the menu manager and register it with specified \a id.
724 Resulting action ID may differ from the requested one. This can happen if
725 requested ID is already in use.
727 If \a id < 0, the action ID is generated automatically.
729 If action has been already added previously, its ID is just returned.
731 The \a menu parameter represents the menu name - it could be a sequence
732 of strings, separated by '|' symbol. For example, "File|Edit" means
733 File->Edit submenu. If menu doesn't exist, it is created automatically.
735 Parameter \a idx defines the index of the menu item in the menu group which
736 is defined by the \a group. If \a idx < 0, the action is added to the
737 end of the menu group.
740 \param menu menu name(s)
741 \param id requested action ID
742 \param group menu group ID
743 \param idx action index (desired position in the menu group)
744 \return action ID or -1 if menu item could not be added
746 int CAM_Module::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx )
748 if ( !a || !menuMgr() )
751 ActionMgrLocker lock( menuMgr(), !myMenuShown );
753 int regId = registerAction( id, a );
754 int intId = menuMgr()->insert( a, menu, group, idx );
757 setMenuShown( a, false );
759 return intId != -1 ? regId : -1;
763 \brief Add menu item.
765 Insert action with \a id identifier to the menu manager.
766 It is assumed that action has been already registered.
768 Resulting action ID may differ from the requested one. This can happen if
769 requested ID is already in use.
771 If action has been already added previously, its ID is just returned.
773 Parameter \a idx defines the index of the menu item in the menu group which
774 is defined by the \a group. If \a idx < 0, the action is added to the
775 end of the menu group.
779 \param group menu group ID
780 \param idx action index (desired position in the menu group)
781 \return action ID or -1 if menu item could not be added
783 int CAM_Module::createMenu( const int id, const int menu, const int group, const int idx )
788 ActionMgrLocker lock( menuMgr(), !myMenuShown );
790 int intId = menuMgr()->insert( action( id ), menu, group, idx );
793 setMenuShown( action( id ), false );
795 return intId != -1 ? id : -1;
799 \brief Add menu item.
801 Insert action with \a id identifier to the menu manager.
802 It is assumed that action has been already registered.
804 Resulting action ID may differ from the requested one. This can happen if
805 requested ID is already in use.
807 If action has been already added previously, its ID is just returned.
809 The \a menu parameter represents the menu name - it could be a sequence
810 of strings, separated by '|' symbol. For example, "File|Edit" means
811 File->Edit submenu. If menu doesn't exist, it is created automatically.
813 Parameter \a idx defines the index of the menu item in the menu group which
814 is defined by the \a group. If \a idx < 0, the action is added to the
815 end of the menu group.
818 \param menu menu name(s)
819 \param group menu group ID
820 \param idx action index (desired position in the menu group)
821 \return action ID or -1 if menu item could not be added
823 int CAM_Module::createMenu( const int id, const QString& menu, const int group, const int idx )
828 ActionMgrLocker lock( menuMgr(), !myMenuShown );
830 int intId = menuMgr()->insert( action( id ), menu, group, idx );
833 setMenuShown( action( id ), false );
835 return intId != -1 ? id : -1;
839 \brief Show/hide all module's menus.
840 \param on if \c true, show menus, otherwise, hide all menus
843 void CAM_Module::setMenuShown( const bool on )
847 QtxActionMenuMgr* mMgr = menuMgr();
851 bool upd = mMgr->isUpdatesEnabled();
852 mMgr->setUpdatesEnabled( false );
854 QAction* sep = separator();
855 for ( QMap<int, QAction*>::Iterator it = myActionMap.begin(); it != myActionMap.end(); ++it )
857 if ( it.value() != sep )
858 mMgr->setShown( mMgr->actionId( it.value() ), on );
861 mMgr->setUpdatesEnabled( upd );
867 \brief Show/hide specified menu item.
869 \param on if \c true, show menu item, otherwise, hide it
871 void CAM_Module::setMenuShown( QAction* a, const bool on )
874 menuMgr()->setShown( menuMgr()->actionId( a ), on );
878 \brief Show/hide specified menu item.
879 \param id menu item ID
880 \param on if \c true, show menu item, otherwise, hide it
882 void CAM_Module::setMenuShown( const int id, const bool on )
884 setMenuShown( action( id ), on );
888 \brief Show/hide all module's toolbars.
889 \param on if \c true, show toolbars, otherwise, hide all toolbars
892 void CAM_Module::setToolShown( const bool on )
896 QtxActionToolMgr* tMgr = toolMgr();
900 bool upd = tMgr->isUpdatesEnabled();
901 tMgr->setUpdatesEnabled( false );
903 QAction* sep = separator();
904 for ( QMap<int, QAction*>::Iterator it = myActionMap.begin(); it != myActionMap.end(); ++it )
906 if ( it.value() != sep )
907 tMgr->setShown( tMgr->actionId( it.value() ), on );
910 tMgr->setUpdatesEnabled( upd );
916 \brief Show/hide specified toolbar item.
918 \param on if \c true, show toolbar item, otherwise, hide it
920 void CAM_Module::setToolShown( QAction* a, const bool on )
923 toolMgr()->setShown( toolMgr()->actionId( a ), on );
927 \brief Show/hide specified toolbar item.
928 \param id toolbar item ID
929 \param on if \c true, show toolbar item, otherwise, hide it
931 void CAM_Module::setToolShown( const int id, const bool on )
933 setToolShown( action( id ), on );
936 QString CAM_Module::makeActionID(const QString& theInModuleActionID) const
938 return SUIT_ShortcutMgr::makeActionID(name(), theInModuleActionID);
942 \brief Get action by specified \a id.
944 \return action or 0 if not found
946 QAction* CAM_Module::action( const int id ) const
949 if ( myActionMap.contains( id ) )
951 else if ( menuMgr() ) {
952 QMenu* m = menuMgr()->findMenu( id );
953 if ( m ) a = m->menuAction();
959 \brief Get action ID.
961 \return action ID or -1 if not found
963 int CAM_Module::actionId( const QAction* a ) const
966 for ( QMap<int, QAction*>::ConstIterator it = myActionMap.begin(); it != myActionMap.end() && id == -1; ++it )
968 if ( it.value() == a )
975 \brief Create new instance of QtxAction and register action with specified \a id.
977 Resulting action ID may differ from the requested one. This can happen if
978 requested ID is already in use.
980 If \a id < 0, the action ID is generated automatically.
982 \param id required action ID
983 \param text tooltip text
984 \param icon action icon
985 \param menu menu text
986 \param tip status bar tip
987 \param key will be disabled by SUIT_ShortcutMgr!
988 \param parent parent object
989 \param toggle if \c true, the action will be toggled
990 \param reciever action activation signal receiver object
991 \param member action activation signal receiver slot
992 \param inModuleActionID module-unique action ID
994 QAction* CAM_Module::createAction( const int id, const QString& text, const QIcon& icon,
995 const QString& menu, const QString& tip, const int key,
996 QObject* parent, const bool toggle, QObject* reciever,
997 const char* member, const QString& inModuleActionID )
999 return createAction( id, text, icon, menu, tip, QKeySequence(key), parent, toggle, reciever, member, inModuleActionID );
1003 \brief Create new instance of QtxAction and register action with specified \a id.
1005 Resulting action ID may differ from the requested one. This can happen if
1006 requested ID is already in use.
1008 If \a id < 0, the action ID is generated automatically.
1010 \param id required action ID
1011 \param text tooltip text
1012 \param icon action icon
1013 \param menu menu text
1014 \param tip status bar tip
1015 \param key will be disabled by SUIT_ShortcutMgr!
1016 \param parent parent object
1017 \param toggle if \c true, the action will be toggled
1018 \param reciever action activation signal receiver object
1019 \param member action activation signal receiver slot
1020 \param inModuleActionID module-unique action ID
1022 QAction* CAM_Module::createAction( const int id, const QString& text, const QIcon& icon,
1023 const QString& menu, const QString& tip, const QKeySequence& key,
1024 QObject* parent, const bool toggle, QObject* reciever,
1025 const char* member, const QString& inModuleActionID )
1027 const QString actionID = makeActionID(inModuleActionID);
1028 QtxAction* a = new QtxAction( text, icon, menu, key, parent, toggle, actionID );
1029 a->setStatusTip( tip );
1031 connect( a, SIGNAL( triggered( bool ) ), this, SLOT( moduleActionActivated() ), Qt::UniqueConnection );
1033 if ( reciever && member )
1034 connect( a, SIGNAL( triggered( bool ) ), reciever, member );
1036 registerAction( id, a );
1042 \brief Create new action group.
1043 \param id action group ID
1044 \param exclusive \c true for exclusive action group
1045 \return created action group
1047 QtxActionGroup* CAM_Module::createActionGroup( const int id, const bool exclusive )
1049 QtxActionGroup* a = qobject_cast<QtxActionGroup*>( action( id ) );
1051 a = new QtxActionGroup( this );
1052 registerAction( id, a );
1054 a->setExclusive( exclusive );
1059 \brief Register action in the internal action map.
1061 If action has been already added previously, its ID is just returned.
1062 If \a id < 0, the action ID is generated automatically.
1064 \param id action required ID
1068 int CAM_Module::registerAction( const int id, QAction* a )
1071 for ( QMap<int, QAction*>::ConstIterator it = myActionMap.begin(); it != myActionMap.end() && ident == -1; ++it )
1072 if ( it.value() == a )
1078 static int generatedId = -1;
1079 ident = id < 0 ? --generatedId : id;
1081 myActionMap.insert( ident, a );
1084 menuMgr()->registerAction( a );
1087 toolMgr()->registerAction( a );
1089 if ( application() && application()->desktop() &&
1090 a->shortcutContext() != Qt::WidgetShortcut &&
1091 a->shortcutContext() != Qt::WidgetWithChildrenShortcut )
1092 application()->desktop()->addAction( a );
1098 \brief Unregister action from the internal action map.
1101 \return \c true on success or \c false if action is in use
1103 bool CAM_Module::unregisterAction( const int id )
1105 return unregisterAction( action( id ) );
1109 \brief Unregister action from the internal action map.
1112 \return \c true on success or \c false if action is in use
1114 bool CAM_Module::unregisterAction( QAction* a )
1119 int id = menuMgr()->actionId( a );
1120 if ( id != -1 && menuMgr()->containsMenu( id, -1 ) )
1124 int id = toolMgr()->actionId( a );
1125 if ( id != -1 && toolMgr()->containsAction( id ) )
1129 menuMgr()->unRegisterAction( menuMgr()->actionId( a ) );
1131 toolMgr()->unRegisterAction( toolMgr()->actionId( a ) );
1136 \brief Create separator action.
1138 Separator action can be used in menus or toolbars.
1140 \return new separator action
1142 QAction* CAM_Module::separator()
1144 return QtxActionMgr::separator();
1148 \brief Update visibility state of the module objects.
1150 void CAM_Module::updateModuleVisibilityState() {
1155 \brief Activate GUI operation of module by its ID.
1156 This method is called from CAM_Application::startOperation().
1157 \param actionId is a numerical unique operation id.
1159 bool CAM_Module::activateOperation( int /*actionId*/ )
1165 \brief Activate GUI operation of module by its ID.
1166 This method is called from CAM_Application::startOperation().
1167 \param actionId is a string unique operation id.
1169 bool CAM_Module::activateOperation( const QString& /*actionId*/ )
1175 \brief Activate GUI operation of module by its ID and \a pluginName.
1176 This method is called from CAM_Application::startOperation().
1177 \param actionId is a string unique operation id.
1178 \param pluginName is a name of a plugin where the operation is implemented.
1180 bool CAM_Module::activateOperation( const QString& /*actionId*/, const QString& /*pluginName*/ )
1187 \brief Connect data model of the module to the active study
1188 \param camStudy CAM study object
1190 void CAM_Module::connectToStudy( CAM_Study* camStudy )
1192 CAM_Application* app = camStudy ? dynamic_cast<CAM_Application*>( camStudy->application() ) : 0;
1196 CAM_DataModel* prev = 0;
1197 CAM_Application::ModuleList mods = app->modules();
1198 for( QList<CAM_Module*>::const_iterator it = mods.begin(); it != mods.end(); ++it )
1200 CAM_DataModel* dm = (*it)->dataModel();
1201 if( (*it) == this && !camStudy->containsDataModel( dm ) )
1204 camStudy->insertDataModel( (*it)->dataModel(), prev );
1206 camStudy->insertDataModel( (*it)->dataModel(), 0 );
1213 \fn void CAM_Module::contextMenuPopup( const QString& type, QMenu* menu, QString& title );
1214 \brief Create context popup menu.
1215 \param type popup menu context
1216 \param menu popup menu
1217 \param title popup menu title, which can be set by the module if required
1221 \fn void CAM_Module::updateCommandsStatus();
1222 \brief Update menu/toolbar actions.
1226 bool CAM_Module::abortAllOperations()
1232 \brief Called when an action is triggered
1234 void CAM_Module::moduleActionActivated()
1236 QAction* action = qobject_cast<QAction*>( sender() );
1237 if ( action && !action->isSeparator() && isActionLoggingEnabled() )
1238 logAction( action );
1242 \brief Log given action.
1243 \param action GUI action being logged.
1245 Default implementation just forwards to CAM_Applicaion::logAction();
1247 void CAM_Module::logAction( QAction* action )
1249 CAM_Application::logAction( action, moduleName() );
1253 \brief Return \c true if action logging is enabled.
1255 bool CAM_Module::isActionLoggingEnabled() const
1257 return myActionLoggingEnabled;
1261 \brief Enable / disable action logging.
1262 \param enabled \c true to enable logging, or \c false to disable it.
1264 void CAM_Module::setActionLoggingEnabled( bool enabled )
1266 myActionLoggingEnabled = enabled;