GUI: Read errors from report XML file.
This commits adds new "Open XML" item to File-menu. Selecting this menuitem allows user to select report file to open. When the file is read the error data is printed to debug output. Later patches will implement adding error data back to the GUI.
This commit is contained in:
parent
81449a823a
commit
5e14abf735
|
@ -73,6 +73,7 @@
|
|||
<property name="title">
|
||||
<string>&File</string>
|
||||
</property>
|
||||
<addaction name="mActionOpenXML"/>
|
||||
<addaction name="mActionSave"/>
|
||||
<addaction name="mActionQuit"/>
|
||||
</widget>
|
||||
|
@ -347,6 +348,11 @@
|
|||
<string>Error categories</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="mActionOpenXML">
|
||||
<property name="text">
|
||||
<string>&Open XML...</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
|
|
|
@ -56,6 +56,7 @@ MainWindow::MainWindow() :
|
|||
connect(mUI.mActionCheckDirectory, SIGNAL(triggered()), this, SLOT(CheckDirectory()));
|
||||
connect(mUI.mActionSettings, SIGNAL(triggered()), this, SLOT(ProgramSettings()));
|
||||
connect(mUI.mActionClearResults, SIGNAL(triggered()), this, SLOT(ClearResults()));
|
||||
connect(mUI.mActionOpenXML, SIGNAL(triggered()), this, SLOT(OpenXML()));
|
||||
|
||||
connect(mUI.mActionShowStyle, SIGNAL(toggled(bool)), this, SLOT(ShowStyle(bool)));
|
||||
connect(mUI.mActionShowErrors, SIGNAL(toggled(bool)), this, SLOT(ShowErrors(bool)));
|
||||
|
@ -431,6 +432,22 @@ void MainWindow::ClearResults()
|
|||
mUI.mActionSave->setEnabled(false);
|
||||
}
|
||||
|
||||
void MainWindow::OpenXML()
|
||||
{
|
||||
QString selectedFilter;
|
||||
QString filter(tr("XML files (*.xml)"));
|
||||
QString selectedFile = QFileDialog::getOpenFileName(this,
|
||||
tr("Open the report file"),
|
||||
QString(),
|
||||
filter,
|
||||
&selectedFilter);
|
||||
|
||||
if (!selectedFile.isEmpty())
|
||||
{
|
||||
mUI.mResults->ReadErrorsXml(selectedFile);
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::EnableCheckButtons(bool enable)
|
||||
{
|
||||
mUI.mActionStop->setEnabled(!enable);
|
||||
|
|
|
@ -67,6 +67,12 @@ public slots:
|
|||
*/
|
||||
void ClearResults();
|
||||
|
||||
/**
|
||||
* @brief Slot to open XML report file
|
||||
*
|
||||
*/
|
||||
void OpenXML();
|
||||
|
||||
/**
|
||||
* @brief Show errors with type "style"
|
||||
* @param checked Should errors be shown (true) or hidden (false)
|
||||
|
|
|
@ -41,6 +41,17 @@ bool Report::Create()
|
|||
return succeed;
|
||||
}
|
||||
|
||||
bool Report::Open()
|
||||
{
|
||||
bool succeed = false;
|
||||
if (!mFile.isOpen())
|
||||
{
|
||||
mFile.setFileName(mFilename);
|
||||
succeed = mFile.open(QIODevice::ReadOnly | QIODevice::Text);
|
||||
}
|
||||
return succeed;
|
||||
}
|
||||
|
||||
void Report::Close()
|
||||
{
|
||||
if (mFile.isOpen())
|
||||
|
|
|
@ -50,6 +50,12 @@ public:
|
|||
*/
|
||||
virtual bool Create();
|
||||
|
||||
/**
|
||||
* @brief Open the existing report (file).
|
||||
* @return true if succeeded, false if file could not be created.
|
||||
*/
|
||||
virtual bool Open();
|
||||
|
||||
/**
|
||||
* @brief Close the report (file).
|
||||
*/
|
||||
|
|
|
@ -217,3 +217,29 @@ void ResultsView::DisableProgressbar()
|
|||
{
|
||||
mUI.mProgress->setEnabled(false);
|
||||
}
|
||||
|
||||
void ResultsView::ReadErrorsXml(const QString &filename)
|
||||
{
|
||||
XmlReport *report = new XmlReport(filename, this);
|
||||
if (report)
|
||||
{
|
||||
if (report->Open())
|
||||
report->Read();
|
||||
else
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText(tr("Failed to read the report."));
|
||||
msgBox.setIcon(QMessageBox::Critical);
|
||||
msgBox.exec();
|
||||
}
|
||||
delete report;
|
||||
report = NULL;
|
||||
}
|
||||
else
|
||||
{
|
||||
QMessageBox msgBox;
|
||||
msgBox.setText(tr("Failed to read the report."));
|
||||
msgBox.setIcon(QMessageBox::Critical);
|
||||
msgBox.exec();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -129,6 +129,14 @@ public:
|
|||
void Translate();
|
||||
|
||||
void DisableProgressbar();
|
||||
|
||||
/**
|
||||
* @brief Read errors from report XML file.
|
||||
* @param filename Report file to read.
|
||||
*
|
||||
*/
|
||||
void ReadErrorsXml(const QString &filename);
|
||||
|
||||
signals:
|
||||
|
||||
/**
|
||||
|
|
|
@ -18,16 +18,27 @@
|
|||
|
||||
#include <QFile>
|
||||
#include <QXmlStreamWriter>
|
||||
#include <qdebug>
|
||||
#include "xmlreport.h"
|
||||
|
||||
static const char ResultElementName[] = "results";
|
||||
static const char ErrorElementName[] = "error";
|
||||
static const char FilenameAttribute[] = "file";
|
||||
static const char LineAttribute[] = "line";
|
||||
static const char IdAttribute[] = "id";
|
||||
static const char SeverityAttribute[] = "severity";
|
||||
static const char MsgAttribute[] = "msg";
|
||||
|
||||
XmlReport::XmlReport(const QString &filename, QObject * parent) :
|
||||
Report(filename, parent),
|
||||
mXmlReader(NULL),
|
||||
mXmlWriter(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
XmlReport::~XmlReport()
|
||||
{
|
||||
delete mXmlReader;
|
||||
delete mXmlWriter;
|
||||
Close();
|
||||
}
|
||||
|
@ -43,11 +54,22 @@ bool XmlReport::Create()
|
|||
return success;
|
||||
}
|
||||
|
||||
bool XmlReport::Open()
|
||||
{
|
||||
bool success = false;
|
||||
if (Report::Open())
|
||||
{
|
||||
mXmlReader = new QXmlStreamReader(Report::GetFile());
|
||||
success = true;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
void XmlReport::WriteHeader()
|
||||
{
|
||||
mXmlWriter->setAutoFormatting(true);
|
||||
mXmlWriter->writeStartDocument();
|
||||
mXmlWriter->writeStartElement("results");
|
||||
mXmlWriter->writeStartElement(ResultElementName);
|
||||
}
|
||||
|
||||
void XmlReport::WriteFooter()
|
||||
|
@ -65,11 +87,66 @@ 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
|
||||
*/
|
||||
|
||||
mXmlWriter->writeStartElement("error");
|
||||
mXmlWriter->writeAttribute("file", files[files.size() - 1]);
|
||||
mXmlWriter->writeAttribute("line", lines[lines.size() - 1]);
|
||||
mXmlWriter->writeAttribute("id", id);
|
||||
mXmlWriter->writeAttribute("severity", severity);
|
||||
mXmlWriter->writeAttribute("msg", msg);
|
||||
mXmlWriter->writeStartElement(ErrorElementName);
|
||||
mXmlWriter->writeAttribute(FilenameAttribute, files[files.size() - 1]);
|
||||
mXmlWriter->writeAttribute(LineAttribute, lines[lines.size() - 1]);
|
||||
mXmlWriter->writeAttribute(IdAttribute, id);
|
||||
mXmlWriter->writeAttribute(SeverityAttribute, severity);
|
||||
mXmlWriter->writeAttribute(MsgAttribute, msg);
|
||||
mXmlWriter->writeEndElement();
|
||||
}
|
||||
|
||||
void XmlReport::Read()
|
||||
{
|
||||
bool insideResults = false;
|
||||
if (!mXmlReader)
|
||||
{
|
||||
qDebug() << "You must Open() the file before reading it!";
|
||||
return;
|
||||
}
|
||||
while (!mXmlReader->atEnd())
|
||||
{
|
||||
switch (mXmlReader->readNext())
|
||||
{
|
||||
case QXmlStreamReader::StartElement:
|
||||
if (mXmlReader->name() == ResultElementName)
|
||||
insideResults = true;
|
||||
|
||||
// Read error element from inside result element
|
||||
if (insideResults && mXmlReader->name() == ErrorElementName)
|
||||
ReadError(mXmlReader);
|
||||
break;
|
||||
|
||||
case QXmlStreamReader::EndElement:
|
||||
if (mXmlReader->name() == ResultElementName)
|
||||
insideResults = false;
|
||||
break;
|
||||
|
||||
// Not handled
|
||||
case QXmlStreamReader::NoToken:
|
||||
case QXmlStreamReader::Invalid:
|
||||
case QXmlStreamReader::StartDocument:
|
||||
case QXmlStreamReader::EndDocument:
|
||||
case QXmlStreamReader::Characters:
|
||||
case QXmlStreamReader::Comment:
|
||||
case QXmlStreamReader::DTD:
|
||||
case QXmlStreamReader::EntityReference:
|
||||
case QXmlStreamReader::ProcessingInstruction:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void XmlReport::ReadError(QXmlStreamReader *reader)
|
||||
{
|
||||
if (reader->name().toString() == ErrorElementName)
|
||||
{
|
||||
QXmlStreamAttributes attribs = reader->attributes();
|
||||
QString filename = attribs.value("", FilenameAttribute).toString();
|
||||
QString line = attribs.value("", LineAttribute).toString();
|
||||
QString id = attribs.value("", IdAttribute).toString();
|
||||
QString severity = attribs.value("", SeverityAttribute).toString();
|
||||
QString msg = attribs.value("", MsgAttribute).toString();
|
||||
qDebug() << "Error: " << filename << " " << line << " " << id << " " << severity << " " << msg;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QFile>
|
||||
#include <QXmlStreamReader>
|
||||
#include <QXmlStreamWriter>
|
||||
#include "report.h"
|
||||
|
||||
|
@ -47,6 +48,11 @@ public:
|
|||
*/
|
||||
virtual bool Create();
|
||||
|
||||
/**
|
||||
* @brief Open existing report file.
|
||||
*/
|
||||
bool Open();
|
||||
|
||||
/**
|
||||
* @brief Write report header.
|
||||
*/
|
||||
|
@ -63,7 +69,23 @@ public:
|
|||
virtual void WriteError(const QStringList &files, const QStringList &lines,
|
||||
const QString &id, const QString &severity, const QString &msg);
|
||||
|
||||
/**
|
||||
* @brief Read contents of the report file.
|
||||
*/
|
||||
void Read();
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Read and parse error item from XML stream.
|
||||
* @param reader XML stream reader to use.
|
||||
*/
|
||||
void ReadError(QXmlStreamReader *reader);
|
||||
|
||||
private:
|
||||
/**
|
||||
* @brief XML stream reader for reading the report in XML format.
|
||||
*/
|
||||
QXmlStreamReader *mXmlReader;
|
||||
|
||||
/**
|
||||
* @brief XML stream writer for writing the report in XML format.
|
||||
|
|
Loading…
Reference in New Issue