From a9e4d972b88faee11543090456cbffc898f78e65 Mon Sep 17 00:00:00 2001 From: xavier Date: Thu, 12 Jan 2012 06:47:02 +0000 Subject: [PATCH] Added method TitleBlockTemplate::saveToXmlFile(). git-svn-id: svn+ssh://svn.tuxfamily.org/svnroot/qet/qet/branches/0.3@1456 bfdf4180-ca20-0410-9c96-a3a8aa849046 --- sources/titleblocktemplate.cpp | 32 +++++++++++++++++++++++++++++++- sources/titleblocktemplate.h | 1 + 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/sources/titleblocktemplate.cpp b/sources/titleblocktemplate.cpp index eefc9cf78..a13bd3835 100644 --- a/sources/titleblocktemplate.cpp +++ b/sources/titleblocktemplate.cpp @@ -117,9 +117,39 @@ bool TitleBlockTemplate::loadFromXmlElement(const QDomElement &xml_element) { return(true); } +/** + Save the title block template into an XML file. + @param filepath The file path this title block template should be saved to. + @return true if the operation succeeds, false otherwise +*/ +bool TitleBlockTemplate::saveToXmlFile(const QString &filepath) { + if (filepath.isEmpty()) return(false); + + // open the file + QFile xml_file(filepath); + if (!xml_file.open(QIODevice::WriteOnly | QIODevice::Text)) { + return(false); + } + + // generate the XML document + QDomDocument doc; + QDomElement e = doc.createElement("root"); + bool saving = saveToXmlElement(e); + if (!saving) return(false); + doc.appendChild(e); + + // write the file + QTextStream out(&xml_file); + out.setCodec("UTF-8"); + out << doc.toString(4); + xml_file.close(); + + return(true); +} + /** Save the title block template as XML. - @param xml_element The XMl element this title block template should be saved to. + @param xml_element The XML element this title block template should be saved to. @return true if the export succeeds, false otherwise */ bool TitleBlockTemplate::saveToXmlElement(QDomElement &xml_element) const { diff --git a/sources/titleblocktemplate.h b/sources/titleblocktemplate.h index b95debb89..76f08d1dd 100644 --- a/sources/titleblocktemplate.h +++ b/sources/titleblocktemplate.h @@ -47,6 +47,7 @@ class TitleBlockTemplate : public QObject { static QFont fontForCell(const TitleBlockCell &); bool loadFromXmlFile(const QString &); bool loadFromXmlElement(const QDomElement &); + bool saveToXmlFile(const QString &); bool saveToXmlElement(QDomElement &) const; TitleBlockTemplate *clone() const; QString name() const;