From: vsr Date: Wed, 1 Nov 2006 14:48:01 +0000 (+0000) Subject: Add methods to set boolean preference X-Git-Tag: V3_2_3pre1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=369dd44f6b8e4225bc60290421203342807d3ef2;p=modules%2Fgui.git Add methods to set boolean preference --- diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx index c415e2bf6..15ee7c264 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx @@ -496,6 +496,35 @@ void SalomePyQt::addDoubleSetting( const QString& name, const double value, bool ProcessVoidEvent( new TEvent( name, value, autoValue ) ); } +/*! + SalomePyQt::addBoolSetting + Adds an boolean setting to the application preferences + parameter is obsolete parameter and currently not used. To be removed lately. + This function is obsolete. Use addSetting() instead. +*/ +void SalomePyQt::addBoolSetting( const QString& name, const bool value, bool autoValue ) +{ + class TEvent: public SALOME_Event { + QString myName; + bool myValue; + bool myAutoValue; + public: + TEvent( const QString& name, const bool value, bool autoValue ) + : myName( name ), myValue( value ), myAutoValue( autoValue ) {} + virtual void Execute() { + if ( SUIT_Session::session() ) { + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + QStringList sl = QStringList::split( ":", myName ); + QString _sec = sl.count() > 1 ? sl[ 0 ].stripWhiteSpace() : QString( DEFAULT_SECTION ); + QString _nam = sl.count() > 1 ? sl[ 1 ].stripWhiteSpace() : sl.count() > 0 ? sl[ 0 ].stripWhiteSpace() : QString( "" ); + if ( !_sec.isEmpty() && !_nam.isEmpty() ) + resMgr->setValue( _sec, _nam, myValue ); + } + } + }; + ProcessVoidEvent( new TEvent( name, value, autoValue ) ); +} + /*! SalomePyQt::removeSettings Removes a setting from the application preferences @@ -602,6 +631,32 @@ void SalomePyQt::addSetting( const QString& section, const QString& name, const ProcessVoidEvent( new TEvent( section, name, value ) ); } +/*! + SalomePyQt::addSetting + Adds a boolean setting to the application preferences + (note: the last "dumb" parameter is used in order to avoid + sip compilation error because of conflicting int and bool types) +*/ +void SalomePyQt::addSetting( const QString& section, const QString& name, const bool value, const int ) +{ + class TEvent: public SALOME_Event { + QString mySection; + QString myName; + bool myValue; + public: + TEvent( const QString& section, const QString& name, bool 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 ) ); +} + /*! SalomePyQt::addSetting Adds a string setting to the application preferences @@ -703,7 +758,7 @@ public: /*! \return an double setting from the application preferences */ -double SalomePyQt::doubleSetting( const QString& section, const QString& name, const int def ) +double SalomePyQt::doubleSetting( const QString& section, const QString& name, const double def ) { return ProcessEvent( new TGetDblSettingEvent( section, name, def ) ); } diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h index ba3a97588..d160c193c 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h @@ -147,10 +147,11 @@ public: static void addSetting ( const QString&, const QString&, const double ); static void addSetting ( const QString&, const QString&, const int ); + static void addSetting ( const QString&, const QString&, const bool, const int ); static void addSetting ( const QString&, const QString&, const QString& ); static void addSetting ( const QString&, const QString&, const QColor& ); static int integerSetting( const QString&, const QString&, const int = 0 ); - static double doubleSetting ( const QString&, const QString&, const int = 0 ); + static double doubleSetting ( const QString&, const QString&, const double = 0 ); static bool boolSetting ( const QString&, const QString&, const bool = 0 ); static QString stringSetting ( const QString&, const QString&, const QString& = QString("") ); static QColor colorSetting ( const QString&, const QString&, const QColor& = QColor() ); @@ -159,6 +160,7 @@ public: // obsolete static void addStringSetting( const QString&, const QString&, bool = true ); static void addIntSetting ( const QString&, const int, bool = true ); + static void addBoolSetting ( const QString&, const bool, bool = true ); static void addDoubleSetting( const QString&, const double, bool = true ); static void removeSettings ( const QString& ); static QString getSetting ( const QString& ); diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip index a7240ab53..f73f7b0ea 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip @@ -133,10 +133,11 @@ public: static void addSetting ( const QString&, const QString&, const double ); static void addSetting ( const QString&, const QString&, const int /Constrained/ ); + static void addSetting ( const QString&, const QString&, const bool, const int ); static void addSetting ( const QString&, const QString&, const QString& ); static void addSetting ( const QString&, const QString&, const QColor& ); static int integerSetting( const QString&, const QString&, int = 0 ); - static double doubleSetting ( const QString&, const QString&, int = 0 ); + static double doubleSetting ( const QString&, const QString&, double = 0 ); static bool boolSetting ( const QString&, const QString&, bool = false ); static QString stringSetting ( const QString&, const QString&, const QString& = QString("") ); static QColor colorSetting ( const QString&, const QString&, const QColor& = QColor() ); @@ -147,6 +148,7 @@ public: static void addStringSetting( const QString&, const QString&, bool = true ); static void addIntSetting ( const QString&, const int, bool = true ); static void addDoubleSetting( const QString&, const double, bool = true ); + static void addBoolSetting ( const QString&, const bool, bool = true ); static void removeSettings ( const QString& ); static QString getSetting ( const QString& ); diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt_v4.sip b/src/SALOME_PYQT/SalomePyQt/SalomePyQt_v4.sip index d1b732046..c550e2409 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt_v4.sip +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt_v4.sip @@ -132,10 +132,11 @@ public: static void addSetting ( const QString&, const QString&, const double ) /ReleaseGIL/ ; static void addSetting ( const QString&, const QString&, const int /Constrained/ ) /ReleaseGIL/ ; + static void addSetting ( const QString&, const QString&, const bool, const int ) /ReleaseGIL/ ; static void addSetting ( const QString&, const QString&, const QString& ) /ReleaseGIL/ ; static void addSetting ( const QString&, const QString&, const QColor& ) /ReleaseGIL/ ; static int integerSetting( const QString&, const QString&, const int = 0 ) /ReleaseGIL/ ; - static double doubleSetting ( const QString&, const QString&, const int = 0 ) /ReleaseGIL/ ; + static double doubleSetting ( const QString&, const QString&, const double = 0 ) /ReleaseGIL/ ; static bool boolSetting ( const QString&, const QString&, const bool = false ) /ReleaseGIL/ ; static QString stringSetting ( const QString&, const QString&, const QString& = QString("") ) /ReleaseGIL/ ; static QColor colorSetting ( const QString&, const QString&, const QColor& = QColor() ) /ReleaseGIL/ ; @@ -146,6 +147,7 @@ public: static void addStringSetting( const QString&, const QString&, bool = true ) /ReleaseGIL/ ; static void addIntSetting ( const QString&, const int, bool = true ) /ReleaseGIL/ ; static void addDoubleSetting( const QString&, const double, bool = true ) /ReleaseGIL/ ; + static void addBoolSetting ( const QString&, const bool, bool = true ) /ReleaseGIL/ ; static void removeSettings ( const QString& ) /ReleaseGIL/ ; static QString getSetting ( const QString& ) /ReleaseGIL/ ;