From bf2e7db673ba8161bb5c1261fbc5ab0b04420620 Mon Sep 17 00:00:00 2001 From: sbh Date: Tue, 22 Jan 2013 07:35:49 +0000 Subject: [PATCH] refs #2566 ability to export settings in xml file --- src/Qtx/QtxResourceMgr.cxx | 36 +++++++++++++++++++++++++++++++++++- src/Qtx/QtxResourceMgr.h | 1 + 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/src/Qtx/QtxResourceMgr.cxx b/src/Qtx/QtxResourceMgr.cxx index f834f3b11..2691df6de 100644 --- a/src/Qtx/QtxResourceMgr.cxx +++ b/src/Qtx/QtxResourceMgr.cxx @@ -1091,8 +1091,11 @@ bool QtxResourceMgr::Format::save( Resources* res ) Qtx::mkDir( Qtx::dir( res->myFileName ) ); + QString name = res->myFileName; QtxResourceMgr* mgr = res->resMgr(); - QString name = mgr ? mgr->userFileName( mgr->appName(), false ) : res->myFileName; + if( mgr && name.isEmpty() ) { + name = mgr->userFileName( mgr->appName(), false ); + } return save( name, res->mySections ); } @@ -2238,6 +2241,37 @@ bool QtxResourceMgr::save() return fmt->save( myResources[0] ); } +/*! + \brief Save all resources to a resource file with given name. + \param theFileName resources file name + \return \c true on success and \c false on error +*/ +bool QtxResourceMgr::saveAs( const QString& theFileName ) +{ + initialize( true ); + + Format* fmt = format( currentFormat() ); + if ( !fmt ) + return false; + + if ( myResources.isEmpty() || !myHasUserValues ) + return true; + + Resources* allResources = myResources[0]; + allResources->setFile( theFileName ); + if( hasValue("import-export-settings", "exportable-sections") ){ + QSet allSections = allResources->sections().toSet(); + QString expSections; + value( "import-export-settings", "exportable-sections", expSections ); + QSet exportSections = expSections.split(",").toSet(); + QSet excludedSections = allSections.subtract( exportSections ); + foreach( QString eachSection, excludedSections ) { + allResources->removeSection( eachSection ); + } + } + return fmt->save( allResources ); +} + /*! \brief Get all sections names. \return list of section names diff --git a/src/Qtx/QtxResourceMgr.h b/src/Qtx/QtxResourceMgr.h index 14514a28d..223059ff9 100644 --- a/src/Qtx/QtxResourceMgr.h +++ b/src/Qtx/QtxResourceMgr.h @@ -156,6 +156,7 @@ public: bool load(); bool import( const QString& ); bool save(); + bool saveAs( const QString& ); QStringList sections() const; QStringList sections(const QRegExp&) const; -- 2.39.2