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::SALOME_PYQT_DataModelLight(CAM_Module * theModule)
: LightApp_DataModel( theModule ),
myFileName( "" ),
- myStudyURL( "" )
+ myStudyURL( "" ),
+ myModified( false )
{
}
return false;
LightApp_DataModel::open( theURL, aDoc, theListOfFiles );
+
+ setModified( false );
return aModule->open(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;
//=================================================================================
// 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
QStringList& );
virtual bool isModified () const;
- virtual bool isSaved () const;
+ void setModified( bool );
virtual void update ( LightApp_DataObject* = 0, LightApp_Study* = 0 );
private:
QString myFileName;
QString myStudyURL;
+ bool myModified;
};
#endif // SALOME_PYQT_DATAMODELLIGHT_H
#endif
#include <SALOME_PYQT_ModuleLight.h> // this include must be first!!!
+#include <SALOME_PYQT_DataModelLight.h>
#include "SalomePyQt.h"
#include <QApplication>
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<SALOME_PYQT_DataModelLight*>( 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<SALOME_PYQT_DataModelLight*>( module->dataModel() );
+ LightApp_Application* aLApp =
+ dynamic_cast<LightApp_Application*>( module->application() );
+ if ( !aModel || !aLApp )
+ return;
+
+ aModel->setModified( myFlag );
+ aLApp->updateActions();
+ }
+ };
+ ProcessVoidEvent( new TEvent( flag ) );
+}
+
/*!
\brief Default resource file section name.
\internal
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& );
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/ ;