Salome HOME
1) Fix a bug of Selection object in PyQt modules - create the only instance of Select...
authorvsr <vsr@opencascade.com>
Tue, 9 Aug 2005 10:19:03 +0000 (10:19 +0000)
committervsr <vsr@opencascade.com>
Tue, 9 Aug 2005 10:19:03 +0000 (10:19 +0000)
2) Replace QAction class by QtxAction class throughout (workaround SIP behaviour)

src/SALOME_PYQT/SalomePyQt/Makefile.in
src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx
src/SALOME_PYQT/SalomePyQt/SalomePyQt.h
src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip
src/SALOME_PYQT/SalomePyQt/SalomePyQt_v4.sip

index b1be9c4a1a3f2563455a39f7405fc2f1166df666..9a55f64137006743c8c5aa6f7f035d8fa13ec4fe 100644 (file)
@@ -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)
index 87fdbb7143ebe512fc32fd4445a8d879b0e4d04c..e01efbd3d205ff89f497ff16c90383c66486cb4c 100644 (file)
@@ -14,7 +14,6 @@
 #include <qmenubar.h>
 #include <qwidget.h>
 #include <qpopupmenu.h>
-#include <qaction.h>
 #include <qstringlist.h>
 
 #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<SalomeApp_Application*, SALOME_Selection*> 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<SalomeApp_Application*>( 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<SalomeApp_Application*>( 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<SALOME_PYQT_Module*>( 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<SALOME_PYQT_Module*>( 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<SALOME_PYQT_Module*>( 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 ) );
 }
index d15002283dc9ef931554d544938ca9da1a8217b3..f39dba9bfb2eebb4cdcc726f09f734697455f245 100644 (file)
 #include <qcolor.h>
 
 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 );
index 9b4b3ee6663f214ed40f0afc99570822b83aedbd..2490c3929ae185741aaf38ed64f56c016ad78edc 100644 (file)
 
 class SALOME_Selection : QObject
 {
-
 %HeaderCode
 #include <SalomePyQt.h>
 %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 <QtxAction.h>
+%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 <SalomePyQt.h>
 %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/ );
index 4de783e98e243f84265ef40088b437204aac2818..a7a43beaff64d04efbe4919b74d1b3050b3ee625 100644 (file)
@@ -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 <QtxAction.h>
+%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/ );