GUI: Add suppressions to project file
This commit is contained in:
parent
8da0d84905
commit
24a9da3771
|
@ -562,6 +562,11 @@ Settings MainWindow::GetCppcheckSettings()
|
||||||
QMessageBox::information(this, tr("Information"), tr("Failed to load the selected library %1").arg(filename));
|
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
|
// Only check the given -D configuration
|
||||||
if (!defines.isEmpty())
|
if (!defines.isEmpty())
|
||||||
result._maxConfigs = 1;
|
result._maxConfigs = 1;
|
||||||
|
|
|
@ -95,7 +95,10 @@ bool Project::Edit()
|
||||||
dlg.SetPaths(paths);
|
dlg.SetPaths(paths);
|
||||||
QStringList ignorepaths = mPFile->GetExcludedPaths();
|
QStringList ignorepaths = mPFile->GetExcludedPaths();
|
||||||
dlg.SetExcludedPaths(ignorepaths);
|
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();
|
int rv = dlg.exec();
|
||||||
if (rv == QDialog::Accepted) {
|
if (rv == QDialog::Accepted) {
|
||||||
|
@ -109,7 +112,10 @@ bool Project::Edit()
|
||||||
mPFile->SetCheckPaths(paths);
|
mPFile->SetCheckPaths(paths);
|
||||||
QStringList excludedpaths = dlg.GetExcludedPaths();
|
QStringList excludedpaths = dlg.GetExcludedPaths();
|
||||||
mPFile->SetExcludedPaths(excludedpaths);
|
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();
|
bool writeSuccess = mPFile->Write();
|
||||||
if (!writeSuccess) {
|
if (!writeSuccess) {
|
||||||
|
|
|
@ -46,6 +46,8 @@ static const char ExcludePathName[] = "path";
|
||||||
static const char ExcludePathNameAttrib[] = "name";
|
static const char ExcludePathNameAttrib[] = "name";
|
||||||
static const char LibrariesElementName[] = "libraries";
|
static const char LibrariesElementName[] = "libraries";
|
||||||
static const char LibraryElementName[] = "library";
|
static const char LibraryElementName[] = "library";
|
||||||
|
static const char SuppressionsElementName[] = "suppressions";
|
||||||
|
static const char SuppressionElementName[] = "suppression";
|
||||||
|
|
||||||
ProjectFile::ProjectFile(QObject *parent) :
|
ProjectFile::ProjectFile(QObject *parent) :
|
||||||
QObject(parent)
|
QObject(parent)
|
||||||
|
@ -102,9 +104,13 @@ bool ProjectFile::Read(const QString &filename)
|
||||||
if (insideProject && xmlReader.name() == IgnoreElementName)
|
if (insideProject && xmlReader.name() == IgnoreElementName)
|
||||||
ReadExcludes(xmlReader);
|
ReadExcludes(xmlReader);
|
||||||
|
|
||||||
// Find libraries list from insid project element
|
// Find libraries list from inside project element
|
||||||
if (insideProject && xmlReader.name() == LibrariesElementName)
|
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;
|
break;
|
||||||
|
|
||||||
|
@ -175,6 +181,15 @@ QStringList ProjectFile::GetLibraries() const
|
||||||
return libraries;
|
return libraries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QStringList ProjectFile::GetSuppressions() const
|
||||||
|
{
|
||||||
|
QStringList suppressions;
|
||||||
|
foreach(QString suppression, mSuppressions) {
|
||||||
|
suppressions << suppression;
|
||||||
|
}
|
||||||
|
return suppressions;
|
||||||
|
}
|
||||||
|
|
||||||
void ProjectFile::ReadRootPath(QXmlStreamReader &reader)
|
void ProjectFile::ReadRootPath(QXmlStreamReader &reader)
|
||||||
{
|
{
|
||||||
QXmlStreamAttributes attribs = reader.attributes();
|
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;
|
QXmlStreamReader::TokenType type;
|
||||||
bool allRead = false;
|
bool allRead = false;
|
||||||
|
@ -352,17 +367,17 @@ void ProjectFile::ReadLibraries(QXmlStreamReader &reader)
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case QXmlStreamReader::StartElement:
|
case QXmlStreamReader::StartElement:
|
||||||
// Read library-elements
|
// Read library-elements
|
||||||
if (reader.name().toString() == LibraryElementName) {
|
if (reader.name().toString() == elementname) {
|
||||||
type = reader.readNext();
|
type = reader.readNext();
|
||||||
if (type == QXmlStreamReader::Characters) {
|
if (type == QXmlStreamReader::Characters) {
|
||||||
QString library = reader.text().toString();
|
QString text = reader.text().toString();
|
||||||
mLibraries << library;
|
stringlist << text;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case QXmlStreamReader::EndElement:
|
case QXmlStreamReader::EndElement:
|
||||||
if (reader.name().toString() == LibrariesElementName)
|
if (reader.name().toString() != elementname)
|
||||||
allRead = true;
|
allRead = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -406,6 +421,11 @@ void ProjectFile::SetLibraries(const QStringList &libraries)
|
||||||
mLibraries = libraries;
|
mLibraries = libraries;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ProjectFile::SetSuppressions(const QStringList &suppressions)
|
||||||
|
{
|
||||||
|
mSuppressions = suppressions;
|
||||||
|
}
|
||||||
|
|
||||||
bool ProjectFile::Write(const QString &filename)
|
bool ProjectFile::Write(const QString &filename)
|
||||||
{
|
{
|
||||||
if (!filename.isEmpty())
|
if (!filename.isEmpty())
|
||||||
|
@ -467,17 +487,31 @@ bool ProjectFile::Write(const QString &filename)
|
||||||
xmlWriter.writeEndElement();
|
xmlWriter.writeEndElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mLibraries.isEmpty()) {
|
WriteStringList(xmlWriter,
|
||||||
xmlWriter.writeStartElement(LibrariesElementName);
|
mLibraries,
|
||||||
foreach(QString library, mLibraries) {
|
LibrariesElementName,
|
||||||
xmlWriter.writeStartElement(LibraryElementName);
|
LibraryElementName);
|
||||||
xmlWriter.writeCharacters(library);
|
|
||||||
xmlWriter.writeEndElement();
|
WriteStringList(xmlWriter,
|
||||||
}
|
mSuppressions,
|
||||||
xmlWriter.writeEndElement();
|
SuppressionsElementName,
|
||||||
}
|
SuppressionElementName);
|
||||||
|
|
||||||
xmlWriter.writeEndDocument();
|
xmlWriter.writeEndDocument();
|
||||||
file.close();
|
file.close();
|
||||||
return true;
|
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();
|
||||||
|
}
|
||||||
|
|
|
@ -84,6 +84,12 @@ public:
|
||||||
*/
|
*/
|
||||||
QStringList GetLibraries() const;
|
QStringList GetLibraries() const;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Get list suppressions.
|
||||||
|
* @return list of suppressions.
|
||||||
|
*/
|
||||||
|
QStringList GetSuppressions() const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Get filename for the project file.
|
* @brief Get filename for the project file.
|
||||||
* @return file name.
|
* @return file name.
|
||||||
|
@ -126,16 +132,31 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set list of libraries.
|
* @brief Set list of libraries.
|
||||||
* @param paths List of libraries.
|
* @param libraries List of libraries.
|
||||||
*/
|
*/
|
||||||
void SetLibraries(const QStringList &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).
|
* @brief Write project file (to disk).
|
||||||
* @param filename Filename to use.
|
* @param filename Filename to use.
|
||||||
*/
|
*/
|
||||||
bool Write(const QString &filename = QString());
|
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.
|
* @brief Set filename for the project file.
|
||||||
* @param filename Filename to use.
|
* @param filename Filename to use.
|
||||||
|
@ -177,10 +198,12 @@ protected:
|
||||||
void ReadExcludes(QXmlStreamReader &reader);
|
void ReadExcludes(QXmlStreamReader &reader);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Read list of libraries.
|
* @brief Read string list
|
||||||
* @param reader XML stream reader.
|
* @param stringlist destination string list
|
||||||
*/
|
* @param reader XML stream reader
|
||||||
void ReadLibraries(QXmlStreamReader &reader);
|
* @param elementname elementname for each string
|
||||||
|
*/
|
||||||
|
void ReadStringList(QStringList &stringlist, QXmlStreamReader &reader, const char elementname[]);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
@ -221,6 +244,11 @@ private:
|
||||||
* @brief List of libraries.
|
* @brief List of libraries.
|
||||||
*/
|
*/
|
||||||
QStringList mLibraries;
|
QStringList mLibraries;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief List of suppressions.
|
||||||
|
*/
|
||||||
|
QStringList mSuppressions;
|
||||||
};
|
};
|
||||||
/// @}
|
/// @}
|
||||||
#endif // PROJECT_FILE_H
|
#endif // PROJECT_FILE_H
|
||||||
|
|
|
@ -276,6 +276,54 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
<widget class="QWidget" name="tab_4">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Suppressions</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_6">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_7">
|
||||||
|
<property name="text">
|
||||||
|
<string>Suppression list:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QListWidget" name="mListSuppressions"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="mBtnAddSuppression">
|
||||||
|
<property name="text">
|
||||||
|
<string>Add</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="mBtnRemoveSuppression">
|
||||||
|
<property name="text">
|
||||||
|
<string>Remove</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
|
|
@ -22,11 +22,14 @@
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
|
#include <QInputDialog>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "projectfiledialog.h"
|
#include "projectfiledialog.h"
|
||||||
#include "library.h"
|
#include "library.h"
|
||||||
|
#include "cppcheck.h"
|
||||||
|
#include "errorlogger.h"
|
||||||
|
|
||||||
ProjectFileDialog::ProjectFileDialog(const QString &path, QWidget *parent)
|
ProjectFileDialog::ProjectFileDialog(const QString &path, QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
|
@ -83,6 +86,8 @@ ProjectFileDialog::ProjectFileDialog(const QString &path, QWidget *parent)
|
||||||
connect(mUI.mBtnRemoveIgnorePath, SIGNAL(clicked()), this, SLOT(RemoveExcludePath()));
|
connect(mUI.mBtnRemoveIgnorePath, SIGNAL(clicked()), this, SLOT(RemoveExcludePath()));
|
||||||
connect(mUI.mBtnIncludeUp, SIGNAL(clicked()), this, SLOT(MoveIncludePathUp()));
|
connect(mUI.mBtnIncludeUp, SIGNAL(clicked()), this, SLOT(MoveIncludePathUp()));
|
||||||
connect(mUI.mBtnIncludeDown, SIGNAL(clicked()), this, SLOT(MoveIncludePathDown()));
|
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()
|
ProjectFileDialog::~ProjectFileDialog()
|
||||||
|
@ -195,13 +200,24 @@ QStringList ProjectFileDialog::GetExcludedPaths() const
|
||||||
QStringList ProjectFileDialog::GetLibraries() const
|
QStringList ProjectFileDialog::GetLibraries() const
|
||||||
{
|
{
|
||||||
QStringList libraries;
|
QStringList libraries;
|
||||||
for (int i = 0; i < mLibraryCheckboxes.size(); i++) {
|
foreach(const QCheckBox *checkbox, mLibraryCheckboxes) {
|
||||||
if (mLibraryCheckboxes[i]->isChecked())
|
if (checkbox->isChecked())
|
||||||
libraries << mLibraryCheckboxes[i]->text();
|
libraries << checkbox->text();
|
||||||
}
|
}
|
||||||
return libraries;
|
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)
|
void ProjectFileDialog::SetRootPath(const QString &root)
|
||||||
{
|
{
|
||||||
QString newroot = QDir::toNativeSeparators(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()
|
void ProjectFileDialog::AddIncludeDir()
|
||||||
{
|
{
|
||||||
const QFileInfo inf(mFilePath);
|
const QFileInfo inf(mFilePath);
|
||||||
|
@ -360,3 +382,33 @@ void ProjectFileDialog::MoveIncludePathDown()
|
||||||
mUI.mListIncludeDirs->insertItem(row, item);
|
mUI.mListIncludeDirs->insertItem(row, item);
|
||||||
mUI.mListIncludeDirs->setCurrentItem(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;
|
||||||
|
}
|
||||||
|
|
|
@ -77,6 +77,12 @@ public:
|
||||||
*/
|
*/
|
||||||
QStringList GetLibraries() const;
|
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.
|
* @brief Set project root path to dialog control.
|
||||||
* @param root Project root path to set to dialog control.
|
* @param root Project root path to set to dialog control.
|
||||||
|
@ -113,6 +119,12 @@ public:
|
||||||
*/
|
*/
|
||||||
void SetLibraries(const QStringList &libraries);
|
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:
|
protected slots:
|
||||||
/**
|
/**
|
||||||
* @brief Browse for include directory.
|
* @brief Browse for include directory.
|
||||||
|
@ -170,6 +182,16 @@ protected slots:
|
||||||
*/
|
*/
|
||||||
void MoveIncludePathDown();
|
void MoveIncludePathDown();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Add suppression to the list
|
||||||
|
*/
|
||||||
|
void AddSuppression();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Remove selected suppression from the list
|
||||||
|
*/
|
||||||
|
void RemoveSuppression();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue