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 bool CAM_Module::activateModule( SUIT_Study* study )
97 bool CAM_Module::deactivateModule( SUIT_Study* )
102 void CAM_Module::studyClosed( SUIT_Study* study )
104 CAM_Study* camDoc = dynamic_cast<CAM_Study*>( study );
108 if ( camDoc->containsDataModel( dataModel() ) )
109 camDoc->removeDataModel( dataModel() );
112 void CAM_Module::studyChanged( SUIT_Study* , SUIT_Study* )
116 CAM_DataModel* CAM_Module::createDataModel()
118 return new CAM_DataModel( this );
121 void CAM_Module::setModuleName( const QString& name )
126 void CAM_Module::setModuleIcon( const QPixmap& icon )
131 QtxActionMenuMgr* CAM_Module::menuMgr() const
133 QtxActionMenuMgr* mgr = 0;
134 if ( application() && application()->desktop() )
135 mgr = application()->desktop()->menuMgr();
139 QtxActionToolMgr* CAM_Module::toolMgr() const
141 QtxActionToolMgr* mgr = 0;
142 if ( application() && application()->desktop() )
143 mgr = application()->desktop()->toolMgr();
147 int CAM_Module::createTool( const QString& name )
152 return toolMgr()->createToolBar( name );
155 int CAM_Module::createTool( QAction* a, const int tBar, const int id, const int idx )
160 int regId = registerAction( id, a );
161 int intId = toolMgr()->insert( a, tBar, idx );
162 return intId != -1 ? regId : -1;
165 int CAM_Module::createTool( QAction* a, const QString& tBar, const int id, const int idx )
170 int regId = registerAction( id, a );
171 int intId = toolMgr()->insert( a, tBar, idx );
172 return intId != -1 ? regId : -1;
175 int CAM_Module::createTool( const int id, const int tBar, const int idx )
180 int intId = toolMgr()->insert( action( id ), tBar, idx );
181 return intId != -1 ? id : -1;
184 int CAM_Module::createTool( const int id, const QString& tBar, const int idx )
189 int intId = toolMgr()->insert( action( id ), tBar, idx );
190 return intId != -1 ? id : -1;
193 int CAM_Module::createMenu( const QString& subMenu, const int menu,
194 const int id, const int group, const int index )
199 return menuMgr()->insert( subMenu, menu, group, index );
202 int CAM_Module::createMenu( const QString& subMenu, const QString& menu,
203 const int id, const int group, const int index )
208 return menuMgr()->insert( subMenu, menu, group, index );
211 int CAM_Module::createMenu( QAction* a, const int menu, const int id, const int group, const int index )
213 if ( !a || !menuMgr() )
216 int regId = registerAction( id, a );
217 int intId = menuMgr()->insert( a, menu, group, index );
218 return intId != -1 ? regId : -1;
221 int CAM_Module::createMenu( QAction* a, const QString& menu, const int id, const int group, const int index )
223 if ( !a || !menuMgr() )
226 int regId = registerAction( id, a );
227 int intId = menuMgr()->insert( a, menu, group, index );
228 return intId != -1 ? regId : -1;
231 int CAM_Module::createMenu( const int id, const int menu, const int group, const int index )
236 int intId = menuMgr()->insert( action( id ), menu, group, index );
237 return intId != -1 ? id : -1;
240 int CAM_Module::createMenu( const int id, const QString& menu, const int group, const int index )
245 int intId = menuMgr()->insert( action( id ), menu, group, index );
246 return intId != -1 ? id : -1;
249 void CAM_Module::setMenuShown( const bool on )
251 QtxActionMenuMgr* mMgr = menuMgr();
255 bool upd = mMgr->isUpdatesEnabled();
256 mMgr->setUpdatesEnabled( false );
258 QAction* sep = separator();
259 for ( QMap<int, QAction*>::Iterator it = myActionMap.begin(); it != myActionMap.end(); ++it )
261 if ( it.data() != sep )
262 mMgr->setShown( mMgr->actionId( it.data() ), on );
265 mMgr->setUpdatesEnabled( upd );
270 void CAM_Module::setMenuShown( QAction* a, const bool on )
273 menuMgr()->setShown( menuMgr()->actionId( a ), on );
276 void CAM_Module::setMenuShown( const int id, const bool on )
278 setMenuShown( action( id ), on );
281 void CAM_Module::setToolShown( const bool on )
283 QtxActionToolMgr* tMgr = toolMgr();
287 bool upd = tMgr->isUpdatesEnabled();
288 tMgr->setUpdatesEnabled( false );
290 QAction* sep = separator();
291 for ( QMap<int, QAction*>::Iterator it = myActionMap.begin(); it != myActionMap.end(); ++it )
293 if ( it.data() != sep )
294 tMgr->setShown( tMgr->actionId( it.data() ), on );
297 tMgr->setUpdatesEnabled( upd );
302 void CAM_Module::setToolShown( QAction* a, const bool on )
305 toolMgr()->setShown( toolMgr()->actionId( a ), on );
308 void CAM_Module::setToolShown( const int id, const bool on )
310 setToolShown( action( id ), on );
313 QAction* CAM_Module::action( const int id ) const
316 if ( myActionMap.contains( id ) )
321 int CAM_Module::actionId( const QAction* a ) const
324 for ( QMap<int, QAction*>::ConstIterator it = myActionMap.begin(); it != myActionMap.end() && id == -1; ++it )
326 if ( it.data() == a )
332 QAction* CAM_Module::createAction( const int id, const QString& text, const QIconSet& icon,
333 const QString& menu, const QString& tip, const int key,
334 QObject* parent, const bool toggle, QObject* reciever, const char* member )
336 QtxAction* a = new QtxAction( text, icon, menu, key, parent, 0, toggle );
337 a->setStatusTip( tip );
339 if ( reciever && member )
340 connect( a, SIGNAL( activated() ), reciever, member );
342 registerAction( id, a );
347 int CAM_Module::registerAction( const int id, QAction* a )
350 for ( QMap<int, QAction*>::ConstIterator it = myActionMap.begin(); it != myActionMap.end() && ident == -1; ++it )
351 if ( it.data() == a )
357 static int generatedId = -1;
358 ident = id < 0 ? --generatedId : id;
360 myActionMap.insert( id, a );
363 menuMgr()->registerAction( a );
366 toolMgr()->registerAction( a );
371 QAction* CAM_Module::separator()
373 return QtxActionMgr::separator();