From 4aa2876ca09eb50db1bba2248e843344b8efbdf5 Mon Sep 17 00:00:00 2001 From: Akhilesh Nema Date: Fri, 15 Jan 2016 16:52:22 +0100 Subject: [PATCH] Fixed #7278 (GUI: error rechecking with some files) --- gui/erroritem.h | 1 + gui/mainwindow.cpp | 5 +++-- gui/resultstree.cpp | 38 +++++++++++++++++++++++++++++++------- gui/resultstree.h | 8 ++++++++ gui/resultsview.cpp | 5 +++++ gui/resultsview.h | 8 ++++++++ gui/xmlreportv2.cpp | 8 ++++++++ lib/errorlogger.cpp | 2 ++ 8 files changed, 66 insertions(+), 9 deletions(-) diff --git a/gui/erroritem.h b/gui/erroritem.h index 4031f177c..3c5f601ee 100644 --- a/gui/erroritem.h +++ b/gui/erroritem.h @@ -84,6 +84,7 @@ Q_DECLARE_METATYPE(ErrorItem); class ErrorLine { public: QString file; + QString file0; unsigned int line; QString errorId; bool inconclusive; diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 0b7c11f0a..cfaf97452 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -221,8 +221,6 @@ void MainWindow::HandleCLIParams(const QStringList ¶ms) LoadProjectFile(params[index + 1]); } else if ((index = params.indexOf(QRegExp(".*\\.cppcheck$", Qt::CaseInsensitive), 0)) >= 0 && index < params.length() && QFile(params[index]).exists()) { LoadProjectFile(params[index]); - } else if ((index = params.indexOf(QRegExp(".*\\.xml$", Qt::CaseInsensitive), 0)) >= 0 && index < params.length() && QFile(params[index]).exists()) { - LoadResults(params[index]); } else if (params.contains("-l")) { QString logFile; index = params.indexOf("-l"); @@ -239,6 +237,8 @@ void MainWindow::HandleCLIParams(const QStringList ¶ms) } else { LoadResults(logFile); } + } else if ((index = params.indexOf(QRegExp(".*\\.xml$", Qt::CaseInsensitive), 0)) >= 0 && index < params.length() && QFile(params[index]).exists()) { + LoadResults(params[index],QDir::currentPath()); } else DoCheckFiles(params); } @@ -815,6 +815,7 @@ void MainWindow::ReCheckSelected(QStringList files, bool all) for (int i = 0; i < files.size(); ++i) mUI.mResults->ClearRecheckFile(files[i]); + mCurrentDirectory = mUI.mResults->GetCheckDirectory(); FileList pathList; pathList.AddPathList(files); if (mProject) diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index 0d7533275..d6b650851 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -171,7 +171,7 @@ bool ResultsTree::AddErrorItem(const ErrorItem &item) data["line"] = item.lines[0]; data["id"] = item.errorId; data["inconclusive"] = item.inconclusive; - data["file0"] = item.file0; + data["file0"] = StripPath(item.file0, true); stditem->setData(QVariant(data)); //Add backtrace files as children @@ -347,8 +347,11 @@ void ResultsTree::ClearRecheckFile(const QString &filename) if (!item) continue; + QString actualfile((!mCheckPath.isEmpty() && filename.startsWith(mCheckPath)) ? filename.mid(mCheckPath.length() + 1) : filename); QVariantMap data = item->data().toMap(); - if (filename == data["file"].toString()) { + QString storedfile = data["file"].toString(); + storedfile = ((!mCheckPath.isEmpty() && storedfile.startsWith(mCheckPath)) ? storedfile.mid(mCheckPath.length() + 1) : storedfile); + if (actualfile == storedfile) { mModel.removeRow(i); break; } @@ -833,12 +836,27 @@ void ResultsTree::RecheckSelectedFiles() item = item->parent(); QVariantMap data = item->data().toMap(); QString currentFile = data["file"].toString(); - if (Path::isHeader(currentFile.toStdString())) { - if (!selectedItems.contains(data["file0"].toString())) - selectedItems<SetCheckDirectory(dir); } +QString ResultsView::GetCheckDirectory(void) +{ + return mUI.mTree->GetCheckDirectory(); +} + void ResultsView::CheckingStarted(int count) { mUI.mProgress->setVisible(true); diff --git a/gui/resultsview.h b/gui/resultsview.h index d27a7907b..96fac8e3c 100644 --- a/gui/resultsview.h +++ b/gui/resultsview.h @@ -106,6 +106,14 @@ public: */ void SetCheckDirectory(const QString &dir); + /** + * @brief Get the directory we are checking + * + * @return Directory containing source files + */ + + QString GetCheckDirectory(void); + /** * @brief Inform the view that checking has started * diff --git a/gui/xmlreportv2.cpp b/gui/xmlreportv2.cpp index 0f760d4c4..db903d41e 100644 --- a/gui/xmlreportv2.cpp +++ b/gui/xmlreportv2.cpp @@ -27,6 +27,7 @@ #include "xmlreport.h" #include "xmlreportv2.h" #include "cppcheck.h" +#include "path.h" static const char ResultElementName[] = "results"; static const char CppcheckElementName[] = "cppcheck"; @@ -34,6 +35,7 @@ static const char ErrorElementName[] = "error"; static const char ErrorsElementName[] = "errors"; static const char LocationElementName[] = "location"; static const char FilenameAttribute[] = "file"; +static const char IncludedFromFilenameAttribute[] = "file0"; static const char LineAttribute[] = "line"; static const char IdAttribute[] = "id"; static const char SeverityAttribute[] = "severity"; @@ -120,6 +122,9 @@ void XmlReportV2::WriteError(const ErrorItem &error) mXmlWriter->writeStartElement(LocationElementName); QString file = QDir::toNativeSeparators(error.files[i]); + if (Path::isHeader(file.toStdString()) && !error.file0.isEmpty()) { + mXmlWriter->writeAttribute(IncludedFromFilenameAttribute, quoteMessage(error.file0)); + } file = XmlReport::quoteMessage(file); mXmlWriter->writeAttribute(FilenameAttribute, file); const QString line = QString::number(error.lines[i]); @@ -206,9 +211,12 @@ ErrorItem XmlReportV2::ReadError(QXmlStreamReader *reader) if (mXmlReader->name() == LocationElementName) { QXmlStreamAttributes attribs = mXmlReader->attributes(); QString file = attribs.value("", FilenameAttribute).toString(); + QString file0 = attribs.value("", IncludedFromFilenameAttribute).toString(); file = XmlReport::unquoteMessage(file); if (item.file.isEmpty()) item.file = file; + if (!file0.isEmpty()) + item.file0 = XmlReport::unquoteMessage(file0); item.files.push_back(file); const int line = attribs.value("", LineAttribute).toString().toUInt(); item.lines.push_back(line); diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index 387b5fe87..f04be089e 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -287,6 +287,8 @@ std::string ErrorLogger::ErrorMessage::toXML(bool verbose, int version) const for (std::list::const_reverse_iterator it = _callStack.rbegin(); it != _callStack.rend(); ++it) { printer.OpenElement("location", false); + if (Path::isHeader((*it).getfile()) && !file0.empty()) + printer.PushAttribute("file0", Path::toNativeSeparators(file0).c_str()); printer.PushAttribute("file", (*it).getfile().c_str()); printer.PushAttribute("line", (*it).line); printer.CloseElement(false);