From 81449a823a222f3739b12a3a6f01d47b6bb78474 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Sat, 10 Jul 2010 13:53:44 +0300 Subject: [PATCH 01/10] GUI: Refactoring xmlreport to use pointer to stream writing class. --- gui/xmlreport.cpp | 30 ++++++++++++++++-------------- gui/xmlreport.h | 2 +- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/gui/xmlreport.cpp b/gui/xmlreport.cpp index f597bd54a..41dbfe5f3 100644 --- a/gui/xmlreport.cpp +++ b/gui/xmlreport.cpp @@ -21,12 +21,14 @@ #include "xmlreport.h" XmlReport::XmlReport(const QString &filename, QObject * parent) : - Report(filename, parent) + Report(filename, parent), + mXmlWriter(NULL) { } XmlReport::~XmlReport() { + delete mXmlWriter; Close(); } @@ -35,7 +37,7 @@ bool XmlReport::Create() bool success = false; if (Report::Create()) { - mXmlWriter.setDevice(Report::GetFile()); + mXmlWriter = new QXmlStreamWriter(Report::GetFile()); success = true; } return success; @@ -43,15 +45,15 @@ bool XmlReport::Create() void XmlReport::WriteHeader() { - mXmlWriter.setAutoFormatting(true); - mXmlWriter.writeStartDocument(); - mXmlWriter.writeStartElement("results"); + mXmlWriter->setAutoFormatting(true); + mXmlWriter->writeStartDocument(); + mXmlWriter->writeStartElement("results"); } void XmlReport::WriteFooter() { - mXmlWriter.writeEndElement(); - mXmlWriter.writeEndDocument(); + mXmlWriter->writeEndElement(); + mXmlWriter->writeEndDocument(); } void XmlReport::WriteError(const QStringList &files, const QStringList &lines, @@ -63,11 +65,11 @@ 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.writeEndElement(); + 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->writeEndElement(); } diff --git a/gui/xmlreport.h b/gui/xmlreport.h index ab017b43e..cacdd4dec 100644 --- a/gui/xmlreport.h +++ b/gui/xmlreport.h @@ -68,7 +68,7 @@ private: /** * @brief XML stream writer for writing the report in XML format. */ - QXmlStreamWriter mXmlWriter; + QXmlStreamWriter *mXmlWriter; }; /// @} #endif // XML_REPORT_H From 5e14abf735df761cf58ecdb3a5b854b045acc1f1 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Sat, 10 Jul 2010 16:37:36 +0300 Subject: [PATCH 02/10] 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. --- gui/main.ui | 6 +++ gui/mainwindow.cpp | 17 +++++++++ gui/mainwindow.h | 6 +++ gui/report.cpp | 11 ++++++ gui/report.h | 6 +++ gui/resultsview.cpp | 26 +++++++++++++ gui/resultsview.h | 8 ++++ gui/xmlreport.cpp | 91 +++++++++++++++++++++++++++++++++++++++++---- gui/xmlreport.h | 22 +++++++++++ 9 files changed, 186 insertions(+), 7 deletions(-) diff --git a/gui/main.ui b/gui/main.ui index 3e0a708c3..3317d4452 100644 --- a/gui/main.ui +++ b/gui/main.ui @@ -73,6 +73,7 @@ &File + @@ -347,6 +348,11 @@ Error categories + + + &Open XML... + + diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp index 15d4b08de..81acef2b7 100644 --- a/gui/mainwindow.cpp +++ b/gui/mainwindow.cpp @@ -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); diff --git a/gui/mainwindow.h b/gui/mainwindow.h index 0fa17db2d..3142dccaa 100644 --- a/gui/mainwindow.h +++ b/gui/mainwindow.h @@ -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) diff --git a/gui/report.cpp b/gui/report.cpp index 0fbfc4e54..cd2c911bd 100644 --- a/gui/report.cpp +++ b/gui/report.cpp @@ -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()) diff --git a/gui/report.h b/gui/report.h index 5459e31ee..9e8972951 100644 --- a/gui/report.h +++ b/gui/report.h @@ -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). */ diff --git a/gui/resultsview.cpp b/gui/resultsview.cpp index f0f3e37f2..9c3b14a77 100644 --- a/gui/resultsview.cpp +++ b/gui/resultsview.cpp @@ -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(); + } +} diff --git a/gui/resultsview.h b/gui/resultsview.h index cb3f4abb1..6b9161581 100644 --- a/gui/resultsview.h +++ b/gui/resultsview.h @@ -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: /** diff --git a/gui/xmlreport.cpp b/gui/xmlreport.cpp index 41dbfe5f3..30d0e2d6b 100644 --- a/gui/xmlreport.cpp +++ b/gui/xmlreport.cpp @@ -18,16 +18,27 @@ #include #include +#include #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; + } +} diff --git a/gui/xmlreport.h b/gui/xmlreport.h index cacdd4dec..06c0fbf35 100644 --- a/gui/xmlreport.h +++ b/gui/xmlreport.h @@ -23,6 +23,7 @@ #include #include #include +#include #include #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. From 0e9d0e9bde155e2bfa5a87deb648571c3389a3b2 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Sat, 10 Jul 2010 18:20:45 +0300 Subject: [PATCH 03/10] GUI: Refactor error data passing to use own class. --- gui/csvreport.cpp | 9 +++------ gui/csvreport.h | 5 ++--- gui/report.h | 18 +++++++++++++++--- gui/resultstree.cpp | 22 +++++++++------------- gui/txtreport.cpp | 15 ++++++--------- gui/txtreport.h | 5 ++--- gui/xmlreport.cpp | 13 ++++++------- gui/xmlreport.h | 4 ++-- 8 files changed, 45 insertions(+), 46 deletions(-) diff --git a/gui/csvreport.cpp b/gui/csvreport.cpp index 7a4c5efab..db47fcdb2 100644 --- a/gui/csvreport.cpp +++ b/gui/csvreport.cpp @@ -51,19 +51,16 @@ void CsvReport::WriteFooter() // No footer for CSV report } -void CsvReport::WriteError(const QStringList &files, const QStringList &lines, - const QString &id, const QString &severity, const QString &msg) +void CsvReport::WriteError(const ErrorItem &error) { - Q_UNUSED(id); - /* Error as CSV line gui/test.cpp,23,error,Mismatching allocation and deallocation: k */ QString line; - line += QString("%1,%2,").arg(files[files.size() - 1]).arg(lines[lines.size() - 1]); - line += QString("%1,%2").arg(severity).arg(msg); + line += QString("%1,%2,").arg(error.files[error.files.size() - 1]).arg(error.lines[error.lines.size() - 1]); + line += QString("%1,%2").arg(error.severity).arg(error.msg); mTxtWriter << line << endl; } diff --git a/gui/csvreport.h b/gui/csvreport.h index 23e3eadef..5661a03d5 100644 --- a/gui/csvreport.h +++ b/gui/csvreport.h @@ -60,10 +60,9 @@ public: /** * @brief Write error to report. + * @param error Error data. */ - virtual void WriteError(const QStringList &files, const QStringList &lines, - const QString &id, const QString &severity, - const QString &msg); + virtual void WriteError(const ErrorItem &error); private: diff --git a/gui/report.h b/gui/report.h index 9e8972951..386911dd0 100644 --- a/gui/report.h +++ b/gui/report.h @@ -27,6 +27,19 @@ /// @addtogroup GUI /// @{ +/** +* @brief A class containing error data. +*/ +class ErrorItem +{ +public: + QStringList files; + QStringList lines; + QString id; + QString severity; + QString msg; +}; + /** * @brief A base class for reports. */ @@ -73,10 +86,9 @@ public: /** * @brief Write error to report. + * @param error Error data. */ - virtual void WriteError(const QStringList &files, const QStringList &lines, - const QString &id, const QString &severity, - const QString &msg) = 0; + virtual void WriteError(const ErrorItem &error) = 0; protected: diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index e69138a81..a01785b59 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -601,8 +601,6 @@ void ResultsTree::SaveErrors(Report *report, QStandardItem *item) return; } - //qDebug() << item->text() << "has" << item->rowCount() << "errors"; - for (int i = 0; i < item->rowCount(); i++) { QStandardItem *error = item->child(i, 0); @@ -622,17 +620,15 @@ void ResultsTree::SaveErrors(Report *report, QStandardItem *item) //Convert it to QVariantMap QVariantMap data = userdata.toMap(); - QString severity = ShowTypeToString(VariantToShowType(data["severity"])); - QString message = data["message"].toString(); - QString id = data["id"].toString(); + ErrorItem item; + item.severity = ShowTypeToString(VariantToShowType(data["severity"])); + item.msg = data["message"].toString(); + item.id = data["id"].toString(); QString file = StripPath(data["file"].toString(), true); QString line = data["line"].toString(); - QStringList files; - QStringList lines; - - files << file; - lines << line; + item.files << file; + item.lines << line; for (int j = 0; j < error->rowCount(); j++) { @@ -645,11 +641,11 @@ void ResultsTree::SaveErrors(Report *report, QStandardItem *item) file = StripPath(child_data["file"].toString(), true); line = child_data["line"].toString(); - files << file; - lines << line; + item.files << file; + item.lines << line; } - report->WriteError(files, lines, id, severity, message); + report->WriteError(item); } } diff --git a/gui/txtreport.cpp b/gui/txtreport.cpp index 0cf4728ba..0a064f354 100644 --- a/gui/txtreport.cpp +++ b/gui/txtreport.cpp @@ -51,11 +51,8 @@ void TxtReport::WriteFooter() // No footer for txt report } -void TxtReport::WriteError(const QStringList &files, const QStringList &lines, - const QString &id, const QString &severity, const QString &msg) +void TxtReport::WriteError(const ErrorItem &error) { - Q_UNUSED(id); - /* Error example from the core program in text [gui/test.cpp:23] -> [gui/test.cpp:14]: (error) Mismatching allocation and deallocation: k @@ -63,21 +60,21 @@ void TxtReport::WriteError(const QStringList &files, const QStringList &lines, QString line; - for (int i = 0; i < lines.size(); i++) + for (int i = 0; i < error.lines.size(); i++) { - line += QString("[%1:%2]").arg(files[i]).arg(lines[i]); - if (i < lines.size() - 1 && lines.size() > 0) + line += QString("[%1:%2]").arg(error.files[i]).arg(error.lines[i]); + if (i < error.lines.size() - 1 && error.lines.size() > 0) { line += " -> "; } - if (i == lines.size() - 1) + if (i == error.lines.size() - 1) { line += ": "; } } - line += QString("(%1) %2").arg(severity).arg(msg); + line += QString("(%1) %2").arg(error.severity).arg(error.msg); mTxtWriter << line << endl; } diff --git a/gui/txtreport.h b/gui/txtreport.h index f3035536a..8dab58622 100644 --- a/gui/txtreport.h +++ b/gui/txtreport.h @@ -58,10 +58,9 @@ public: /** * @brief Write error to report. + * @param error Error data. */ - virtual void WriteError(const QStringList &files, const QStringList &lines, - const QString &id, const QString &severity, - const QString &msg); + virtual void WriteError(const ErrorItem &error); private: diff --git a/gui/xmlreport.cpp b/gui/xmlreport.cpp index 30d0e2d6b..d8b5d2212 100644 --- a/gui/xmlreport.cpp +++ b/gui/xmlreport.cpp @@ -78,8 +78,7 @@ void XmlReport::WriteFooter() mXmlWriter->writeEndDocument(); } -void XmlReport::WriteError(const QStringList &files, const QStringList &lines, - const QString &id, const QString &severity, const QString &msg) +void XmlReport::WriteError(const ErrorItem &error) { /* Error example from the core program in xml @@ -88,11 +87,11 @@ void XmlReport::WriteError(const QStringList &files, const QStringList &lines, */ 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->writeAttribute(FilenameAttribute, error.files[error.files.size() - 1]); + mXmlWriter->writeAttribute(LineAttribute, error.lines[error.lines.size() - 1]); + mXmlWriter->writeAttribute(IdAttribute, error.id); + mXmlWriter->writeAttribute(SeverityAttribute, error.severity); + mXmlWriter->writeAttribute(MsgAttribute, error.msg); mXmlWriter->writeEndElement(); } diff --git a/gui/xmlreport.h b/gui/xmlreport.h index 06c0fbf35..5cc99d769 100644 --- a/gui/xmlreport.h +++ b/gui/xmlreport.h @@ -65,9 +65,9 @@ public: /** * @brief Write error to report. + * @param error Error data. */ - virtual void WriteError(const QStringList &files, const QStringList &lines, - const QString &id, const QString &severity, const QString &msg); + virtual void WriteError(const ErrorItem &error); /** * @brief Read contents of the report file. From 2f0202d1051b517b1954f95158e8497adb680051 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Sat, 10 Jul 2010 20:30:31 +0300 Subject: [PATCH 04/10] GUI: More refactoring to use ErrorItem and ErrorLine. --- gui/erroritem.h | 56 +++++++++++++++++++++++++++++++ gui/gui.pro | 1 + gui/report.h | 14 +------- gui/resultstree.cpp | 82 ++++++++++++++++++++------------------------- gui/resultstree.h | 28 ++++------------ gui/resultsview.cpp | 15 ++++++++- 6 files changed, 116 insertions(+), 80 deletions(-) create mode 100644 gui/erroritem.h diff --git a/gui/erroritem.h b/gui/erroritem.h new file mode 100644 index 000000000..a5eb88abb --- /dev/null +++ b/gui/erroritem.h @@ -0,0 +1,56 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2010 Daniel Marjamäki and 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 ERRORITEM_H +#define ERRORITEM_H + +#include +#include + +/// @addtogroup GUI +/// @{ + +/** +* @brief A class containing error data for one error. +*/ +class ErrorItem +{ +public: + QString file; + QStringList files; + QStringList lines; + QString id; + QString severity; + QString msg; +}; + +/** +* @brief A class containing error data for one shown error line. +*/ +class ErrorLine +{ +public: + QString file; + QString line; + QString id; + QString severity; + QString msg; +}; + +/// @} +#endif // ERRORITEM_H diff --git a/gui/gui.pro b/gui/gui.pro index 0ef54b270..d0c23068c 100644 --- a/gui/gui.pro +++ b/gui/gui.pro @@ -50,6 +50,7 @@ HEADERS += mainwindow.h \ applicationdialog.h \ aboutdialog.h \ common.h \ + erroritem.h \ fileviewdialog.h \ projectfile.h \ report.h \ diff --git a/gui/report.h b/gui/report.h index 386911dd0..83a22e148 100644 --- a/gui/report.h +++ b/gui/report.h @@ -23,23 +23,11 @@ #include #include #include +#include "erroritem.h" /// @addtogroup GUI /// @{ -/** -* @brief A class containing error data. -*/ -class ErrorItem -{ -public: - QStringList files; - QStringList lines; - QString id; - QString severity; - QString msg; -}; - /** * @brief A base class for reports. */ diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index a01785b59..096c6e94c 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -25,6 +25,7 @@ #include #include #include +#include "erroritem.h" #include "resultstree.h" #include "xmlreport.h" @@ -67,28 +68,21 @@ QStandardItem *ResultsTree::CreateItem(const QString &name) return item; } -void ResultsTree::AddErrorItem(const QString &file, - const QString &severity, - const QString &message, - const QStringList &files, - const QVariantList &lines, - const QString &id) +void ResultsTree::AddErrorItem(const ErrorItem &item) { - Q_UNUSED(file); - - if (files.isEmpty()) + if (item.files.isEmpty()) { return; } - QString realfile = StripPath(files[0], false); + QString realfile = StripPath(item.files[0], false); if (realfile.isEmpty()) { realfile = tr("Undefined file"); } - bool hide = !mShowTypes[SeverityToShowType(severity)]; + bool hide = !mShowTypes[SeverityToShowType(item.severity)]; //if there is at least one error that is not hidden, we have a visible error if (!hide) @@ -96,48 +90,49 @@ void ResultsTree::AddErrorItem(const QString &file, mVisibleErrors = true; } + ErrorLine line; + line.file = realfile; + line.id = item.id; + line.line = item.lines[0]; + line.msg = item.msg; + line.severity = item.severity; //Create the base item for the error and ensure it has a proper //file item as a parent - QStandardItem *item = AddBacktraceFiles(EnsureFileItem(files[0], hide), - realfile, - lines[0].toInt(), - severity, - message, - hide, - SeverityToIcon(severity)); + QStandardItem *stditem = AddBacktraceFiles(EnsureFileItem(line.file, hide), + line, + hide, + SeverityToIcon(line.severity)); - if (!item) + if (!stditem) return; //Add user data to that item QMap data; - data["severity"] = SeverityToShowType(severity); - data["message"] = message; - data["file"] = files[0]; - data["line"] = lines[0]; - data["id"] = id; - item->setData(QVariant(data)); + data["severity"] = SeverityToShowType(line.severity); + data["message"] = line.msg; + data["file"] = line.file; + data["line"] = line.line; + data["id"] = line.id; + stditem->setData(QVariant(data)); //Add backtrace files as children - for (int i = 1; i < files.size() && i < lines.size(); i++) + for (int i = 1; i < item.files.size() && i < item.lines.size(); i++) { + line.file = item.files[i]; + line.line = item.lines[i]; QStandardItem *child_item; - - child_item = AddBacktraceFiles(item, - StripPath(files[i], false), - lines[i].toInt(), - severity, - message, + child_item = AddBacktraceFiles(stditem, + line, hide, ":images/go-down.png"); //Add user data to that item QMap child_data; - child_data["severity"] = SeverityToShowType(severity); - child_data["message"] = message; - child_data["file"] = files[i]; - child_data["line"] = lines[i]; - child_data["id"] = id; + child_data["severity"] = SeverityToShowType(line.severity); + child_data["message"] = line.msg; + child_data["file"] = line.file; + child_data["line"] = line.line; + child_data["id"] = line.id; child_item->setData(QVariant(child_data)); } @@ -150,10 +145,7 @@ void ResultsTree::AddErrorItem(const QString &file, } QStandardItem *ResultsTree::AddBacktraceFiles(QStandardItem *parent, - const QString &file, - const int line, - const QString &severity, - const QString &message, + const ErrorLine &item, const bool hide, const QString &icon) @@ -164,12 +156,12 @@ QStandardItem *ResultsTree::AddBacktraceFiles(QStandardItem *parent, } QList list; - list << CreateItem(file); - list << CreateItem(tr(severity.toLatin1())); - list << CreateItem(QString("%1").arg(line)); + list << CreateItem(item.file); + list << CreateItem(tr(item.severity.toLatin1())); + list << CreateItem(QString("%1").arg(item.line)); //TODO message has parameter names so we'll need changes to the core //cppcheck so we can get proper translations - list << CreateItem(tr(message.toLatin1())); + list << CreateItem(tr(item.msg.toLatin1())); // Check for duplicate rows and don't add them if found for (int i = 0; i < parent->rowCount(); i++) diff --git a/gui/resultstree.h b/gui/resultstree.h index a234d7af0..6f2ae6620 100644 --- a/gui/resultstree.h +++ b/gui/resultstree.h @@ -25,11 +25,13 @@ #include #include #include +#include #include "common.h" #include "applicationlist.h" -#include class Report; +class ErrorItem; +class ErrorLine; /// @addtogroup GUI /// @{ @@ -50,19 +52,9 @@ public: /** * @brief Add a new item to the tree * - * @param file filename - * @param severity error severity - * @param message error message - * @param files list of files affected by the error - * @param lines list of file line numers affected by the error - * @param id error id + * @param item Error item data */ - void AddErrorItem(const QString &file, - const QString &severity, - const QString &message, - const QStringList &files, - const QVariantList &lines, - const QString &id); + void AddErrorItem(const ErrorItem &item); /** * @brief Clear all errors from the tree @@ -224,19 +216,13 @@ protected: * @brief Add a new error item beneath a file or a backtrace item beneath an error * * @param parent Parent for the item. Either a file item or an error item - * @param file Filename of the error - * @param line Line numer - * @param severity Error severity - * @param message Error message + * @param item Error line data * @param hide Should this be hidden (true) or shown (false) * @param icon Should a default backtrace item icon be added * @return newly created QStandardItem * */ QStandardItem *AddBacktraceFiles(QStandardItem *parent, - const QString &file, - const int line, - const QString &severity, - const QString &message, + const ErrorLine &item, const bool hide, const QString &icon); diff --git a/gui/resultsview.cpp b/gui/resultsview.cpp index 9c3b14a77..e13f8b6ba 100644 --- a/gui/resultsview.cpp +++ b/gui/resultsview.cpp @@ -74,7 +74,20 @@ void ResultsView::Error(const QString &file, const QString &id) { mErrorsFound = true; - mUI.mTree->AddErrorItem(file, severity, message, files, lines, id); + ErrorItem item; + item.file = file; + item.files = files; + item.id = id; + item.msg = message; + item.severity = severity; + + QVariant line; + foreach(line, lines) + { + item.lines.append(line.toString()); + } + + mUI.mTree->AddErrorItem(item); emit GotResults(); } From faa483b8d0b36a542a6b1b90508f1d3f808f3a23 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Sat, 10 Jul 2010 20:54:33 +0300 Subject: [PATCH 05/10] GUI: Use integer list instead of variant list for line numbers. --- gui/erroritem.h | 2 +- gui/resultstree.cpp | 4 ++-- gui/resultsview.cpp | 9 ++------- gui/resultsview.h | 2 +- gui/threadhandler.cpp | 4 ++-- gui/threadresult.cpp | 2 +- gui/threadresult.h | 2 +- gui/xmlreport.cpp | 3 ++- 8 files changed, 12 insertions(+), 16 deletions(-) diff --git a/gui/erroritem.h b/gui/erroritem.h index a5eb88abb..ed4215aad 100644 --- a/gui/erroritem.h +++ b/gui/erroritem.h @@ -33,7 +33,7 @@ class ErrorItem public: QString file; QStringList files; - QStringList lines; + QList lines; QString id; QString severity; QString msg; diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index 096c6e94c..d63fe7ea8 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -617,7 +617,7 @@ void ResultsTree::SaveErrors(Report *report, QStandardItem *item) item.msg = data["message"].toString(); item.id = data["id"].toString(); QString file = StripPath(data["file"].toString(), true); - QString line = data["line"].toString(); + unsigned int line = data["line"].toUInt(); item.files << file; item.lines << line; @@ -631,7 +631,7 @@ void ResultsTree::SaveErrors(Report *report, QStandardItem *item) QVariantMap child_data = child_userdata.toMap(); file = StripPath(child_data["file"].toString(), true); - line = child_data["line"].toString(); + line = child_data["line"].toUInt(); item.files << file; item.lines << line; diff --git a/gui/resultsview.cpp b/gui/resultsview.cpp index e13f8b6ba..aeab7e85f 100644 --- a/gui/resultsview.cpp +++ b/gui/resultsview.cpp @@ -70,7 +70,7 @@ void ResultsView::Error(const QString &file, const QString &severity, const QString &message, const QStringList &files, - const QVariantList &lines, + const QList &lines, const QString &id) { mErrorsFound = true; @@ -78,15 +78,10 @@ void ResultsView::Error(const QString &file, item.file = file; item.files = files; item.id = id; + item.lines = lines; item.msg = message; item.severity = severity; - QVariant line; - foreach(line, lines) - { - item.lines.append(line.toString()); - } - mUI.mTree->AddErrorItem(item); emit GotResults(); } diff --git a/gui/resultsview.h b/gui/resultsview.h index 6b9161581..a940fdebb 100644 --- a/gui/resultsview.h +++ b/gui/resultsview.h @@ -169,7 +169,7 @@ public slots: const QString &severity, const QString &message, const QStringList &files, - const QVariantList &lines, + const QList &lines, const QString &id); /** diff --git a/gui/threadhandler.cpp b/gui/threadhandler.cpp index 2dad5df0e..feae8b503 100644 --- a/gui/threadhandler.cpp +++ b/gui/threadhandler.cpp @@ -145,13 +145,13 @@ void ThreadHandler::Initialize(ResultsView *view) const QString &, const QString &, const QStringList &, - const QVariantList &, + const QList &, const QString &)), view, SLOT(Error(const QString &, const QString &, const QString &, const QStringList &, - const QVariantList &, + const QList &, const QString &))); } diff --git a/gui/threadresult.cpp b/gui/threadresult.cpp index 56ca9ee16..165edb528 100644 --- a/gui/threadresult.cpp +++ b/gui/threadresult.cpp @@ -47,7 +47,7 @@ void ThreadResult::reportErr(const ErrorLogger::ErrorMessage &msg) { QMutexLocker locker(&mutex); - QVariantList lines; + QList lines; QStringList files; for (std::list::const_iterator tok = msg._callStack.begin(); diff --git a/gui/threadresult.h b/gui/threadresult.h index c1b1b9a66..494d5db16 100644 --- a/gui/threadresult.h +++ b/gui/threadresult.h @@ -98,7 +98,7 @@ signals: const QString &severity, const QString &message, const QStringList &files, - const QVariantList &lines, + const QList &lines, const QString &id); protected: diff --git a/gui/xmlreport.cpp b/gui/xmlreport.cpp index d8b5d2212..56a58fbd0 100644 --- a/gui/xmlreport.cpp +++ b/gui/xmlreport.cpp @@ -88,7 +88,8 @@ void XmlReport::WriteError(const ErrorItem &error) mXmlWriter->writeStartElement(ErrorElementName); mXmlWriter->writeAttribute(FilenameAttribute, error.files[error.files.size() - 1]); - mXmlWriter->writeAttribute(LineAttribute, error.lines[error.lines.size() - 1]); + const QString line = QString::number(error.lines[error.lines.size() - 1]); + mXmlWriter->writeAttribute(LineAttribute, line); mXmlWriter->writeAttribute(IdAttribute, error.id); mXmlWriter->writeAttribute(SeverityAttribute, error.severity); mXmlWriter->writeAttribute(MsgAttribute, error.msg); From 352941f5dfcbdebbbeb8a40caa2b0b48f3a47a00 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Sun, 11 Jul 2010 01:04:53 +0300 Subject: [PATCH 06/10] GUI: Fix transporting errors. Need to register integer list as new metatype so that Qt's type system knows how to use it. Adding also additional constructors for the ErrorItem. --- gui/erroritem.cpp | 39 +++++++++++++++++++++++++++++++++++++++ gui/erroritem.h | 6 ++++++ gui/gui.pro | 1 + gui/main.cpp | 4 ++++ 4 files changed, 50 insertions(+) create mode 100644 gui/erroritem.cpp diff --git a/gui/erroritem.cpp b/gui/erroritem.cpp new file mode 100644 index 000000000..98f620671 --- /dev/null +++ b/gui/erroritem.cpp @@ -0,0 +1,39 @@ +/* + * Cppcheck - A tool for static C/C++ code analysis + * Copyright (C) 2007-2010 Daniel Marjamäki and 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 "erroritem.h" + +ErrorItem::ErrorItem(const ErrorItem &item) +{ + file = item.file; + files = item.files; + lines = item.lines; + id = item.id; + severity = item.severity; + msg = item.msg; +} + +ErrorItem::ErrorItem(const ErrorLine &line) +{ + file = line.file; + files.append(line.file); + lines.append(line.line.toUInt()); + id = line.id; + severity = line.severity; + msg = line.msg; +} diff --git a/gui/erroritem.h b/gui/erroritem.h index ed4215aad..73fc661d9 100644 --- a/gui/erroritem.h +++ b/gui/erroritem.h @@ -22,6 +22,8 @@ #include #include +class ErrorLine; + /// @addtogroup GUI /// @{ @@ -31,6 +33,10 @@ class ErrorItem { public: + ErrorItem() { } + ErrorItem(const ErrorItem &item); + ErrorItem(const ErrorLine &line); + QString file; QStringList files; QList lines; diff --git a/gui/gui.pro b/gui/gui.pro index d0c23068c..84265f8ea 100644 --- a/gui/gui.pro +++ b/gui/gui.pro @@ -71,6 +71,7 @@ SOURCES += main.cpp \ aboutdialog.cpp \ fileviewdialog.cpp \ projectfile.cpp \ + erroritem.cpp \ report.cpp \ txtreport.cpp \ xmlreport.cpp \ diff --git a/gui/main.cpp b/gui/main.cpp index 2309e7a64..02ee24eae 100644 --- a/gui/main.cpp +++ b/gui/main.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "mainwindow.h" int main(int argc, char *argv[]) @@ -27,6 +28,9 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); app.setWindowIcon(QIcon(":icon.png")); + // Register this metatype that is used to transfer error info + qRegisterMetaType>("QList"); + // Set codecs so that UTF-8 strings in sources are handled correctly. QTextCodec::setCodecForTr(QTextCodec::codecForName("UTF-8")); QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); From 9a5166075f6f0ed039c82e925852b59fcf2db775 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Sun, 11 Jul 2010 01:07:40 +0300 Subject: [PATCH 07/10] GUI: Fix line numbers and filenames in errors. When converting to use new ErrorItem and ErrorLine I made few mistakes in how I handled the data. And for some reason there was not even warnings about converting integers to QStrings. --- gui/resultstree.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index d63fe7ea8..4b14ee8d2 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -93,7 +93,7 @@ void ResultsTree::AddErrorItem(const ErrorItem &item) ErrorLine line; line.file = realfile; line.id = item.id; - line.line = item.lines[0]; + line.line = QString::number(item.lines[0]); line.msg = item.msg; line.severity = item.severity; //Create the base item for the error and ensure it has a proper @@ -108,17 +108,17 @@ void ResultsTree::AddErrorItem(const ErrorItem &item) //Add user data to that item QMap data; - data["severity"] = SeverityToShowType(line.severity); - data["message"] = line.msg; - data["file"] = line.file; - data["line"] = line.line; - data["id"] = line.id; + data["severity"] = SeverityToShowType(item.severity); + data["message"] = item.msg; + data["file"] = item.files[0]; + data["line"] = QString::number(item.lines[0]); + data["id"] = item.id; stditem->setData(QVariant(data)); //Add backtrace files as children for (int i = 1; i < item.files.size() && i < item.lines.size(); i++) { - line.file = item.files[i]; + line.file = StripPath(item.files[i], false); line.line = item.lines[i]; QStandardItem *child_item; child_item = AddBacktraceFiles(stditem, @@ -130,7 +130,7 @@ void ResultsTree::AddErrorItem(const ErrorItem &item) QMap child_data; child_data["severity"] = SeverityToShowType(line.severity); child_data["message"] = line.msg; - child_data["file"] = line.file; + child_data["file"] = item.files[i]; child_data["line"] = line.line; child_data["id"] = line.id; child_item->setData(QVariant(child_data)); From f894b192093d1e221c52720654edbdc2242ad73c Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Sun, 11 Jul 2010 02:02:08 +0300 Subject: [PATCH 08/10] GUI: Add errors read from XML report to GUI. --- gui/report.cpp | 1 + gui/resultsview.cpp | 10 +++++++++- gui/xmlreport.cpp | 27 +++++++++++++++++---------- gui/xmlreport.h | 4 ++-- 4 files changed, 29 insertions(+), 13 deletions(-) diff --git a/gui/report.cpp b/gui/report.cpp index cd2c911bd..2f5e150e3 100644 --- a/gui/report.cpp +++ b/gui/report.cpp @@ -17,6 +17,7 @@ */ #include +#include "erroritem.h" #include "report.h" Report::Report(const QString &filename, QObject * parent) : diff --git a/gui/resultsview.cpp b/gui/resultsview.cpp index aeab7e85f..e6f7a7945 100644 --- a/gui/resultsview.cpp +++ b/gui/resultsview.cpp @@ -229,10 +229,11 @@ void ResultsView::DisableProgressbar() void ResultsView::ReadErrorsXml(const QString &filename) { XmlReport *report = new XmlReport(filename, this); + QList errors; if (report) { if (report->Open()) - report->Read(); + errors = report->Read(); else { QMessageBox msgBox; @@ -250,4 +251,11 @@ void ResultsView::ReadErrorsXml(const QString &filename) msgBox.setIcon(QMessageBox::Critical); msgBox.exec(); } + + ErrorLine line; + foreach(line, errors) + { + ErrorItem item(line); + mUI.mTree->AddErrorItem(item); + } } diff --git a/gui/xmlreport.cpp b/gui/xmlreport.cpp index 56a58fbd0..57873feba 100644 --- a/gui/xmlreport.cpp +++ b/gui/xmlreport.cpp @@ -19,6 +19,7 @@ #include #include #include +#include "erroritem.h" #include "xmlreport.h" static const char ResultElementName[] = "results"; @@ -96,13 +97,14 @@ void XmlReport::WriteError(const ErrorItem &error) mXmlWriter->writeEndElement(); } -void XmlReport::Read() +QList XmlReport::Read() { + QList errors; bool insideResults = false; if (!mXmlReader) { qDebug() << "You must Open() the file before reading it!"; - return; + return errors; } while (!mXmlReader->atEnd()) { @@ -114,7 +116,10 @@ void XmlReport::Read() // Read error element from inside result element if (insideResults && mXmlReader->name() == ErrorElementName) - ReadError(mXmlReader); + { + ErrorLine line = ReadError(mXmlReader); + errors.append(line); + } break; case QXmlStreamReader::EndElement: @@ -135,18 +140,20 @@ void XmlReport::Read() break; } } + return errors; } -void XmlReport::ReadError(QXmlStreamReader *reader) +ErrorLine XmlReport::ReadError(QXmlStreamReader *reader) { + ErrorLine line; 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; + line.file = attribs.value("", FilenameAttribute).toString(); + line.line = attribs.value("", LineAttribute).toString(); + line.id = attribs.value("", IdAttribute).toString(); + line.severity = attribs.value("", SeverityAttribute).toString(); + line.msg = attribs.value("", MsgAttribute).toString(); } + return line; } diff --git a/gui/xmlreport.h b/gui/xmlreport.h index 5cc99d769..f850707c3 100644 --- a/gui/xmlreport.h +++ b/gui/xmlreport.h @@ -72,14 +72,14 @@ public: /** * @brief Read contents of the report file. */ - void Read(); + QList Read(); protected: /** * @brief Read and parse error item from XML stream. * @param reader XML stream reader to use. */ - void ReadError(QXmlStreamReader *reader); + ErrorLine ReadError(QXmlStreamReader *reader); private: /** From b8793b15294ddb2d86360f483b8579e627f451a7 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Sun, 11 Jul 2010 14:22:55 +0300 Subject: [PATCH 09/10] GUI: Ask file location from user if not found. When loading report from XML there is no full paths so the file's real path is not known and cppcheck cannot open it. So if the file has no absolute path then we ask where the file is located from the user. --- gui/resultstree.cpp | 38 +++++++++++++++++++++++++++++++++++++- gui/resultstree.h | 6 ++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index 4b14ee8d2..5a230b5a8 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include "erroritem.h" #include "resultstree.h" @@ -444,7 +445,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e) void ResultsTree::StartApplication(QStandardItem *target, int application) { - //If there are now application's specified, tell the user about it + //If there are no applications specified, tell the user about it if (mApplications->GetApplicationCount() == 0) { QMessageBox msg(QMessageBox::Information, @@ -468,6 +469,26 @@ void ResultsTree::StartApplication(QStandardItem *target, int application) //Replace (file) with filename QString file = data["file"].toString(); + + QFileInfo info(file); + if (!info.exists()) + { + if (info.isAbsolute()) + { + QMessageBox msgbox(this); + msgbox.setWindowTitle("Cppcheck"); + msgbox.setText(tr("Could not find the file!")); + msgbox.setIcon(QMessageBox::Critical); + msgbox.exec(); + } + else + { + QString dir = AskFileDir(file); + dir += '/'; + file = dir + file; + } + } + if (file.indexOf(" ") > -1) { file.insert(0, "\""); @@ -498,6 +519,21 @@ void ResultsTree::StartApplication(QStandardItem *target, int application) } } +QString ResultsTree::AskFileDir(const QString &file) +{ + QString text = tr("Could not find file:\n%1\nPlease select the directory where file is located.").arg(file); + QMessageBox msgbox(this); + msgbox.setWindowTitle("Cppcheck"); + msgbox.setText(text); + msgbox.setIcon(QMessageBox::Warning); + msgbox.exec(); + + QString dir = QFileDialog::getExistingDirectory(this, tr("Select Directory"), + "", + QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); + return dir; +} + void ResultsTree::CopyFilename() { CopyPath(mContextItem, false); diff --git a/gui/resultstree.h b/gui/resultstree.h index 6f2ae6620..5f35c6f63 100644 --- a/gui/resultstree.h +++ b/gui/resultstree.h @@ -262,6 +262,12 @@ protected: */ void LoadSettings(); + /** + * @brief Ask directory where file is located. + * @param file File name. + * @return Directory user chose. + */ + QString AskFileDir(const QString &file); /** * @brief Create a new QStandardItem From c9d63fa454e6954a0ca1215b1e9b9441c2a01817 Mon Sep 17 00:00:00 2001 From: Kimmo Varis Date: Sun, 11 Jul 2010 16:20:19 +0300 Subject: [PATCH 10/10] GUI: Remember user-selected base path. Remember the base path user selects when opening files from loaded XML report. --- gui/resultstree.cpp | 16 ++++++++++++---- gui/resultsview.cpp | 1 + 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/gui/resultstree.cpp b/gui/resultstree.cpp index 5a230b5a8..bd24bb1cd 100644 --- a/gui/resultstree.cpp +++ b/gui/resultstree.cpp @@ -33,7 +33,6 @@ ResultsTree::ResultsTree(QWidget * parent) : QTreeView(parent), mContextItem(0), - mCheckPath(""), mVisibleErrors(false) { for (int i = 0; i < SHOW_NONE; i++) @@ -483,9 +482,17 @@ void ResultsTree::StartApplication(QStandardItem *target, int application) } else { - QString dir = AskFileDir(file); - dir += '/'; - file = dir + file; + QDir checkdir(mCheckPath); + if (checkdir.isAbsolute() && checkdir.exists()) + { + file = mCheckPath + "/" + file; + } + else + { + QString dir = AskFileDir(file); + dir += '/'; + file = dir + file; + } } } @@ -531,6 +538,7 @@ QString ResultsTree::AskFileDir(const QString &file) QString dir = QFileDialog::getExistingDirectory(this, tr("Select Directory"), "", QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); + mCheckPath = dir; return dir; } diff --git a/gui/resultsview.cpp b/gui/resultsview.cpp index e6f7a7945..2e941979a 100644 --- a/gui/resultsview.cpp +++ b/gui/resultsview.cpp @@ -258,4 +258,5 @@ void ResultsView::ReadErrorsXml(const QString &filename) ErrorItem item(line); mUI.mTree->AddErrorItem(item); } + mUI.mTree->SetCheckDirectory(""); }