Version: 9.12.0
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

Represents container for settings read from the resource file.

Member Typedef Documentation

◆ OptionsMap

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

◆ SectionMap

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

Constructor & Destructor Documentation

◆ Resources()

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

Constructor.

Parameters
mgrparent resources manager
fileNameresources file name

◆ ~Resources()

QtxResourceMgr::Resources::~Resources ( )
virtual

Destructor.

Member Function Documentation

◆ clear()

void QtxResourceMgr::Resources::clear ( )

Remove all sections.

◆ file()

QString QtxResourceMgr::Resources::file ( ) const

Get resources file name.

This file is used to load/save operations.

Returns
file name
See also
setFile()

◆ fileName()

QString QtxResourceMgr::Resources::fileName ( const QString &  sect,
const QString &  prefix,
const QString &  name,
const OptionsMap constants 
) 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 \sec
See also
path(), file(), makeSubstitution()

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

◆ hasSection()

bool QtxResourceMgr::Resources::hasSection ( const QString &  sect) const

Check section existence.

Parameters
sectsection name
Returns
true if section exists

◆ hasValue()

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

References QtxResourceMgr::hasSection().

◆ loadPixmap()

QPixmap QtxResourceMgr::Resources::loadPixmap ( const QString &  sect,
const QString &  prefix,
const QString &  name,
const OptionsMap constants 
) 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

References QtxResourceMgr::constants().

◆ loadTranslator()

QTranslator * QtxResourceMgr::Resources::loadTranslator ( const QString &  sect,
const QString &  prefix,
const QString &  name,
const OptionsMap constants 
) 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

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

◆ makeSubstitution()

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

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)

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

◆ parameters()

QStringList QtxResourceMgr::Resources::parameters ( const QString &  sec) const

Get all parameters name in specified section.

Parameters
secsection name
Returns
list of settings names

References QtxResourceMgr::hasSection().

◆ path()

QString QtxResourceMgr::Resources::path ( const QString &  sec,
const QString &  prefix,
const QString &  name,
const OptionsMap constants 
) 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()

References QtxResourceMgr::constants().

◆ removeSection()

void QtxResourceMgr::Resources::removeSection ( const QString &  sect)

Remove resourcs section.

Parameters
sectsecton name

◆ removeValue()

void QtxResourceMgr::Resources::removeValue ( const QString &  sect,
const QString &  name 
)

Remove parameter from the section.

Parameters
sectsection name
nameparameter name

◆ resMgr()

QtxResourceMgr * QtxResourceMgr::Resources::resMgr ( ) const
protected

Get resource manager.

Returns
resource manager pointer

◆ section() [1/2]

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

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

◆ section() [2/2]

const QtxResourceMgr::Section QtxResourceMgr::Resources::section ( const QString &  sn) const
private

Get resources section by specified name.

Parameters
snsection name
Returns
resources section

◆ sections()

QStringList QtxResourceMgr::Resources::sections ( ) const

Get all sections names.

Returns
list of section names

◆ setFile()

void QtxResourceMgr::Resources::setFile ( const QString &  fn)

Set resources file name.

Parameters
fnfile name
See also
file()

◆ setValue()

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

◆ value()

QString QtxResourceMgr::Resources::value ( const QString &  sect,
const QString &  name,
const bool  subst,
const OptionsMap constants 
) 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()

References QtxResourceMgr::constants(), and QtxResourceMgr::hasValue().

Friends And Related Function Documentation

◆ QtxResourceMgr::Format

friend class QtxResourceMgr::Format
friend

Member Data Documentation

◆ myFileName

QString QtxResourceMgr::Resources::myFileName
private

resources file name

◆ myMgr

QtxResourceMgr* QtxResourceMgr::Resources::myMgr
private

resources manager

◆ myPixmapCache

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

pixmaps cache

◆ mySections

SectionMap QtxResourceMgr::Resources::mySections
private

sections map


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