Merge branch 'master' of git@github.com:danmar/cppcheck
This commit is contained in:
commit
24e22ac942
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* Cppcheck - A tool for static C/C++ code analysis
|
||||
* Copyright (C) 2007-2009 Daniel Marjamäki, Reijo Tomperi, Nicolas Le Cam,
|
||||
* Leandro Penz, Kimmo Varis, Vesa Pikki
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/
|
||||
*/
|
||||
|
||||
#ifndef COMMON_H
|
||||
#define COMMON_H
|
||||
|
||||
|
||||
typedef enum
|
||||
{
|
||||
SHOW_ALL,
|
||||
SHOW_STYLE,
|
||||
SHOW_SECURITY,
|
||||
SHOW_UNUSED,
|
||||
SHOW_ERRORS,
|
||||
SHOW_NONE
|
||||
}
|
||||
ShowTypes;
|
||||
|
||||
#endif
|
|
@ -30,16 +30,38 @@ MainWindow::MainWindow() :
|
|||
mSettings(tr("CppCheck"), tr("CppCheck-GUI")),
|
||||
mActionExit(tr("E&xit"), this),
|
||||
mActionCheckFiles(tr("&Check files(s)"), this),
|
||||
mActionCheckDirectory(tr("&Check directory"), this),
|
||||
mActionClearResults(tr("Clear &results"), this),
|
||||
mActionReCheck(tr("Recheck files"), this),
|
||||
mActionCheckDirectory(tr("Check &directory"), this),
|
||||
mActionSettings(tr("&Settings"), this),
|
||||
mActionShowAll(tr("Show &more errors"), this),
|
||||
mActionShowSecurity(tr("Show &security errors"), this),
|
||||
mActionShowStyle(tr("Show s&tyle errors"), this),
|
||||
mActionShowUnused(tr("Show errors on &unused functions"), this),
|
||||
mActionShowErrors(tr("Show &common errors"), this),
|
||||
mResults(mSettings)
|
||||
{
|
||||
QMenu *menu = menuBar()->addMenu(tr("&File"));
|
||||
menu->addAction(&mActionCheckFiles);
|
||||
menu->addAction(&mActionCheckDirectory);
|
||||
menu->addAction(&mActionReCheck);
|
||||
menu->addAction(&mActionClearResults);
|
||||
menu->addSeparator();
|
||||
menu->addAction(&mActionExit);
|
||||
|
||||
QMenu *menuview = menuBar()->addMenu(tr("&View"));
|
||||
mActionShowAll.setCheckable(true);
|
||||
mActionShowSecurity.setCheckable(true);
|
||||
mActionShowStyle.setCheckable(true);
|
||||
mActionShowUnused.setCheckable(true);
|
||||
mActionShowErrors.setCheckable(true);
|
||||
|
||||
menuview->addAction(&mActionShowAll);
|
||||
menuview->addAction(&mActionShowSecurity);
|
||||
menuview->addAction(&mActionShowStyle);
|
||||
menuview->addAction(&mActionShowUnused);
|
||||
menuview->addAction(&mActionShowErrors);
|
||||
|
||||
QMenu *menuprogram = menuBar()->addMenu(tr("&Program"));
|
||||
menuprogram->addAction(&mActionSettings);
|
||||
|
||||
|
@ -50,9 +72,19 @@ MainWindow::MainWindow() :
|
|||
connect(&mActionCheckFiles, SIGNAL(triggered()), this, SLOT(CheckFiles()));
|
||||
connect(&mActionCheckDirectory, SIGNAL(triggered()), this, SLOT(CheckDirectory()));
|
||||
connect(&mActionSettings, SIGNAL(triggered()), this, SLOT(ProgramSettings()));
|
||||
connect(&mActionClearResults, SIGNAL(triggered()), this, SLOT(ClearResults()));
|
||||
|
||||
connect(&mActionShowAll, SIGNAL(toggled(bool)), this, SLOT(ShowAll(bool)));
|
||||
connect(&mActionShowSecurity, SIGNAL(toggled(bool)), this, SLOT(ShowSecurity(bool)));
|
||||
connect(&mActionShowStyle, SIGNAL(toggled(bool)), this, SLOT(ShowStyle(bool)));
|
||||
connect(&mActionShowUnused, SIGNAL(toggled(bool)), this, SLOT(ShowUnused(bool)));
|
||||
connect(&mActionShowErrors, SIGNAL(toggled(bool)), this, SLOT(ShowErrors(bool)));
|
||||
|
||||
connect(&mActionReCheck, SIGNAL(triggered()), this, SLOT(ReCheck()));
|
||||
connect(&mThread, SIGNAL(Done()), this, SLOT(CheckDone()));
|
||||
LoadSettings();
|
||||
mThread.Initialize(&mResults);
|
||||
setWindowTitle(tr("CppCheck"));
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
|
@ -71,6 +103,18 @@ void MainWindow::LoadSettings()
|
|||
resize(mSettings.value(tr("Window width"), 800).toInt(),
|
||||
mSettings.value(tr("Window height"), 600).toInt());
|
||||
}
|
||||
|
||||
mActionShowAll.setChecked(mSettings.value(tr("Show all"), true).toBool());
|
||||
mActionShowSecurity.setChecked(mSettings.value(tr("Show security"), true).toBool());
|
||||
mActionShowStyle.setChecked(mSettings.value(tr("Show style"), true).toBool());
|
||||
mActionShowUnused.setChecked(mSettings.value(tr("Show unused"), true).toBool());
|
||||
mActionShowErrors.setChecked(mSettings.value(tr("Show errors"), true).toBool());
|
||||
|
||||
mResults.ShowResults(SHOW_ALL, mActionShowAll.isChecked());
|
||||
mResults.ShowResults(SHOW_ERRORS, mActionShowErrors.isChecked());
|
||||
mResults.ShowResults(SHOW_SECURITY, mActionShowSecurity.isChecked());
|
||||
mResults.ShowResults(SHOW_STYLE, mActionShowStyle.isChecked());
|
||||
mResults.ShowResults(SHOW_UNUSED, mActionShowUnused.isChecked());
|
||||
}
|
||||
|
||||
void MainWindow::SaveSettings()
|
||||
|
@ -78,6 +122,12 @@ void MainWindow::SaveSettings()
|
|||
mSettings.setValue(tr("Window width"), size().width());
|
||||
mSettings.setValue(tr("Window height"), size().height());
|
||||
mSettings.setValue(tr("Window maximized"), isMaximized());
|
||||
|
||||
mSettings.setValue(tr("Show all"), mActionShowAll.isChecked());
|
||||
mSettings.setValue(tr("Show security"), mActionShowSecurity.isChecked());
|
||||
mSettings.setValue(tr("Show style"), mActionShowStyle.isChecked());
|
||||
mSettings.setValue(tr("Show unused"), mActionShowUnused.isChecked());
|
||||
mSettings.setValue(tr("Show errors"), mActionShowErrors.isChecked());
|
||||
}
|
||||
|
||||
|
||||
|
@ -102,8 +152,8 @@ void MainWindow::DoCheckFiles(QFileDialog::FileMode mode)
|
|||
mThread.ClearFiles();
|
||||
mThread.SetFiles(RemoveUnacceptedFiles(fileNames));
|
||||
mSettings.setValue(tr("Check path"), dialog.directory().absolutePath());
|
||||
mActionCheckFiles.setDisabled(true);
|
||||
mThread.Check(GetCppCheckSettings());
|
||||
EnableCheckButtons(false);
|
||||
mThread.Check(GetCppCheckSettings(), false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,7 +175,7 @@ Settings MainWindow::GetCppCheckSettings()
|
|||
result._checkCodingStyle = true;
|
||||
result._errorsOnly = false;
|
||||
result._verbose = true;
|
||||
result._force = true;
|
||||
result._force = mSettings.value(tr("Check force"), 1).toBool();
|
||||
result._xml = false;
|
||||
result._unusedFunctions = true;
|
||||
result._security = true;
|
||||
|
@ -186,7 +236,7 @@ QStringList MainWindow::RemoveUnacceptedFiles(const QStringList &list)
|
|||
|
||||
void MainWindow::CheckDone()
|
||||
{
|
||||
mActionCheckFiles.setDisabled(false);
|
||||
EnableCheckButtons(true);
|
||||
}
|
||||
|
||||
void MainWindow::ProgramSettings()
|
||||
|
@ -198,3 +248,48 @@ void MainWindow::ProgramSettings()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::ReCheck()
|
||||
{
|
||||
ClearResults();
|
||||
EnableCheckButtons(false);
|
||||
mThread.Check(GetCppCheckSettings(), true);
|
||||
}
|
||||
|
||||
void MainWindow::ClearResults()
|
||||
{
|
||||
mResults.Clear();
|
||||
}
|
||||
|
||||
void MainWindow::EnableCheckButtons(bool enable)
|
||||
{
|
||||
mActionCheckFiles.setEnabled(enable);
|
||||
mActionReCheck.setEnabled(enable);
|
||||
mActionCheckDirectory.setEnabled(enable);
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::ShowAll(bool checked)
|
||||
{
|
||||
mResults.ShowResults(SHOW_ALL, checked);
|
||||
}
|
||||
|
||||
void MainWindow::ShowSecurity(bool checked)
|
||||
{
|
||||
mResults.ShowResults(SHOW_SECURITY, checked);
|
||||
}
|
||||
|
||||
void MainWindow::ShowStyle(bool checked)
|
||||
{
|
||||
mResults.ShowResults(SHOW_STYLE, checked);
|
||||
}
|
||||
|
||||
void MainWindow::ShowUnused(bool checked)
|
||||
{
|
||||
mResults.ShowResults(SHOW_UNUSED, checked);
|
||||
}
|
||||
|
||||
void MainWindow::ShowErrors(bool checked)
|
||||
{
|
||||
mResults.ShowResults(SHOW_ERRORS, checked);
|
||||
}
|
||||
|
|
|
@ -49,6 +49,14 @@ public slots:
|
|||
*
|
||||
*/
|
||||
void CheckFiles();
|
||||
void ReCheck();
|
||||
void ClearResults();
|
||||
|
||||
void ShowAll(bool checked);
|
||||
void ShowSecurity(bool checked);
|
||||
void ShowStyle(bool checked);
|
||||
void ShowUnused(bool checked);
|
||||
void ShowErrors(bool checked);
|
||||
|
||||
/**
|
||||
* @brief Slot for check directory menu item
|
||||
|
@ -66,6 +74,7 @@ protected slots:
|
|||
*/
|
||||
void CheckDone();
|
||||
protected:
|
||||
void EnableCheckButtons(bool enable);
|
||||
void DoCheckFiles(QFileDialog::FileMode mode);
|
||||
QStringList GetFilesRecursively(const QString &path);
|
||||
QStringList RemoveDuplicates(const QStringList &list);
|
||||
|
@ -102,6 +111,19 @@ protected:
|
|||
*/
|
||||
QAction mActionCheckFiles;
|
||||
|
||||
/**
|
||||
* @brief Menu action to clear results
|
||||
*
|
||||
*/
|
||||
QAction mActionClearResults;
|
||||
|
||||
/**
|
||||
* @brief Menu action to re check
|
||||
*
|
||||
*/
|
||||
QAction mActionReCheck;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Menu action to check a directory
|
||||
*
|
||||
|
@ -114,6 +136,13 @@ protected:
|
|||
*/
|
||||
QAction mActionSettings;
|
||||
|
||||
QAction mActionShowAll;
|
||||
QAction mActionShowSecurity;
|
||||
QAction mActionShowStyle;
|
||||
QAction mActionShowUnused;
|
||||
QAction mActionShowErrors;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Results for checking
|
||||
|
|
|
@ -63,24 +63,32 @@ void ResultsTree::AddErrorItem(const QString &file,
|
|||
if (realfile.isEmpty())
|
||||
realfile = "Undefined file";
|
||||
|
||||
QStandardItem *fileitem = FindFileItem(realfile);
|
||||
ErrorItem item;
|
||||
item.file = realfile;
|
||||
item.type = SeverityToShowType(severity);
|
||||
item.message = message;
|
||||
item.files = files;
|
||||
item.lines = lines;
|
||||
mItems << item;
|
||||
|
||||
if (!fileitem)
|
||||
if (mShowTypes[item.type])
|
||||
{
|
||||
//qDebug()<<"No previous error for file"<<realfile;
|
||||
fileitem = CreateItem(realfile);
|
||||
mModel.appendRow(fileitem);
|
||||
AddItem(mItems.size() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
//qDebug() << "Adding error for file" << realfile << ". Message is" << message;
|
||||
ShowTypes ResultsTree::SeverityToShowType(const QString & severity)
|
||||
{
|
||||
if (severity == "all")
|
||||
return SHOW_ALL;
|
||||
if (severity == "error")
|
||||
return SHOW_ERRORS;
|
||||
if (severity == "style")
|
||||
return SHOW_STYLE;
|
||||
if (severity == "security")
|
||||
return SHOW_SECURITY;
|
||||
|
||||
QList<QStandardItem*> list;
|
||||
list << CreateItem(severity);
|
||||
list << CreateItem(QString("%1").arg(lines[0]));
|
||||
list << CreateItem(message);
|
||||
fileitem->appendRow(list);
|
||||
|
||||
//qDebug()<<"\n";
|
||||
return SHOW_NONE;
|
||||
}
|
||||
|
||||
QStandardItem *ResultsTree::FindFileItem(const QString &name)
|
||||
|
@ -94,6 +102,7 @@ QStandardItem *ResultsTree::FindFileItem(const QString &name)
|
|||
void ResultsTree::Clear()
|
||||
{
|
||||
mModel.removeRows(0, mModel.rowCount());
|
||||
mItems.clear();
|
||||
}
|
||||
|
||||
void ResultsTree::LoadSettings()
|
||||
|
@ -114,3 +123,71 @@ void ResultsTree::SaveSettings()
|
|||
mSettings.setValue(temp, columnWidth(i));
|
||||
}
|
||||
}
|
||||
|
||||
void ResultsTree::ShowResults(ShowTypes type, bool show)
|
||||
{
|
||||
if (type != SHOW_NONE)
|
||||
{
|
||||
if (mShowTypes[type] != show)
|
||||
{
|
||||
mShowTypes[type] = show;
|
||||
RefreshTree();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void ResultsTree::RefreshTree()
|
||||
{
|
||||
mModel.removeRows(0, mModel.rowCount());
|
||||
for (int i = 0;i < mItems.size();i++)
|
||||
{
|
||||
if (mShowTypes[mItems[i].type])
|
||||
{
|
||||
AddItem(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString ResultsTree::ShowTypeToString(ShowTypes type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case SHOW_ALL:
|
||||
return "all";
|
||||
case SHOW_ERRORS:
|
||||
return "error";
|
||||
case SHOW_STYLE:
|
||||
return "style";
|
||||
case SHOW_SECURITY:
|
||||
return "security";
|
||||
case SHOW_UNUSED:
|
||||
return "unused";
|
||||
case SHOW_NONE:
|
||||
return "none";
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
void ResultsTree::AddItem(int index)
|
||||
{
|
||||
if (index >= 0 && index < mItems.size())
|
||||
{
|
||||
QStandardItem *fileitem = FindFileItem(mItems[index].file);
|
||||
if (!fileitem)
|
||||
{
|
||||
//qDebug()<<"No previous error for file"<<realfile;
|
||||
fileitem = CreateItem(mItems[index].file);
|
||||
mModel.appendRow(fileitem);
|
||||
}
|
||||
|
||||
QList<QStandardItem*> list;
|
||||
list << CreateItem(ShowTypeToString(mItems[index].type));
|
||||
list << CreateItem(QString("%1").arg(mItems[index].lines[0]));
|
||||
list << CreateItem(mItems[index].message);
|
||||
fileitem->appendRow(list);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
#include <QStandardItemModel>
|
||||
#include <QStandardItem>
|
||||
#include <QSettings>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/**
|
||||
* @brief Cppcheck's results are shown in this tree
|
||||
|
@ -55,7 +55,24 @@ public:
|
|||
*
|
||||
*/
|
||||
void Clear();
|
||||
|
||||
void ShowResults(ShowTypes type, bool show);
|
||||
protected:
|
||||
void AddItem(int index);
|
||||
void RefreshTree();
|
||||
ShowTypes SeverityToShowType(const QString &severity);
|
||||
QString ShowTypeToString(ShowTypes type);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
QString file;
|
||||
ShowTypes type;
|
||||
QString message;
|
||||
QStringList files;
|
||||
QList<int> lines;
|
||||
}ErrorItem;
|
||||
|
||||
QList<ErrorItem> mItems;
|
||||
/**
|
||||
* @brief Load all settings
|
||||
* Colum widths
|
||||
|
@ -95,6 +112,8 @@ protected:
|
|||
*
|
||||
*/
|
||||
QSettings &mSettings;
|
||||
|
||||
bool mShowTypes[SHOW_NONE];
|
||||
private:
|
||||
};
|
||||
|
||||
|
|
|
@ -63,3 +63,8 @@ void ResultsView::Error(const QString &file,
|
|||
{
|
||||
mTree->AddErrorItem(file, severity, message, files, lines);
|
||||
}
|
||||
|
||||
void ResultsView::ShowResults(ShowTypes type, bool show)
|
||||
{
|
||||
mTree->ShowResults(type, show);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#include <QProgressBar>
|
||||
#include "../src/errorlogger.h"
|
||||
#include "resultstree.h"
|
||||
#include "common.h"
|
||||
|
||||
|
||||
/**
|
||||
* @brief Widget to show cppcheck progressbar and result
|
||||
|
@ -35,9 +37,12 @@ class ResultsView : public QWidget
|
|||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
|
||||
ResultsView(QSettings &settings);
|
||||
virtual ~ResultsView();
|
||||
|
||||
void ShowResults(ShowTypes type, bool show);
|
||||
|
||||
/**
|
||||
* @brief Clear results
|
||||
*
|
||||
|
|
|
@ -33,22 +33,24 @@ ThreadHandler::~ThreadHandler()
|
|||
|
||||
void ThreadHandler::ClearFiles()
|
||||
{
|
||||
mLastFiles.clear();
|
||||
mResults.ClearFiles();
|
||||
}
|
||||
|
||||
void ThreadHandler::SetFiles(const QStringList &files)
|
||||
{
|
||||
mResults.SetFiles(files);
|
||||
mLastFiles = files;
|
||||
QString file;
|
||||
qDebug() << "Files to check:";
|
||||
foreach(file, files)
|
||||
{
|
||||
qDebug() << file;
|
||||
}
|
||||
}
|
||||
|
||||
void ThreadHandler::Check(Settings settings)
|
||||
void ThreadHandler::Check(Settings settings, bool recheck)
|
||||
{
|
||||
if (recheck && mRunningThreadCount == 0)
|
||||
{
|
||||
mResults.SetFiles(mLastFiles);
|
||||
}
|
||||
|
||||
if (mResults.GetFileCount() == 0 || mRunningThreadCount > 0 || settings._jobs <= 0)
|
||||
{
|
||||
qDebug() << "Can't start checking if there's no files to check or if check is in progress.";
|
||||
|
@ -126,8 +128,6 @@ void ThreadHandler::Stop()
|
|||
{
|
||||
mThreads[i]->terminate();
|
||||
}
|
||||
|
||||
mResults.ClearFiles();
|
||||
}
|
||||
|
||||
void ThreadHandler::Initialize(ResultsView *view)
|
||||
|
|
|
@ -57,7 +57,7 @@ public:
|
|||
*/
|
||||
void SetFiles(const QStringList &files);
|
||||
|
||||
void Check(Settings settings);
|
||||
void Check(Settings settings, bool recheck);
|
||||
|
||||
|
||||
signals:
|
||||
|
@ -66,6 +66,7 @@ protected slots:
|
|||
void Stop();
|
||||
void ThreadDone();
|
||||
protected:
|
||||
QStringList mLastFiles;
|
||||
void RemoveThreads();
|
||||
ThreadResult mResults;
|
||||
QList<CheckThread *> mThreads;
|
||||
|
|
Loading…
Reference in New Issue