From 4f1be723ee2210b4e0b619183158402407eed046 Mon Sep 17 00:00:00 2001 From: vsr Date: Thu, 17 Jun 2010 19:52:06 +0000 Subject: [PATCH] Improve resource manager: add functions to - get all sections names matching specified regular expression - get all sections names with specified parent sub-section name - get all sub-sections for the specified parent sub-section name --- src/Qtx/QtxResourceMgr.cxx | 78 +++++++++++++++++++++++++++++++++++++- src/Qtx/QtxResourceMgr.h | 4 ++ 2 files changed, 80 insertions(+), 2 deletions(-) diff --git a/src/Qtx/QtxResourceMgr.cxx b/src/Qtx/QtxResourceMgr.cxx index f68c292bc..cc2189b11 100644 --- a/src/Qtx/QtxResourceMgr.cxx +++ b/src/Qtx/QtxResourceMgr.cxx @@ -2096,6 +2096,63 @@ QStringList QtxResourceMgr::sections() const return map.keys(); } +/*! + \brief Get all sections names matching specified regular expression. + \param re searched regular expression + \return list of sections names +*/ +QStringList QtxResourceMgr::sections(const QRegExp& re) const +{ + return sections().filter( re ); +} + +/*! + \brief 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". + + \param names parent sub-sections names + \return list of sections names +*/ +QStringList QtxResourceMgr::sections(const QStringList& names) const +{ + QStringList nm = names; + nm << ".+"; + QRegExp re( QString( "^%1$" ).arg( nm.join( sectionsToken() ) ) ); + return sections( re ); +} + +/*! + \brief 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". + + \param section parent sub-section name + \param full if \c true return full names of child sub-sections, if \c false, + return only top-level sub-sections names + \return list of sub-sections names +*/ +QStringList QtxResourceMgr::subSections(const QString& section, const bool full) const +{ + QStringList names = sections( QStringList() << section ); + QMutableListIterator it( names ); + while ( it.hasNext() ) { + QString name = it.next().mid( section.size() ).trimmed(); + if ( name.isEmpty() ) { + it.remove(); + continue; + } + if ( !full ) name = name.split( sectionsToken() ).first(); + it.setValue( name ); + } + names.removeDuplicates(); + names.sort(); + return names; +} + /*! \brief Get all parameters name in specified section. \param sec section name @@ -2163,7 +2220,7 @@ QString QtxResourceMgr::path( const QString& sect, const QString& prefix, const \brief Get application resources section name. By default, application resources section name is "resources" but - it can be changed by setting the corresponding resources manager option. + it can be changed by setting the "res_section_name" resources manager option. \return section corresponding to the resources directories \sa option(), setOption() @@ -2180,7 +2237,7 @@ QString QtxResourceMgr::resSection() const \brief Get application language section name. By default, application language section name is "language" but - it can be changed by setting the corresponding resources manager option. + it can be changed by setting the "lang_section_name" resources manager option. \return section corresponding to the application language settings \sa option(), setOption() @@ -2193,6 +2250,23 @@ QString QtxResourceMgr::langSection() const return res; } +/*! + \brief 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. + + \return string corresponding to the current section separator token + \sa option(), setOption() +*/ +QString QtxResourceMgr::sectionsToken() const +{ + QString res = option( "section_token" ); + if ( res.isEmpty() ) + res = QString( ":" ); + return res; +} + /*! \brief Get default pixmap. diff --git a/src/Qtx/QtxResourceMgr.h b/src/Qtx/QtxResourceMgr.h index 5c9970777..a15205bc2 100644 --- a/src/Qtx/QtxResourceMgr.h +++ b/src/Qtx/QtxResourceMgr.h @@ -143,6 +143,7 @@ public: QString resSection() const; QString langSection() const; + QString sectionsToken() const; QPixmap loadPixmap( const QString&, const QString& ) const; QPixmap loadPixmap( const QString&, const QString&, const bool ) const; @@ -161,6 +162,9 @@ public: bool save(); QStringList sections() const; + QStringList sections(const QRegExp&) const; + QStringList sections(const QStringList&) const; + QStringList subSections(const QString&, const bool = true) const; QStringList parameters( const QString& ) const; void refresh(); -- 2.39.2