Version: 9.15.0
QtxResourceMgr Class Reference

Application resources manager. More...

#include <QtxResourceMgr.h>

Inheritance diagram for QtxResourceMgr:
Inheritance graph

Classes

class  Format
 Generic resources files reader/writer class. More...
 
class  IniFormat
 Reader/writer for .ini resources files. More...
 
class  JsonFormat
 Reader/writer for .json resources files. More...
 
class  Resources
 Represents container for settings read from the resource file. More...
 
class  SalomexFormat
 Reader/writer for .salomex resources files. This is an alias for JSON format. More...
 
class  XmlFormat
 Reader/writer for .xml resources files. More...
 

Public Types

enum  WorkingMode { AllowUserValues , IgnoreUserValues }
 Working mode; defines a way how resource manager handles user preferences. More...
 
typedef IMap< QString, QString > Section
 resource section More...
 

Public Member Functions

 QtxResourceMgr ()
 Default constructor. More...
 
 QtxResourceMgr (const QString &, const QString &=QString())
 Constructs the resource manager. More...
 
virtual ~QtxResourceMgr ()
 Destructor. More...
 
QString appName () const
 Get the application name. More...
 
QStringList dirList () const
 Get the resource directories list. More...
 
bool checkExisting () const
 Get the "check existance" flag. More...
 
virtual void setCheckExisting (const bool)
 Set the "check existance" flag. More...
 
bool isPixmapCached () const
 Get "cached pixmaps" option value. More...
 
void setIsPixmapCached (const bool)
 Switch "cached pixmaps" option on/off. More...
 
void clear ()
 Remove all resources from the resources manager. More...
 
WorkingMode workingMode () const
 Get current working mode. More...
 
WorkingMode setWorkingMode (WorkingMode)
 Set resource manager's working mode. More...
 
bool value (const QString &, const QString &, int &) const
 Get interger parameter value. More...
 
bool value (const QString &, const QString &, double &) const
 Get double parameter value. More...
 
bool value (const QString &, const QString &, bool &) const
 Get boolean parameter value. More...
 
bool value (const QString &, const QString &, QColor &) const
 Get color parameter value. More...
 
bool value (const QString &, const QString &, QFont &) const
 Get font parameter value. More...
 
bool value (const QString &, const QString &, QByteArray &) const
 Get byte array parameter value. More...
 
bool value (const QString &, const QString &, QLinearGradient &) const
 Get linear gradient parameter value. More...
 
bool value (const QString &, const QString &, QRadialGradient &) const
 Get radial gradient parameter value. More...
 
bool value (const QString &, const QString &, QConicalGradient &) const
 Get conical gradient parameter value. More...
 
bool value (const QString &, const QString &, Qtx::BackgroundData &) const
 Get background parameter value. More...
 
bool value (const QString &, const QString &, QString &, const bool=true) const
 Get string parameter value (native format). More...
 
int integerValue (const QString &, const QString &, const int=0) const
 Get interger parameter value. More...
 
double doubleValue (const QString &, const QString &, const double=0) const
 Get double parameter value. More...
 
bool booleanValue (const QString &, const QString &, const bool=false) const
 Get boolean parameter value. More...
 
QFont fontValue (const QString &, const QString &, const QFont &=QFont()) const
 Get font parameter value. More...
 
QColor colorValue (const QString &, const QString &, const QColor &=QColor()) const
 Get color parameter value. More...
 
QString stringValue (const QString &, const QString &, const QString &=QString(), const bool=true) const
 Get string parameter value. More...
 
QByteArray byteArrayValue (const QString &, const QString &, const QByteArray &=QByteArray()) const
 Get byte array parameter value. More...
 
QLinearGradient linearGradientValue (const QString &, const QString &, const QLinearGradient &=QLinearGradient()) const
 Get linear gradient parameter value. More...
 
QRadialGradient radialGradientValue (const QString &, const QString &, const QRadialGradient &=QRadialGradient()) const
 Get radial gradient parameter value. More...
 
QConicalGradient conicalGradientValue (const QString &, const QString &, const QConicalGradient &=QConicalGradient()) const
 Get conical gradient parameter value. More...
 
Qtx::BackgroundData backgroundValue (const QString &, const QString &, const Qtx::BackgroundData &=Qtx::BackgroundData()) const
 Get background parameter value. More...
 
bool hasSection (const QString &) const
 Check section existence. More...
 
bool hasValue (const QString &, const QString &) const
 Check parameter existence. More...
 
void setValue (const QString &, const QString &, const int)
 Set integer parameter value. More...
 
void setValue (const QString &, const QString &, const double)
 Set double parameter value. More...
 
void setValue (const QString &, const QString &, const bool)
 Set boolean parameter value. More...
 
void setValue (const QString &, const QString &, const QFont &)
 Set font parameter value. More...
 
void setValue (const QString &, const QString &, const QColor &)
 Set color parameter value. More...
 
void setValue (const QString &, const QString &, const QString &)
 Set string parameter value. More...
 
void setValue (const QString &, const QString &, const QByteArray &)
 Set byte array parameter value. More...
 
void setValue (const QString &, const QString &, const QLinearGradient &)
 Set linear gradient parameter value. More...
 
void setValue (const QString &, const QString &, const QRadialGradient &)
 Set radial gradient parameter value. More...
 
void setValue (const QString &, const QString &, const QConicalGradient &)
 Set conical gradient parameter value. More...
 
void setValue (const QString &, const QString &, const Qtx::BackgroundData &)
 Set background parameter value. More...
 
void remove (const QString &)
 Remove resources section. More...
 
void remove (const QString &, const QString &)
 Remove the specified parameter. More...
 
QString currentFormat () const
 Get current configuration files format. More...
 
void setCurrentFormat (const QString &)
 Set current configuration files format. More...
 
Formatformat (const QString &) const
 Get configuration files format by specified format name. More...
 
void installFormat (Format *)
 Install configuration files format. More...
 
void removeFormat (Format *)
 Remove configuration files format. More...
 
QStringList options () const
 Get resource format options names. More...
 
QString option (const QString &) const
 Get the string value of the specified resources format option. More...
 
void setOption (const QString &, const QString &)
 Set the string value of the specified resources format option. More...
 
QStringList constants () const
 Get names of all known constants. More...
 
QString constant (const QString &) const
 Get the value of the known constant. More...
 
void setConstant (const QString &, const QString &)
 Set the value of the constant. More...
 
QPixmap defaultPixmap () const
 Get default pixmap. More...
 
virtual void setDefaultPixmap (const QPixmap &)
 Set default pixmap. More...
 
QString resSection () const
 Get application resources section name. More...
 
QString langSection () const
 Get application language section name. More...
 
QString sectionsToken () const
 Get sections separator token. More...
 
QPixmap loadPixmap (const QString &, const QString &) const
 Load pixmap resource. More...
 
QPixmap loadPixmap (const QString &, const QString &, const bool) const
 Load pixmap resource. This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
QPixmap loadPixmap (const QString &, const QString &, const QPixmap &) const
 Load pixmap resource. This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. More...
 
void loadLanguage (const QString &=QString(), const QString &=QString())
 Load translation files according to the specified language. More...
 
void raiseTranslators (const QString &)
 Move all translators corresponding to the specified translation context to the top of translators stack (increase their priority). More...
 
void removeTranslators (const QString &)
 Remove all translators corresponding to the specified translation context. More...
 
void loadTranslator (const QString &, const QString &)
 Load translation file. More...
 
void loadTranslators (const QString &, const QStringList &)
 Load translation files for the specified translation context. More...
 
void addTranslator (const QString &, QTranslator *)
 Add custom translator. More...
 
QString path (const QString &, const QString &, const QString &) const
 Get absolute path to the file which name is defined by the parameter. More...
 
bool load ()
 Load all resources from all resource files (global and user). More...
 
bool import (const QString &)
 Import resources from specified resource file. More...
 
bool save ()
 Save all resources to the user resource files. More...
 
bool addResource (const QString &)
 Load resource from given file. More...
 
QStringList sections () const
 Get all sections names. More...
 
QStringList sections (const QRegExp &) const
 Get all sections names matching specified regular expression. More...
 
QStringList sections (const QStringList &) const
 Get all sections names with the prefix specified by passed list of parent sections names. More...
 
QStringList subSections (const QString &, const bool=true) const
 Get list of sub-sections names for the specified parent section name. More...
 
QStringList parameters (const QString &) const
 Get all parameters name in specified section. More...
 
QStringList parameters (const QStringList &) const
 Get all parameters name in specified list of sub-sections names. More...
 
void refresh ()
 Copy all parameters to the user resources in order to saved them lately in the user home folder. More...
 
QString language (const QString &=QString()) const
 Select language to be used. More...
 

Protected Member Functions

virtual QString defaultLanguage () const
 Specify default language for the application. More...
 
virtual void setDirList (const QStringList &)
 Set the resource directories (where global confguration files are searched). More...
 
virtual void setResource (const QString &, const QString &, const QString &)
 Set parameter value. More...
 
virtual QString userFileName (const QString &, const bool=true) const
 Get user configuration file name. More...
 
virtual QString globalFileName (const QString &) const
 Get global configuration file name. More...
 
virtual void saved ()
 This function is called after user configuration file is saved. Can be redefined in the successor classes, default implementation does nothing. More...
 

Private Types

typedef QList< Resources * > ResList
 
typedef QList< QTranslator * > TransList
 
typedef QList< Format * > FormatList
 
typedef QMap< QString, QString > OptionsMap
 
typedef QMap< QString, TransListTransListMap
 

Private Member Functions

void initialize (const bool=true) const
 Initialise resources manager. More...
 
QString substMacro (const QString &, const QMap< QChar, QString > &) const
 Perform substitution of the patterns like %A, %B, etc by values from the map. More...
 

Private Attributes

QString myAppName
 application name More...
 
QStringList myDirList
 list of resources directories More...
 
FormatList myFormats
 list of formats More...
 
OptionsMap myOptions
 options map More...
 
OptionsMap myConstants
 constants map More...
 
ResList myResources
 resources list More...
 
bool myCheckExist
 "check existance" flag More...
 
TransListMap myTranslator
 map of loaded translators More...
 
QPixmap * myDefaultPix
 default icon More...
 
bool myIsPixmapCached
 "cached pixmaps" flag More...
 
bool myHasUserValues
 true if user preferences has been read More...
 
WorkingMode myWorkingMode
 working mode More...
 

Friends

class QtxResourceMgr::Format
 

Detailed Description

Application resources manager.

This class can be used to define settings, save/load settings and application preferences to the resource file(s), load translation files (internationalization mechanism), load pixmaps and other resources from external files, etc.

Currently it supports .ini, .xml, and .json resources file formats. To implement own resources file format, inherit from the Format class and implement virtual Format::load() and Format::save() methods.

Resources manager is initialized by the (symbolic) name of the application. The parameter resVarTemplate specifies the template for the environment variable which should point to the resource directory or list of directories. Environment variable name is calculated by substitution of "%1" substring in the resVarTemplate parameter (if it contains such substring) by the application name (appName). By default, resVarTemplate is set to "%1Resources". For example, if the application name is "MyApp", the environment variable "MyAppResources" will be inspected in this case.

Resource manager can handle several global application configuration files and one user configuration file. Location of global configuration files is defined by the environment variable (see above) and these files are always read-only. The name of the global configuration files is retrieved by calling virtual method globalFileName() which can be redefined in the QtxResourceMgr class successors. User configuration file always situated in the user's home directory. It's name is defined by calling virtual method userFileName() which can be also redefined in the QtxResourceMgr class successors. This is the only file which the preferences changed by the user during the application session are written to (usually when the application closes).

Resources environment variable should contain one or several resource directories (separated by ";" symbol on Windows and ":" or ";" on Linux). Each resource directory can contain application global configuration file. The user configuration file has the highest priority, for the global configuration files the priority is decreasing from left to right, i.e. the first directory in the directoris list, defined by the resources environment variable has higher priority. Priority has the meaning when searching requested resources (application preference, pixmap file name, translation file, etc).

When retrieving preferences, it is sometimes helpful to ignore values coming from the user preference file and take into account only global preferences. To do this, use setWorkingMode() method passing QtxResourceMgr::IgnoreUserValues enumerator as parameter.

Resources manager operates with such terms like options, sections and parameters. Parametets are named application resources, for example, application preferences like integer, double, boolean or string values, pictures, font and color definitions, etc. Parameters are organized inside the resources files into the named groups - sections. Options are special kind of resoures which allow customizing resource files interpreting. For example, by default language settings are defined in the resource file in the section "language". It is possible to change this section name by setting "language" option to another value (see setOption()).

Retrieving preferences values can be done by using one of value() methods, each returns true if the corresponding preference is found. Another way is to use integerValue(), doubleValue(), etc methods, which allow specifying default value which is used if the specified preference is not found. Removing of preferences or sections can be done using remove(const QString& sect) or remove(const QString& sect, const QString& name) methods. To add the preference or to change exiting preference value use setValue() methods family. Methods hasSection() and hasValue() can be used to check existence of section or preference (in the specified section). List of all sections can be retrieved with the sections() method, and list of all settings names in some specified section can be obtained with parameters() method.

Pixmaps can be loaded with the loadPixmap() methods. If the specified pixmap is not found, the default one is returned. Default pixmap can be set by setDefaultPixmap().

One of the key feature of the resources manager is support of application internationalization mechanism. Translation files for the specified language can be loaded with loadLanguage() method.

Member Typedef Documentation

◆ FormatList

◆ OptionsMap

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

◆ ResList

◆ Section

typedef IMap<QString, QString> QtxResourceMgr::Section

resource section

◆ TransList

◆ TransListMap

typedef QMap<QString, TransList> QtxResourceMgr::TransListMap
private

Member Enumeration Documentation

◆ WorkingMode

Working mode; defines a way how resource manager handles user preferences.

Enumerator
AllowUserValues 

User values are processed by the resource manager.

IgnoreUserValues 

User values are ignored by the resource manager.

Constructor & Destructor Documentation

◆ QtxResourceMgr() [1/2]

QtxResourceMgr::QtxResourceMgr ( )

Default constructor.

References installFormat(), and setOption().

◆ QtxResourceMgr() [2/2]

QtxResourceMgr::QtxResourceMgr ( const QString &  appName,
const QString &  resVarTemplate = QString() 
)

Constructs the resource manager.

Parameters
appNameapplication name
resVarTemplateresource environment variable pattern

References appName(), Qtx::getenv(), installFormat(), setDirList(), and setOption().

◆ ~QtxResourceMgr()

QtxResourceMgr::~QtxResourceMgr ( )
virtual

Destructor.

Destroy the resource manager and free allocated memory.

References myDefaultPix, myFormats, myResources, myTranslator, and removeTranslators().

Member Function Documentation

◆ addResource()

bool QtxResourceMgr::addResource ( const QString &  fname)

Load resource from given file.

References appName(), format(), globalFileName(), QtxResourceMgr::Format::load(), myDirList, and myResources.

◆ addTranslator()

void QtxResourceMgr::addTranslator ( const QString &  prefix,
QTranslator translator 
)

Add custom translator.

Parameters
prefixparameter which defines translation context (for example, package name)
translatortranslator being installed
See also
loadLanguage(), loadTranslators()

References myTranslator.

◆ appName()

QString QtxResourceMgr::appName ( ) const

Get the application name.

Returns
application name

References myAppName.

◆ backgroundValue()

Qtx::BackgroundData QtxResourceMgr::backgroundValue ( const QString &  sect,
const QString &  name,
const Qtx::BackgroundData def = Qtx::BackgroundData() 
) const

Get background parameter value.

If the specified parameter is not found, the specified default value is returned instead.

Parameters
sectsection name
nameparameter name
defdefault value
Returns
parameter value (or default value if parameter is not found)

References value().

◆ booleanValue()

bool QtxResourceMgr::booleanValue ( const QString &  sect,
const QString &  name,
const bool  def = false 
) const

Get boolean parameter value.

If the specified parameter is not found or can not be converted to the boolean value, the specified default value is returned instead.

Parameters
sectsection name
nameparameter name
defdefault value
Returns
parameter value (or default value if parameter is not found)

References value().

◆ byteArrayValue()

QByteArray QtxResourceMgr::byteArrayValue ( const QString &  sect,
const QString &  name,
const QByteArray &  def = QByteArray() 
) const

Get byte array parameter value.

If the specified parameter is not found, the specified default value is returned instead.

Parameters
sectsection name
nameparameter name
defdefault value
Returns
parameter value (or default value if parameter is not found)

References value().

◆ checkExisting()

bool QtxResourceMgr::checkExisting ( ) const

Get the "check existance" flag.

If this flag is true then preference can be set (with setValue() method) only if it doesn't exist or if the value is changed.

Returns
true if "check existance" flag is set

References myCheckExist.

◆ clear()

void QtxResourceMgr::clear ( )

Remove all resources from the resources manager.

References myResources.

◆ colorValue()

QColor QtxResourceMgr::colorValue ( const QString &  sect,
const QString &  name,
const QColor &  def = QColor() 
) const

Get color parameter value.

If the specified parameter is not found or can not be converted to the color value, the specified default value is returned instead.

Parameters
sectsection name
nameparameter name
defdefault value
Returns
parameter value (or default value if parameter is not found)

References value().

◆ conicalGradientValue()

QConicalGradient QtxResourceMgr::conicalGradientValue ( const QString &  sect,
const QString &  name,
const QConicalGradient &  def = QConicalGradient() 
) const

Get conical gradient parameter value.

If the specified parameter is not found, the specified default value is returned instead.

Parameters
sectsection name
nameparameter name
defdefault value
Returns
parameter value (or default value if parameter is not found)

References value().

◆ constant()

QString QtxResourceMgr::constant ( const QString &  name) const

Get the value of the known constant.

If constant is not set, null QString is returned.

Parameters
nameconstant name
Returns
constant value
See also
setConstant(), constants()

References myConstants.

◆ constants()

QStringList QtxResourceMgr::constants ( ) const

Get names of all known constants.

Returns
list of constants names
See also
constant(), setConstant

References myConstants.

◆ currentFormat()

QString QtxResourceMgr::currentFormat ( ) const

Get current configuration files format.

Returns
configuration files format name

References myFormats.

◆ defaultLanguage()

QString QtxResourceMgr::defaultLanguage ( ) const
protectedvirtual

Specify default language for the application.

Reimplemented in SUIT_ResourceMgr.

◆ defaultPixmap()

QPixmap QtxResourceMgr::defaultPixmap ( ) const

Get default pixmap.

Default pixmap is used when requested pixmap resource is not found.

Returns
default pixmap
See also
setDefaultPixmap(), loadPixmap()

References myDefaultPix, and pixmap_not_found_xpm.

◆ dirList()

QStringList QtxResourceMgr::dirList ( ) const

Get the resource directories list.

Home user directory (where the user application configuration file is situated) is not included. This is that directories list defined by the application resources environment variable.

Returns
list of directories names

References myDirList.

◆ doubleValue()

double QtxResourceMgr::doubleValue ( const QString &  sect,
const QString &  name,
const double  def = 0 
) const

Get double parameter value.

If the specified parameter is not found or can not be converted to the double value, the specified default value is returned instead.

Parameters
sectsection name
nameparameter name
defdefault value
Returns
parameter value (or default value if parameter is not found)

References value().

◆ fontValue()

QFont QtxResourceMgr::fontValue ( const QString &  sect,
const QString &  name,
const QFont &  def = QFont() 
) const

Get font parameter value.

If the specified parameter is not found or can not be converted to the font value, the specified default value is returned instead.

Parameters
sectsection name
nameparameter name
defdefault value
Returns
parameter value (or default value if parameter is not found)

References value().

◆ format()

QtxResourceMgr::Format * QtxResourceMgr::format ( const QString &  fmt) const

Get configuration files format by specified format name.

Parameters
fmtconfiguration files format name
Returns
format object or 0 if format is not defined

References myFormats.

◆ globalFileName()

QString QtxResourceMgr::globalFileName ( const QString &  appName) const
protectedvirtual

Get global configuration file name.

This method can be redefined in the successor class to customize the global configuration file name. Global configuration files are searched in the directories specified by the application resources environment variable (e.g. MyAppResources). By default <appName>.<format> file name is used (e.g. MyApp.xml).

Parameters
appNameapplication name
Returns
global configuration file name
See also
userFileName()

References appName(), and currentFormat().

◆ hasSection()

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

Check section existence.

Parameters
sectsection name
Returns
true if section exists

References IgnoreUserValues, initialize(), myHasUserValues, myResources, and workingMode().

◆ hasValue()

bool QtxResourceMgr::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 IgnoreUserValues, initialize(), myHasUserValues, myResources, and workingMode().

◆ import()

bool QtxResourceMgr::import ( const QString &  fname)

Import resources from specified resource file.

Parameters
fnameresources file name
Returns
true on success and false on error

References currentFormat(), QtxResourceMgr::Resources::file(), format(), QtxResourceMgr::Format::load(), myHasUserValues, myResources, and QtxResourceMgr::Resources::setFile().

◆ initialize()

void QtxResourceMgr::initialize ( const bool  autoLoad = true) const
private

Initialise resources manager.

Prepare the resources containers and load resources (if autoLoad is true).

Parameters
autoLoadif true (default) then all resources are loaded

References Qtx::addSlash(), appName(), globalFileName(), load(), myDirList, myHasUserValues, myResources, path(), and userFileName().

◆ installFormat()

void QtxResourceMgr::installFormat ( QtxResourceMgr::Format form)

Install configuration files format.

Added format becomes current.

Parameters
formformat object to be installed

References myFormats.

◆ integerValue()

int QtxResourceMgr::integerValue ( const QString &  sect,
const QString &  name,
const int  def = 0 
) const

Get interger parameter value.

If the specified parameter is not found or can not be converted to the integer value, the specified default value is returned instead.

Parameters
sectsection name
nameparameter name
defdefault value
Returns
parameter value (or default value if parameter is not found)

References value().

◆ isPixmapCached()

bool QtxResourceMgr::isPixmapCached ( ) const

Get "cached pixmaps" option value.

Resources manager allows possibility to cache loaded pixmaps that allow to improve application performance. This feature is turned on by default - all loaded pixmaps are stored in the internal map. Switching of this feature on/off can be done by setIsPixmapCached() method.

Returns
true if pixmap cache is turned on
See also
setIsPixmapCached()

References myIsPixmapCached.

◆ langSection()

QString QtxResourceMgr::langSection ( ) const

Get application language section name.

By default, application language section name is "language" but it can be changed by setting the "lang_section_name" resources manager option.

Returns
section corresponding to the application language settings
See also
option(), setOption()

References option().

◆ language()

QString QtxResourceMgr::language ( const QString &  preferableLanguage = QString()) const

Select language to be used.

Parameters
preferableLanguagepreferable language name (if empty, default language is used)

References defaultLanguage(), langSection(), and value().

◆ linearGradientValue()

QLinearGradient QtxResourceMgr::linearGradientValue ( const QString &  sect,
const QString &  name,
const QLinearGradient &  def = QLinearGradient() 
) const

Get linear gradient parameter value.

If the specified parameter is not found, the specified default value is returned instead.

Parameters
sectsection name
nameparameter name
defdefault value
Returns
parameter value (or default value if parameter is not found)

References value().

◆ load()

bool QtxResourceMgr::load ( )

Load all resources from all resource files (global and user).

Returns
true on success and false on error
See also
save()

References currentFormat(), format(), initialize(), QtxResourceMgr::Format::load(), and myResources.

◆ loadLanguage()

void QtxResourceMgr::loadLanguage ( const QString &  pref = QString(),
const QString &  preferableLanguage = QString() 
)

Load translation files according to the specified language.

Names of the translation files are calculated according to the pattern specified by the "translators" option (this option is read from the section "language" of resources files). By default, "%P_msg_%L.qm" pattern is used. Keywords %A, %P, %L in the pattern are substituted by the application name, prefix and language name correspondingly. For example, for prefix "SUIT" and language "en", all translation files "SUIT_msg_en.qm" are searched and loaded.

If prefix is empty or null string, all translation files specified in the "resources" section of resources files are loaded (actually, the section is retrieved from resSection() method). If language is not specified, it is retrieved from the langSection() method, and if the latest is also empty, by default "en" (English) language is used. By default, settings from the user preferences file are also loaded (if user resource file is valid, see userFileName()). To avoid loading user settings, pass false as first parameter.

Parameters
prefparameter which defines translation context (for example, package name)
preferableLanguagelanguage name
See also
resSection(), langSection(), loadTranslators()

References appName(), initialize(), langSection(), language(), loadTranslators(), option(), parameters(), Qtx::qtDir(), resSection(), setOption(), substMacro(), and value().

◆ loadPixmap() [1/3]

QPixmap QtxResourceMgr::loadPixmap ( const QString &  prefix,
const QString &  name 
) const

Load pixmap resource.

Parameters
prefixparameter which refers to the resources directory (directories)
namepixmap file name
Returns
pixmap loaded from the file
See also
defaultPixmap(), setDefaultPixmap()

◆ loadPixmap() [2/3]

QPixmap QtxResourceMgr::loadPixmap ( const QString &  prefix,
const QString &  name,
const bool  useDef 
) const

Load pixmap resource. This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
prefixparameter which refers to the resources directory (directories)
namepixmap file name
useDefif false, default pixmap is not returned if resource is not found, in this case null pixmap is returned instead
Returns
pixmap loaded from the file
See also
defaultPixmap(), setDefaultPixmap()

References defaultPixmap(), and loadPixmap().

◆ loadPixmap() [3/3]

QPixmap QtxResourceMgr::loadPixmap ( const QString &  prefix,
const QString &  name,
const QPixmap &  defPix 
) const

Load pixmap resource. This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Parameters
prefixparameter which refers to the resources directory (directories)
namepixmap file name
defPixdefault which should be used if the resource file doesn't exist
Returns
pixmap loaded from the file
See also
defaultPixmap(), setDefaultPixmap()

References IgnoreUserValues, initialize(), myConstants, myHasUserValues, myResources, resSection(), and workingMode().

◆ loadTranslator()

void QtxResourceMgr::loadTranslator ( const QString &  prefix,
const QString &  name 
)

Load translation file.

Parameters
prefixparameter which defines translation context (for example, package name)
nametranslator file name
See also
loadLanguage(), loadTranslators()

References IgnoreUserValues, initialize(), QtxResourceMgr::Resources::loadTranslator(), myConstants, myResources, myTranslator, resSection(), and workingMode().

◆ loadTranslators()

void QtxResourceMgr::loadTranslators ( const QString &  prefix,
const QStringList &  translators 
)

Load translation files for the specified translation context.

Parameters
prefixparameter which defines translation context (for example, package name)
translatorslist of translation files
See also
loadLanguage()

References IgnoreUserValues, initialize(), myConstants, myHasUserValues, myResources, myTranslator, resSection(), and workingMode().

◆ option()

QString QtxResourceMgr::option ( const QString &  opt) const

Get the string value of the specified resources format option.

If option does not exist, null QString is returned.

Parameters
optoption name
Returns
option value
See also
setOption(), options()

References myOptions.

◆ options()

QStringList QtxResourceMgr::options ( ) const

Get resource format options names.

Returns
list of options names

References myOptions.

◆ parameters() [1/2]

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

Get all parameters name in specified section.

Parameters
secsection name
Returns
list of settings names

References IgnoreUserValues, initialize(), myResources, QtxResourceMgr::Resources::parameters(), and workingMode().

◆ parameters() [2/2]

QStringList QtxResourceMgr::parameters ( const QStringList &  names) const

Get all parameters name in specified list of sub-sections names.

Sub-sections are separated inside the section name by the sections separator token, for example "splash:color:label".

Parameters
namesparent sub-sections names
Returns
list of settings names

References parameters(), and sectionsToken().

◆ path()

QString QtxResourceMgr::path ( const QString &  sect,
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. 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

References IgnoreUserValues, myConstants, myHasUserValues, myResources, and workingMode().

◆ radialGradientValue()

QRadialGradient QtxResourceMgr::radialGradientValue ( const QString &  sect,
const QString &  name,
const QRadialGradient &  def = QRadialGradient() 
) const

Get radial gradient parameter value.

If the specified parameter is not found, the specified default value is returned instead.

Parameters
sectsection name
nameparameter name
defdefault value
Returns
parameter value (or default value if parameter is not found)

References value().

◆ raiseTranslators()

void QtxResourceMgr::raiseTranslators ( const QString &  prefix)

Move all translators corresponding to the specified translation context to the top of translators stack (increase their priority).

Parameters
prefixparameter which defines translation context (for example, package name)

References myTranslator.

◆ refresh()

void QtxResourceMgr::refresh ( )

Copy all parameters to the user resources in order to saved them lately in the user home folder.

References parameters(), sections(), setResource(), and stringValue().

◆ remove() [1/2]

void QtxResourceMgr::remove ( const QString &  sect)

Remove resources section.

Parameters
sectsection name

References initialize(), and myResources.

◆ remove() [2/2]

void QtxResourceMgr::remove ( const QString &  sect,
const QString &  name 
)

Remove the specified parameter.

Parameters
sectsection name
nameparameter name

References initialize(), and myResources.

◆ removeFormat()

void QtxResourceMgr::removeFormat ( QtxResourceMgr::Format form)

Remove configuration files format.

Parameters
formformat object to be uninstalled

References myFormats.

◆ removeTranslators()

void QtxResourceMgr::removeTranslators ( const QString &  prefix)

Remove all translators corresponding to the specified translation context.

Parameters
prefixparameter which defines translation context (for example, package name)

References myTranslator.

◆ resSection()

QString QtxResourceMgr::resSection ( ) const

Get application resources section name.

By default, application resources section name is "resources" but it can be changed by setting the "res_section_name" resources manager option.

Returns
section corresponding to the resources directories
See also
option(), setOption()

References option().

◆ save()

bool QtxResourceMgr::save ( )

Save all resources to the user resource files.

Returns
true on success and false on error

References currentFormat(), format(), initialize(), myHasUserValues, myResources, QtxResourceMgr::Format::save(), and saved().

◆ saved()

void QtxResourceMgr::saved ( )
protectedvirtual

This function is called after user configuration file is saved. Can be redefined in the successor classes, default implementation does nothing.

◆ sections() [1/3]

QStringList QtxResourceMgr::sections ( ) const

Get all sections names.

Returns
list of section names

References IgnoreUserValues, initialize(), myHasUserValues, myResources, and workingMode().

◆ sections() [2/3]

QStringList QtxResourceMgr::sections ( const QRegExp &  re) const

Get all sections names matching specified regular expression.

Parameters
researched regular expression
Returns
list of sections names

References sections().

◆ sections() [3/3]

QStringList QtxResourceMgr::sections ( const QStringList &  names) const

Get all sections names with the prefix specified by passed list of parent sections names.

Sub-sections are separated inside the section name by the sections separator token, for example "splash:color:label".

Parameters
namesparent sub-sections names
Returns
list of sections names

References sections(), and sectionsToken().

◆ sectionsToken()

QString QtxResourceMgr::sectionsToken ( ) const

Get sections separator token.

By default, sections separator token is colon symbol ":" but it can be changed by setting the "section_token" resources manager option.

Returns
string corresponding to the current section separator token
See also
option(), setOption()

References option().

◆ setCheckExisting()

void QtxResourceMgr::setCheckExisting ( const bool  on)
virtual

Set the "check existance" flag.

Parameters
onnew flag value

References myCheckExist.

◆ setConstant()

void QtxResourceMgr::setConstant ( const QString &  name,
const QString &  value 
)

Set the value of the constant.

Parameters
nameconstant name
valueconstant value
See also
constants(), constants()

References myConstants, and value().

◆ setCurrentFormat()

void QtxResourceMgr::setCurrentFormat ( const QString &  fmt)

Set current configuration files format.

Parameters
fmtconfiguration files format name

References Qtx::addSlash(), appName(), format(), globalFileName(), myDirList, myFormats, myResources, and userFileName().

◆ setDefaultPixmap()

void QtxResourceMgr::setDefaultPixmap ( const QPixmap &  pix)
virtual

Set default pixmap.

Default pixmap is used when requested pixmap resource is not found.

Parameters
pixdefault pixmap
See also
defaultPixmap(), loadPixmap()

References myDefaultPix.

◆ setDirList()

void QtxResourceMgr::setDirList ( const QStringList &  dl)
protectedvirtual

Set the resource directories (where global confguration files are searched).

This function also clears all currently set resources.

Parameters
dldirectories list

References myDirList, and myResources.

◆ setIsPixmapCached()

void QtxResourceMgr::setIsPixmapCached ( const bool  on)

Switch "cached pixmaps" option on/off.

Parameters
onenable pixmap cache if true and disable it if false
See also
isPixmapCached()

References myIsPixmapCached.

◆ setOption()

void QtxResourceMgr::setOption ( const QString &  opt,
const QString &  val 
)

Set the string value of the specified resources format option.

Parameters
optoption name
valoption value
See also
option(), options()

References myOptions.

◆ setResource()

void QtxResourceMgr::setResource ( const QString &  sect,
const QString &  name,
const QString &  val 
)
protectedvirtual

Set parameter value.

Parameters
sectsection name
nameparameter name
valparameter value

References initialize(), myHasUserValues, and myResources.

◆ setValue() [1/11]

void QtxResourceMgr::setValue ( const QString &  sect,
const QString &  name,
const bool  val 
)

Set boolean parameter value.

Parameters
sectsection name
nameparameter name
valparameter value

References checkExisting(), setResource(), and value().

◆ setValue() [2/11]

void QtxResourceMgr::setValue ( const QString &  sect,
const QString &  name,
const double  val 
)

Set double parameter value.

Parameters
sectsection name
nameparameter name
valparameter value

References checkExisting(), setResource(), and value().

◆ setValue() [3/11]

void QtxResourceMgr::setValue ( const QString &  sect,
const QString &  name,
const int  val 
)

Set integer parameter value.

Parameters
sectsection name
nameparameter name
valparameter value

References checkExisting(), setResource(), and value().

◆ setValue() [4/11]

void QtxResourceMgr::setValue ( const QString &  sect,
const QString &  name,
const QByteArray &  val 
)

Set byte array parameter value.

Parameters
sectsection name
nameparameter name
valparameter value

References checkExisting(), setResource(), and value().

◆ setValue() [5/11]

void QtxResourceMgr::setValue ( const QString &  sect,
const QString &  name,
const QColor &  val 
)

Set color parameter value.

Parameters
sectsection name
nameparameter name
valparameter value

References checkExisting(), Qtx::colorToString(), setResource(), and value().

◆ setValue() [6/11]

void QtxResourceMgr::setValue ( const QString &  sect,
const QString &  name,
const QConicalGradient &  val 
)

Set conical gradient parameter value.

Parameters
sectsection name
nameparameter name
valparameter value

References checkExisting(), Qtx::gradientToString(), setResource(), and value().

◆ setValue() [7/11]

void QtxResourceMgr::setValue ( const QString &  sect,
const QString &  name,
const QFont &  val 
)

Set font parameter value.

Parameters
sectsection name
nameparameter name
valparameter value

References checkExisting(), setResource(), and value().

◆ setValue() [8/11]

void QtxResourceMgr::setValue ( const QString &  sect,
const QString &  name,
const QLinearGradient &  val 
)

Set linear gradient parameter value.

Parameters
sectsection name
nameparameter name
valparameter value

References checkExisting(), Qtx::gradientToString(), setResource(), and value().

◆ setValue() [9/11]

void QtxResourceMgr::setValue ( const QString &  sect,
const QString &  name,
const QRadialGradient &  val 
)

Set radial gradient parameter value.

Parameters
sectsection name
nameparameter name
valparameter value

References checkExisting(), Qtx::gradientToString(), setResource(), and value().

◆ setValue() [10/11]

void QtxResourceMgr::setValue ( const QString &  sect,
const QString &  name,
const QString &  val 
)

Set string parameter value.

Parameters
sectsection name
nameparameter name
valparameter value

References checkExisting(), setResource(), and value().

◆ setValue() [11/11]

void QtxResourceMgr::setValue ( const QString &  sect,
const QString &  name,
const Qtx::BackgroundData val 
)

Set background parameter value.

Parameters
sectsection name
nameparameter name
valparameter value

References Qtx::backgroundToString(), checkExisting(), setResource(), and value().

◆ setWorkingMode()

QtxResourceMgr::WorkingMode QtxResourceMgr::setWorkingMode ( WorkingMode  mode)

Set resource manager's working mode.

The resource manager can operate in the following working modes: AllowUserValues : methods values(), hasValue(), hasSection() take into account user values (default) IgnoreUserValues : methods values(), hasValue(), hasSection() do not take into account user values

Note, that setValue() method always put the value to the user settings file.

Parameters
modenew working mode
Returns
previous working mode
See also
workingMode(), value(), hasValue(), hasSection(), setValue()

References myWorkingMode.

◆ stringValue()

QString QtxResourceMgr::stringValue ( const QString &  sect,
const QString &  name,
const QString &  def = QString(),
const bool  subst = true 
) const

Get string parameter value.

If the specified parameter is not found, the specified default value is returned instead.

Parameters
sectsection name
nameparameter name
defdefault value
Returns
parameter value (or default value if parameter is not found)

References value().

◆ subSections()

QStringList QtxResourceMgr::subSections ( const QString &  section,
const bool  full = true 
) const

Get list of sub-sections names for the specified parent section name.

Sub-sections are separated inside the section name by the sections separator token, for example "splash:color:label".

Parameters
sectionparent sub-section name
fullif true return full names of child sub-sections, if false, return only top-level sub-sections names
Returns
list of sub-sections names

References sections(), and sectionsToken().

◆ substMacro()

QString QtxResourceMgr::substMacro ( const QString &  src,
const QMap< QChar, QString > &  substMap 
) const
private

Perform substitution of the patterns like %A, %B, etc by values from the map.

Used by loadLanguage().

Parameters
srcsring to be processed
substMapmap of values for replacing
Returns
processed string

References rx.

◆ userFileName()

QString QtxResourceMgr::userFileName ( const QString &  appName,
const bool  = true 
) const
protectedvirtual

Get user configuration file name.

This method can be redefined in the successor class to customize the user configuration file name. User configuration file is always situated in the user's home directory. By default .<appName>rc file is used on Linux (e.g. .MyApprc) and <appName>.<format> under Windows (e.g. MyApp.xml).

Parameter for_load (not used in default implementation) specifies the usage mode, i.e. if user configuration file is opened for reading or writing. This allows customizing a way of application resources initializing (for example, if the user configuraion file includes version number and there is no file corresponding to this version in the user's home directory, it could be good idea to try the configuration file from the previous versions of the application).

Parameters
appNameapplication name
for_loadboolean flag indicating that file is opened for loading or saving (not used in default implementation)
Returns
user configuration file name
See also
globalFileName()

Reimplemented in SUIT_ResourceMgr.

References Qtx::addSlash(), appName(), and currentFormat().

◆ value() [1/11]

bool QtxResourceMgr::value ( const QString &  sect,
const QString &  name,
bool &  bVal 
) const

Get boolean parameter value.

Parameters
sectsection name
nameparameter name
bValparameter to return resulting boolean value
Returns
true if parameter is found and false if parameter is not found (in this case bVal value is undefined)

References value().

◆ value() [2/11]

bool QtxResourceMgr::value ( const QString &  sect,
const QString &  name,
double &  dVal 
) const

Get double parameter value.

Parameters
sectsection name
nameparameter name
dValparameter to return resulting double value
Returns
true if parameter is found and false if parameter is not found (in this case dVal value is undefined)

References value().

◆ value() [3/11]

bool QtxResourceMgr::value ( const QString &  sect,
const QString &  name,
int &  iVal 
) const

Get interger parameter value.

Parameters
sectsection name
nameparameter name
iValparameter to return resulting integer value
Returns
true if parameter is found and false if parameter is not found (in this case iVal value is undefined)

◆ value() [4/11]

bool QtxResourceMgr::value ( const QString &  sect,
const QString &  name,
QByteArray &  baVal 
) const

Get byte array parameter value.

Parameters
sectsection name
nameparameter name
baValparameter to return resulting byte array value
Returns
true if parameter is found and false if parameter is not found (in this case baVal value is undefined)

References value().

◆ value() [5/11]

bool QtxResourceMgr::value ( const QString &  sect,
const QString &  name,
QColor &  cVal 
) const

Get color parameter value.

Parameters
sectsection name
nameparameter name
cValparameter to return resulting color value
Returns
true if parameter is found and false if parameter is not found (in this case cVal value is undefined)

References Qtx::stringToColor(), and value().

◆ value() [6/11]

bool QtxResourceMgr::value ( const QString &  sect,
const QString &  name,
QConicalGradient &  gVal 
) const

Get conical gradient parameter value.

Parameters
sectsection name
nameparameter name
gValparameter to return resulting conical gradient value
Returns
true if parameter is found and false if parameter is not found (in this case gVal value is undefined)

References Qtx::stringToConicalGradient(), and value().

◆ value() [7/11]

bool QtxResourceMgr::value ( const QString &  sect,
const QString &  name,
QFont &  fVal 
) const

Get font parameter value.

Parameters
sectsection name
nameparameter name
fValparameter to return resulting font value
Returns
true if parameter is found and false if parameter is not found (in this case fVal value is undefined)

References value().

◆ value() [8/11]

bool QtxResourceMgr::value ( const QString &  sect,
const QString &  name,
QLinearGradient &  gVal 
) const

Get linear gradient parameter value.

Parameters
sectsection name
nameparameter name
gValparameter to return resulting linear gradient value
Returns
true if parameter is found and false if parameter is not found (in this case gVal value is undefined)

References Qtx::stringToLinearGradient(), and value().

◆ value() [9/11]

bool QtxResourceMgr::value ( const QString &  sect,
const QString &  name,
QRadialGradient &  gVal 
) const

Get radial gradient parameter value.

Parameters
sectsection name
nameparameter name
gValparameter to return resulting radial gradient value
Returns
true if parameter is found and false if parameter is not found (in this case gVal value is undefined)

References Qtx::stringToRadialGradient(), and value().

◆ value() [10/11]

bool QtxResourceMgr::value ( const QString &  sect,
const QString &  name,
QString &  val,
const bool  subst = true 
) const

Get string parameter value (native format).

Parameters
sectsection name
nameparameter name
valparameter to return resulting byte array value
substif true perform environment variables substitution
Returns
true if parameter is found and false if parameter is not found (in this case val value is undefined)

References IgnoreUserValues, initialize(), myConstants, myHasUserValues, myResources, and workingMode().

◆ value() [11/11]

bool QtxResourceMgr::value ( const QString &  sect,
const QString &  name,
Qtx::BackgroundData bgVal 
) const

Get background parameter value.

Parameters
sectsection name
nameparameter name
bgValparameter to return resulting background value
Returns
true if parameter is found and false if parameter is not found (in this case bgVal value is undefined)

References Qtx::BackgroundData::isValid(), Qtx::stringToBackground(), and value().

◆ workingMode()

QtxResourceMgr::WorkingMode QtxResourceMgr::workingMode ( ) const

Get current working mode.

Returns
current working mode
See also
setWorkingMode(), value(), hasValue(), hasSection(), setValue()

References myWorkingMode.

Friends And Related Function Documentation

◆ QtxResourceMgr::Format

friend class QtxResourceMgr::Format
friend

Member Data Documentation

◆ myAppName

QString QtxResourceMgr::myAppName
private

application name

◆ myCheckExist

bool QtxResourceMgr::myCheckExist
private

"check existance" flag

◆ myConstants

OptionsMap QtxResourceMgr::myConstants
private

constants map

◆ myDefaultPix

QPixmap* QtxResourceMgr::myDefaultPix
private

default icon

◆ myDirList

QStringList QtxResourceMgr::myDirList
private

list of resources directories

◆ myFormats

FormatList QtxResourceMgr::myFormats
private

list of formats

◆ myHasUserValues

bool QtxResourceMgr::myHasUserValues
private

true if user preferences has been read

◆ myIsPixmapCached

bool QtxResourceMgr::myIsPixmapCached
private

"cached pixmaps" flag

◆ myOptions

OptionsMap QtxResourceMgr::myOptions
private

options map

◆ myResources

ResList QtxResourceMgr::myResources
private

resources list

◆ myTranslator

TransListMap QtxResourceMgr::myTranslator
private

map of loaded translators

◆ myWorkingMode

WorkingMode QtxResourceMgr::myWorkingMode
private

working mode


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