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();
}
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 );
}
/*!
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,
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
\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()
{
};
bool SalomePyQt::hasSetting( const QString& section, const QString& name )
{
- return ProcessEvent( new THasColorSettingEvent( section, name ) );
+ return ProcessEvent( new THasSettingEvent( section, name ) );
}
/*!
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& );
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/ ;