From 030f2ea70b63791945210b1c1d43e2b34e6fa42b Mon Sep 17 00:00:00 2001 From: vsr Date: Mon, 27 Feb 2006 14:59:26 +0000 Subject: [PATCH] Dynamic menus in Python: * provide method to unregister action --- src/CAM/CAM_Module.cxx | 44 ++++++++++++++++++++++++++++++++++++++---- src/CAM/CAM_Module.h | 6 ++++-- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/CAM/CAM_Module.cxx b/src/CAM/CAM_Module.cxx index 885f6e05d..0caabbe7f 100755 --- a/src/CAM/CAM_Module.cxx +++ b/src/CAM/CAM_Module.cxx @@ -299,12 +299,13 @@ int CAM_Module::createTool( const int id, const QString& tBar, const int idx ) *\retval Return -1 if something wrong. */ int CAM_Module::createMenu( const QString& subMenu, const int menu, - const int id, const int group, const int index ) + const int id, const int group, const int index, + const bool enableEmpty ) { if ( !menuMgr() ) return -1; - return menuMgr()->insert( subMenu, menu, group, index ); + return menuMgr()->insert( subMenu, menu, group, id, index, enableEmpty ); } /*! Create menu. @@ -318,12 +319,13 @@ int CAM_Module::createMenu( const QString& subMenu, const int menu, *\retval Return -1 if something wrong. */ int CAM_Module::createMenu( const QString& subMenu, const QString& menu, - const int id, const int group, const int index ) + const int id, const int group, const int index, + const bool enableEmpty ) { if ( !menuMgr() ) return -1; - return menuMgr()->insert( subMenu, menu, group, index ); + return menuMgr()->insert( subMenu, menu, group, id, index, enableEmpty ); } @@ -572,6 +574,40 @@ int CAM_Module::registerAction( const int id, QAction* a ) return ident; } +/*! Unregister an action. + * \param id - id for action. + * \retval true if succeded, false if action is used + */ +bool CAM_Module::unregisterAction( const int id ) +{ + return unregisterAction( action( id ) ); +} + +/*! Unregister an action. + * \param a - action + * \retval true if succeded, false if action is used + */ +bool CAM_Module::unregisterAction( QAction* a ) +{ + if ( !a ) + return false; + if ( menuMgr() ) { + int id = menuMgr()->actionId( a ); + if ( id != -1 && menuMgr()->contains( id, -1 ) ) + return false; + } + if ( toolMgr() ) { + int id = toolMgr()->actionId( a ); + if ( id != -1 && toolMgr()->contains( id ) ) + return false; + } + if ( menuMgr() ) + menuMgr()->unRegisterAction( menuMgr()->actionId( a ) ); + if ( toolMgr() ) + toolMgr()->unRegisterAction( toolMgr()->actionId( a ) ); + return true; +} + /*! Return qt action manager separator.*/ QAction* CAM_Module::separator() { diff --git a/src/CAM/CAM_Module.h b/src/CAM/CAM_Module.h index 7b525996c..7b32a4013 100755 --- a/src/CAM/CAM_Module.h +++ b/src/CAM/CAM_Module.h @@ -106,8 +106,8 @@ protected: /** @name Create menu methods.*/ //@{ - int createMenu( const QString&, const int, const int = -1, const int = -1, const int = -1 ); - int createMenu( const QString&, const QString&, const int = -1, const int = -1, const int = -1 ); + int createMenu( const QString&, const int, const int = -1, const int = -1, const int = -1, const bool = false ); + int createMenu( const QString&, const QString&, const int = -1, const int = -1, const int = -1, const bool = false ); int createMenu( const int, const int, const int = -1, const int = -1 ); int createMenu( const int, const QString&, const int = -1, const int = -1 ); int createMenu( QAction*, const int, const int = -1, const int = -1, const int = -1 ); @@ -123,6 +123,8 @@ protected: //@} int registerAction( const int, QAction* ); + bool unregisterAction( const int ); + bool unregisterAction( QAction* ); QAction* createAction( const int, const QString&, const QIconSet&, const QString&, const QString&, const int, QObject* = 0, const bool = false, QObject* = 0, const char* = 0 ); -- 2.39.2