From: vsr Date: Tue, 17 Jan 2006 16:34:32 +0000 (+0000) Subject: Fix a bug : in Python modules which connect directly to the selection by SalomePyQt... X-Git-Tag: T2_2_9pre~10 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=953d639a6ee67d0f2536d7fb54fcff1653b43619;p=modules%2Fkernel.git Fix a bug : in Python modules which connect directly to the selection by SalomePyQt::getSelection() method, selection is lost after saving of the study (because selection object is recreated in this case). --- diff --git a/src/SALOMEGUI/QAD_Study.cxx b/src/SALOMEGUI/QAD_Study.cxx index 370df0689..e811a535d 100644 --- a/src/SALOMEGUI/QAD_Study.cxx +++ b/src/SALOMEGUI/QAD_Study.cxx @@ -1333,6 +1333,8 @@ void QAD_Study::Selection( QString aSelection ) SALOME_Selection* Sel = SALOME_Selection::Selection( QString(myTitle + "_" + aSelection) ); mySelection = aSelection; + + emit selectionModified( this ); } /*! diff --git a/src/SALOMEGUI/QAD_Study.h b/src/SALOMEGUI/QAD_Study.h index 409b2aba4..3e5ef37b0 100644 --- a/src/SALOMEGUI/QAD_Study.h +++ b/src/SALOMEGUI/QAD_Study.h @@ -162,6 +162,7 @@ signals: void docOperationTerminated( bool ); void closed(); void supervStudyFrameClosing( QAD_ViewFrame* ); + void selectionModified( QAD_Study* ); public slots: void onStudyFrameActivated( QAD_StudyFrame* ); diff --git a/src/SALOME_PYQT/Makefile.in b/src/SALOME_PYQT/Makefile.in index 74bbf6d53..1310f9493 100644 --- a/src/SALOME_PYQT/Makefile.in +++ b/src/SALOME_PYQT/Makefile.in @@ -27,7 +27,7 @@ endif SIP_FLAGS = -t WS_X11 -t $(QT_VERS) $(PYQT_SIPFLAGS) -s ".cc" -c . -I $(PYQT_SIPS) # Sip common sources SIP_SRC = sipSalomePyQtSalomePyQt.cc \ - sipSalomePyQtSALOME_Selection.cc + sipSalomePyQtSalomePyQt_Selection.cc # Sip version-specific sources ifeq ($(SIP_VERS),v4_old) @@ -97,7 +97,8 @@ LIB_SRC = SalomePyQt.cxx \ $(MOC_SRC) # Library moc sources -LIB_MOC = SALOME_PYQT_GUI.h +LIB_MOC = SALOME_PYQT_GUI.h \ + SalomePyQt.h # Client IDL LIB_CLIENT_IDL = SALOME_Exception.idl SALOME_GenericObj.idl diff --git a/src/SALOME_PYQT/SalomePyQt.cxx b/src/SALOME_PYQT/SalomePyQt.cxx index 863616548..1c97c3c23 100644 --- a/src/SALOME_PYQT/SalomePyQt.cxx +++ b/src/SALOME_PYQT/SalomePyQt.cxx @@ -5,7 +5,7 @@ // File : SalomePyQt.cxx // Module : SALOME -#include "SalomePyQt.hxx" +#include "SalomePyQt.h" #include #include @@ -21,6 +21,118 @@ #include "QAD_Config.h" #include "QAD_Settings.h" +//==================================================================================== +// SalomePyQt_Selection class. +//==================================================================================== +static QMap SelMap; + +/*! + SalomePyQt_Selection::GetSelection + Creates or finds the selection object (one per study). +*/ +SalomePyQt_Selection* SalomePyQt_Selection::GetSelection( QAD_Study* study ) +{ + SalomePyQt_Selection* sel = 0; + if ( study && SelMap.find( study ) != SelMap.end() ) + sel = SelMap[ study ]; + else + sel = SelMap[ study ] = new SalomePyQt_Selection( study ); + return sel; +} + +/*! + SalomePyQt_Selection::SalomePyQt_Selection + Selection constructor. +*/ +SalomePyQt_Selection::SalomePyQt_Selection( QObject* p ) : + QObject( p ), myStudy( 0 ), mySelection( 0 ) +{ + myStudy = dynamic_cast( p ); + if ( myStudy ) { + mySelection = SALOME_Selection::Selection( myStudy->getSelection() ); + if ( mySelection ) { + connect( mySelection, SIGNAL( currentSelectionChanged() ), + this, SIGNAL( currentSelectionChanged() ) ); + connect( mySelection, SIGNAL( destroyed() ), + this, SLOT ( onSelectionDestroyed() ) ); + connect( myStudy, SIGNAL( selectionModified( QAD_Study* ) ), + this, SLOT ( onSelectionModified() ) ); + } + } +} +/*! + SalomePyQt_Selection::~SalomePyQt_Selection + Selection destructor. Removes selection object from the map. +*/ +SalomePyQt_Selection::~SalomePyQt_Selection() +{ + if ( myStudy && SelMap.find( myStudy ) != SelMap.end() ) + SelMap.remove( myStudy ); +} + +/*! + SalomePyQt_Selection::onSelectionDestroyed + Watches for the selection destroying (e.g. when study is closed). +*/ +void SalomePyQt_Selection::onSelectionDestroyed() +{ + mySelection = 0; +} + +/*! + SalomePyQt_Selection::onSelectionModified + Updates and reconnect selection when it is changed (e.g. when study is saved). +*/ +void SalomePyQt_Selection::onSelectionModified() +{ + if ( mySelection ) { + disconnect( mySelection, SIGNAL( currentSelectionChanged() ), + this, SIGNAL( currentSelectionChanged() ) ); + disconnect( mySelection, SIGNAL( destroyed() ), + this, SLOT ( onSelectionDestroyed() ) ); + } + + mySelection = myStudy ? SALOME_Selection::Selection( myStudy->getSelection() ) : 0; + + if ( mySelection ) { + connect( mySelection, SIGNAL( currentSelectionChanged() ), + this, SIGNAL( currentSelectionChanged() ) ); + connect( mySelection, SIGNAL( destroyed() ), + this, SLOT ( onSelectionDestroyed() ) ); + } +} + +/*! + SalomePyQt_Selection::Clear + Clears the selection. +*/ +void SalomePyQt_Selection::Clear() +{ + if ( mySelection ) mySelection->Clear(); +} + +/*! + SalomePyQt_Selection::ClearIObjects + Clears the selection and emits the signal. +*/ +void SalomePyQt_Selection::ClearIObjects() +{ + if ( mySelection ) mySelection->ClearIObjects(); +} + +/*! + SalomePyQt_Selection::ClearFilters + Removes all selection filters. +*/ +void SalomePyQt_Selection::ClearFilters() +{ + if ( mySelection ) mySelection->ClearFilters(); +} + +//==================================================================================== +// SalomePyQt class +//==================================================================================== + using namespace std; QWidget* SalomePyQt::getDesktop() @@ -43,9 +155,9 @@ int SalomePyQt::getStudyId() return QAD_Application::getDesktop()->getActiveApp()->getActiveStudy()->getStudyId(); } -SALOME_Selection* SalomePyQt::getSelection() +SalomePyQt_Selection* SalomePyQt::getSelection() { - return SALOME_Selection::Selection(QAD_Application::getDesktop()->getActiveApp()->getActiveStudy()->getSelection()); + return SalomePyQt_Selection::GetSelection(QAD_Application::getDesktop()->getActiveApp()->getActiveStudy()); } void SalomePyQt::putInfo( const QString& msg ) diff --git a/src/SALOME_PYQT/SalomePyQt.h b/src/SALOME_PYQT/SalomePyQt.h new file mode 100644 index 000000000..05f160a55 --- /dev/null +++ b/src/SALOME_PYQT/SalomePyQt.h @@ -0,0 +1,92 @@ +// Copyright (C) 2003 CEA/DEN, EDF R&D +// +// +// +// File : SalomePyQt.h +// Module : SALOME + +#ifndef _SALOME_PYQT_H +#define _SALOME_PYQT_H + +#include +#include +#include +#include + +class QAD_Study; +class SALOME_Selection; +class SalomePyQt_Selection : public QObject +{ + Q_OBJECT + +public: + ~SalomePyQt_Selection(); + static SalomePyQt_Selection* GetSelection( QAD_Study* ); + + void Clear(); + void ClearIObjects(); + void ClearFilters(); + +signals: + void currentSelectionChanged(); + +private slots: + void onSelectionDestroyed(); + void onSelectionModified(); + +private: + QAD_Study* myStudy; + SALOME_Selection* mySelection; + + SalomePyQt_Selection( QObject* ); +}; + +enum MenuName { + File = 1, + View = 2, + Edit = 3, + Preferences = 4, + Tools = 5, + Window = 6, + Help = 7 +}; + +class SalomePyQt +{ +public: + static QWidget* getDesktop(); + static QWorkspace* getMainFrame(); + static QMenuBar* getMainMenuBar(); + static QPopupMenu* getPopupMenu( const MenuName menu ); + static SalomePyQt_Selection* getSelection(); + static int getStudyId(); + static void putInfo( const QString& ); + static void putInfo( const QString&, int ); + + static const QString& getActiveComponent(); + + static void updateObjBrowser( int studyId, bool updateSelection); + + static void addStringSetting(QString _name, QString _value, bool _autoValue); + static void addIntSetting(QString _name, int _value, bool _autoValue); + static void addDoubleSetting(QString _name, double _value, bool _autoValue); + static bool removeSettings(QString name); + static QString getSetting(QString name); + + static QString getFileName(QWidget* parent, + const QString& initial, + const QStringList& filters, + const QString& caption, + bool open); + static QStringList getOpenFileNames(QWidget* parent, + const QString& initial, + const QStringList& filters, + const QString& caption); + static QString getExistingDirectory(QWidget* parent, + const QString& initial, + const QString& caption); + static void helpContext(const QString& source, const QString& context); + static bool dumpView(const QString& filename); +}; + +#endif diff --git a/src/SALOME_PYQT/SalomePyQt.hxx b/src/SALOME_PYQT/SalomePyQt.hxx deleted file mode 100644 index 91c369aff..000000000 --- a/src/SALOME_PYQT/SalomePyQt.hxx +++ /dev/null @@ -1,66 +0,0 @@ -// Copyright (C) 2003 CEA/DEN, EDF R&D -// -// -// -// File : SalomePyQt.hxx -// Module : SALOME - -#ifndef _SALOME_PYQT_H -#define _SALOME_PYQT_H - -#include - -#include -#include -#include -#include - -enum MenuName { - File = 1, - View = 2, - Edit = 3, - Preferences = 4, - Tools = 5, - Window = 6, - Help = 7 -}; - -class SalomePyQt -{ -public: - static QWidget* getDesktop(); - static QWorkspace* getMainFrame(); - static QMenuBar* getMainMenuBar(); - static QPopupMenu* getPopupMenu( const MenuName menu ); - static SALOME_Selection* getSelection(); - static int getStudyId(); - static void putInfo( const QString& ); - static void putInfo( const QString&, int ); - - static const QString& getActiveComponent(); - - static void updateObjBrowser( int studyId, bool updateSelection); - - static void addStringSetting(QString _name, QString _value, bool _autoValue); - static void addIntSetting(QString _name, int _value, bool _autoValue); - static void addDoubleSetting(QString _name, double _value, bool _autoValue); - static bool removeSettings(QString name); - static QString getSetting(QString name); - - static QString getFileName(QWidget* parent, - const QString& initial, - const QStringList& filters, - const QString& caption, - bool open); - static QStringList getOpenFileNames(QWidget* parent, - const QString& initial, - const QStringList& filters, - const QString& caption); - static QString getExistingDirectory(QWidget* parent, - const QString& initial, - const QString& caption); - static void helpContext(const QString& source, const QString& context); - static bool dumpView(const QString& filename); -}; - -#endif diff --git a/src/SALOME_PYQT/SalomePyQt.sip b/src/SALOME_PYQT/SalomePyQt.sip index ebfac3e00..3a727bcf2 100644 --- a/src/SALOME_PYQT/SalomePyQt.sip +++ b/src/SALOME_PYQT/SalomePyQt.sip @@ -3,18 +3,20 @@ %Import qtmod.sip -class SALOME_Selection : QObject +class SalomePyQt_Selection : QObject { %HeaderCode -#include +#include %End - public: - SALOME_Selection(const QString &); void Clear(); void ClearIObjects(); + void ClearFilters(); + +private: + SalomePyQt_Selection( QObject* /TransferThis/ ); signals: void currentSelectionChanged(); @@ -34,33 +36,41 @@ class SalomePyQt { %HeaderCode -#include +#include %End public: - static QWidget* getDesktop(); - static QWorkspace* getMainFrame(); - static QMenuBar* getMainMenuBar(); - static QPopupMenu* getPopupMenu( const MenuName ); - static SALOME_Selection* getSelection(); - static int getStudyId(); - static void putInfo( const QString& ); - static void putInfo( const QString&, int ); - - static const QString& getActiveComponent(); - - static void updateObjBrowser( int, bool ); - - - static bool removeSettings(QString); - static QString getSetting(QString); - static void addStringSetting(QString, QString, bool); - static void addIntSetting(QString, int, bool); - static void addDoubleSetting(QString, double, bool); - - static QString getFileName(QWidget*, const QString&, const QStringList&, const QString&, bool); - static QStringList getOpenFileNames(QWidget*, const QString&, const QStringList&, const QString&); - static QString getExistingDirectory(QWidget*, const QString&, const QString&); - static void helpContext(const QString&, const QString&); - static bool dumpView(const QString&); + static QWidget* getDesktop(); + static QWorkspace* getMainFrame(); + static QMenuBar* getMainMenuBar(); + static QPopupMenu* getPopupMenu( const MenuName ); + static SalomePyQt_Selection* getSelection() /Factory/; + static int getStudyId(); + static void putInfo( const QString& ); + static void putInfo( const QString&, int ); + + static const QString& getActiveComponent(); + + static void updateObjBrowser( int, bool ); + + + static bool removeSettings(QString); + static QString getSetting(QString); + static void addStringSetting(QString, QString, bool); + static void addIntSetting(QString, int, bool); + static void addDoubleSetting(QString, double, bool); + + static QString getFileName(QWidget*, + const QString&, + const QStringList&, + const QString&, bool) /ReleaseGIL/; + static QStringList getOpenFileNames(QWidget*, + const QString&, + const QStringList&, + const QString&) /ReleaseGIL/; + static QString getExistingDirectory(QWidget*, + const QString&, + const QString&) /ReleaseGIL/; + static void helpContext(const QString&, const QString&); + static bool dumpView(const QString&); }; diff --git a/src/SALOME_PYQT/SalomePyQt_v4.sip b/src/SALOME_PYQT/SalomePyQt_v4.sip index 69bbcfd13..d747b2d54 100644 --- a/src/SALOME_PYQT/SalomePyQt_v4.sip +++ b/src/SALOME_PYQT/SalomePyQt_v4.sip @@ -2,16 +2,20 @@ %Import qtmod.sip -class SALOME_Selection : QObject + +class SalomePyQt_Selection : QObject { %TypeHeaderCode -#include +#include %End public: - SALOME_Selection(const QString &); void Clear(); void ClearIObjects(); + void ClearFilters(); + +private: + SalomePyQt_Selection( QObject* /TransferThis/ ); signals: void currentSelectionChanged(); @@ -30,33 +34,41 @@ enum MenuName { class SalomePyQt { %TypeHeaderCode -#include +#include %End public: - static QWidget* getDesktop(); - static QWorkspace* getMainFrame(); - static QMenuBar* getMainMenuBar(); - static QPopupMenu* getPopupMenu( const MenuName ); - static SALOME_Selection* getSelection(); - static int getStudyId(); - static void putInfo( const QString& ); - static void putInfo( const QString&, int ); - - static const QString& getActiveComponent(); - - static void updateObjBrowser( int, bool ); - - - static bool removeSettings(QString); - static QString getSetting(QString); - static void addStringSetting(QString, QString, bool); - static void addIntSetting(QString, int, bool); - static void addDoubleSetting(QString, double, bool); - - static QString getFileName(QWidget*, const QString&, const QStringList&, const QString&, bool); - static QStringList getOpenFileNames(QWidget*, const QString&, const QStringList&, const QString&); - static QString getExistingDirectory(QWidget*, const QString&, const QString&); - static void helpContext(const QString&, const QString&); - static bool dumpView(const QString&); + static QWidget* getDesktop(); + static QWorkspace* getMainFrame(); + static QMenuBar* getMainMenuBar(); + static QPopupMenu* getPopupMenu( const MenuName ); + static SalomePyQt_Selection* getSelection() /Factory/; + static int getStudyId(); + static void putInfo( const QString& ); + static void putInfo( const QString&, int ); + + static const QString& getActiveComponent(); + + static void updateObjBrowser( int, bool ); + + + static bool removeSettings(QString); + static QString getSetting(QString); + static void addStringSetting(QString, QString, bool); + static void addIntSetting(QString, int, bool); + static void addDoubleSetting(QString, double, bool); + + static QString getFileName(QWidget*, + const QString&, + const QStringList&, + const QString&, bool) /ReleaseGIL/; + static QStringList getOpenFileNames(QWidget*, + const QString&, + const QStringList&, + const QString&) /ReleaseGIL/; + static QString getExistingDirectory(QWidget*, + const QString&, + const QString&) /ReleaseGIL/; + static void helpContext(const QString&, const QString&); + static bool dumpView(const QString&); };