From: stv Date: Fri, 18 Nov 2011 10:08:51 +0000 (+0000) Subject: Activation of signal "moduleActivated()" performs via custom event in ModuleAction... X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=7abdd849dce3734fe11bb95ebcd60a6491b77644;p=modules%2Fgui.git Activation of signal "moduleActivated()" performs via custom event in ModuleAction. This allow to perform safe ModuleAction combobox deletion (not in slot connected to activation signal of combobox). This deletion occurs during changing active module if module use QApplication::processEvents() (force threat DeferredDelete event) in activation/deactivation procedures. --- diff --git a/src/LightApp/LightApp_ModuleAction.cxx b/src/LightApp/LightApp_ModuleAction.cxx index 584496a58..14b633dcc 100755 --- a/src/LightApp/LightApp_ModuleAction.cxx +++ b/src/LightApp/LightApp_ModuleAction.cxx @@ -24,7 +24,11 @@ #include #include -#include + +#include +#include + +#include /*! \class LightApp_ModuleAction::ActionSet @@ -181,6 +185,23 @@ QWidget* LightApp_ModuleAction::ComboAction::createWidget( QWidget* parent ) \param item identifier */ +/*! + \class LightApp_ModuleAction::ActivateEvent + \brief Internal class to represent custom event for transfer the activation item id. + \internal +*/ +class LightApp_ModuleAction::ActivateEvent : public QEvent +{ +public: + ActivateEvent( QEvent::Type type, int id ) : QEvent( type ), myId( id ) {}; + ~ActivateEvent() {}; + + int id() const { return myId; } + +private: + int myId; +}; + /*! \class LightApp_ModuleAction \brief An action, representing the list of modules to be inserted to the @@ -413,6 +434,19 @@ void LightApp_ModuleAction::removedFrom( QWidget* w ) w->removeAction( mySet ); } +/*! + \brief Perform delayed activation with specified id. + \param e custom event + \return \c true if the event was processed successfully and \c false otherwise. +*/ +bool LightApp_ModuleAction::event( QEvent* e ) +{ + if ( e->type() == QEvent::MaxUser ) + activate( ((ActivateEvent*)e)->id(), false ); + else + return QtxAction::event( e ); +} + /*! \fn void LightApp_ModuleAction::moduleActivated( const QString& name ); \brief Emitted when the module is activated @@ -568,5 +602,5 @@ void LightApp_ModuleAction::onChanged() */ void LightApp_ModuleAction::onComboActivated( int id ) { - activate( id, false ); + QApplication::postEvent( this, new ActivateEvent( QEvent::MaxUser, id ) ); } diff --git a/src/LightApp/LightApp_ModuleAction.h b/src/LightApp/LightApp_ModuleAction.h index 47c4a85ae..56f2efa97 100755 --- a/src/LightApp/LightApp_ModuleAction.h +++ b/src/LightApp/LightApp_ModuleAction.h @@ -40,6 +40,7 @@ class LIGHTAPP_EXPORT LightApp_ModuleAction : public QtxAction private: class ActionSet; class ComboAction; + class ActivateEvent; public: enum { None = 0x00, Buttons = 0x01, ComboItem = 0x02, All = Buttons | ComboItem }; @@ -67,7 +68,9 @@ protected: virtual void addedTo( QWidget* ); virtual void removedFrom( QWidget* ); -signals: + virtual bool event( QEvent* ); + +Q_SIGNALS: void moduleActivated( const QString& ); private: @@ -99,11 +102,11 @@ public: QList widgets() const; +Q_SIGNALS: + void activatedId( int ); + protected: virtual QWidget* createWidget( QWidget* ); - -signals: - void activatedId( int ); }; #endif // LIGHTAPP_MODULEACTION_H