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;