1 #include "CAM_Module.h"
3 #include "CAM_DataModel.h"
4 #include "CAM_Application.h"
8 #include <QtxActionMenuMgr.h>
9 #include <QtxActionToolMgr.h>
11 static const char* ModuleIcon[] = {
18 " .................. ",
27 " .................. ",
31 " .. .. .. .. .. .. ",
33 " .. .. .. .. .. .. ",
36 QPixmap MYPixmap( ModuleIcon );
38 CAM_Module::CAM_Module()
46 CAM_Module::CAM_Module( const QString& name )
55 CAM_Module::~CAM_Module()
61 void CAM_Module::initialize( CAM_Application* app )
66 QPixmap CAM_Module::moduleIcon() const
71 QString CAM_Module::moduleName() const
76 CAM_DataModel* CAM_Module::dataModel() const
80 CAM_Module* that = (CAM_Module*)this;
81 that->myDataModel = that->createDataModel();
82 that->myDataModel->initialize();
87 CAM_Application* CAM_Module::application() const
92 void CAM_Module::activateModule( SUIT_Study* study )
96 void CAM_Module::deactivateModule( SUIT_Study* )
100 void CAM_Module::studyClosed( SUIT_Study* study )
102 CAM_Study* camDoc = dynamic_cast<CAM_Study*>( study );
106 if ( camDoc->containsDataModel( dataModel() ) )
107 camDoc->removeDataModel( dataModel() );
110 void CAM_Module::studyChanged( SUIT_Study* , SUIT_Study* )
114 CAM_DataModel* CAM_Module::createDataModel()
116 return new CAM_DataModel( this );
119 void CAM_Module::setModuleName( const QString& name )
124 void CAM_Module::setModuleIcon( const QPixmap& icon )
129 QtxActionMenuMgr* CAM_Module::menuMgr() const
131 QtxActionMenuMgr* mgr = 0;
132 if ( application() && application()->desktop() )
133 mgr = application()->desktop()->menuMgr();
137 QtxActionToolMgr* CAM_Module::toolMgr() const
139 QtxActionToolMgr* mgr = 0;
140 if ( application() && application()->desktop() )
141 mgr = application()->desktop()->toolMgr();
145 int CAM_Module::createTool( const QString& name )
150 return toolMgr()->createToolBar( name );
153 int CAM_Module::createTool( QAction* a, const int tBar, const int id, const int idx )
158 int regId = registerAction( id, a );
159 int intId = toolMgr()->insert( a, tBar, idx );
160 return intId != -1 ? regId : -1;
163 int CAM_Module::createTool( QAction* a, const QString& tBar, const int id, const int idx )
168 int regId = registerAction( id, a );
169 int intId = toolMgr()->insert( a, tBar, idx );
170 return intId != -1 ? regId : -1;
173 int CAM_Module::createTool( const int id, const int tBar, const int idx )
178 int intId = toolMgr()->insert( action( id ), tBar, idx );
179 return intId != -1 ? id : -1;
182 int CAM_Module::createTool( const int id, const QString& tBar, const int idx )
187 int intId = toolMgr()->insert( action( id ), tBar, idx );
188 return intId != -1 ? id : -1;
191 int CAM_Module::createMenu( const QString& subMenu, const int menu,
192 const int id, const int group, const int index )
197 return menuMgr()->insert( subMenu, menu, group, index );
200 int CAM_Module::createMenu( const QString& subMenu, const QString& menu,
201 const int id, const int group, const int index )
206 return menuMgr()->insert( subMenu, menu, group, index );
209 int CAM_Module::createMenu( QAction* a, const int menu, const int id, const int group, const int index )
211 if ( !a || !menuMgr() )
214 int regId = registerAction( id, a );
215 int intId = menuMgr()->insert( a, menu, group, index );
216 return intId != -1 ? regId : -1;
219 int CAM_Module::createMenu( QAction* a, const QString& menu, const int id, const int group, const int index )
221 if ( !a || !menuMgr() )
224 int regId = registerAction( id, a );
225 int intId = menuMgr()->insert( a, menu, group, index );
226 return intId != -1 ? regId : -1;
229 int CAM_Module::createMenu( const int id, const int menu, const int group, const int index )
234 int intId = menuMgr()->insert( action( id ), menu, group, index );
235 return intId != -1 ? id : -1;
238 int CAM_Module::createMenu( const int id, const QString& menu, const int group, const int index )
243 int intId = menuMgr()->insert( action( id ), menu, group, index );
244 return intId != -1 ? id : -1;
247 void CAM_Module::setMenuShown( const bool on )
249 QtxActionMenuMgr* mMgr = menuMgr();
253 bool upd = mMgr->isUpdatesEnabled();
254 mMgr->setUpdatesEnabled( false );
256 QAction* sep = separator();
257 for ( QMap<int, QAction*>::Iterator it = myActionMap.begin(); it != myActionMap.end(); ++it )
259 if ( it.data() != sep )
260 mMgr->setShown( mMgr->actionId( it.data() ), on );
263 mMgr->setUpdatesEnabled( upd );
268 void CAM_Module::setMenuShown( QAction* a, const bool on )
271 menuMgr()->setShown( menuMgr()->actionId( a ), on );
274 void CAM_Module::setMenuShown( const int id, const bool on )
276 setMenuShown( action( id ), on );
279 void CAM_Module::setToolShown( const bool on )
281 QtxActionToolMgr* tMgr = toolMgr();
285 bool upd = tMgr->isUpdatesEnabled();
286 tMgr->setUpdatesEnabled( false );
288 QAction* sep = separator();
289 for ( QMap<int, QAction*>::Iterator it = myActionMap.begin(); it != myActionMap.end(); ++it )
291 if ( it.data() != sep )
292 tMgr->setShown( tMgr->actionId( it.data() ), on );
295 tMgr->setUpdatesEnabled( upd );
300 void CAM_Module::setToolShown( QAction* a, const bool on )
303 toolMgr()->setShown( toolMgr()->actionId( a ), on );
306 void CAM_Module::setToolShown( const int id, const bool on )
308 setToolShown( action( id ), on );
311 QAction* CAM_Module::action( const int id ) const
314 if ( myActionMap.contains( id ) )
319 int CAM_Module::actionId( const QAction* a ) const
322 for ( QMap<int, QAction*>::ConstIterator it = myActionMap.begin(); it != myActionMap.end() && id == -1; ++it )
324 if ( it.data() == a )
330 QAction* CAM_Module::createAction( const int id, const QString& text, const QIconSet& icon,
331 const QString& menu, const QString& tip, const int key,
332 QObject* parent, const bool toggle, QObject* reciever, const char* member )
334 QtxAction* a = new QtxAction( text, icon, menu, key, parent, 0, toggle );
335 a->setStatusTip( tip );
337 if ( reciever && member )
338 connect( a, SIGNAL( activated() ), reciever, member );
340 registerAction( id, a );
345 int CAM_Module::registerAction( const int id, QAction* a )
348 for ( QMap<int, QAction*>::ConstIterator it = myActionMap.begin(); it != myActionMap.end() && ident == -1; ++it )
349 if ( it.data() == a )
355 static int generatedId = -1;
356 ident = id < 0 ? --generatedId : id;
358 myActionMap.insert( id, a );
361 menuMgr()->registerAction( a );
364 toolMgr()->registerAction( a );
369 QAction* CAM_Module::separator()
371 return QtxActionMgr::separator();