Back to index

salome-gui  6.5.0
Public Member Functions | Protected Member Functions | Private Types | Private Member Functions | Private Attributes | Friends
QtxResourceMgr::Resources Class Reference

Represents container for settings read from the resource file. More...

Collaboration diagram for QtxResourceMgr::Resources:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Resources (QtxResourceMgr *, const QString &)
 Constructor.
virtual ~Resources ()
 Destructor.
QString file () const
 Get resources file name.
void setFile (const QString &)
 Set resources file name.
QString value (const QString &, const QString &, const bool) const
 Get string representation of parameter value.
void setValue (const QString &, const QString &, const QString &)
 Set parameter value.
bool hasSection (const QString &) const
 Check section existence.
bool hasValue (const QString &, const QString &) const
 Check parameter existence.
void removeSection (const QString &)
 Remove resourcs section.
void removeValue (const QString &, const QString &)
 Remove parameter from the section.
QPixmap loadPixmap (const QString &, const QString &, const QString &) const
 Load and return pixmap from external file.
QTranslator * loadTranslator (const QString &, const QString &, const QString &) const
 Load translator.
QString makeSubstitution (const QString &, const QString &, const QString &) const
 Substitute variables by their values.
void clear ()
 Remove all sections.
QStringList sections () const
 Get all sections names.
QStringList parameters (const QString &) const
 Get all parameters name in specified section.
QString path (const QString &, const QString &, const QString &) const
 Get absolute path to the file which name is defined by the parameter.

Protected Member Functions

QtxResourceMgrresMgr () const
 Get resource manager.

Private Types

typedef QMap< QString, Section > SectionMap

Private Member Functions

Section section (const QString &)
 Get resources section by specified name.
const Section section (const QString &) const
 Get resources section by specified name.
QString fileName (const QString &, const QString &, const QString &) const
 Get file path.

Private Attributes

QtxResourceMgrmyMgr
 resources manager
SectionMap mySections
 sections map
QString myFileName
 resources file name
QMap< QString, QPixmap > myPixmapCache
 pixmaps cache

Friends

class QtxResourceMgr::Format

Detailed Description

Represents container for settings read from the resource file.

Definition at line 52 of file QtxResourceMgr.cxx.


Member Typedef Documentation

typedef QMap<QString, Section> QtxResourceMgr::Resources::SectionMap [private]

Definition at line 92 of file QtxResourceMgr.cxx.


Constructor & Destructor Documentation

QtxResourceMgr::Resources::Resources ( QtxResourceMgr mgr,
const QString &  fileName 
)

Constructor.

Parameters:
mgrparent resources manager
fileNameresources file name

Definition at line 108 of file QtxResourceMgr.cxx.

: myMgr( mgr ),
  myFileName( fileName )
{
}

Destructor.

Definition at line 117 of file QtxResourceMgr.cxx.

{
}

Member Function Documentation

Remove all sections.

Definition at line 229 of file QtxResourceMgr.cxx.

{
  mySections.clear();
}

Get resources file name.

This file is used to load/save operations.

Returns:
file name
See also:
setFile()

Definition at line 129 of file QtxResourceMgr.cxx.

{
  return myFileName;
}
QString QtxResourceMgr::Resources::fileName ( const QString &  sect,
const QString &  prefix,
const QString &  name 
) const [private]

Get file path.

The file name is defined by name argument, while directory name is retrieved from resources parameter prefix of section sec. Both directory and file name can be relative. If the directory is relative, it is calculated from the initial resources file name (see file()). Directory parameter can contain environment variables, which are substituted automatically. File existence is not checked.

Parameters:
secsection name
prefixparameter containing directory name
namefile name
Returns:
absolute file path or null QString if prefix parameter does not exist in section
See also:
path(), file(), makeSubstitution()

Definition at line 334 of file QtxResourceMgr.cxx.

{
  QString path;
  if ( hasValue( sect, prefix ) )
  {
    path = value( sect, prefix, true );
    if ( !path.isEmpty() )
    {
      if ( QFileInfo( path ).isRelative() )
        path = Qtx::addSlash( Qtx::dir( myFileName, true ) ) + path;

      path = Qtx::addSlash( path ) + name;
    }
  }
  if( !path.isEmpty() )
  {
    QString fname = QDir::convertSeparators( path );
    QFileInfo inf( fname );
    fname = inf.absoluteFilePath();
    return fname;
  }
  return QString();
}
bool QtxResourceMgr::Resources::hasSection ( const QString &  sect) const

Check section existence.

Parameters:
sectsection name
Returns:
true if section exists

Definition at line 185 of file QtxResourceMgr.cxx.

{
  return mySections.contains( sect );
}
bool QtxResourceMgr::Resources::hasValue ( const QString &  sect,
const QString &  name 
) const

Check parameter existence.

Parameters:
sectsection name
nameparameter name
Returns:
true if parameter exists in specified section

Definition at line 196 of file QtxResourceMgr.cxx.

{
  return hasSection( sect ) && section( sect ).contains( name );
}
QPixmap QtxResourceMgr::Resources::loadPixmap ( const QString &  sect,
const QString &  prefix,
const QString &  name 
) const

Load and return pixmap from external file.

If QtxResourceMgr::isPixmapCached() is true then cached pixmap is returned (if it is already loaded), otherwise it is loaded from file. If the file name is invalid, null pixmap is returned.

Parameters:
sectsection name
prefixparameter containing resources directory name
namepixmap file name
Returns:
pixmap loaded from file

Definition at line 370 of file QtxResourceMgr.cxx.

{
  QString fname = fileName( sect, prefix, name );
  bool toCache = resMgr() ? resMgr()->isPixmapCached() : false;
  QPixmap p;
  if( toCache && myPixmapCache.contains( fname ) )
    p = myPixmapCache[fname];
  else
  {
    p.load( fname );
    if( toCache )
      ( ( QMap<QString,QPixmap>& )myPixmapCache ).insert( fname, p );
  }
  return p;
}
QTranslator * QtxResourceMgr::Resources::loadTranslator ( const QString &  sect,
const QString &  prefix,
const QString &  name 
) const

Load translator.

Parameters:
sectsection name
prefixparameter containing resources directory
nametranslation file name
Returns:
just created and loaded translator or 0 in case of error

Definition at line 393 of file QtxResourceMgr.cxx.

{
  QTranslator* trans = new QtxTranslator( 0 );
  QString fname = QDir::convertSeparators( fileName( sect, prefix, name ) );
  if ( !trans->load( Qtx::file( fname, false ), Qtx::dir( fname ) ) )
  {
    delete trans;
    trans = 0;
  }
  return trans;
}
QString QtxResourceMgr::Resources::makeSubstitution ( const QString &  str,
const QString &  sect,
const QString &  name 
) const

Substitute variables by their values.

Environment variable is substituted by its value. For other variables resource manager tries to find value among defined resources parameters.

Parameters:
strstring to be processed
sectsection, where variables are searched
namename of variable which must be ignored during substitution
Returns:
processed string (with all substitutions made)

Definition at line 416 of file QtxResourceMgr.cxx.

{
  QString res = str;

  QMap<QString, int> ignoreMap;
  ignoreMap.insert( name, 0 );

  int start( 0 ), len( 0 );
  while ( true )
  {
    QString envName = Qtx::findEnvVar( res, start, len );
    if ( envName.isNull() )
      break;

    QString newStr;
    if ( ::getenv( envName.toLatin1() ) )
      newStr = QString( ::getenv( envName.toLatin1() ) );

    if ( newStr.isNull() )
    {
      if ( ignoreMap.contains( envName ) )
      {
        start += len;
        continue;
      }

      if ( hasValue( sect, envName ) )
        newStr = value( sect, envName, false );
      ignoreMap.insert( envName, 0 );
    }
    res.replace( start, len, newStr );
  }

  res.replace( "$$", "$" );
  res.replace( "%%", "%" );

  return res;
}
QStringList QtxResourceMgr::Resources::parameters ( const QString &  sec) const

Get all parameters name in specified section.

Parameters:
secsection name
Returns:
list of settings names

Definition at line 248 of file QtxResourceMgr.cxx.

{
  if ( !hasSection( sec ) )
    return QStringList();

  return section( sec ).keys();
}
QString QtxResourceMgr::Resources::path ( const QString &  sec,
const QString &  prefix,
const QString &  name 
) const

Get absolute path to the file which name is defined by the parameter.

The file name is defined by name argument, while directory name is retrieved from resources parameter prefix of section sec. Both directory and file name can be relative. If the directory is relative, it is calculated from the initial resources file name (see file()). Directory parameter can contain environment variables, which are substituted automatically.

Parameters:
secsection name
prefixparameter containing directory name
namefile name
Returns:
absolute file path or null QString if file does not exist
See also:
fileName(), file(), makeSubstitution()

Definition at line 271 of file QtxResourceMgr.cxx.

{
  QString filePath = fileName( sec, prefix, name );
  if ( !filePath.isEmpty() )
  {
    if ( !QFileInfo( filePath ).exists() )
      filePath = QString();
  }
  return filePath;
}

Remove resourcs section.

Parameters:
sectsecton name

Definition at line 205 of file QtxResourceMgr.cxx.

{
  mySections.remove( sect );
}
void QtxResourceMgr::Resources::removeValue ( const QString &  sect,
const QString &  name 
)

Remove parameter from the section.

Parameters:
sectsection name
nameparameter name

Definition at line 215 of file QtxResourceMgr.cxx.

{
  if ( !mySections.contains( sect ) )
    return;

  mySections[sect].remove( name );

  if ( mySections[sect].isEmpty() )
    mySections.remove( sect );
}

Get resource manager.

Returns:
resource manager pointer

Definition at line 286 of file QtxResourceMgr.cxx.

{
  return myMgr;
}
QtxResourceMgr::Section QtxResourceMgr::Resources::section ( const QString &  sn) [private]

Get resources section by specified name.

If section does not exist it is created (empty).

Parameters:
snsection name
Returns:
resources section

Definition at line 299 of file QtxResourceMgr.cxx.

{
  if ( !mySections.contains( sn ) )
    mySections.insert( sn, Section() );

  return mySections[sn];
}
const QtxResourceMgr::Section QtxResourceMgr::Resources::section ( const QString &  sn) const [private]

Get resources section by specified name.

Parameters:
snsection name
Returns:
resources section

Definition at line 312 of file QtxResourceMgr.cxx.

{
  return mySections[sn];
}
QStringList QtxResourceMgr::Resources::sections ( ) const

Get all sections names.

Returns:
list of section names

Definition at line 238 of file QtxResourceMgr.cxx.

{
  return mySections.keys();
}
void QtxResourceMgr::Resources::setFile ( const QString &  fn)

Set resources file name.

Parameters:
fnfile name
See also:
file()

Definition at line 139 of file QtxResourceMgr.cxx.

{
  myFileName = fn;
}
void QtxResourceMgr::Resources::setValue ( const QString &  sect,
const QString &  name,
const QString &  val 
)

Set parameter value.

Parameters:
sectsection name
nameparameter name
valparameter value
See also:
value(), makeSubstitution()

Definition at line 172 of file QtxResourceMgr.cxx.

{
  if ( !mySections.contains( sect ) )
    mySections.insert( sect, Section() );

  mySections[sect].insert( name, val );
}
QString QtxResourceMgr::Resources::value ( const QString &  sect,
const QString &  name,
const bool  subst 
) const

Get string representation of parameter value.

Parameters:
sectsection name
nameparameter name
substif true, perform variables substitution
Returns:
parameter value or null QString if there is no such parameter
See also:
setValue(), makeSubstitution()

Definition at line 152 of file QtxResourceMgr.cxx.

{
  QString val;

  if ( hasValue( sect, name ) )
  {
    val = section( sect )[name];
    if ( subst )
      val = makeSubstitution( val, sect, name );
  }
  return val;
}

Friends And Related Function Documentation

friend class QtxResourceMgr::Format [friend]

Definition at line 100 of file QtxResourceMgr.cxx.


Member Data Documentation

resources file name

Definition at line 97 of file QtxResourceMgr.cxx.

resources manager

Definition at line 95 of file QtxResourceMgr.cxx.

QMap<QString,QPixmap> QtxResourceMgr::Resources::myPixmapCache [private]

pixmaps cache

Definition at line 98 of file QtxResourceMgr.cxx.

sections map

Definition at line 96 of file QtxResourceMgr.cxx.


The documentation for this class was generated from the following file: