From: vsr Date: Wed, 10 Aug 2016 15:35:18 +0000 (+0300) Subject: Allow setting / getting QByteArray preference item in Python modules. X-Git-Tag: V8_1_0rc1~8^2~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=b9401b2aed78108aae22a0a2f83498705ec03d5f;p=modules%2Fgui.git Allow setting / getting QByteArray preference item in Python modules. --- diff --git a/src/Qtx/QtxResourceMgr.cxx b/src/Qtx/QtxResourceMgr.cxx index 6c294ace7..d0d2d356d 100644 --- a/src/Qtx/QtxResourceMgr.cxx +++ b/src/Qtx/QtxResourceMgr.cxx @@ -1573,23 +1573,29 @@ bool QtxResourceMgr::value( const QString& sect, const QString& name, QByteArray if ( !value( sect, name, val, true ) ) return false; - baVal.clear(); - QStringList lst = val.split( QRegExp( "[\\s|,]" ), QString::SkipEmptyParts ); - for ( QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it ) - { - int base = 10; - QString str = *it; - if ( str.startsWith( "#" ) ) + if ( val.startsWith( QLatin1String("@ByteArray(") ) && + val.endsWith( QLatin1Char(')' ) ) ) { + baVal = QByteArray( val.midRef( 11, val.size() - 12 ).toLatin1() ); + } + else { + baVal.clear(); + QStringList lst = val.split( QRegExp( "[\\s|,]" ), QString::SkipEmptyParts ); + for ( QStringList::ConstIterator it = lst.begin(); it != lst.end(); ++it ) { - base = 16; - str = str.mid( 1 ); + int base = 10; + QString str = *it; + if ( str.startsWith( "#" ) ) + { + base = 16; + str = str.mid( 1 ); + } + bool ok = false; + int num = str.toInt( &ok, base ); + if ( !ok || num < 0 || num > 255 ) + continue; + + baVal.append( (char)num ); } - bool ok = false; - int num = str.toInt( &ok, base ); - if ( !ok || num < 0 || num > 255 ) - continue; - - baVal.append( (char)num ); } return !baVal.isEmpty(); } @@ -2052,14 +2058,12 @@ void QtxResourceMgr::setValue( const QString& sect, const QString& name, const Q if ( checkExisting() && value( sect, name, res ) && res == val ) return; - char buf[8]; - QStringList lst; - for ( int i = 0; i < val.size(); i++ ) - { - ::sprintf( buf, "#%02X", (unsigned char)val.at( i ) ); - lst.append( QString( buf ) ); - } - setResource( sect, name, lst.join( " " ) ); + QString result; + result = QLatin1String("@ByteArray("); + result += QString::fromLatin1(val.constData(), val.size()); + result += QLatin1Char(')'); + + setResource( sect, name, result ); } /*! diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx index 10dc38380..71ddbfa0d 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.cxx @@ -1152,6 +1152,34 @@ void SalomePyQt::addSetting( const QString& section, const QString& name, const ProcessVoidEvent( new TEvent( section, name, value ) ); } +/*! + \brief Add byte array 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 QByteArray& value ) +{ + class TEvent: public SALOME_Event + { + QString mySection; + QString myName; + QByteArray myValue; + public: + TEvent( const QString& section, const QString& name, const QByteArray& 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, @@ -1322,6 +1350,40 @@ QColor SalomePyQt::colorSetting ( const QString& section, const QString& name, c return ProcessEvent( new TGetColorSettingEvent( section, name, def ) ); } +/*! + \fn QByteArray SalomePyQt::byteArraySetting( const QString& section, + const QString& name, + const QByteArray def ); + \brief Get byte array 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 TGetByteArraySettingEvent: public SALOME_Event +{ +public: + typedef QByteArray TResult; + TResult myResult; + QString mySection; + QString myName; + TResult myDefault; + TGetByteArraySettingEvent( const QString& section, const QString& name, const QByteArray& 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->byteArrayValue( mySection, myName, myDefault ) : myDefault; + } + } +}; +QByteArray SalomePyQt::byteArraySetting ( const QString& section, const QString& name, const QByteArray& def ) +{ + return ProcessEvent( new TGetByteArraySettingEvent( section, name, def ) ); +} + /*! \brief Remove setting from the application preferences. \param section resources file section name @@ -1355,14 +1417,14 @@ void SalomePyQt::removeSetting( const QString& section, const QString& name ) \return \c true if setting exists */ -class THasColorSettingEvent: public SALOME_Event +class THasSettingEvent: public SALOME_Event { public: typedef bool TResult; TResult myResult; QString mySection; QString myName; - THasColorSettingEvent( const QString& section, const QString& name ) + THasSettingEvent( const QString& section, const QString& name ) : mySection( section ), myName( name ) {} virtual void Execute() { @@ -1374,7 +1436,7 @@ public: }; bool SalomePyQt::hasSetting( const QString& section, const QString& name ) { - return ProcessEvent( new THasColorSettingEvent( section, name ) ); + return ProcessEvent( new THasSettingEvent( section, name ) ); } /*! diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h index 4dcf7bd8f..60d7be45d 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.h @@ -251,11 +251,13 @@ public: 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 void addSetting ( const QString&, const QString&, const QByteArray& ); static int integerSetting( 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() ); + static QByteArray byteArraySetting( const QString&, const QString&, const QByteArray& = QByteArray() ); static void removeSetting ( const QString&, const QString& ); static bool hasSetting ( const QString&, const QString& ); diff --git a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip index d7fba9118..212f3725c 100644 --- a/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip +++ b/src/SALOME_PYQT/SalomePyQt/SalomePyQt.sip @@ -355,11 +355,13 @@ public: 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 void addSetting ( const QString&, const QString&, const QByteArray& ) /ReleaseGIL/ ; static int integerSetting( 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/ ; + static QByteArray byteArraySetting( const QString&, const QString&, const QByteArray& = QByteArray() ) /ReleaseGIL/ ; static void removeSetting ( const QString&, const QString& ) /ReleaseGIL/ ; static bool hasSetting ( const QString&, const QString& ) /ReleaseGIL/ ;