Added settings dialog to select what kind of errors are visible.
This commit is contained in:
parent
d008592a84
commit
5e1994068a
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include <QThread>
|
||||
#include "../src/cppcheck.h"
|
||||
#include "../src/settings.h"
|
||||
#include "threadresult.h"
|
||||
|
||||
/**
|
||||
|
|
|
@ -12,7 +12,6 @@ CONFIG += warn_on debug
|
|||
|
||||
# Input
|
||||
HEADERS += mainwindow.h \
|
||||
checkdialog.h \
|
||||
checkthread.h \
|
||||
resultsview.h \
|
||||
resultstree.h \
|
||||
|
@ -41,7 +40,6 @@ HEADERS += mainwindow.h \
|
|||
|
||||
SOURCES += main.cpp \
|
||||
mainwindow.cpp\
|
||||
checkdialog.cpp \
|
||||
checkthread.cpp \
|
||||
resultsview.cpp \
|
||||
resultstree.cpp \
|
||||
|
|
|
@ -21,24 +21,35 @@
|
|||
#include "mainwindow.h"
|
||||
#include <QDebug>
|
||||
#include <QMenu>
|
||||
#include <QDirIterator>
|
||||
#include <QMenuBar>
|
||||
#include "../src/filelister.h"
|
||||
|
||||
|
||||
MainWindow::MainWindow() :
|
||||
mSettings(tr("CppCheck"), tr("CppCheck-GUI")),
|
||||
mExit(tr("E&xit"), this),
|
||||
mCheck(tr("&Check"), this),
|
||||
mActionExit(tr("E&xit"), this),
|
||||
mActionCheckFiles(tr("&Check files(s)"), this),
|
||||
mActionCheckDirectory(tr("&Check directory"), this),
|
||||
mActionSettings(tr("&Settings"), this),
|
||||
mResults(mSettings)
|
||||
{
|
||||
QMenu *menu = menuBar()->addMenu(tr("&File"));
|
||||
menu->addAction(&mCheck);
|
||||
menu->addAction(&mActionCheckFiles);
|
||||
menu->addAction(&mActionCheckDirectory);
|
||||
menu->addSeparator();
|
||||
menu->addAction(&mExit);
|
||||
menu->addAction(&mActionExit);
|
||||
|
||||
QMenu *menuprogram = menuBar()->addMenu(tr("&Program"));
|
||||
menuprogram->addAction(&mActionSettings);
|
||||
|
||||
setCentralWidget(&mResults);
|
||||
|
||||
|
||||
connect(&mExit, SIGNAL(triggered()), this, SLOT(close()));
|
||||
connect(&mCheck, SIGNAL(triggered()), this, SLOT(Check()));
|
||||
connect(&mActionExit, SIGNAL(triggered()), this, SLOT(close()));
|
||||
connect(&mActionCheckFiles, SIGNAL(triggered()), this, SLOT(CheckFiles()));
|
||||
connect(&mActionCheckDirectory, SIGNAL(triggered()), this, SLOT(CheckDirectory()));
|
||||
connect(&mActionSettings, SIGNAL(triggered()), this, SLOT(ProgramSettings()));
|
||||
connect(&mThread, SIGNAL(Done()), this, SLOT(CheckDone()));
|
||||
LoadSettings();
|
||||
mThread.Initialize(&mResults);
|
||||
|
@ -46,7 +57,7 @@ MainWindow::MainWindow() :
|
|||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
//dtor
|
||||
SaveSettings();
|
||||
}
|
||||
|
||||
void MainWindow::LoadSettings()
|
||||
|
@ -70,22 +81,120 @@ void MainWindow::SaveSettings()
|
|||
}
|
||||
|
||||
|
||||
void MainWindow::Check()
|
||||
void MainWindow::DoCheckFiles(QFileDialog::FileMode mode)
|
||||
{
|
||||
CheckDialog dialog(mSettings);
|
||||
if (dialog.exec() == QDialog::Accepted)
|
||||
QFileDialog dialog(this);
|
||||
dialog.setDirectory(QDir(mSettings.value(tr("Check path"),"").toString()));
|
||||
dialog.setFileMode(mode);
|
||||
|
||||
if (dialog.exec())
|
||||
{
|
||||
QStringList selected = dialog.selectedFiles();
|
||||
QStringList fileNames;
|
||||
QString selection;
|
||||
|
||||
foreach(selection,selected)
|
||||
{
|
||||
fileNames << RemoveUnacceptedFiles(GetFilesRecursively(selection));
|
||||
}
|
||||
|
||||
mResults.Clear();
|
||||
mThread.ClearFiles();
|
||||
mThread.SetFiles(dialog.GetSelectedFiles());
|
||||
mSettings.setValue(tr("Check path"), dialog.GetDefaultPath());
|
||||
dialog.SaveCheckboxValues();
|
||||
mCheck.setDisabled(true);
|
||||
mThread.Check(dialog.GetSettings());
|
||||
mThread.SetFiles(RemoveUnacceptedFiles(fileNames));
|
||||
mSettings.setValue(tr("Check path"), dialog.directory().absolutePath());
|
||||
mActionCheckFiles.setDisabled(true);
|
||||
mThread.Check(GetCppCheckSettings());
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::CheckFiles()
|
||||
{
|
||||
DoCheckFiles(QFileDialog::ExistingFiles);
|
||||
}
|
||||
|
||||
void MainWindow::CheckDirectory()
|
||||
{
|
||||
DoCheckFiles(QFileDialog::DirectoryOnly);
|
||||
}
|
||||
|
||||
Settings MainWindow::GetCppCheckSettings()
|
||||
{
|
||||
Settings result;
|
||||
result._debug = false;
|
||||
result._showAll = true;
|
||||
result._checkCodingStyle = true;
|
||||
result._errorsOnly = false;
|
||||
result._verbose = true;
|
||||
result._force = true;
|
||||
result._xml = false;
|
||||
result._unusedFunctions = true;
|
||||
result._security = true;
|
||||
result._jobs = mSettings.value(tr("Check threads"), 1).toInt();
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
QStringList MainWindow::RemoveDuplicates(const QStringList &list)
|
||||
{
|
||||
QHash<QString, int> hash;
|
||||
QString str;
|
||||
foreach(str, list)
|
||||
{
|
||||
hash[str] = 0;
|
||||
}
|
||||
|
||||
return QStringList(hash.uniqueKeys());
|
||||
}
|
||||
|
||||
QStringList MainWindow::GetFilesRecursively(const QString &path)
|
||||
{
|
||||
QFileInfo info(path);
|
||||
QStringList list;
|
||||
|
||||
if (info.isDir())
|
||||
{
|
||||
QDirIterator it(path, QDirIterator::Subdirectories);
|
||||
|
||||
while (it.hasNext())
|
||||
{
|
||||
list << it.next();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
list << path;
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
QStringList MainWindow::RemoveUnacceptedFiles(const QStringList &list)
|
||||
{
|
||||
QStringList result;
|
||||
QString str;
|
||||
foreach(str, list)
|
||||
{
|
||||
if (FileLister::AcceptFile(str.toStdString()))
|
||||
{
|
||||
result << str;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::CheckDone()
|
||||
{
|
||||
mCheck.setDisabled(false);
|
||||
mActionCheckFiles.setDisabled(false);
|
||||
}
|
||||
|
||||
void MainWindow::ProgramSettings()
|
||||
{
|
||||
SettingsDialog dialog(mSettings);
|
||||
if (dialog.exec() == QDialog::Accepted)
|
||||
{
|
||||
dialog.SaveCheckboxValues();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,10 +25,11 @@
|
|||
#include "resultsview.h"
|
||||
#include <QSettings>
|
||||
#include <QAction>
|
||||
#include "../src/settings.h"
|
||||
#include <QFileDialog>
|
||||
|
||||
|
||||
#include "checkdialog.h"
|
||||
#include "threadhandler.h"
|
||||
#include "settingsdialog.h"
|
||||
|
||||
/**
|
||||
* @brief Main window for cppcheck-gui
|
||||
|
@ -44,10 +45,18 @@ public:
|
|||
public slots:
|
||||
|
||||
/**
|
||||
* @brief Slot for check menu item
|
||||
* @brief Slot for check files menu item
|
||||
*
|
||||
*/
|
||||
void Check();
|
||||
void CheckFiles();
|
||||
|
||||
/**
|
||||
* @brief Slot for check directory menu item
|
||||
*
|
||||
*/
|
||||
void CheckDirectory();
|
||||
|
||||
void ProgramSettings();
|
||||
|
||||
protected slots:
|
||||
|
||||
|
@ -57,6 +66,11 @@ protected slots:
|
|||
*/
|
||||
void CheckDone();
|
||||
protected:
|
||||
void DoCheckFiles(QFileDialog::FileMode mode);
|
||||
QStringList GetFilesRecursively(const QString &path);
|
||||
QStringList RemoveDuplicates(const QStringList &list);
|
||||
Settings GetCppCheckSettings();
|
||||
QStringList RemoveUnacceptedFiles(const QStringList &list);
|
||||
|
||||
/**
|
||||
* @brief Load program settings
|
||||
|
@ -80,13 +94,26 @@ protected:
|
|||
* @brief Menu action to exit program
|
||||
*
|
||||
*/
|
||||
QAction mExit;
|
||||
QAction mActionExit;
|
||||
|
||||
/**
|
||||
* @brief Menu action to open checkdialog
|
||||
* @brief Menu action to check files
|
||||
*
|
||||
*/
|
||||
QAction mCheck;
|
||||
QAction mActionCheckFiles;
|
||||
|
||||
/**
|
||||
* @brief Menu action to check a directory
|
||||
*
|
||||
*/
|
||||
QAction mActionCheckDirectory;
|
||||
|
||||
/**
|
||||
* @brief Menu action to open settings dialog
|
||||
*
|
||||
*/
|
||||
QAction mActionSettings;
|
||||
|
||||
|
||||
/**
|
||||
* @brief Results for checking
|
||||
|
|
|
@ -26,7 +26,7 @@ ResultsTree::ResultsTree(QSettings &settings) :
|
|||
{
|
||||
setModel(&mModel);
|
||||
QStringList labels;
|
||||
labels << tr("Filename && severity") << tr("Message");
|
||||
labels << tr("severity")<<tr("Line") << tr("Message");
|
||||
mModel.setHorizontalHeaderLabels(labels);
|
||||
|
||||
LoadSettings();
|
||||
|
@ -53,22 +53,34 @@ void ResultsTree::AddErrorItem(const QString &file,
|
|||
const QStringList &files,
|
||||
const QList<int> &lines)
|
||||
{
|
||||
Q_UNUSED(files);
|
||||
Q_UNUSED(lines);
|
||||
Q_UNUSED(file);
|
||||
|
||||
if (files.isEmpty())
|
||||
return;
|
||||
|
||||
QString realfile = files[0];
|
||||
|
||||
if (realfile.isEmpty())
|
||||
realfile = "Undefined file";
|
||||
|
||||
QStandardItem *fileitem = FindFileItem(realfile);
|
||||
|
||||
QStandardItem *fileitem = FindFileItem(file);
|
||||
if (!fileitem)
|
||||
{
|
||||
fileitem = CreateItem(file);
|
||||
//qDebug()<<"No previous error for file"<<realfile;
|
||||
fileitem = CreateItem(realfile);
|
||||
mModel.appendRow(fileitem);
|
||||
}
|
||||
|
||||
qDebug() << "Adding error for file" << file << ". Message is" << message;
|
||||
//qDebug() << "Adding error for file" << realfile << ". Message is" << message;
|
||||
|
||||
QList<QStandardItem*> list;
|
||||
list << CreateItem(severity);
|
||||
list << CreateItem(QString("%1").arg(lines[0]));
|
||||
list << CreateItem(message);
|
||||
fileitem->appendRow(list);
|
||||
mModel.appendRow(fileitem);
|
||||
|
||||
//qDebug()<<"\n";
|
||||
}
|
||||
|
||||
QStandardItem *ResultsTree::FindFileItem(const QString &name)
|
||||
|
|
|
@ -19,13 +19,126 @@
|
|||
|
||||
|
||||
#include "settingsdialog.h"
|
||||
#include <QLabel>
|
||||
#include <QDebug>
|
||||
|
||||
SettingsDialog::SettingsDialog()
|
||||
SettingsDialog::SettingsDialog(QSettings &programSettings) :
|
||||
mSettings(programSettings)
|
||||
{
|
||||
//ctor
|
||||
QPushButton *cancel = new QPushButton(tr("Cancel"));
|
||||
QPushButton *ok = new QPushButton(tr("Ok"));
|
||||
|
||||
//Main layout
|
||||
QVBoxLayout *layout = new QVBoxLayout();
|
||||
|
||||
//Layout for ok/cancel buttons
|
||||
QHBoxLayout *buttonLayout = new QHBoxLayout();
|
||||
|
||||
//Number of jobs
|
||||
QHBoxLayout *jobsLayout = new QHBoxLayout();
|
||||
mJobs = new QLineEdit(programSettings.value(tr("Check threads"), 1).toString());
|
||||
jobsLayout->addWidget(new QLabel(tr("Number of threads: ")));
|
||||
jobsLayout->addWidget(mJobs);
|
||||
mJobs->setValidator(new QIntValidator(this));
|
||||
layout->addLayout(jobsLayout);
|
||||
|
||||
|
||||
//Show All
|
||||
mShowAll = AddCheckbox(layout, tr("Show all"), tr("Check show all"), false);
|
||||
|
||||
//Check Coding Style
|
||||
mCheckCodingStyle = AddCheckbox(layout, tr("Check Coding Style"), tr("Check coding style"), false);
|
||||
|
||||
//Errors only
|
||||
mErrorsOnly = AddCheckbox(layout, tr("Errors only"), tr("Check errors only"), false);
|
||||
|
||||
//Verbose
|
||||
mVerbose = AddCheckbox(layout, tr("Verbose"), tr("Check verbose"), false);
|
||||
|
||||
//Force
|
||||
mForce = AddCheckbox(layout, tr("Force"), tr("Check force"), false);
|
||||
|
||||
//Unused functions
|
||||
mUnusedFunctions = AddCheckbox(layout, tr("Unused functions"), tr("Check unused functions"), false);
|
||||
|
||||
//Security
|
||||
mSecurity = AddCheckbox(layout, tr("Security"), tr("Check security"), false);
|
||||
|
||||
|
||||
|
||||
buttonLayout->addWidget(ok);
|
||||
buttonLayout->addWidget(cancel);
|
||||
layout->addLayout(buttonLayout);
|
||||
|
||||
|
||||
connect(ok, SIGNAL(clicked()),
|
||||
this, SLOT(accept()));
|
||||
connect(cancel, SIGNAL(clicked()),
|
||||
this, SLOT(reject()));
|
||||
|
||||
setWindowTitle(tr("Settings"));
|
||||
setLayout(layout);
|
||||
LoadSettings();
|
||||
}
|
||||
|
||||
SettingsDialog::~SettingsDialog()
|
||||
{
|
||||
//dtor
|
||||
SaveSettings();
|
||||
}
|
||||
|
||||
Qt::CheckState SettingsDialog::BoolToCheckState(bool yes)
|
||||
{
|
||||
if (yes)
|
||||
{
|
||||
return Qt::Checked;
|
||||
}
|
||||
return Qt::Unchecked;
|
||||
}
|
||||
|
||||
bool SettingsDialog::CheckStateToBool(Qt::CheckState state)
|
||||
{
|
||||
if (state == Qt::Checked)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
QCheckBox* SettingsDialog::AddCheckbox(QVBoxLayout *layout,
|
||||
const QString &label,
|
||||
const QString &settings,
|
||||
bool value)
|
||||
{
|
||||
QCheckBox *result = new QCheckBox(label);
|
||||
result->setCheckState(BoolToCheckState(mSettings.value(settings, value).toBool()));
|
||||
layout->addWidget(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
void SettingsDialog::LoadSettings()
|
||||
{
|
||||
resize(mSettings.value(tr("Check dialog width"), 800).toInt(), mSettings.value(tr("Check dialog height"), 600).toInt());
|
||||
}
|
||||
|
||||
void SettingsDialog::SaveSettings()
|
||||
{
|
||||
mSettings.setValue(tr("Check dialog width"), size().width());
|
||||
mSettings.setValue(tr("Check dialog height"), size().height());
|
||||
}
|
||||
|
||||
void SettingsDialog::SaveCheckboxValues()
|
||||
{
|
||||
mSettings.setValue(tr("Check threads"), mJobs->text().toInt());
|
||||
SaveCheckboxValue(mShowAll, tr("Check show all"));
|
||||
SaveCheckboxValue(mCheckCodingStyle, tr("Check coding style"));
|
||||
SaveCheckboxValue(mErrorsOnly, tr("Check errors only"));
|
||||
SaveCheckboxValue(mVerbose, tr("Check verbose"));
|
||||
SaveCheckboxValue(mForce, tr("Check force"));
|
||||
SaveCheckboxValue(mUnusedFunctions, tr("Check unused functions"));
|
||||
SaveCheckboxValue(mSecurity, tr("Check security"));
|
||||
}
|
||||
|
||||
void SettingsDialog::SaveCheckboxValue(QCheckBox *box, const QString &name)
|
||||
{
|
||||
mSettings.setValue(name, CheckStateToBool(box->checkState()));
|
||||
}
|
||||
|
|
|
@ -22,6 +22,14 @@
|
|||
#define SETTINGSDIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QLineEdit>
|
||||
#include <QComboBox>
|
||||
#include <QSettings>
|
||||
#include <QCheckBox>
|
||||
#include <QVBoxLayout>
|
||||
#include <QPushButton>
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Settings dialog
|
||||
|
@ -30,9 +38,116 @@
|
|||
class SettingsDialog : public QDialog
|
||||
{
|
||||
public:
|
||||
SettingsDialog();
|
||||
SettingsDialog(QSettings &programSettings);
|
||||
virtual ~SettingsDialog();
|
||||
void SaveCheckboxValues();
|
||||
protected:
|
||||
/**
|
||||
* @brief Load saved values
|
||||
* Loads dialog size and column widths.
|
||||
*
|
||||
*/
|
||||
void SaveSettings();
|
||||
|
||||
/**
|
||||
* @brief Save settings
|
||||
* Save dialog size and column widths.
|
||||
*
|
||||
*/
|
||||
void LoadSettings();
|
||||
|
||||
/**
|
||||
* @brief Save a single checkboxes value
|
||||
*
|
||||
* @param box checkbox to save
|
||||
* @param name name for QSettings to store the value
|
||||
*/
|
||||
void SaveCheckboxValue(QCheckBox *box, const QString &name);
|
||||
|
||||
/**
|
||||
* @brief Add a new checkbox to layout
|
||||
*
|
||||
* @param layout layout to add to
|
||||
* @param label label for the checkbox
|
||||
* @param settings QSettings name for default value
|
||||
* @return newly created QCheckBox
|
||||
*/
|
||||
QCheckBox* AddCheckbox(QVBoxLayout *layout,
|
||||
const QString &label,
|
||||
const QString &settings,
|
||||
bool value);
|
||||
|
||||
/**
|
||||
* @brief Convert bool to Qt::CheckState
|
||||
*
|
||||
* @param yes value to convert
|
||||
* @return value converted to Qt::CheckState
|
||||
*/
|
||||
Qt::CheckState BoolToCheckState(bool yes);
|
||||
|
||||
/**
|
||||
* @brief Converts Qt::CheckState to bool
|
||||
*
|
||||
* @param state Qt::CheckState to convert
|
||||
* @return converted value
|
||||
*/
|
||||
bool CheckStateToBool(Qt::CheckState state);
|
||||
|
||||
/**
|
||||
* @brief How many threads should cppcheck have
|
||||
*
|
||||
*/
|
||||
QLineEdit *mJobs;
|
||||
|
||||
/**
|
||||
* @brief Cppcheck setting
|
||||
*
|
||||
*/
|
||||
QCheckBox *mShowAll;
|
||||
|
||||
/**
|
||||
* @brief Cppcheck setting
|
||||
*
|
||||
*/
|
||||
QCheckBox *mCheckCodingStyle;
|
||||
|
||||
/**
|
||||
* @brief Cppcheck setting
|
||||
*
|
||||
*/
|
||||
QCheckBox *mErrorsOnly;
|
||||
|
||||
/**
|
||||
* @brief Cppcheck setting
|
||||
*
|
||||
*/
|
||||
QCheckBox *mVerbose;
|
||||
|
||||
/**
|
||||
* @brief Cppcheck setting
|
||||
*
|
||||
*/
|
||||
QCheckBox *mForce;
|
||||
|
||||
/**
|
||||
* @brief Cppcheck setting
|
||||
*
|
||||
*/
|
||||
QCheckBox *mUnusedFunctions;
|
||||
|
||||
/**
|
||||
* @brief Cppcheck setting
|
||||
*
|
||||
*/
|
||||
QCheckBox *mSecurity;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @brief Settings
|
||||
*
|
||||
*/
|
||||
QSettings &mSettings;
|
||||
private:
|
||||
};
|
||||
|
||||
|
|
|
@ -39,6 +39,11 @@ void ThreadHandler::ClearFiles()
|
|||
void ThreadHandler::SetFiles(const QStringList &files)
|
||||
{
|
||||
mResults.SetFiles(files);
|
||||
QString file;
|
||||
qDebug()<<"Files to check:";
|
||||
foreach(file,files) {
|
||||
qDebug()<<file;
|
||||
}
|
||||
}
|
||||
|
||||
void ThreadHandler::Check(Settings settings)
|
||||
|
@ -46,6 +51,7 @@ void ThreadHandler::Check(Settings settings)
|
|||
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.";
|
||||
emit Done();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include <QObject>
|
||||
#include <QStringList>
|
||||
#include "../src/settings.h"
|
||||
#include "../src/cppcheck.h"
|
||||
#include "threadresult.h"
|
||||
#include "checkthread.h"
|
||||
|
|
Loading…
Reference in New Issue