diff --git a/gui/mainwindow.cpp b/gui/mainwindow.cpp
index 234d0aebe..b926b8c4a 100644
--- a/gui/mainwindow.cpp
+++ b/gui/mainwindow.cpp
@@ -562,6 +562,11 @@ Settings MainWindow::GetCppcheckSettings()
QMessageBox::information(this, tr("Information"), tr("Failed to load the selected library %1").arg(filename));
}
+ QStringList suppressions = pfile->GetSuppressions();
+ foreach(QString suppression, suppressions) {
+ result.nomsg.addSuppressionLine(suppression.toStdString());
+ }
+
// Only check the given -D configuration
if (!defines.isEmpty())
result._maxConfigs = 1;
diff --git a/gui/project.cpp b/gui/project.cpp
index 75f53daa2..7283550dc 100644
--- a/gui/project.cpp
+++ b/gui/project.cpp
@@ -95,7 +95,10 @@ bool Project::Edit()
dlg.SetPaths(paths);
QStringList ignorepaths = mPFile->GetExcludedPaths();
dlg.SetExcludedPaths(ignorepaths);
- dlg.SetLibraries(mPFile->GetLibraries());
+ QStringList libraries = mPFile->GetLibraries();
+ dlg.SetLibraries(libraries);
+ QStringList suppressions = mPFile->GetSuppressions();
+ dlg.SetSuppressions(suppressions);
int rv = dlg.exec();
if (rv == QDialog::Accepted) {
@@ -109,7 +112,10 @@ bool Project::Edit()
mPFile->SetCheckPaths(paths);
QStringList excludedpaths = dlg.GetExcludedPaths();
mPFile->SetExcludedPaths(excludedpaths);
- mPFile->SetLibraries(dlg.GetLibraries());
+ QStringList libraries = dlg.GetLibraries();
+ mPFile->SetLibraries(libraries);
+ QStringList suppressions = dlg.GetSuppressions();
+ mPFile->SetSuppressions(suppressions);
bool writeSuccess = mPFile->Write();
if (!writeSuccess) {
diff --git a/gui/projectfile.cpp b/gui/projectfile.cpp
index 96df1da3a..1a75a0607 100644
--- a/gui/projectfile.cpp
+++ b/gui/projectfile.cpp
@@ -46,6 +46,8 @@ static const char ExcludePathName[] = "path";
static const char ExcludePathNameAttrib[] = "name";
static const char LibrariesElementName[] = "libraries";
static const char LibraryElementName[] = "library";
+static const char SuppressionsElementName[] = "suppressions";
+static const char SuppressionElementName[] = "suppression";
ProjectFile::ProjectFile(QObject *parent) :
QObject(parent)
@@ -102,9 +104,13 @@ bool ProjectFile::Read(const QString &filename)
if (insideProject && xmlReader.name() == IgnoreElementName)
ReadExcludes(xmlReader);
- // Find libraries list from insid project element
+ // Find libraries list from inside project element
if (insideProject && xmlReader.name() == LibrariesElementName)
- ReadLibraries(xmlReader);
+ ReadStringList(mLibraries, xmlReader,LibraryElementName);
+
+ // Find suppressions list from inside project element
+ if (insideProject && xmlReader.name() == SuppressionsElementName)
+ ReadStringList(mSuppressions, xmlReader,SuppressionElementName);
break;
@@ -175,6 +181,15 @@ QStringList ProjectFile::GetLibraries() const
return libraries;
}
+QStringList ProjectFile::GetSuppressions() const
+{
+ QStringList suppressions;
+ foreach(QString suppression, mSuppressions) {
+ suppressions << suppression;
+ }
+ return suppressions;
+}
+
void ProjectFile::ReadRootPath(QXmlStreamReader &reader)
{
QXmlStreamAttributes attribs = reader.attributes();
@@ -343,7 +358,7 @@ void ProjectFile::ReadExcludes(QXmlStreamReader &reader)
}
-void ProjectFile::ReadLibraries(QXmlStreamReader &reader)
+void ProjectFile::ReadStringList(QStringList &stringlist, QXmlStreamReader &reader, const char elementname[])
{
QXmlStreamReader::TokenType type;
bool allRead = false;
@@ -352,17 +367,17 @@ void ProjectFile::ReadLibraries(QXmlStreamReader &reader)
switch (type) {
case QXmlStreamReader::StartElement:
// Read library-elements
- if (reader.name().toString() == LibraryElementName) {
+ if (reader.name().toString() == elementname) {
type = reader.readNext();
if (type == QXmlStreamReader::Characters) {
- QString library = reader.text().toString();
- mLibraries << library;
+ QString text = reader.text().toString();
+ stringlist << text;
}
}
break;
case QXmlStreamReader::EndElement:
- if (reader.name().toString() == LibrariesElementName)
+ if (reader.name().toString() != elementname)
allRead = true;
break;
@@ -406,6 +421,11 @@ void ProjectFile::SetLibraries(const QStringList &libraries)
mLibraries = libraries;
}
+void ProjectFile::SetSuppressions(const QStringList &suppressions)
+{
+ mSuppressions = suppressions;
+}
+
bool ProjectFile::Write(const QString &filename)
{
if (!filename.isEmpty())
@@ -467,17 +487,31 @@ bool ProjectFile::Write(const QString &filename)
xmlWriter.writeEndElement();
}
- if (!mLibraries.isEmpty()) {
- xmlWriter.writeStartElement(LibrariesElementName);
- foreach(QString library, mLibraries) {
- xmlWriter.writeStartElement(LibraryElementName);
- xmlWriter.writeCharacters(library);
- xmlWriter.writeEndElement();
- }
- xmlWriter.writeEndElement();
- }
+ WriteStringList(xmlWriter,
+ mLibraries,
+ LibrariesElementName,
+ LibraryElementName);
+
+ WriteStringList(xmlWriter,
+ mSuppressions,
+ SuppressionsElementName,
+ SuppressionElementName);
xmlWriter.writeEndDocument();
file.close();
return true;
}
+
+void ProjectFile::WriteStringList(QXmlStreamWriter &xmlWriter, const QStringList &stringlist, const char startelementname[], const char stringelementname[])
+{
+ if (stringlist.isEmpty())
+ return;
+
+ xmlWriter.writeStartElement(startelementname);
+ foreach(QString str, stringlist) {
+ xmlWriter.writeStartElement(stringelementname);
+ xmlWriter.writeCharacters(str);
+ xmlWriter.writeEndElement();
+ }
+ xmlWriter.writeEndElement();
+}
diff --git a/gui/projectfile.h b/gui/projectfile.h
index fa9a1dc66..006046e94 100644
--- a/gui/projectfile.h
+++ b/gui/projectfile.h
@@ -84,6 +84,12 @@ public:
*/
QStringList GetLibraries() const;
+ /**
+ * @brief Get list suppressions.
+ * @return list of suppressions.
+ */
+ QStringList GetSuppressions() const;
+
/**
* @brief Get filename for the project file.
* @return file name.
@@ -126,16 +132,31 @@ public:
/**
* @brief Set list of libraries.
- * @param paths List of libraries.
+ * @param libraries List of libraries.
*/
void SetLibraries(const QStringList &libraries);
+ /**
+ * @brief Set list of suppressions.
+ * @param suppressions List of suppressions.
+ */
+ void SetSuppressions(const QStringList &suppressions);
+
/**
* @brief Write project file (to disk).
* @param filename Filename to use.
*/
bool Write(const QString &filename = QString());
+ /**
+ * @brief Write string list
+ * @param xmlWriter xml writer
+ * @param stringlist string list to write
+ * @param startelementname name of start element
+ * @param stringelementname name of each string element
+ */
+ static void WriteStringList(QXmlStreamWriter &xmlWriter, const QStringList &stringlist, const char startelementname[], const char stringelementname[]);
+
/**
* @brief Set filename for the project file.
* @param filename Filename to use.
@@ -177,10 +198,12 @@ protected:
void ReadExcludes(QXmlStreamReader &reader);
/**
- * @brief Read list of libraries.
- * @param reader XML stream reader.
- */
- void ReadLibraries(QXmlStreamReader &reader);
+ * @brief Read string list
+ * @param stringlist destination string list
+ * @param reader XML stream reader
+ * @param elementname elementname for each string
+ */
+ void ReadStringList(QStringList &stringlist, QXmlStreamReader &reader, const char elementname[]);
private:
@@ -221,6 +244,11 @@ private:
* @brief List of libraries.
*/
QStringList mLibraries;
+
+ /**
+ * @brief List of suppressions.
+ */
+ QStringList mSuppressions;
};
/// @}
#endif // PROJECT_FILE_H
diff --git a/gui/projectfile.ui b/gui/projectfile.ui
index 6d73e49a3..d5cec19b9 100644
--- a/gui/projectfile.ui
+++ b/gui/projectfile.ui
@@ -276,6 +276,54 @@
+
+
+ Suppressions
+
+
+ -
+
+
+ Suppression list:
+
+
+
+ -
+
+
+ -
+
+
-
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+ Add
+
+
+
+ -
+
+
+ Remove
+
+
+
+
+
+
+
-
diff --git a/gui/projectfiledialog.cpp b/gui/projectfiledialog.cpp
index f138c0023..73467a215 100644
--- a/gui/projectfiledialog.cpp
+++ b/gui/projectfiledialog.cpp
@@ -22,11 +22,14 @@
#include
#include
#include
+#include
#include
#include
#include "common.h"
#include "projectfiledialog.h"
#include "library.h"
+#include "cppcheck.h"
+#include "errorlogger.h"
ProjectFileDialog::ProjectFileDialog(const QString &path, QWidget *parent)
: QDialog(parent)
@@ -83,6 +86,8 @@ ProjectFileDialog::ProjectFileDialog(const QString &path, QWidget *parent)
connect(mUI.mBtnRemoveIgnorePath, SIGNAL(clicked()), this, SLOT(RemoveExcludePath()));
connect(mUI.mBtnIncludeUp, SIGNAL(clicked()), this, SLOT(MoveIncludePathUp()));
connect(mUI.mBtnIncludeDown, SIGNAL(clicked()), this, SLOT(MoveIncludePathDown()));
+ connect(mUI.mBtnAddSuppression, SIGNAL(clicked()), this, SLOT(AddSuppression()));
+ connect(mUI.mBtnRemoveSuppression, SIGNAL(clicked()), this, SLOT(RemoveSuppression()));
}
ProjectFileDialog::~ProjectFileDialog()
@@ -195,13 +200,24 @@ QStringList ProjectFileDialog::GetExcludedPaths() const
QStringList ProjectFileDialog::GetLibraries() const
{
QStringList libraries;
- for (int i = 0; i < mLibraryCheckboxes.size(); i++) {
- if (mLibraryCheckboxes[i]->isChecked())
- libraries << mLibraryCheckboxes[i]->text();
+ foreach(const QCheckBox *checkbox, mLibraryCheckboxes) {
+ if (checkbox->isChecked())
+ libraries << checkbox->text();
}
return libraries;
}
+QStringList ProjectFileDialog::GetSuppressions() const
+{
+ QStringList suppressions;
+ const int count = mUI.mListSuppressions->count();
+ for (int i = 0; i < count; i++) {
+ QListWidgetItem *item = mUI.mListSuppressions->item(i);
+ suppressions << item->text();
+ }
+ return suppressions;
+}
+
void ProjectFileDialog::SetRootPath(const QString &root)
{
QString newroot = QDir::toNativeSeparators(root);
@@ -251,6 +267,12 @@ void ProjectFileDialog::SetLibraries(const QStringList &libraries)
}
}
+void ProjectFileDialog::SetSuppressions(const QStringList &suppressions)
+{
+ mUI.mListSuppressions->clear();
+ mUI.mListSuppressions->addItems(suppressions);
+}
+
void ProjectFileDialog::AddIncludeDir()
{
const QFileInfo inf(mFilePath);
@@ -360,3 +382,33 @@ void ProjectFileDialog::MoveIncludePathDown()
mUI.mListIncludeDirs->insertItem(row, item);
mUI.mListIncludeDirs->setCurrentItem(item);
}
+
+void ProjectFileDialog::AddSuppression()
+{
+ class QErrorLogger : public ErrorLogger {
+ public:
+ virtual void reportOut(const std::string &outmsg) {}
+ virtual void reportErr(const ErrorLogger::ErrorMessage &msg) {
+ errorIds << QString::fromStdString(msg._id);
+ }
+ QStringList errorIds;
+ };
+
+ QErrorLogger errorLogger;
+ CppCheck cppcheck(errorLogger,false);
+ cppcheck.getErrorMessages();
+ errorLogger.errorIds.sort();
+
+ bool ok;
+ QString item = QInputDialog::getItem(this, tr("Add Suppression"),
+ tr("Select error id suppress:"), errorLogger.errorIds, 0, false, &ok);
+ if (ok && !item.isEmpty())
+ mUI.mListSuppressions->addItem(item);
+}
+
+void ProjectFileDialog::RemoveSuppression()
+{
+ const int row = mUI.mListSuppressions->currentRow();
+ QListWidgetItem *item = mUI.mListSuppressions->takeItem(row);
+ delete item;
+}
diff --git a/gui/projectfiledialog.h b/gui/projectfiledialog.h
index a4852a82e..66481de78 100644
--- a/gui/projectfiledialog.h
+++ b/gui/projectfiledialog.h
@@ -77,6 +77,12 @@ public:
*/
QStringList GetLibraries() const;
+ /**
+ * @brief Return suppressions from the dialog control.
+ * @return List of suppressions.
+ */
+ QStringList GetSuppressions() const;
+
/**
* @brief Set project root path to dialog control.
* @param root Project root path to set to dialog control.
@@ -113,6 +119,12 @@ public:
*/
void SetLibraries(const QStringList &libraries);
+ /**
+ * @brief Set suppressions to dialog control.
+ * @param paths List of suppressions to set to dialog control.
+ */
+ void SetSuppressions(const QStringList &suppressions);
+
protected slots:
/**
* @brief Browse for include directory.
@@ -170,6 +182,16 @@ protected slots:
*/
void MoveIncludePathDown();
+ /**
+ * @brief Add suppression to the list
+ */
+ void AddSuppression();
+
+ /**
+ * @brief Remove selected suppression from the list
+ */
+ void RemoveSuppression();
+
protected:
/**