X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSALOME_PYQT%2FSalomePyQt%2FSalomePyQt.cxx;h=7169cc1b2f862448a1daf93a93f23b4b1099510f;hb=00be77fd72d1e9378e32b88a468ec16bebb9b806;hp=53c3740594586c69b32992a8aeb21678299de29a;hpb=e4ca636fd09c3e9dc4ecb0c210db146d2efc900c;p=modules%2Fgui.git diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx index 53c374059..7169cc1b2 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx @@ -67,8 +67,10 @@ #include #include #include +#include #include + namespace { /*! @@ -329,6 +331,90 @@ void SALOME_Selection::ClearFilters() ProcessVoidEvent( new TEvent( mySelMgr ) ); } +/*! + \class UserDefinedContent + \brief The class represents base class for user defined widget that + can be inserted to the Preferences dialog. +*/ + +/*! + \brief Constructor +*/ +UserDefinedContent::UserDefinedContent() + : QWidget() +{ +} + +/*! + \brief Called from Preferences dialog to store settings to the resource file. +*/ +void UserDefinedContent::store() +{ +} + +/*! + \brief Called from Preferences dialog to restore settings from the resource file. +*/ +void UserDefinedContent::retrieve() +{ +} + +/*! + \class SgPyQtUserDefinedContent + \brief A Wrapper for UserDefinedContent class. + \internal +*/ +class SgPyQtUserDefinedContent: public QtxUserDefinedContent +{ +public: + SgPyQtUserDefinedContent(UserDefinedContent*); + virtual ~SgPyQtUserDefinedContent(); + + void store( QtxResourceMgr*, QtxPreferenceMgr* ); + void retrieve( QtxResourceMgr*, QtxPreferenceMgr* ); + +private: + UserDefinedContent* myContent; +}; + +/*! + \brief Create custom item for Preferences dialog wrapping widget passed from Python. + \internal +*/ +SgPyQtUserDefinedContent::SgPyQtUserDefinedContent(UserDefinedContent* content) + : QtxUserDefinedContent( 0 ), myContent( content ) +{ + QVBoxLayout* l = new QVBoxLayout( this ); + l->setContentsMargins( 0, 0, 0, 0 ); + l->addWidget( myContent ); +} + +/*! + \brief Destructor. + \internal +*/ +SgPyQtUserDefinedContent::~SgPyQtUserDefinedContent() +{ +} + +/*! + \brief Called from Preferences dialog to store settings to the resource file. + \internal +*/ +void SgPyQtUserDefinedContent::store( QtxResourceMgr*, QtxPreferenceMgr* ) +{ + myContent->store(); +} + +/*! + \brief Called from Preferences dialog to restore settings from the resource file. + \internal +*/ +void SgPyQtUserDefinedContent::retrieve( QtxResourceMgr*, QtxPreferenceMgr* ) +{ + myContent->retrieve(); +} + /*! \class SalomePyQt \brief The class provides utility functions which can be used in the Python @@ -512,30 +598,6 @@ QTreeView* SalomePyQt::getObjectBrowser() return ProcessEvent( new TGetObjectBrowserEvent() ); } -/*! - \fn int SalomePyQt::getStudyId(); - \brief Get active study's identifier. - \return active study ID or 0 if there is no active study -*/ - -class TGetStudyIdEvent: public SALOME_Event -{ -public: - typedef int TResult; - TResult myResult; - TGetStudyIdEvent() : myResult( 0 ) {} - virtual void Execute() - { - if ( LightApp_Study* aStudy = getActiveStudy() ) { - myResult = aStudy->id(); - } - } -}; -int SalomePyQt::getStudyId() -{ - return ProcessEvent( new TGetStudyIdEvent() ); -} - /*! \fn SALOME_Selection* SalomePyQt::getSelection(); \brief Get the selection object for the current study. @@ -586,6 +648,50 @@ void SalomePyQt::setSelection( const QStringList& entryList) return ProcessVoidEvent( new TSetSelectionEvent(entryList) ); } +/*! + \fn void SalomePyQt::enableSelector(); + \brief enable PyQt_Selector (on module activation, for instance) +*/ + +class TEnableSelectorEvent: public SALOME_Event +{ +public: + TEnableSelectorEvent() {} + virtual void Execute() + { + SALOME_PYQT_ModuleLight* module = dynamic_cast( getActiveModule() ); + if ( !module ) return; + module->enableSelector(); + } +}; +void SalomePyQt::enableSelector() +{ + return ProcessVoidEvent( new TEnableSelectorEvent() ); +} + + +/*! + \fn void SalomePyQt::disableSelector(); + \brief disable PyQt_Selector (on module activation, for instance) +*/ + +class TdisableSelectorEvent: public SALOME_Event +{ +public: + TdisableSelectorEvent() {} + virtual void Execute() + { + SALOME_PYQT_ModuleLight* module = dynamic_cast( getActiveModule() ); + if ( !module ) return; + module->disableSelector(); + } +}; +void SalomePyQt::disableSelector() +{ + return ProcessVoidEvent( new TdisableSelectorEvent() ); +} + + /*! \fn void SalomePyQt::putInfo( const QString& msg, const int sec ); \brief Put an information message to the current application's @@ -694,37 +800,23 @@ bool SalomePyQt::activateModule( const QString& modName ) } /*! - \brief Update an Object Browser of the specified (by identifier) study. - - If \a studyId <= 0 the active study's object browser is updated. - The \a updateSelection parameter is obsolete and currently is not used. - This parameter will be removed in future, so try to avoid its usage in - your code. - - \brief studyId study identifier - \brief updateSelection update selection flag (not used) - \sa getActiveStudy() + \brief Update an Object Browser of the study. */ -void SalomePyQt::updateObjBrowser( const int studyId, bool updateSelection ) +void SalomePyQt::updateObjBrowser() { class TEvent: public SALOME_Event { - int myStudyId; - bool myUpdateSelection; public: - TEvent( const int studyId, bool updateSelection ) - : myStudyId( studyId ), myUpdateSelection( updateSelection ) {} + TEvent() {} virtual void Execute() { if ( SUIT_Session::session() ) { - if ( getActiveStudy() && myStudyId <= 0 ) - myStudyId = getActiveStudy()->id(); - if ( myStudyId > 0 ) { + if ( getActiveStudy() ) { QList apps = SUIT_Session::session()->applications(); QList::Iterator it; for( it = apps.begin(); it != apps.end(); ++it ) { LightApp_Application* anApp = dynamic_cast( *it ); - if ( anApp && anApp->activeStudy() && anApp->activeStudy()->id() == myStudyId ) { + if ( anApp && anApp->activeStudy() ) { anApp->updateObjectBrowser(); return; } @@ -733,7 +825,7 @@ void SalomePyQt::updateObjBrowser( const int studyId, bool updateSelection ) } } }; - ProcessVoidEvent( new TEvent( studyId, updateSelection ) ); + ProcessVoidEvent( new TEvent() ); } @@ -1268,6 +1360,34 @@ void SalomePyQt::addSetting( const QString& section, const QString& name, const ProcessVoidEvent( new TEvent( section, name, value ) ); } +/*! + \brief Add font setting to the application preferences. + \param section resources file section name + \param name setting name + \param value new setting value +*/ +void SalomePyQt::addSetting( const QString& section, const QString& name, const QFont& value ) +{ + class TEvent: public SALOME_Event + { + QString mySection; + QString myName; + QFont myValue; + public: + TEvent( const QString& section, const QString& name, const QFont& value ) + : mySection( section ), myName( name ), myValue( value ) {} + virtual void Execute() + { + if ( SUIT_Session::session() ) { + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + if ( !mySection.isEmpty() && !myName.isEmpty() ) + resMgr->setValue( mySection, myName, myValue ); + } + } + }; + ProcessVoidEvent( new TEvent( section, name, value ) ); +} + /*! \fn int SalomePyQt::integerSetting( const QString& section, const QString& name, @@ -1444,7 +1564,7 @@ QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, c /*! \fn QByteArray SalomePyQt::byteArraySetting( const QString& section, const QString& name, - const QByteArray def ); + const QByteArray& def ); \brief Get byte array setting from the application preferences. \param section resources file section name \param name setting name @@ -1475,6 +1595,40 @@ QByteArray SalomePyQt::byteArraySetting ( const QString& section, const QString& return ProcessEvent( new TGetByteArraySettingEvent( section, name, def ) ); } +/*! + \fn QByteArray SalomePyQt::fontSetting( const QString& section, + const QString& name, + const QFont& def ); + \brief Get font setting from the application preferences. + \param section resources file section name + \param name setting name + \param def default value which is returned if the setting is not found + \return setting value +*/ + +class TGetFontSettingEvent: public SALOME_Event +{ +public: + typedef QFont TResult; + TResult myResult; + QString mySection; + QString myName; + TResult myDefault; + TGetFontSettingEvent( const QString& section, const QString& name, const QFont& def ) + : mySection( section ), myName( name ), myDefault( def ) {} + virtual void Execute() + { + if ( SUIT_Session::session() ) { + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + myResult = ( !mySection.isEmpty() && !myName.isEmpty() ) ? resMgr->fontValue( mySection, myName, myDefault ) : myDefault; + } + } +}; +QFont SalomePyQt::fontSetting ( const QString& section, const QString& name, const QFont& def ) +{ + return ProcessEvent( new TGetFontSettingEvent( section, name, def ) ); +} + /*! \brief Remove setting from the application preferences. \param section resources file section name @@ -2396,7 +2550,39 @@ void SalomePyQt::setPreferenceProperty( const int id, } } }; - ProcessVoidEvent( new TEvent( id, prop, var) ); + ProcessVoidEvent( new TEvent( id, prop, var ) ); +} + +/*! + \brief Set specific widget as a custom preferences item. + \param id preferences identifier + \param prop preferences property name + \param widget custom widget +*/ +void SalomePyQt::setPreferencePropertyWg( const int id, + const QString& prop, + UserDefinedContent* widget ) +{ + class TEvent: public SALOME_Event + { + int myId; + QString myProp; + UserDefinedContent* myWidget; + public: + TEvent( const int id, const QString& prop, UserDefinedContent* widget ) + : myId( id ), myProp( prop ), myWidget( widget ) {} + virtual void Execute() + { + LightApp_Module* module = getActiveModule(); + if ( module ) { + LightApp_Preferences* pref = module->getApp()->preferences(); + if ( pref ) { + pref->setItemProperty( myProp, (qint64) new SgPyQtUserDefinedContent( myWidget ), myId ); + } + } + } + }; + ProcessVoidEvent( new TEvent( id, prop, widget ) ); } /*!