GUI: Refactoring xmlreport to use pointer to stream writing class.

This commit is contained in:
Kimmo Varis 2010-07-10 13:53:44 +03:00
parent 2e03e60218
commit 81449a823a
2 changed files with 17 additions and 15 deletions

View File

@ -21,12 +21,14 @@
#include "xmlreport.h" #include "xmlreport.h"
XmlReport::XmlReport(const QString &filename, QObject * parent) : XmlReport::XmlReport(const QString &filename, QObject * parent) :
Report(filename, parent) Report(filename, parent),
mXmlWriter(NULL)
{ {
} }
XmlReport::~XmlReport() XmlReport::~XmlReport()
{ {
delete mXmlWriter;
Close(); Close();
} }
@ -35,7 +37,7 @@ bool XmlReport::Create()
bool success = false; bool success = false;
if (Report::Create()) if (Report::Create())
{ {
mXmlWriter.setDevice(Report::GetFile()); mXmlWriter = new QXmlStreamWriter(Report::GetFile());
success = true; success = true;
} }
return success; return success;
@ -43,15 +45,15 @@ bool XmlReport::Create()
void XmlReport::WriteHeader() void XmlReport::WriteHeader()
{ {
mXmlWriter.setAutoFormatting(true); mXmlWriter->setAutoFormatting(true);
mXmlWriter.writeStartDocument(); mXmlWriter->writeStartDocument();
mXmlWriter.writeStartElement("results"); mXmlWriter->writeStartElement("results");
} }
void XmlReport::WriteFooter() void XmlReport::WriteFooter()
{ {
mXmlWriter.writeEndElement(); mXmlWriter->writeEndElement();
mXmlWriter.writeEndDocument(); mXmlWriter->writeEndDocument();
} }
void XmlReport::WriteError(const QStringList &files, const QStringList &lines, void XmlReport::WriteError(const QStringList &files, const QStringList &lines,
@ -63,11 +65,11 @@ void XmlReport::WriteError(const QStringList &files, const QStringList &lines,
The callstack seems to be ignored here aswell, instead last item of the stack is used The callstack seems to be ignored here aswell, instead last item of the stack is used
*/ */
mXmlWriter.writeStartElement("error"); mXmlWriter->writeStartElement("error");
mXmlWriter.writeAttribute("file", files[files.size() - 1]); mXmlWriter->writeAttribute("file", files[files.size() - 1]);
mXmlWriter.writeAttribute("line", lines[lines.size() - 1]); mXmlWriter->writeAttribute("line", lines[lines.size() - 1]);
mXmlWriter.writeAttribute("id", id); mXmlWriter->writeAttribute("id", id);
mXmlWriter.writeAttribute("severity", severity); mXmlWriter->writeAttribute("severity", severity);
mXmlWriter.writeAttribute("msg", msg); mXmlWriter->writeAttribute("msg", msg);
mXmlWriter.writeEndElement(); mXmlWriter->writeEndElement();
} }

View File

@ -68,7 +68,7 @@ private:
/** /**
* @brief XML stream writer for writing the report in XML format. * @brief XML stream writer for writing the report in XML format.
*/ */
QXmlStreamWriter mXmlWriter; QXmlStreamWriter *mXmlWriter;
}; };
/// @} /// @}
#endif // XML_REPORT_H #endif // XML_REPORT_H