From cfcbe62885f89313a14b5960c8f959dbcdaaa20e Mon Sep 17 00:00:00 2001 From: san Date: Wed, 16 Nov 2011 16:05:37 +0000 Subject: [PATCH] PPGP issue #5: Cannot save study after modification of PPGP module SalomePyQt API extended with two methods isModified() and setModified(). These methods allows light Python modules to control modification status of the C++ data model class according to the actual state of Python data. --- .../SALOME_PYQT_DataModelLight.cxx | 23 +++--- .../SALOME_PYQT_DataModelLight.h | 3 +- src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx | 71 +++++++++++++++++++ src/SALOME_PYQT/SalomePyQt/SalomePyQt.h | 3 + src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip | 5 +- 5 files changed, 95 insertions(+), 10 deletions(-) diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_DataModelLight.cxx b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_DataModelLight.cxx index 2fc1d07c5..837029613 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_DataModelLight.cxx +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_DataModelLight.cxx @@ -40,7 +40,8 @@ SALOME_PYQT_DataModelLight::SALOME_PYQT_DataModelLight(CAM_Module * theModule) : LightApp_DataModel( theModule ), myFileName( "" ), - myStudyURL( "" ) + myStudyURL( "" ), + myModified( false ) { } @@ -66,6 +67,8 @@ bool SALOME_PYQT_DataModelLight::open( const QString& theURL, CAM_Study* study, return false; LightApp_DataModel::open( theURL, aDoc, theListOfFiles ); + + setModified( false ); return aModule->open(theListOfFiles); @@ -93,6 +96,9 @@ bool SALOME_PYQT_DataModelLight::save( QStringList& theListOfFiles) theListOfFiles.append(QString(aTmpDir.c_str())); int listSize = theListOfFiles.size(); aModule->save(theListOfFiles); + + setModified( false ); + //Return true if in the List of files was added item(s) //else return false return theListOfFiles.size() > listSize; @@ -148,23 +154,24 @@ bool SALOME_PYQT_DataModelLight::dumpPython( const QString& theURL, //================================================================================= // function : isModified() -// purpose : default implementation, always returns false so as not to mask study's isModified() +// purpose : returns this model's modification status that can be controlled +// with help of setModified() calls by the underlying Python module //================================================================================= bool SALOME_PYQT_DataModelLight::isModified() const { - return false; + return myModified; } //================================================================================= -// function : isSaved() -// purpose : default implementation, always returns true so as not to mask study's isSaved() +// function : setModified() +// purpose : sets the model's modification status, should be used by +// the underlying Python module when its data changes. //================================================================================= -bool SALOME_PYQT_DataModelLight::isSaved() const +void SALOME_PYQT_DataModelLight::setModified( bool flag ) { - return true; + myModified = flag; } - //================================================================================= // function : close() // purpose : Close data model operation diff --git a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_DataModelLight.h b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_DataModelLight.h index 6f604cdc3..6a9e35391 100644 --- a/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_DataModelLight.h +++ b/src/SALOME_PYQT/SALOME_PYQT_GUILight/SALOME_PYQT_DataModelLight.h @@ -52,7 +52,7 @@ public: QStringList& ); virtual bool isModified () const; - virtual bool isSaved () const; + void setModified( bool ); virtual void update ( LightApp_DataObject* = 0, LightApp_Study* = 0 ); @@ -61,6 +61,7 @@ public: private: QString myFileName; QString myStudyURL; + bool myModified; }; #endif // SALOME_PYQT_DATAMODELLIGHT_H diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx index 3385b7245..632f4713d 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx @@ -32,6 +32,7 @@ #endif #include // this include must be first!!! +#include #include "SalomePyQt.h" #include @@ -612,6 +613,76 @@ void SalomePyQt::updateObjBrowser( const int studyId, bool updateSelection ) ProcessVoidEvent( new TEvent( studyId, updateSelection ) ); } + +/*! + SalomePyQt::isModified() + \return The modification status of the data model + for the currently active Python module + \sa setModified() +*/ +class TIsModifiedEvent: public SALOME_Event +{ +public: + typedef bool TResult; + TResult myResult; + TIsModifiedEvent() : myResult( false ) {} + virtual void Execute() + { + SALOME_PYQT_ModuleLight* module = getActiveModule(); + if ( !module ) + return; + + SALOME_PYQT_DataModelLight* aModel = + dynamic_cast( module->dataModel() ); + if ( aModel ) + myResult = aModel->isModified(); + } +}; +bool SalomePyQt::isModified() +{ + return ProcessEvent(new TIsModifiedEvent()); +} + +/*! + SalomePyQt::setModified() + + Sets the modification status of the data model for + the currently active Python module. This method should be used + by the Python code in order to enable/disable "Save" operation + depending on the module's data state. + + \param New modification status of the data model + + \sa isModified() +*/ +void SalomePyQt::setModified( bool flag ) +{ + class TEvent: public SALOME_Event + { + bool myFlag; + public: + TEvent( bool flag ) + : myFlag( flag ) {} + virtual void Execute() + { + SALOME_PYQT_ModuleLight* module = getActiveModule(); + if ( !module ) + return; + + SALOME_PYQT_DataModelLight* aModel = + dynamic_cast( module->dataModel() ); + LightApp_Application* aLApp = + dynamic_cast( module->application() ); + if ( !aModel || !aLApp ) + return; + + aModel->setModified( myFlag ); + aLApp->updateActions(); + } + }; + ProcessVoidEvent( new TEvent( flag ) ); +} + /*! \brief Default resource file section name. \internal diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h index 52920dee6..2fd65b871 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h @@ -133,6 +133,9 @@ public: static bool activateModule( const QString& ); static void updateObjBrowser( const int = 0, bool = true ); + static bool isModified(); + static void setModified( 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& ); diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip index a8f419999..7c2090b6f 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip @@ -215,7 +215,10 @@ public: static const QString getActiveComponent() /ReleaseGIL/ ; static SIP_PYOBJECT getActivePythonModule() /ReleaseGIL/ ; static bool activateModule( const QString& ) /ReleaseGIL/ ; - static void updateObjBrowser( const int = 0, bool = true ) /ReleaseGIL/ ; + static void updateObjBrowser( const int = 0, bool = true ) /ReleaseGIL/ ; + + static bool isModified() /ReleaseGIL/ ; + static void setModified( bool ) /ReleaseGIL/ ; static QString getFileName ( QWidget*, const QString&, const QStringList&, const QString&, bool ) /ReleaseGIL/ ; static QStringList getOpenFileNames ( QWidget*, const QString&, const QStringList&, const QString& ) /ReleaseGIL/ ; -- 2.39.2