Skip to content

Commit 9eacceb

Browse files
committed
GUI: Read XML format version 2 files.
Implement the parsing of XML format v2 error data.
1 parent d31703e commit 9eacceb

2 files changed

Lines changed: 60 additions & 15 deletions

File tree

gui/xmlreportv2.cpp

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -180,28 +180,67 @@ QList<ErrorItem> XmlReportV2::Read()
180180

181181
ErrorItem XmlReportV2::ReadError(QXmlStreamReader *reader)
182182
{
183+
/*
184+
Error example from the core program in xml
185+
<error id="mismatchAllocDealloc" severity="error" msg="Mismatching allocation and deallocation: k"
186+
verbose="Mismatching allocation and deallocation: k">
187+
<location file="..\..\test\test.cxx" line="16"/>
188+
<location file="..\..\test\test.cxx" line="32"/>
189+
</error>
190+
*/
191+
183192
ErrorItem item;
184193
if (reader->name().toString() == ErrorElementName)
185194
{
186195
QXmlStreamAttributes attribs = reader->attributes();
187-
const QString file = attribs.value("", FilenameAttribute).toString();
188-
item.file = file;
189-
item.files.push_back(file);
190-
const int line = attribs.value("", LineAttribute).toString().toUInt();
191-
item.lines.push_back(line);
192196
item.id = attribs.value("", IdAttribute).toString();
193197
item.severity = attribs.value("", SeverityAttribute).toString();
198+
item.summary = attribs.value("", MsgAttribute).toString();
199+
item.message = attribs.value("", VerboseAttribute).toString();
194200

195-
// NOTE: This dublicates the message to Summary-field. But since
196-
// old XML format doesn't have separate summary and verbose messages
197-
// we must add same message to both data so it shows up in GUI.
198-
// Check if there is full stop and cut the summary to it.
199-
QString summary = attribs.value("", MsgAttribute).toString();
200-
const int ind = summary.indexOf('.');
201-
if (ind != -1)
202-
summary = summary.left(ind + 1);
203-
item.summary = summary;
204-
item.message = attribs.value("", MsgAttribute).toString();
201+
ReadLocations(item);
205202
}
206203
return item;
207204
}
205+
206+
void XmlReportV2::ReadLocations(ErrorItem &item)
207+
{
208+
QList<ErrorItem> errors;
209+
bool allRead = false;
210+
while (!allRead && !mXmlReader->atEnd())
211+
{
212+
switch (mXmlReader->readNext())
213+
{
214+
case QXmlStreamReader::StartElement:
215+
if (mXmlReader->name() != LocationElementName)
216+
continue; // Skip other than location elements
217+
{
218+
QXmlStreamAttributes attribs = mXmlReader->attributes();
219+
const QString file = attribs.value("", FilenameAttribute).toString();
220+
if (item.file.isEmpty())
221+
item.file = file;
222+
item.files.push_back(file);
223+
const int line = attribs.value("", LineAttribute).toString().toUInt();
224+
item.lines.push_back(line);
225+
}
226+
break;
227+
228+
case QXmlStreamReader::EndElement:
229+
if (mXmlReader->name() == LocationElementName)
230+
allRead = true;
231+
break;
232+
233+
// Not handled
234+
case QXmlStreamReader::NoToken:
235+
case QXmlStreamReader::Invalid:
236+
case QXmlStreamReader::StartDocument:
237+
case QXmlStreamReader::EndDocument:
238+
case QXmlStreamReader::Characters:
239+
case QXmlStreamReader::Comment:
240+
case QXmlStreamReader::DTD:
241+
case QXmlStreamReader::EntityReference:
242+
case QXmlStreamReader::ProcessingInstruction:
243+
break;
244+
}
245+
}
246+
}

gui/xmlreportv2.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,12 @@ class XmlReportV2 : public XmlReport
8181
*/
8282
ErrorItem ReadError(QXmlStreamReader *reader);
8383

84+
/**
85+
* @brief Read and parse error items location elements from XML stream.
86+
* @param item ErrorItem to write the location data.
87+
*/
88+
void ReadLocations(ErrorItem &item);
89+
8490
private:
8591
/**
8692
* @brief XML stream reader for reading the report in XML format.

0 commit comments

Comments
 (0)