From 172be66403632ce77f5f38c996afab375e0d88e2 Mon Sep 17 00:00:00 2001 From: vsr Date: Tue, 9 Aug 2005 10:19:03 +0000 Subject: [PATCH] 1) Fix a bug of Selection object in PyQt modules - create the only instance of Selection per study; 2) Replace QAction class by QtxAction class throughout (workaround SIP behaviour) --- src/SALOME_PYQT/SalomePyQt/Makefile.in | 3 +- src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx | 111 ++++++++++++------- src/SALOME_PYQT/SalomePyQt/SalomePyQt.h | 27 +++-- src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip | 70 +++++++++--- src/SALOME_PYQT/SalomePyQt/SalomePyQt_v4.sip | 68 ++++++++++-- 5 files changed, 198 insertions(+), 81 deletions(-) diff --git a/src/SALOME_PYQT/SalomePyQt/Makefile.in b/src/SALOME_PYQT/SalomePyQt/Makefile.in index b1be9c4a1..9a55f6413 100644 --- a/src/SALOME_PYQT/SalomePyQt/Makefile.in +++ b/src/SALOME_PYQT/SalomePyQt/Makefile.in @@ -27,7 +27,8 @@ endif SIP_FLAGS = -t WS_X11 -t $(QT_VERS) -s ".cc" -c . -I $(PYQT_SIPS) # Sip common sources SIP_SRC = sipSalomePyQtSalomePyQt.cc \ - sipSalomePyQtSALOME_Selection.cc + sipSalomePyQtSALOME_Selection.cc \ + sipSalomePyQtQtxAction.cc # Sip version-specific sources ifeq ($(SIP_VERS),v4_old) diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx index 87fdbb714..e01efbd3d 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx @@ -14,7 +14,6 @@ #include #include #include -#include #include #include "SALOME_Event.hxx" @@ -28,6 +27,7 @@ #include "SalomeApp_Study.h" #include "SalomeApp_SelectionMgr.h" #include "OB_Browser.h" +#include "QtxAction.h" using namespace std; @@ -58,18 +58,45 @@ static SalomeApp_Study* getActiveStudy() //==================================================================================== // SALOME_Selection class. //==================================================================================== +static QMap SelMap; + +/*! + SALOME_Selection::GetSelection + Creates or finds the selection object (one per study). +*/ +SALOME_Selection* SALOME_Selection::GetSelection( SalomeApp_Application* app ) +{ + SALOME_Selection* sel = 0; + if ( app && SelMap.find( app ) != SelMap.end() ) + sel = SelMap[ app ]; + else + sel = SelMap[ app ] = new SALOME_Selection( app ); + return sel; +} + /*! SALOME_Selection::SALOME_Selection - Selection constructor. Gets an instance of selection manager. + Selection constructor. */ -SALOME_Selection::SALOME_Selection() : mySelMgr( 0 ) +SALOME_Selection::SALOME_Selection( QObject* p ) : QObject( p ), mySelMgr( 0 ) { - if ( SalomeApp_Application* anApp = getApplication() ) { - mySelMgr = anApp->selectionMgr(); + SalomeApp_Application* app = dynamic_cast( p ); + if ( app ) { + mySelMgr = app->selectionMgr(); connect( mySelMgr, SIGNAL( selectionChanged() ), this, SIGNAL( currentSelectionChanged() ) ); connect( mySelMgr, SIGNAL( destroyed() ), this, SLOT ( onSelMgrDestroyed() ) ); } } +/*! + SALOME_Selection::~SALOME_Selection + Selection destructor. Removes selection object from the map. +*/ +SALOME_Selection::~SALOME_Selection() +{ + SalomeApp_Application* app = dynamic_cast( parent() ); + if ( app && SelMap.find( app ) != SelMap.end() ) + SelMap.remove( app ); +} /*! SALOME_Selection::onSelMgrDestroyed @@ -266,7 +293,7 @@ public: TResult myResult; TGetSelectionEvent() : myResult( 0 ) {} virtual void Execute() { - myResult = new SALOME_Selection(); + myResult = SALOME_Selection::GetSelection( getApplication() ); } }; SALOME_Selection* SalomePyQt::getSelection() @@ -912,9 +939,9 @@ public: : myCase( 1 ), myId( id ), myTbId( tBar ), myIndex( idx ) {} CrTool( const int id, const QString& tBar, const int idx ) : myCase( 2 ), myId( id ), myTbName( tBar ), myIndex( idx ) {} - CrTool( QAction* action, const int tbId, const int id, const int idx ) + CrTool( QtxAction* action, const int tbId, const int id, const int idx ) : myCase( 3 ), myAction( action ), myTbId( tbId ), myId( id ), myIndex( idx ) {} - CrTool( QAction* action, const QString& tBar, const int id, const int idx ) + CrTool( QtxAction* action, const QString& tBar, const int id, const int idx ) : myCase( 4 ), myAction( action ), myTbName( tBar ), myId( id ), myIndex( idx ) {} int execute( SALOME_PYQT_Module* module ) const @@ -936,12 +963,12 @@ public: return -1; } private: - int myCase; - QString myTbName; - int myTbId; - QAction* myAction; - int myId; - int myIndex; + int myCase; + QString myTbName; + int myTbId; + QtxAction* myAction; + int myId; + int myIndex; }; class TCreateToolEvent: public SALOME_Event { public: @@ -975,12 +1002,12 @@ int SalomePyQt::createTool( const int id, const QString& tBar, const int idx ) return ProcessEvent( new TCreateToolEvent( CrTool( id, tBar, idx ) ) ); } // add action with id and index to the existing tollbar -int SalomePyQt::createTool( QAction* a, const int tBar, const int id, const int idx ) +int SalomePyQt::createTool( QtxAction* a, const int tBar, const int id, const int idx ) { return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) ); } // add action with id and index to the existing tollbar -int SalomePyQt::createTool( QAction* a, const QString& tBar, const int id, const int idx ) +int SalomePyQt::createTool( QtxAction* a, const QString& tBar, const int id, const int idx ) { return ProcessEvent( new TCreateToolEvent( CrTool( a, tBar, id, idx ) ) ); } @@ -1007,9 +1034,9 @@ public: : myCase( 2 ), myId( id ), myMenuId( menu ), myGroup( group ), myIndex( idx ) {} CrMenu( const int id, const QString& menu, const int group, const int idx ) : myCase( 3 ), myId( id ), myMenuName( menu ), myGroup( group ), myIndex( idx ) {} - CrMenu( QAction* action, const int menu, const int id, const int group, const int idx ) + CrMenu( QtxAction* action, const int menu, const int id, const int group, const int idx ) : myCase( 4 ), myAction( action ), myMenuId( menu ), myId( id ), myGroup( group ), myIndex( idx ) {} - CrMenu( QAction* action, const QString& menu, const int id, const int group, const int idx ) + CrMenu( QtxAction* action, const QString& menu, const int id, const int group, const int idx ) : myCase( 5 ), myAction( action ), myMenuName( menu ), myId( id ), myGroup( group ), myIndex( idx ) {} int execute( SALOME_PYQT_Module* module ) const @@ -1033,14 +1060,14 @@ public: return -1; } private: - int myCase; - QString myMenuName; - int myMenuId; - QString mySubMenuName; - int myGroup; - QAction* myAction; - int myId; - int myIndex; + int myCase; + QString myMenuName; + int myMenuId; + QString mySubMenuName; + int myGroup; + QtxAction* myAction; + int myId; + int myIndex; }; class TCreateMenuEvent: public SALOME_Event { public: @@ -1078,12 +1105,12 @@ int SalomePyQt::createMenu( const int id, const QString& menu, const int group, return ProcessEvent( new TCreateMenuEvent( CrMenu( id, menu, group, idx ) ) ); } -int SalomePyQt::createMenu( QAction* a, const int menu, const int id, const int group, const int idx ) +int SalomePyQt::createMenu( QtxAction* a, const int menu, const int id, const int group, const int idx ) { return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) ); } -int SalomePyQt::createMenu( QAction* a, const QString& menu, const int id, const int group, const int idx ) +int SalomePyQt::createMenu( QtxAction* a, const QString& menu, const int id, const int group, const int idx ) { return ProcessEvent( new TCreateMenuEvent( CrMenu( a, menu, id, group, idx ) ) ); } @@ -1094,7 +1121,7 @@ int SalomePyQt::createMenu( QAction* a, const QString& menu, const int id, const */ class TCreateSepEvent: public SALOME_Event { public: - typedef QAction* TResult; + typedef QtxAction* TResult; TResult myResult; TCreateSepEvent() : myResult( 0 ) {} @@ -1104,11 +1131,11 @@ public: if ( !module ) module = dynamic_cast( anApp->activeModule() ); if ( module ) - myResult = module->createSeparator(); + myResult = (QtxAction*)module->createSeparator(); } } }; -QAction* SalomePyQt::createSeparator() +QtxAction* SalomePyQt::createSeparator() { return ProcessEvent( new TCreateSepEvent() ); } @@ -1126,7 +1153,7 @@ QAction* SalomePyQt::createSeparator() */ class TCreateActionEvent: public SALOME_Event { public: - typedef QAction* TResult; + typedef QtxAction* TResult; TResult myResult; int myId; QString myMenuText; @@ -1145,13 +1172,13 @@ public: if ( !module ) module = dynamic_cast( anApp->activeModule() ); if ( module ) - myResult = module->createAction( myId, myTipText, myIcon, myMenuText, myStatusText, myKey, myToggle ); + myResult = (QtxAction*)module->createAction( myId, myTipText, myIcon, myMenuText, myStatusText, myKey, myToggle ); } } }; -QAction* SalomePyQt::createAction( const int id, const QString& menuText, - const QString& tipText, const QString& statusText, - const QString& icon, const int key, const bool toggle ) +QtxAction* SalomePyQt::createAction( const int id, const QString& menuText, + const QString& tipText, const QString& statusText, + const QString& icon, const int key, const bool toggle ) { return ProcessEvent( new TCreateActionEvent( id, menuText, tipText, statusText, icon, key, toggle ) ); } @@ -1162,7 +1189,7 @@ QAction* SalomePyQt::createAction( const int id, const QString& menuTe */ class TActionEvent: public SALOME_Event { public: - typedef QAction* TResult; + typedef QtxAction* TResult; TResult myResult; int myId; TActionEvent( const int id ) @@ -1173,11 +1200,11 @@ public: if ( !module ) module = dynamic_cast( anApp->activeModule() ); if ( module ) - myResult = module->action( myId ); + myResult = (QtxAction*)module->action( myId ); } } }; -QAction* SalomePyQt::action( const int id ) +QtxAction* SalomePyQt::action( const int id ) { return ProcessEvent( new TActionEvent( id ) ); } @@ -1190,8 +1217,8 @@ class TActionIdEvent: public SALOME_Event { public: typedef int TResult; TResult myResult; - const QAction* myAction; - TActionIdEvent( const QAction* action ) + const QtxAction* myAction; + TActionIdEvent( const QtxAction* action ) : myResult( -1 ), myAction( action ) {} virtual void Execute() { if ( SalomeApp_Application* anApp = getApplication() ) { @@ -1203,7 +1230,7 @@ public: } } }; -int SalomePyQt::actionId( const QAction* a ) +int SalomePyQt::actionId( const QtxAction* a ) { return ProcessEvent( new TActionIdEvent( a ) ); } diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h index d15002283..f39dba9bf 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h @@ -15,17 +15,19 @@ #include class SalomeApp_SelectionMgr; -class QAction; +class SalomeApp_Application; class QMenuBar; class QPopupMenu; class QWidget; +class QtxAction; class SALOME_Selection : public QObject { Q_OBJECT public: - SALOME_Selection(); + ~SALOME_Selection(); + static SALOME_Selection* GetSelection( SalomeApp_Application* ); void Clear(); void ClearIObjects(); @@ -39,6 +41,7 @@ private slots: private: SalomeApp_SelectionMgr* mySelMgr; + SALOME_Selection( QObject* ); }; enum MenuName { @@ -73,10 +76,10 @@ public: static bool dumpView( const QString& ); static int createTool( const QString& ); - static int createTool( const int, const int, const int = -1 ); - static int createTool( const int, const QString&, const int = -1 ); - static int createTool( QAction*, const int, const int = -1, const int = -1 ); - static int createTool( QAction*, const QString&, const int = -1, const int = -1 ); + static int createTool( const int, const int, const int = -1 ); + static int createTool( const int, const QString&, const int = -1 ); + static int createTool( QtxAction*, const int, const int = -1, const int = -1 ); + static int createTool( QtxAction*, const QString&, const int = -1, const int = -1 ); static int createMenu( const QString&, const int = -1, const int = -1, const int = -1 ); @@ -86,19 +89,19 @@ public: const int = -1, const int = -1 ); static int createMenu( const int, const QString& = QString::null, const int = -1, const int = -1 ); - static int createMenu( QAction*, const int, const int = -1, + static int createMenu( QtxAction*, const int, const int = -1, const int = -1, const int = -1 ); - static int createMenu( QAction*, const QString&, const int = -1, + static int createMenu( QtxAction*, const QString&, const int = -1, const int = -1, const int = -1 ); - static QAction* createSeparator(); + static QtxAction* createSeparator(); - static QAction* createAction( const int, const QString&, + static QtxAction* createAction( const int, const QString&, const QString& = QString::null, const QString& = QString::null, const QString& = QString::null, const int = 0, const bool = false ); - static QAction* action( const int ); - static int actionId( const QAction* ); + static QtxAction* action( const int ); + static int actionId( const QtxAction* ); static void addSetting ( const QString&, const QString&, const double ); static void addSetting ( const QString&, const QString&, const int ); diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip index 9b4b3ee66..2490c3929 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip @@ -13,18 +13,18 @@ class SALOME_Selection : QObject { - %HeaderCode #include %End public: - SALOME_Selection(); - void Clear(); void ClearIObjects(); void ClearFilters(); +private: + SALOME_Selection( QObject* /TransferThis/ ); + signals: void currentSelectionChanged(); }; @@ -39,9 +39,51 @@ enum MenuName { Help = 7 }; -class SalomePyQt +class QtxAction { +%TypeHeaderCode +#include +%End + +public: + void setIconSet( const QIconSet& ); + QIconSet iconSet() const; + void setText( const QString& ); + QString text() const; + void setMenuText( const QString& ); + QString menuText() const; + void setToolTip( const QString& ); + QString toolTip() const; + void setStatusTip( const QString& ); + QString statusTip() const; + void setWhatsThis( const QString& ); + QString whatsThis() const; + void setAccel( const QKeySequence& ); + QKeySequence accel() const; + void setToggleAction( bool ); + bool isToggleAction() const; + bool isOn() const; + bool isEnabled() const; + bool isVisible() const; + +public slots: + void activate(); + void toggle(); + void setOn( bool ); + void setEnabled( bool ); + void setDisabled( bool ); + void setVisible( bool ); +signals: + void activated(); + void toggled( bool ); + +private: + QtxAction(const QtxAction &); +}; + +class SalomePyQt +{ %HeaderCode #include %End @@ -66,10 +108,10 @@ public: static bool dumpView( const QString& ); static int createTool( const QString& ); - static int createTool( const int, const int, int = -1 ); - static int createTool( const int, const QString&, int = -1 ); - static int createTool( QAction*, const int, int = -1, int = -1 ); - static int createTool( QAction*, const QString&, int = -1, int = -1 ); + static int createTool( const int, const int, int = -1 ); + static int createTool( const int, const QString&, int = -1 ); + static int createTool( QtxAction*, const int, int = -1, int = -1 ); + static int createTool( QtxAction*, const QString&, int = -1, int = -1 ); static int createMenu( const QString&, const int, int = -1, int = -1 ); @@ -79,19 +121,19 @@ public: int = -1, int = -1 ); static int createMenu( const int, const QString&, int = -1, int = -1 ); - static int createMenu( QAction*, const int, int = -1, + static int createMenu( QtxAction*, const int, int = -1, int = -1, int = -1 ); - static int createMenu( QAction*, const QString&, int = -1, + static int createMenu( QtxAction*, const QString&, int = -1, int = -1, int = -1 ); - static QAction* createSeparator(); + static QtxAction* createSeparator(); - static QAction* createAction( const int, const QString&, + static QtxAction* createAction( const int, const QString&, const QString& = QString::null, const QString& = QString::null, const QString& = QString::null, int = 0, bool = false ); - static QAction* action( const int ); - static int actionId( const QAction* ); + static QtxAction* action( const int ); + static int actionId( const QtxAction* ); static void addSetting ( const QString&, const QString&, const double ); static void addSetting ( const QString&, const QString&, const int /Constrained/ ); diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt_v4.sip b/src/SALOME_PYQT/SalomePyQt/SalomePyQt_v4.sip index 4de783e98..a7a43beaf 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt_v4.sip +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt_v4.sip @@ -18,12 +18,13 @@ class SALOME_Selection : QObject %End public: - SALOME_Selection(); - void Clear(); void ClearIObjects(); void ClearFilters(); +private: + SALOME_Selection( QObject* /TransferThis/ ); + signals: void currentSelectionChanged(); }; @@ -38,6 +39,49 @@ enum MenuName { Help = 7 }; +class QtxAction +{ +%TypeHeaderCode +#include +%End + +public: + void setIconSet( const QIconSet& ); + QIconSet iconSet() const; + void setText( const QString& ); + QString text() const; + void setMenuText( const QString& ); + QString menuText() const; + void setToolTip( const QString& ); + QString toolTip() const; + void setStatusTip( const QString& ); + QString statusTip() const; + void setWhatsThis( const QString& ); + QString whatsThis() const; + void setAccel( const QKeySequence& ); + QKeySequence accel() const; + void setToggleAction( bool ); + bool isToggleAction() const; + bool isOn() const; + bool isEnabled() const; + bool isVisible() const; + +public slots: + void activate(); + void toggle(); + void setOn( bool ); + void setEnabled( bool ); + void setDisabled( bool ); + void setVisible( bool ); + +signals: + void activated(); + void toggled( bool ); + +private: + QtxAction(const QtxAction &); +}; + class SalomePyQt { %TypeHeaderCode @@ -64,10 +108,10 @@ public: static bool dumpView( const QString& ); static int createTool( const QString& ); - static int createTool( const int, const int, const int = -1 ); - static int createTool( const int, const QString&, const int = -1 ); - static int createTool( QAction*, const int, const int = -1, const int = -1 ); - static int createTool( QAction*, const QString&, const int = -1, const int = -1 ); + static int createTool( const int, const int, const int = -1 ); + static int createTool( const int, const QString&, const int = -1 ); + static int createTool( QtxAction*, const int, const int = -1, const int = -1 ); + static int createTool( QtxAction*, const QString&, const int = -1, const int = -1 ); static int createMenu( const QString&, const int, const int = -1, const int = -1 ); @@ -77,19 +121,19 @@ public: const int = -1, const int = -1 ); static int createMenu( const int, const QString&, const int = -1, const int = -1 ); - static int createMenu( QAction*, const int, const int = -1, + static int createMenu( QtxAction*, const int, const int = -1, const int = -1, const int = -1 ); - static int createMenu( QAction*, const QString&, const int = -1, + static int createMenu( QtxAction*, const QString&, const int = -1, const int = -1, const int = -1 ); - static QAction* createSeparator(); + static QtxAction* createSeparator(); - static QAction* createAction( const int, const QString&, + static QtxAction* createAction( const int, const QString&, const QString& = QString::null, const QString& = QString::null, const QString& = QString::null, const int = 0, const bool = false ); - static QAction* action( const int ); - static int actionId( const QAction* ); + static QtxAction* action( const int ); + static int actionId( const QtxAction* ); static void addSetting ( const QString&, const QString&, const double ); static void addSetting ( const QString&, const QString&, const int /Constrained/ ); -- 2.39.2