#include <stdlib.h>
-/* XPM */
-static const char* pixmap_not_found_xpm[] = {
-"16 16 3 1",
-" c None",
-". c #000000",
-"+ c #A80000",
-" ",
-" ",
-" . . ",
-" .+. .+. ",
-" .+++. .+++. ",
-" .+++.+++. ",
-" .+++++. ",
-" .+++. ",
-" .+++++. ",
-" .+++.+++. ",
-" .+++. .+++. ",
-" .+. .+. ",
-" . . ",
-" ",
-" ",
-" "};
-
/*!
- Class: QtxResourceMgr::Resources
- Level: Internal
+ Class: QtxResourceMgr::Resources
+ Level: Internal
*/
QtxResourceMgr::Resources::Resources( const QString& fileName )
if ( data.startsWith( comment ) )
continue;
- QRegExp rx( "^\\[([\\w\\s]*)\\]$" );
+ QRegExp rx( "^\\[([\\w\\s\\._]*)\\]$" );
if ( rx.search( data ) != -1 )
{
section = rx.cap( 1 );
else if ( data.contains( "=" ) && !section.isEmpty() )
{
int pos = data.find( separator );
- QString key = data.left( pos - 1 ).stripWhiteSpace();
+ QString key = data.left( pos ).stripWhiteSpace();
QString val = data.mid( pos + 1 ).stripWhiteSpace();
secMap[section].insert( key, val );
}
else
res = false;
}
- else
+ else
res = paramNode.isComment();
paramNode = paramNode.nextSibling();
QDomElement sect = doc.createElement( sectionTag() );
sect.setAttribute( nameAttribute(), it.key() );
root.appendChild( sect );
- for ( QMap<QString, QString>::ConstIterator iter = it.data().begin(); iter != it.data().end(); ++iter )
+ for ( Section::ConstIterator iter = it.data().begin(); iter != it.data().end(); ++iter )
{
QDomElement val = doc.createElement( parameterTag() );
val.setAttribute( nameAttribute(), iter.key() );
Level: Public
*/
+/*!
+ \brief Constructs the format object with specified name.
+ \param fmt - name of the format
+*/
QtxResourceMgr::Format::Format( const QString& fmt )
: myFmt( fmt )
{
}
+/*!
+ \brief Destructs the format object.
+*/
QtxResourceMgr::Format::~Format()
{
}
+/*!
+ \brief Returns the format name.
+*/
QString QtxResourceMgr::Format::format() const
{
return myFmt;
}
+/*!
+ \brief Returns the string list of the format options.
+*/
QStringList QtxResourceMgr::Format::options() const
{
return myOpt.keys();
}
+/*!
+ \brief Returns the value of the option with specified name.
+ If option doesn't exist then empty string returned.
+ \param opt - name of the option
+*/
QString QtxResourceMgr::Format::option( const QString& opt ) const
{
QString val;
val = myOpt[opt];
return val;
}
+
+/*!
+ \brief Sets the value of the option with specified name.
+ \param opt - name of the option
+ \param opt - value of the option
+*/
void QtxResourceMgr::Format::setOption( const QString& opt, const QString& val )
{
myOpt.insert( opt, val );
}
+/*!
+ \brief Perform the loading of the resources from resource file.
+ \param res - resources object which will be loaded
+*/
bool QtxResourceMgr::Format::load( Resources* res )
{
if ( !res )
return status;
}
+/*!
+ \brief Perform the saving of the resources into resource file.
+ \param res - resources object which will be saved
+*/
bool QtxResourceMgr::Format::save( Resources* res )
{
if ( !res )
Level: Public
*/
+/*!
+ \brief Constructs the resource manager object for application.
+ \param appName - name of the application which resources will be used.
+ \param resVarTemplate - template for the resource environment variable name which
+ should point to the resource directory list.
+ Default value is "%1Resources". Its mean that for application
+ with name "MyApp" environment variable "MyAppResources" will
+ be used. Template may not have the parameter '%1' substituted
+ by application name. In this case this string will be used as
+ is without substitution.
+ Resource environment variable should contains one or several resource directories
+ separated by symbol ';'. Resource directories list transfered into the setDirList().
+ These directories and the user home directory used for the loading application resources.
+ Each of the resource directories can contains resource file. The name of this file defined
+ by the function globalFileName(). Resource file name in the user home defined by the
+ function userFileName(). Any resource looking firstly in the user home resources then
+ resource directories used in the specified order. All setted resources always stored into
+ the resource file at the user home. Only user home resource file is saved.
+*/
QtxResourceMgr::QtxResourceMgr( const QString& appName, const QString& resVarTemplate )
-: myAppName( appName )
+: myAppName( appName ),
+myCheckExist( true )
{
QString envVar = !resVarTemplate.isEmpty() ? resVarTemplate : QString( "%1Resources" );
if ( envVar.contains( "%1" ) )
setOption( "translators", QString( "%P_msg_%L.qm|%P_images.qm" ) );
}
+/*!
+ \brief Destructs the resource manager object and free allocated memory.
+*/
QtxResourceMgr::~QtxResourceMgr()
{
QStringList prefList = myTranslator.keys();
removeTranslators( *it );
}
+/*!
+ \brief Returns the application name.
+*/
QString QtxResourceMgr::appName() const
{
return myAppName;
}
-QStringList QtxResourceMgr::dirList() const
+/*!
+ \brief Returns the checking of the existance flag. If its 'true' then resource
+ will be setted into the manager only if it doesn't exist or has different
+ value that existing value.
+*/
+bool QtxResourceMgr::checkExisting() const
{
- return myDirList;
+ return myCheckExist;
}
-void QtxResourceMgr::setDirList( const QStringList& dl )
+/*!
+ \brief Sets the checking of the existance flag.
+ \param on - boolean value of the flag.
+*/
+void QtxResourceMgr::setCheckExisting( const bool on )
{
- myDirList = dl;
- for ( ResListIterator it( myResources ); it.current(); ++it )
- delete it.current();
+ myCheckExist = on;
+}
- myResources.clear();
+/*!
+ \brief Returns the resource directories list except user home directory.
+*/
+QStringList QtxResourceMgr::dirList() const
+{
+ return myDirList;
}
+/*!
+ \brief Initialise the manager. Prepare the resource containers and load resources.
+ \param autoLoad - if 'true' then all resources will be loaded.
+*/
void QtxResourceMgr::initialize( const bool autoLoad ) const
{
if ( !myResources.isEmpty() )
QtxResourceMgr* that = (QtxResourceMgr*)this;
- that->myResources.append( new Resources( userFileName( appName() ) ) );
+ if ( !userFileName( appName() ).isEmpty() )
+ that->myResources.append( new Resources( userFileName( appName() ) ) );
+
for ( QStringList::const_iterator it = myDirList.begin(); it != myDirList.end(); ++it )
{
QString path = Qtx::addSlash( *it ) + globalFileName( appName() );
that->load();
}
+/*!
+ \brief Removes all resources from the manager.
+*/
void QtxResourceMgr::clear()
{
for ( ResListIterator it( myResources ); it.current(); ++it )
it.current()->clear();
}
-QString QtxResourceMgr::currentSection() const
-{
- return myCurSection;
-}
-
-void QtxResourceMgr::setCurrentSection( const QString& str )
-{
- myCurSection = str;
-}
-
-bool QtxResourceMgr::value( const QString& name, int& val ) const
-{
- return value( currentSection(), name, val );
-}
-
-bool QtxResourceMgr::value( const QString& name, double& val ) const
-{
- return value( currentSection(), name, val );
-}
-
-bool QtxResourceMgr::value( const QString& name, bool& val ) const
-{
- return value( currentSection(), name, val );
-}
-
-bool QtxResourceMgr::value( const QString& name, QColor& val ) const
-{
- return value( currentSection(), name, val );
-}
-
-bool QtxResourceMgr::value( const QString& name, QString& val, const bool subst ) const
-{
- return value( currentSection(), name, val, subst );
-}
-
+/*!
+ \brief Get the resource value as integer. Returns 'true' if it successfull otherwise
+ returns 'false'.
+ \param sect - Resource section name which contains resource.
+ \param name - Name of the resource.
+ \param iVal - Reference on the variable which should contains the resource output.
+*/
bool QtxResourceMgr::value( const QString& sect, const QString& name, int& iVal ) const
{
QString val;
return ok;
}
+/*!
+ \brief Get the resource value as double. Returns 'true' if it successfull otherwise
+ returns 'false'.
+ \param sect - Resource section name which contains resource.
+ \param name - Name of the resource.
+ \param dVal - Reference on the variable which should contains the resource output.
+*/
bool QtxResourceMgr::value( const QString& sect, const QString& name, double& dVal ) const
{
QString val;
return ok;
}
+/*!
+ \brief Get the resource value as boolean. Returns 'true' if it successfull otherwise
+ returns 'false'.
+ \param sect - Resource section name which contains resource.
+ \param name - Name of the resource.
+ \param bVal - Reference on the variable which should contains the resource output.
+*/
bool QtxResourceMgr::value( const QString& sect, const QString& name, bool& bVal ) const
{
QString val;
return res;
}
+/*!
+ \brief Get the resource value as color. Returns 'true' if it successfull otherwise
+ returns 'false'.
+ \param sect - Resource section name which contains resource.
+ \param name - Name of the resource.
+ \param cVal - Reference on the variable which should contains the resource output.
+*/
bool QtxResourceMgr::value( const QString& sect, const QString& name, QColor& cVal ) const
{
QString val;
return res;
}
+/*!
+ \brief Get the resource value as font. Returns 'true' if it successfull otherwise
+ returns 'false'.
+ \param sect - Resource section name which contains resource.
+ \param name - Name of the resource.
+ \param fVal - Reference on the variable which should contains the resource output.
+*/
+bool QtxResourceMgr::value( const QString& sect, const QString& name, QFont& fVal ) const
+{
+ QString val;
+ if ( !value( sect, name, val, true ) )
+ return false;
+
+ QStringList fontDescr = QStringList::split( ",", val );
+
+ if ( fontDescr.count() < 2 )
+ return false;
+
+ QString family = fontDescr[0];
+ if ( family.isEmpty() )
+ return false;
+
+ fVal = QFont( family );
+
+ for ( int i = 1; i < (int)fontDescr.count(); i++ )
+ {
+ QString curval = fontDescr[i].stripWhiteSpace().lower();
+ if ( curval == QString( "bold" ) )
+ fVal.setBold( true );
+ else if ( curval == QString( "italic" ) )
+ fVal.setItalic( true );
+ else if ( curval == QString( "underline" ) )
+ fVal.setUnderline( true );
+ else
+ {
+ bool isOk = false;
+ int ps = curval.toInt( &isOk );
+ if ( isOk )
+ fVal.setPointSize( ps );
+ }
+ }
+
+ return true;
+}
+
+/*!
+ \brief Get the resource value as string (native format). Returns 'true' if it
+ successfull otherwise returns 'false'.
+ \param sect - Resource section name which contains resource.
+ \param name - Name of the resource.
+ \param val - Reference on the variable which should contains the resource output.
+ \param subst - If 'true' then manager substitute reference on environment variables
+ and other resources by thier values. Default value of this parameter
+ is 'true'
+*/
bool QtxResourceMgr::value( const QString& sect, const QString& name, QString& val, const bool subst ) const
{
initialize();
return ok;
}
-int QtxResourceMgr::integerValue( const QString& name, const int def ) const
-{
- return integerValue( currentSection(), name, def );
-}
-
-double QtxResourceMgr::doubleValue( const QString& name, const double def ) const
-{
- return doubleValue( currentSection(), name, def );
-}
-
-bool QtxResourceMgr::booleanValue( const QString& name, const bool def ) const
-{
- return booleanValue( currentSection(), name, def );
-}
-
-QColor QtxResourceMgr::colorValue( const QString& name, const QColor& def ) const
-{
- return colorValue( currentSection(), name, def );
-}
-
-QString QtxResourceMgr::stringValue( const QString& name, const char* def ) const
-{
- return stringValue( currentSection(), name, def );
-}
-
+/*!
+ \brief Returns the integer resource value. If resource can not be found or converted
+ then specified default value will be returned.
+ \param sect - Resource section name which contains resource.
+ \param name - Name of the resource.
+ \param def - Default resource value which will be used when resource not found.
+*/
int QtxResourceMgr::integerValue( const QString& sect, const QString& name, const int def ) const
{
int val;
return val;
}
+/*!
+ \brief Returns the double resource value. If resource can not be found or converted
+ then specified default value will be returned.
+ \param sect - Resource section name which contains resource.
+ \param name - Name of the resource.
+ \param def - Default resource value which will be used when resource not found.
+*/
double QtxResourceMgr::doubleValue( const QString& sect, const QString& name, const double def ) const
{
double val;
return val;
}
+/*!
+ \brief Returns the boolean resource value. If resource can not be found or converted
+ then specified default value will be returned.
+ \param sect - Resource section name which contains resource.
+ \param name - Name of the resource.
+ \param def - Default resource value which will be used when resource not found.
+*/
bool QtxResourceMgr::booleanValue( const QString& sect, const QString& name, const bool def ) const
{
bool val;
return val;
}
+/*!
+ \brief Returns the font resource value. If resource can not be found or converted
+ then specified default value will be returned.
+ \param sect - Resource section name which contains resource.
+ \param name - Name of the resource.
+ \param def - Default resource value which will be used when resource not found.
+*/
+QFont QtxResourceMgr::fontValue( const QString& sect, const QString& name, const QFont& def ) const
+{
+ QFont font;
+ if( !value( sect, name, font ) )
+ font = def;
+ return font;
+}
+
+/*!
+ \brief Returns the color resource value. If resource can not be found or converted
+ then specified default value will be returned.
+ \param sect - Resource section name which contains resource.
+ \param name - Name of the resource.
+ \param def - Default resource value which will be used when resource not found.
+*/
QColor QtxResourceMgr::colorValue( const QString& sect, const QString& name, const QColor& def ) const
{
QColor val;
return val;
}
-QString QtxResourceMgr::stringValue( const QString& sect, const QString& name, const char* def ) const
+/*!
+ \brief Returns the string resource value. If resource can not be found or converted
+ then specified default value will be returned.
+ \param sect - Resource section name which contains resource.
+ \param name - Name of the resource.
+ \param def - Default resource value which will be used when resource not found.
+*/
+QString QtxResourceMgr::stringValue( const QString& sect, const QString& name, const QString& def ) const
{
QString val;
if ( !value( sect, name, val ) )
return val;
}
-bool QtxResourceMgr::hasValue( const QString& name ) const
-{
- return hasValue( currentSection(), name );
-}
-
+/*!
+ \brief Checks existance of the specified resource.
+ \param sect - Resource section name which contains resource.
+ \param name - Name of the resource.
+*/
bool QtxResourceMgr::hasValue( const QString& sect, const QString& name ) const
{
initialize();
return ok;
}
+/*!
+ \brief Checks existance of the specified resource section.
+ \param sect - Resource section name which contains resource.
+*/
bool QtxResourceMgr::hasSection( const QString& sect ) const
{
initialize();
return ok;
}
-void QtxResourceMgr::setValue( const QString& name, int val )
+/*!
+ \brief Sets the integer resource value.
+ \param sect - Resource section name.
+ \param name - Name of the resource.
+ \param val - Resource value.
+*/
+void QtxResourceMgr::setValue( const QString& sect, const QString& name, int val )
{
- setValue( currentSection(), name, val );
-}
+ int res;
+ if ( checkExisting() && value( sect, name, res ) && res == val )
+ return;
-void QtxResourceMgr::setValue( const QString& name, double val )
-{
- setValue( currentSection(), name, val );
+ setResource( sect, name, QString::number( val ) );
}
-void QtxResourceMgr::setValue( const QString& name, bool val )
+/*!
+ \brief Sets the double resource value.
+ \param sect - Resource section name.
+ \param name - Name of the resource.
+ \param val - Resource value.
+*/
+void QtxResourceMgr::setValue( const QString& sect, const QString& name, double val )
{
- setValue( currentSection(), name, val );
-}
+ double res;
+ if ( checkExisting() && value( sect, name, res ) && res == val )
+ return;
-void QtxResourceMgr::setValue( const QString& name, const QColor& val )
-{
- setValue( currentSection(), name, val );
+ setResource( sect, name, QString::number( val, 'g', 12 ) );
}
-void QtxResourceMgr::setValue( const QString& name, const QString& val )
+/*!
+ \brief Sets the boolean resource value.
+ \param sect - Resource section name.
+ \param name - Name of the resource.
+ \param val - Resource value.
+*/
+void QtxResourceMgr::setValue( const QString& sect, const QString& name, bool val )
{
- setValue( currentSection(), name, val );
-}
+ bool res;
+ if ( checkExisting() && value( sect, name, res ) && res == val )
+ return;
-void QtxResourceMgr::setValue( const QString& sect, const QString& name, int val )
-{
- setValue( sect, name, QString::number( val ) );
+ setResource( sect, name, QString( val ? "true" : "false" ) );
}
-void QtxResourceMgr::setValue( const QString& sect, const QString& name, double val )
+/*!
+ \brief Sets the color resource value.
+ \param sect - Resource section name.
+ \param name - Name of the resource.
+ \param val - Resource value.
+*/
+void QtxResourceMgr::setValue( const QString& sect, const QString& name, const QColor& val )
{
- setValue( sect, name, QString::number( val, 'g', 12 ) );
-}
+ QColor res;
+ if ( checkExisting() && value( sect, name, res ) && res == val )
+ return;
-void QtxResourceMgr::setValue( const QString& sect, const QString& name, bool val )
-{
- setValue( sect, name, QString( val ? "true" : "false" ) );
+ setResource( sect, name, QString( "%1, %2, %3" ).arg( val.red() ).arg( val.green() ).arg( val.blue() ) );
}
-void QtxResourceMgr::setValue( const QString& sect, const QString& name, const QColor& val )
+/*!
+ \brief Sets the font resource value.
+ \param sect - Resource section name.
+ \param name - Name of the resource.
+ \param val - Resource value.
+*/
+void QtxResourceMgr::setValue( const QString& sect, const QString& name, const QFont& val )
{
- setValue( sect, name, QString( "%1, %2, %3").arg( val.red() ).arg( val.green() ).arg( val.blue() ) );
-}
+ QFont res;
+ if ( checkExisting() && value( sect, name, res ) && res == val )
+ return;
-void QtxResourceMgr::setValue( const QString& sect, const QString& name, const QString& val )
-{
- initialize();
+ QStringList fontDescr;
+ fontDescr.append( val.family() );
+ if ( val.bold() )
+ fontDescr.append( "Bold" );
+ if ( val.italic() )
+ fontDescr.append( "Italic" );
+ if ( val.underline() )
+ fontDescr.append( "Underline" );
+ fontDescr.append( QString( "%1" ).arg( val.pointSize() ) );
- if ( !myResources.isEmpty() )
- myResources.first()->setValue( sect, name, val );
+ setResource( sect, name, fontDescr.join( "," ) );
}
-void QtxResourceMgr::remove( const QString& name )
+/*!
+ \brief Sets the string resource value.
+ \param sect - Resource section name.
+ \param name - Name of the resource.
+ \param val - Resource value.
+*/
+void QtxResourceMgr::setValue( const QString& sect, const QString& name, const QString& val )
{
- remove( currentSection(), name );
+ QString res;
+ if ( checkExisting() && value( sect, name, res ) && res == val )
+ return;
+
+ setResource( sect, name, val );
}
-void QtxResourceMgr::remove( const QString& sect, const QString& name )
+/*!
+ \brief Remove the all specified resource section.
+ \param sect - Resource section name.
+*/
+void QtxResourceMgr::remove( const QString& sect )
{
initialize();
for ( ResListIterator it( myResources ); it.current(); ++it )
- it.current()->removeValue( sect, name );
+ it.current()->removeSection( sect );
}
-void QtxResourceMgr::removeSection( const QString& sect )
+/*!
+ \brief Remove the specified resource.
+ \param sect - Resource section name.
+ \param name - Name of the resource.
+*/
+void QtxResourceMgr::remove( const QString& sect, const QString& name )
{
initialize();
for ( ResListIterator it( myResources ); it.current(); ++it )
- it.current()->removeSection( sect );
+ it.current()->removeValue( sect, name );
}
+/*!
+ \brief Returns the current format which operates with resource files.
+*/
QString QtxResourceMgr::currentFormat() const
{
QString fmt;
return fmt;
}
+/*!
+ \brief Sets the current format which operates with resource files.
+ \param fmt - Resource format name.
+*/
void QtxResourceMgr::setCurrentFormat( const QString& fmt )
{
Format* form = format( fmt );
return;
ResListIterator resIt( myResources );
- if ( resIt.current() )
+ if ( myResources.count() > myDirList.count() && resIt.current() ) {
resIt.current()->setFile( userFileName( appName() ) );
- ++resIt;
+ ++resIt;
+ }
for ( QStringList::const_iterator it = myDirList.begin(); it != myDirList.end() && resIt.current(); ++it, ++resIt )
resIt.current()->setFile( Qtx::addSlash( *it ) + globalFileName( appName() ) );
}
+/*!
+ \brief Returns the resource format object by it name.
+ \param fmt - Resource format name.
+*/
QtxResourceMgr::Format* QtxResourceMgr::format( const QString& fmt ) const
{
Format* form = 0;
return form;
}
+/*!
+ \brief Add the resource format to the manager. Newly added become current.
+ \param form - Resource format object.
+*/
void QtxResourceMgr::installFormat( QtxResourceMgr::Format* form )
{
if ( !myFormats.contains( form ) )
myFormats.prepend( form );
}
+/*!
+ \brief Remove the resource format from the manager.
+ \param form - Resource format object.
+*/
void QtxResourceMgr::removeFormat( QtxResourceMgr::Format* form )
{
myFormats.remove( form );
}
+/*!
+ \brief Returns the string list of the resource format options names.
+*/
QStringList QtxResourceMgr::options() const
{
return myOptions.keys();
}
+/*!
+ \brief Returns the string value for the specified option. If option doesn't exist
+ then empty string will be returned.
+ \param opt - Option name.
+*/
QString QtxResourceMgr::option( const QString& opt ) const
{
QString val;
return val;
}
+/*!
+ \brief Sets the string value for the specified option.
+ \param opt - Option name.
+ \param val - Option value.
+*/
void QtxResourceMgr::setOption( const QString& opt, const QString& val )
{
myOptions.insert( opt, val );
}
+/*!
+ \brief Load the all resources from the resource files.
+*/
bool QtxResourceMgr::load()
{
initialize( false );
return res;
}
+/*!
+ \brief Save the changed resources in to the user resource file.
+*/
bool QtxResourceMgr::save()
{
initialize( false );
return fmt->save( myResources.getFirst() );
}
+/*!
+ \brief Returns the string list of the existing section names..
+*/
QStringList QtxResourceMgr::sections() const
{
initialize();
return res;
}
+/*!
+ \brief Returns the string list of the existing resource names in the specified section.
+ \param sec - Resource section name.
+*/
QStringList QtxResourceMgr::parameters( const QString& sec ) const
{
initialize();
- QMap<QString, int> map;
- for ( ResListIterator it( myResources ); it.current(); ++it )
- {
+#if defined(QTX_NO_INDEXED_MAP)
+ typedef QMap<QString, int> PMap;
+#else
+ typedef IMap<QString, int> PMap;
+#endif
+ PMap pmap;
+ ResListIterator it( myResources );
+ it.toLast();
+ for ( ; it.current(); --it ) {
QStringList lst = it.current()->parameters( sec );
for ( QStringList::const_iterator itr = lst.begin(); itr != lst.end(); ++itr )
- map.insert( *itr, 0 );
+ pmap.insert( *itr, 0, false );
}
QStringList res;
- for ( QMap<QString, int>::ConstIterator iter = map.begin(); iter != map.end(); ++iter )
+ for ( PMap::ConstIterator iter = pmap.begin(); iter != pmap.end(); ++iter )
res.append( iter.key() );
return res;
return res;
}
-QPixmap QtxResourceMgr::loadPixmap( const QString& prefix, const QString& name, const bool useDefault ) const
+QPixmap QtxResourceMgr::defaultPixmap() const
+{
+ return myDefaultPix;
+}
+
+void QtxResourceMgr::setDefaultPixmap( const QPixmap& pix )
+{
+ myDefaultPix = pix;
+}
+
+QPixmap QtxResourceMgr::loadPixmap( const QString& prefix, const QString& name ) const
+{
+ return loadPixmap( prefix, name, true );
+}
+
+QPixmap QtxResourceMgr::loadPixmap( const QString& prefix, const QString& name, const bool useDef ) const
+{
+ return loadPixmap( prefix, name, useDef ? defaultPixmap() : QPixmap() );
+}
+
+QPixmap QtxResourceMgr::loadPixmap( const QString& prefix, const QString& name, const QPixmap& defPix ) const
{
initialize();
- static QPixmap defaultPixmap( pixmap_not_found_xpm );
QPixmap pix;
for ( ResListIterator it( myResources ); it.current() && pix.isNull(); ++it )
pix = it.current()->loadPixmap( resSection(), prefix, name );
- if ( pix.isNull() && useDefault )
- return defaultPixmap;
+ if ( pix.isNull() )
+ pix = defPix;
return pix;
}
for ( QStringList::const_iterator it = trList.begin(); it != trList.end(); ++it )
trs.append( substMacro( *it, substMap ).stripWhiteSpace() );
- for ( QStringList::const_iterator itr = trs.begin(); itr != trs.end(); ++itr )
- loadTranslator( prefix, *itr );
+ loadTranslators( prefix, trs );
}
}
-void QtxResourceMgr::loadTranslator( const QString& prefix, const QString& name )
+void QtxResourceMgr::loadTranslators( const QString& prefix, const QStringList& translators )
{
initialize();
QTranslator* trans = 0;
- for ( ResListIterator it( myResources ); it.current() && !trans; ++it )
- trans = it.current()->loadTranslator( resSection(), prefix, name );
+ ResListIterator it( myResources );
+ it.toLast();
+ for ( ; it.current(); --it )
+ {
+ for ( QStringList::const_iterator itr = translators.begin(); itr != translators.end(); ++itr )
+ {
+ trans = it.current()->loadTranslator( resSection(), prefix, *itr );
+ if ( trans )
+ {
+ if ( !myTranslator[prefix].contains( trans ) )
+ myTranslator[prefix].append( trans );
+ qApp->installTranslator( trans );
+ }
+ }
+ }
+}
- if ( !trans )
- return;
+void QtxResourceMgr::loadTranslator( const QString& prefix, const QString& name )
+{
+ initialize();
- if ( !myTranslator[prefix].contains( trans ) )
- myTranslator[prefix].append( trans );
- qApp->installTranslator( trans );
+ QTranslator* trans = 0;
+ ResListIterator it( myResources );
+ it.toLast();
+ for ( ; it.current(); --it )
+ {
+ trans = it.current()->loadTranslator( resSection(), prefix, name );
+ if ( trans )
+ {
+ if ( !myTranslator[prefix].contains( trans ) )
+ myTranslator[prefix].append( trans );
+ qApp->installTranslator( trans );
+ }
+ }
}
void QtxResourceMgr::removeTranslators( const QString& prefix )
{
QStringList pl = parameters( *it );
for ( QStringList::const_iterator itr = pl.begin(); itr != pl.end(); ++itr )
- setValue( *it, *itr, stringValue( *it, *itr ) );
+ setResource( *it, *itr, stringValue( *it, *itr ) );
}
}
+void QtxResourceMgr::setDirList( const QStringList& dl )
+{
+ myDirList = dl;
+ for ( ResListIterator it( myResources ); it.current(); ++it )
+ delete it.current();
+
+ myResources.clear();
+}
+
+void QtxResourceMgr::setResource( const QString& sect, const QString& name, const QString& val )
+{
+ initialize();
+
+ if ( !myResources.isEmpty() )
+ myResources.first()->setValue( sect, name, val );
+}
+
QString QtxResourceMgr::userFileName( const QString& appName ) const
{
QString fileName;