Fixed #7278 (GUI: error rechecking with some files)

This commit is contained in:
Akhilesh Nema 2016-01-15 16:52:22 +01:00 committed by Daniel Marjamäki
parent 979dfc3f4e
commit 4aa2876ca0
8 changed files with 66 additions and 9 deletions

View File

@ -84,6 +84,7 @@ Q_DECLARE_METATYPE(ErrorItem);
class ErrorLine {
public:
QString file;
QString file0;
unsigned int line;
QString errorId;
bool inconclusive;

View File

@ -221,8 +221,6 @@ void MainWindow::HandleCLIParams(const QStringList &params)
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 &params)
} 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)

View File

@ -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<<data["file0"].toString();
if (!currentFile.isEmpty()) {
QString fileNameWithCheckPath;
QFileInfo curfileInfo(currentFile);
if (!curfileInfo.exists() && !mCheckPath.isEmpty() && currentFile.indexOf(mCheckPath) != 0)
fileNameWithCheckPath = mCheckPath + "/" + currentFile;
else
fileNameWithCheckPath = currentFile;
const QFileInfo fileInfo(fileNameWithCheckPath);
if (!fileInfo.exists()) {
AskFileDir(currentFile);
return;
}
if (Path::isHeader(currentFile.toStdString())) {
if (!data["file0"].toString().isEmpty() && !selectedItems.contains(data["file0"].toString())) {
selectedItems<<((!mCheckPath.isEmpty() && (data["file0"].toString().indexOf(mCheckPath) != 0)) ? (mCheckPath + "/" + data["file0"].toString()) : data["file0"].toString());
if (!selectedItems.contains(fileNameWithCheckPath))
selectedItems<<fileNameWithCheckPath;
}
} else if (!selectedItems.contains(fileNameWithCheckPath))
selectedItems<<fileNameWithCheckPath;
}
if (!selectedItems.contains(currentFile))
selectedItems<<currentFile;
}
emit CheckSelected(selectedItems);
}
@ -1043,6 +1061,12 @@ void ResultsTree::SetCheckDirectory(const QString &dir)
mCheckPath = dir;
}
QString ResultsTree::GetCheckDirectory(void)
{
return mCheckPath;
}
QString ResultsTree::StripPath(const QString &path, bool saving) const
{
if ((!saving && mShowFullPath) || (saving && mSaveFullPath)) {

View File

@ -122,6 +122,14 @@ public:
*/
void SetCheckDirectory(const QString &dir);
/**
* @brief Get the directory we are checking
*
* @return Directory containing source files
*/
QString GetCheckDirectory(void);
/**
* @brief Check if there are any visible results in view.
* @return true if there is at least one visible warning/error.

View File

@ -230,6 +230,11 @@ void ResultsView::SetCheckDirectory(const QString &dir)
mUI.mTree->SetCheckDirectory(dir);
}
QString ResultsView::GetCheckDirectory(void)
{
return mUI.mTree->GetCheckDirectory();
}
void ResultsView::CheckingStarted(int count)
{
mUI.mProgress->setVisible(true);

View File

@ -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
*

View File

@ -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);

View File

@ -287,6 +287,8 @@ std::string ErrorLogger::ErrorMessage::toXML(bool verbose, int version) const
for (std::list<FileLocation>::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);