From 2aa1523a2d57f938cdd4f875df5ae01e4a5e21b9 Mon Sep 17 00:00:00 2001 From: PKEuS Date: Sat, 29 Jul 2017 19:36:01 +0200 Subject: [PATCH] GUI: Removed XML format version 1 --- gui/gui.pro | 2 - gui/mainwindow.cpp | 13 +--- gui/report.h | 1 - gui/resultsview.cpp | 17 ++--- gui/xmlreportv1.cpp | 178 -------------------------------------------- gui/xmlreportv1.h | 92 ----------------------- 6 files changed, 11 insertions(+), 292 deletions(-) delete mode 100644 gui/xmlreportv1.cpp delete mode 100644 gui/xmlreportv1.h diff --git a/gui/gui.pro b/gui/gui.pro index 07e36b87f..496925686 100644 --- a/gui/gui.pro +++ b/gui/gui.pro @@ -106,7 +106,6 @@ HEADERS += aboutdialog.h \ translationhandler.h \ txtreport.h \ xmlreport.h \ - xmlreportv1.h \ xmlreportv2.h \ librarydialog.h \ cppchecklibrarydata.h \ @@ -144,7 +143,6 @@ SOURCES += aboutdialog.cpp \ translationhandler.cpp \ txtreport.cpp \ xmlreport.cpp \ - xmlreportv1.cpp \ xmlreportv2.cpp \ librarydialog.cpp \ cppchecklibrarydata.cpp \ diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 3e33b43af..ca0d93974 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -1157,7 +1157,7 @@ void MainWindow::performSelectedFilesCheck(QStringList selectedFilesList) void MainWindow::save() { QString selectedFilter; - const QString filter(tr("XML files version 2 (*.xml);;XML files version 1 (*.xml);;Text files (*.txt);;CSV files (*.csv)")); + const QString filter(tr("XML files (*.xml);;Text files (*.txt);;CSV files (*.csv)")); QString selectedFile = QFileDialog::getSaveFileName(this, tr("Save the report file"), getPath(SETTINGS_LAST_RESULT_PATH), @@ -1166,14 +1166,7 @@ void MainWindow::save() if (!selectedFile.isEmpty()) { Report::Type type = Report::TXT; - if (selectedFilter == tr("XML files version 1 (*.xml)")) { - QMessageBox msgBox(QMessageBox::Icon::Warning, tr("Deprecated XML format"), tr("XML format 1 is deprecated and will be removed in cppcheck 1.81."), QMessageBox::StandardButton::Ok); - msgBox.exec(); - - type = Report::XML; - if (!selectedFile.endsWith(".xml", Qt::CaseInsensitive)) - selectedFile += ".xml"; - } else if (selectedFilter == tr("XML files version 2 (*.xml)")) { + if (selectedFilter == tr("XML files (*.xml)")) { type = Report::XMLV2; if (!selectedFile.endsWith(".xml", Qt::CaseInsensitive)) selectedFile += ".xml"; @@ -1187,7 +1180,7 @@ void MainWindow::save() selectedFile += ".csv"; } else { if (selectedFile.endsWith(".xml", Qt::CaseInsensitive)) - type = Report::XML; + type = Report::XMLV2; else if (selectedFile.endsWith(".txt", Qt::CaseInsensitive)) type = Report::TXT; else if (selectedFile.endsWith(".csv", Qt::CaseInsensitive)) diff --git a/gui/report.h b/gui/report.h index e6f53a994..531be4181 100644 --- a/gui/report.h +++ b/gui/report.h @@ -35,7 +35,6 @@ public: enum Type { TXT, - XML, XMLV2, CSV, }; diff --git a/gui/resultsview.cpp b/gui/resultsview.cpp index cefef7304..2b433b958 100644 --- a/gui/resultsview.cpp +++ b/gui/resultsview.cpp @@ -33,7 +33,6 @@ #include "report.h" #include "txtreport.h" #include "xmlreport.h" -#include "xmlreportv1.h" #include "xmlreportv2.h" #include "csvreport.h" #include "printablereport.h" @@ -153,9 +152,6 @@ void ResultsView::save(const QString &filename, Report::Type type) const case Report::TXT: report = new TxtReport(filename); break; - case Report::XML: - report = new XmlReportV1(filename); - break; case Report::XMLV2: report = new XmlReportV2(filename); break; @@ -313,12 +309,15 @@ void ResultsView::readErrorsXml(const QString &filename) msgBox.exec(); return; } + if (version == 1) { + QMessageBox msgBox; + msgBox.setText(tr("XML format version 1 is no longer supported.")); + msgBox.setIcon(QMessageBox::Critical); + msgBox.exec(); + return; + } - XmlReport *report = NULL; - if (version == 1) - report = new XmlReportV1(filename); - else if (version == 2) - report = new XmlReportV2(filename); + XmlReport *report = new XmlReportV2(filename); QList errors; if (report) { diff --git a/gui/xmlreportv1.cpp b/gui/xmlreportv1.cpp deleted file mode 100644 index 79bd8829f..000000000 --- a/gui/xmlreportv1.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Cppcheck - A tool for static C/C++ code analysis - * Copyright (C) 2007-2016 Cppcheck team. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include "report.h" -#include "erroritem.h" -#include "xmlreport.h" -#include "xmlreportv1.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"; - -XmlReportV1::XmlReportV1(const QString &filename) : - XmlReport(filename), - mXmlReader(NULL), - mXmlWriter(NULL) -{ -} - -XmlReportV1::~XmlReportV1() -{ - delete mXmlReader; - delete mXmlWriter; -} - -bool XmlReportV1::create() -{ - if (Report::create()) { - mXmlWriter = new QXmlStreamWriter(Report::getFile()); - return true; - } - return false; -} - -bool XmlReportV1::open() -{ - if (Report::open()) { - mXmlReader = new QXmlStreamReader(Report::getFile()); - return true; - } - return false; -} - -void XmlReportV1::writeHeader() -{ - mXmlWriter->setAutoFormatting(true); - mXmlWriter->writeStartDocument(); - mXmlWriter->writeStartElement(ResultElementName); -} - -void XmlReportV1::writeFooter() -{ - mXmlWriter->writeEndElement(); - mXmlWriter->writeEndDocument(); -} - -void XmlReportV1::writeError(const ErrorItem &error) -{ - /* - Error example from the core program in xml - - The callstack seems to be ignored here as well, instead last item of the stack is used - */ - - // Don't write inconclusive errors to XML V1 - if (error.inconclusive) - return; - - mXmlWriter->writeStartElement(ErrorElementName); - QString file = QDir::toNativeSeparators(error.errorPath.back().file); - file = XmlReport::quoteMessage(file); - mXmlWriter->writeAttribute(FilenameAttribute, file); - const QString line = QString::number(error.errorPath.back().line); - mXmlWriter->writeAttribute(LineAttribute, line); - mXmlWriter->writeAttribute(IdAttribute, error.errorId); - - // Don't localize severity so we can read these files - mXmlWriter->writeAttribute(SeverityAttribute, GuiSeverity::toString(error.severity)); - const QString message = XmlReport::quoteMessage(error.message); - mXmlWriter->writeAttribute(MsgAttribute, message); - mXmlWriter->writeEndElement(); -} - -QList XmlReportV1::read() -{ - QList errors; - bool insideResults = false; - if (!mXmlReader) { - qDebug() << "You must Open() the file before reading it!"; - return errors; - } - 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) { - ErrorItem item = readError(mXmlReader); - errors.append(item); - } - 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; - } - } - return errors; -} - -ErrorItem XmlReportV1::readError(QXmlStreamReader *reader) -{ - ErrorItem item; - if (reader->name().toString() == ErrorElementName) { - QXmlStreamAttributes attribs = reader->attributes(); - QString file = attribs.value("", FilenameAttribute).toString(); - file = XmlReport::unquoteMessage(file); - QErrorPathItem e; - e.file = file; - e.line = attribs.value("", LineAttribute).toString().toUInt(); - item.errorPath << e; - item.errorId = attribs.value("", IdAttribute).toString(); - item.severity = GuiSeverity::fromString(attribs.value("", SeverityAttribute).toString()); - - // NOTE: This duplicates the message to Summary-field. But since - // old XML format doesn't have separate summary and verbose messages - // we must add same message to both data so it shows up in GUI. - // Check if there is full stop and cut the summary to it. - QString summary = attribs.value("", MsgAttribute).toString(); - const int ind = summary.indexOf('.'); - if (ind != -1) - summary = summary.left(ind + 1); - item.summary = XmlReport::unquoteMessage(summary); - QString message = attribs.value("", MsgAttribute).toString(); - item.message = XmlReport::unquoteMessage(message); - } - return item; -} diff --git a/gui/xmlreportv1.h b/gui/xmlreportv1.h deleted file mode 100644 index 8399b7a53..000000000 --- a/gui/xmlreportv1.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Cppcheck - A tool for static C/C++ code analysis - * Copyright (C) 2007-2016 Cppcheck team. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef XML_REPORTV1_H -#define XML_REPORTV1_H - -#include -#include -#include -#include "xmlreport.h" - -/// @addtogroup GUI -/// @{ - - -/** -* @brief XML file report version 1. -* This report outputs XML-formatted report, version 1. The XML format must match command -* line version's XML output. -*/ -class XmlReportV1 : public XmlReport { -public: - explicit XmlReportV1(const QString &filename); - virtual ~XmlReportV1(); - - /** - * @brief Create the report (file). - * @return true if succeeded, false if file could not be created. - */ - virtual bool create(); - - /** - * @brief Open existing report file. - */ - bool open(); - - /** - * @brief Write report header. - */ - virtual void writeHeader(); - - /** - * @brief Write report footer. - */ - virtual void writeFooter(); - - /** - * @brief Write error to report. - * @param error Error data. - */ - virtual void writeError(const ErrorItem &error); - - /** - * @brief Read contents of the report file. - */ - virtual QList read(); - -protected: - /** - * @brief Read and parse error item from XML stream. - * @param reader XML stream reader to use. - */ - ErrorItem 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. - */ - QXmlStreamWriter *mXmlWriter; -}; -/// @} -#endif // XML_REPORTV1_H