Version: 8.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
QtxResourceMgr::Resources Class Reference

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

Public Member Functions

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

Protected Member Functions

QtxResourceMgrresMgr () const
 Get resource manager. More...
 

Private Types

typedef QMap< QString, SectionSectionMap
 
typedef QMap< QString, QString > OptionsMap
 

Private Member Functions

Section section (const QString &)
 Get resources section by specified name. More...
 
const Section section (const QString &) const
 Get resources section by specified name. More...
 
QString makeSubstitution (const QString &, const QString &, const QString &, const OptionsMap &) const
 Substitute variables by their values. More...
 
QString fileName (const QString &, const QString &, const QString &, const OptionsMap &) const
 Get file path. More...
 

Private Attributes

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

Friends

class QtxResourceMgr::Format
 

Detailed Description

Member Typedef Documentation

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

Constructor & Destructor Documentation

QtxResourceMgr::Resources::Resources ( QtxResourceMgr mgr,
const QString &  fileName 
)
Parameters
mgrparent resources manager
fileNameresources file name
QtxResourceMgr::Resources::~Resources ( )
virtual

Member Function Documentation

void QtxResourceMgr::Resources::clear ( )
QString QtxResourceMgr::Resources::file ( ) const

This file is used to load/save operations.

Returns
file name
See Also
setFile()
QString QtxResourceMgr::Resources::fileName ( const QString &  sect,
const QString &  prefix,
const QString &  name,
const OptionsMap constants 
) const
private

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()

References Qtx::addSlash(), Qtx::dir(), QtxResourceMgr::hasValue(), QtxResourceMgr::path(), and QtxResourceMgr::value().

bool QtxResourceMgr::Resources::hasSection ( const QString &  sect) const
Parameters
sectsection name
Returns
true if section exists
bool QtxResourceMgr::Resources::hasValue ( const QString &  sect,
const QString &  name 
) const
Parameters
sectsection name
nameparameter name
Returns
true if parameter exists in specified section

References QtxResourceMgr::hasSection().

QPixmap QtxResourceMgr::Resources::loadPixmap ( const QString &  sect,
const QString &  prefix,
const QString &  name,
const OptionsMap constants 
) const

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
QTranslator * QtxResourceMgr::Resources::loadTranslator ( const QString &  sect,
const QString &  prefix,
const QString &  name,
const OptionsMap constants 
) const
Parameters
sectsection name
prefixparameter containing resources directory
nametranslation file name
Returns
just created and loaded translator or 0 in case of error

References Qtx::dir(), and Qtx::file().

QString QtxResourceMgr::Resources::makeSubstitution ( const QString &  str,
const QString &  sect,
const QString &  name,
const OptionsMap constants 
) const
private

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)

References Qtx::findEnvVar(), QtxResourceMgr::hasValue(), and QtxResourceMgr::value().

QStringList QtxResourceMgr::Resources::parameters ( const QString &  sec) const
Parameters
secsection name
Returns
list of settings names

References QtxResourceMgr::hasSection().

QString QtxResourceMgr::Resources::path ( const QString &  sec,
const QString &  prefix,
const QString &  name,
const OptionsMap constants 
) const

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()
void QtxResourceMgr::Resources::removeSection ( const QString &  sect)
Parameters
sectsecton name
void QtxResourceMgr::Resources::removeValue ( const QString &  sect,
const QString &  name 
)
Parameters
sectsection name
nameparameter name
QtxResourceMgr * QtxResourceMgr::Resources::resMgr ( ) const
protected
Returns
resource manager pointer
QtxResourceMgr::Section QtxResourceMgr::Resources::section ( const QString &  sn)
private

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

Parameters
snsection name
Returns
resources section

References IMap< Key, Value >::insert().

const QtxResourceMgr::Section QtxResourceMgr::Resources::section ( const QString &  sn) const
private
Parameters
snsection name
Returns
resources section
QStringList QtxResourceMgr::Resources::sections ( ) const
Returns
list of section names
void QtxResourceMgr::Resources::setFile ( const QString &  fn)
Parameters
fnfile name
See Also
file()
void QtxResourceMgr::Resources::setValue ( const QString &  sect,
const QString &  name,
const QString &  val 
)
Parameters
sectsection name
nameparameter name
valparameter value
See Also
value(), makeSubstitution()
QString QtxResourceMgr::Resources::value ( const QString &  sect,
const QString &  name,
const bool  subst,
const OptionsMap constants 
) const
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()

References QtxResourceMgr::hasValue().

Friends And Related Function Documentation

friend class QtxResourceMgr::Format
friend

Member Data Documentation

QString QtxResourceMgr::Resources::myFileName
private
QtxResourceMgr* QtxResourceMgr::Resources::myMgr
private
QMap<QString,QPixmap> QtxResourceMgr::Resources::myPixmapCache
private
SectionMap QtxResourceMgr::Resources::mySections
private

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