Began implementing a simple Qt based GUI.

Also modified astyle scripts to format gui code aswell.
This commit is contained in:
Vesa Pikki 2009-03-01 07:38:21 +00:00
parent 4e465f7073
commit b39c15410b
16 changed files with 1378 additions and 0 deletions

257
gui/checkdialog.cpp Normal file
View File

@ -0,0 +1,257 @@
/*
* 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/
*/
#include "checkdialog.h"
#include <QHBoxLayout>
#include <QStringList>
#include <QLabel>
#include <QIntValidator>
#include <QFileDialog>
#include <QDirIterator>
#include <QDebug>
CheckDialog::CheckDialog(QSettings &programSettings) :
mSettings(programSettings)
{
QPushButton *cancel = new QPushButton("Cancel");
QPushButton *ok = new QPushButton("Ok");
//Main layout
QVBoxLayout *layout = new QVBoxLayout();
//Layout for ok/cancel buttons
QHBoxLayout *buttonLayout = new QHBoxLayout();
//File selection tree
layout->addWidget(new QLabel("Select files to check"));
mFileTree = new QTreeView();
layout->addWidget(mFileTree);
mFileTree->setModel(&mModel);
mFileTree->scrollTo(mModel.index(programSettings.value("Check path", QDir::currentPath()).toString()));
mFileTree->setSelectionMode(QAbstractItemView::ExtendedSelection);
//Number of jobs
mJobs = new QLineEdit(programSettings.value("Check threads", 1).toString());
layout->addWidget(new QLabel("Number of threads"));
layout->addWidget(mJobs);
mJobs->setValidator(new QIntValidator(this));
//Debug
mDebug = AddCheckbox(layout, "Debug", "Check debug", false);
//Show All
mShowAll = AddCheckbox(layout, "Show all", "Check show all", false);
//Check Coding Style
mCheckCodingStyle = AddCheckbox(layout, "Check Coding Style", "Check coding style", false);
//Errors only
mErrorsOnly = AddCheckbox(layout, "Errors only", "Check errors only", false);
//Verbose
mVerbose = AddCheckbox(layout, "Verbose", "Check verbose", false);
//Force
mForce = AddCheckbox(layout, "Force", "Check force", false);
//XML
mXml = AddCheckbox(layout, "XML", "Check xml", false);
//Unused functions
mUnusedFunctions = AddCheckbox(layout, "Unused functions", "Check unused functions", false);
//Security
mSecurity = AddCheckbox(layout, "Security", "Check security", false);
//Vcl
mVcl = AddCheckbox(layout, "Vcl", "Check vcl", 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("Select files to check");
setLayout(layout);
LoadSettings();
}
CheckDialog::~CheckDialog()
{
SaveSettings();
}
QStringList CheckDialog::GetSelectedFiles()
{
QModelIndexList indexes = mFileTree->selectionModel()->selectedRows();
QStringList list;
QModelIndex index;
foreach(index, indexes)
{
list << mModel.filePath(index);
}
return list;
}
Qt::CheckState CheckDialog::BoolToCheckState(bool yes)
{
if (yes)
{
return Qt::Checked;
}
return Qt::Unchecked;
}
bool CheckDialog::CheckStateToBool(Qt::CheckState state)
{
if (state == Qt::Checked)
{
return true;
}
return false;
}
QCheckBox* CheckDialog::AddCheckbox(QVBoxLayout *layout,
const QString &label,
const QString &settings,
bool value)
{
QCheckBox *result = new QCheckBox(label);
result->setCheckState(BoolToCheckState(mSettings.value(settings, value).toInt()));
//layout->addWidget(new QLabel(label));
layout->addWidget(result);
return result;
}
Settings CheckDialog::GetSettings()
{
Settings result;
result._debug = CheckStateToBool(mDebug->checkState());
result._showAll = CheckStateToBool(mShowAll->checkState());
result._checkCodingStyle = CheckStateToBool(mCheckCodingStyle->checkState());
result._errorsOnly = CheckStateToBool(mErrorsOnly->checkState());
result._verbose = CheckStateToBool(mVerbose->checkState());
result._force = CheckStateToBool(mForce->checkState());
result._xml = CheckStateToBool(mXml->checkState());
result._unusedFunctions = CheckStateToBool(mUnusedFunctions->checkState());
result._security = CheckStateToBool(mSecurity->checkState());
result._vcl = CheckStateToBool(mVcl->checkState());
result._jobs = mJobs->text().toInt();
return result;
}
QString CheckDialog::GetDefaultPath()
{
QStringList list = GetSelectedFiles();
int len = 9999;
QString file, shortest;
if (list.size() == 0)
{
return QDir::currentPath();
}
foreach(file, list)
{
if (file.size() < len)
{
shortest = file;
len = file.size();
}
}
return shortest;
}
void CheckDialog::LoadSettings()
{
/*
if (mSettings.value("Check dialog maximized",false).toBool())
{
showMaximized();
}
else
{*/
resize(mSettings.value("Check dialog width", 800).toInt(), mSettings.value("Check dialog height", 600).toInt());
//}
for (int i = 0;i < mModel.columnCount();i++)
{
//mFileTree.columnWidth(i);
QString temp = QString("Check dialog column %1 width").arg(i);
mFileTree->setColumnWidth(i, mSettings.value(temp, 800 / mModel.columnCount()).toInt());
}
}
void CheckDialog::SaveSettings()
{
mSettings.setValue("Check dialog width", size().width());
mSettings.setValue("Check dialog height", size().height());
//mSettings.setValue("Check dialog maximized", isMaximized());
for (int i = 0;i < mModel.columnCount();i++)
{
QString temp = QString("Check dialog column %1 width").arg(i);
mSettings.setValue(temp, mFileTree->columnWidth(i));
}
}
void CheckDialog::SaveCheckboxValues()
{
mSettings.setValue("Check threads", mJobs->text().toInt());
SaveCheckboxValue(mDebug, "Check debug");
SaveCheckboxValue(mShowAll, "Check show all");
SaveCheckboxValue(mCheckCodingStyle, "Check coding style");
SaveCheckboxValue(mErrorsOnly, "Check errors only");
SaveCheckboxValue(mVerbose, "Check verbose");
SaveCheckboxValue(mForce, "Check force");
SaveCheckboxValue(mXml, "Check xml");
SaveCheckboxValue(mUnusedFunctions, "Check unused functions");
SaveCheckboxValue(mSecurity, "Check security");
SaveCheckboxValue(mVcl, "Check vcl");
}
void CheckDialog::SaveCheckboxValue(QCheckBox *box, const QString &name)
{
mSettings.setValue(name, CheckStateToBool(box->checkState()));
}

214
gui/checkdialog.h Normal file
View File

@ -0,0 +1,214 @@
/*
* 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 CHECKDIALOG_H
#define CHECKDIALOG_H
#include <QDialog>
#include <QPushButton>
#include <QCheckBox>
#include <QLineEdit>
#include <QComboBox>
#include <QSettings>
#include "../src/settings.h"
#include <QVBoxLayout>
#include <QTreeView>
#include <QDirModel>
#include <QStandardItem>
/**
* @brief Dialog to select what and how to check
*
*/
class CheckDialog : public QDialog
{
Q_OBJECT
public:
CheckDialog(QSettings &programSettings);
virtual ~CheckDialog();
/**
* @brief Get cppcheck settings based on user selections
*
* @return cppcheck settings
*/
Settings GetSettings();
/**
* @brief Get the root path of current selection
*
* @return default path to use next time
*/
QString GetDefaultPath();
/**
* @brief Get a list of selected files and directories
*
* @return list of selected files
*/
QStringList GetSelectedFiles();
/**
* @brief Save all checkbox values
*
*/
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 Item model for mFileTree
*
*/
QDirModel mModel;
/**
* @brief Filetree to select files from
*
*/
QTreeView *mFileTree;
/**
* @brief How many threads should cppcheck have
*
*/
QLineEdit *mJobs;
/**
* @brief Cppcheck setting
*
*/
QCheckBox *mDebug;
/**
* @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 *mXml;
/**
* @brief Cppcheck setting
*
*/
QCheckBox *mUnusedFunctions;
/**
* @brief Cppcheck setting
*
*/
QCheckBox *mSecurity;
/**
* @brief Cppcheck setting
*
*/
QCheckBox *mVcl;
/**
* @brief Settings
*
*/
QSettings &mSettings;
private:
};
#endif // CHECKDIALOG_H

79
gui/checkthread.cpp Normal file
View File

@ -0,0 +1,79 @@
/*
* 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/
*/
#include "checkthread.h"
#include <QDebug>
CheckThread::CheckThread() : mCppCheck(*this)
{
//ctor
}
CheckThread::~CheckThread()
{
//dtor
}
void CheckThread::SetSettings(Settings settings)
{
mCppCheck.settings(settings);
}
void CheckThread::AddFile(const QString &file)
{
mCppCheck.addFile(file.toStdString());
}
void CheckThread::ClearFiles()
{
mCppCheck.clearFiles();
}
void CheckThread::run()
{
mCppCheck.check();
emit Done();
}
void CheckThread::reportOut(const std::string &outmsg)
{
emit CurrentFile(QString(outmsg.c_str()));
}
void CheckThread::reportErr(const ErrorLogger::ErrorMessage &msg)
{
emit Error(QString(callStackToString(msg._callStack).c_str()),
QString(msg._severity.c_str()),
QString(msg._msg.c_str()));
/*
qDebug()<<"Error: ";
qDebug()<<QString(callStackToString(msg._callStack).c_str());
qDebug()<<QString(msg._severity.c_str());
qDebug()<<QString(msg._msg.c_str());
qDebug()<<endl;
*/
}
void CheckThread::reportStatus(unsigned int index, unsigned int max)
{
emit Progress(index, max);
}

114
gui/checkthread.h Normal file
View File

@ -0,0 +1,114 @@
/*
* 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 CHECKTHREAD_H
#define CHECKTHREAD_H
#include <QThread>
#include "../src/cppcheck.h"
#include "../src/errorlogger.h"
/**
* @brief Thread to run cppcheck
*
*/
class CheckThread : public QThread, public ErrorLogger
{
Q_OBJECT
public:
CheckThread();
virtual ~CheckThread();
/**
* @brief Set settings for cppcheck
*
* @param settings settings for cppcheck
*/
void SetSettings(Settings settings);
/**
* @brief Clear all files from cppcheck
*
*/
void ClearFiles();
/**
* @brief Add a single file to cppcheck
*
* @param file file to add
*/
void AddFile(const QString &file);
/**
* @brief method that is run in a thread
*
*/
void run();
/**
* ErrorLogger methods
*/
void reportOut(const std::string &outmsg);
void reportErr(const ErrorLogger::ErrorMessage &msg);
void reportStatus(unsigned int index, unsigned int max);
signals:
/**
* @brief Currently processed file
*
* @param filename filename
*/
void CurrentFile(const QString &filename);
/**
* @brief Cppcheck progress
*
* @param value progress
* @param max maximum progress
*/
void Progress(int value, int max);
/**
* @brief Error in file
*
* @param filename filename
* @param severity error's severity
* @param message error message
*/
void Error(const QString &filename,
const QString &severity,
const QString &message);
/**
* @brief cpp checking is done
*
*/
void Done();
protected:
/**
* @brief CppCheck itself
*
*/
CppCheck mCppCheck;
private:
};
#endif // CHECKTHREAD_H

63
gui/gui.pro Normal file
View File

@ -0,0 +1,63 @@
######################################################################
# Automatically generated by qmake (2.01a) Sun Feb 22 10:14:18 2009
######################################################################
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
MOC_DIR = temp
OBJECTS_DIR = temp
# Input
HEADERS += mainwindow.h \
checkdialog.h \
checkthread.h \
resultsview.h \
resultstree.h \
settingsdialog.h \
../src/checkbufferoverrun.h \
../src/checkclass.h \
../src/checkdangerousfunctions.h \
../src/checkfunctionusage.h \
../src/checkheaders.h \
../src/checkmemoryleak.h \
../src/checkother.h \
../src/checksecurity.h \
../src/checkstl.h \
../src/cppcheck.h \
../src/cppcheckexecutor.h \
../src/errorlogger.h \
../src/filelister.h \
../src/preprocessor.h \
../src/resource.h \
../src/settings.h \
../src/threadexecutor.h \
../src/token.h \
../src/tokenize.h
SOURCES += main.cpp \
mainwindow.cpp\
checkdialog.cpp \
checkthread.cpp \
resultsview.cpp \
resultstree.cpp \
settingsdialog.cpp \
../src/checkbufferoverrun.cpp \
../src/checkclass.cpp \
../src/checkdangerousfunctions.cpp \
../src/checkfunctionusage.cpp \
../src/checkheaders.cpp \
../src/checkmemoryleak.cpp \
../src/checkother.cpp \
../src/checksecurity.cpp \
../src/checkstl.cpp \
../src/cppcheck.cpp \
../src/cppcheckexecutor.cpp \
../src/errorlogger.cpp \
../src/filelister.cpp \
../src/preprocessor.cpp \
../src/settings.cpp \
../src/threadexecutor.cpp \
../src/token.cpp \
../src/tokenize.cpp

30
gui/main.cpp Normal file
View File

@ -0,0 +1,30 @@
/*
* 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/
*/
#include <QApplication>
#include "mainwindow.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
MainWindow window;
window.show();
return app.exec();
}

107
gui/mainwindow.cpp Normal file
View File

@ -0,0 +1,107 @@
/*
* 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/
*/
#include "mainwindow.h"
#include <QDebug>
#include <QMenu>
#include <QMenuBar>
MainWindow::MainWindow() :
mSettings("CppCheck", "CppCheck-GUI"),
mExit("E&xit", this),
mCheck("&Check", this),
mResults(mSettings)
{
QMenu *menu = menuBar()->addMenu(tr("&File"));
menu->addAction(&mCheck);
menu->addSeparator();
menu->addAction(&mExit);
setCentralWidget(&mResults);
connect(&mExit, SIGNAL(triggered()), this, SLOT(close()));
connect(&mCheck, SIGNAL(triggered()), this, SLOT(Check()));
connect(&mThread, SIGNAL(Done()), this, SLOT(CheckDone()));
connect(&mThread, SIGNAL(CurrentFile(const QString &)),
&mResults, SLOT(CurrentFile(const QString &)));
connect(&mThread, SIGNAL(Progress(int, int)),
&mResults, SLOT(Progress(int, int)));
connect(&mThread, SIGNAL(Error(const QString &, const QString &, const QString &)),
&mResults, SLOT(Error(const QString &, const QString &, const QString &)));
LoadSettings();
}
MainWindow::~MainWindow()
{
//dtor
}
void MainWindow::LoadSettings()
{
if (mSettings.value("Window maximized", false).toBool())
{
showMaximized();
}
else
{
resize(mSettings.value("Window width", 800).toInt(), mSettings.value("Window height", 600).toInt());
}
}
void MainWindow::SaveSettings()
{
mSettings.setValue("Window width", size().width());
mSettings.setValue("Window height", size().height());
mSettings.setValue("Window maximized", isMaximized());
}
void MainWindow::Check()
{
CheckDialog dialog(mSettings);
if (dialog.exec() == QDialog::Accepted)
{
mResults.Clear();
mThread.ClearFiles();
QString str;
qDebug("Selected files:");
foreach(str, dialog.GetSelectedFiles())
{
qDebug() << str;
mThread.AddFile(str);
}
mSettings.setValue("Check path", dialog.GetDefaultPath());
dialog.SaveCheckboxValues();
mThread.SetSettings(dialog.GetSettings());
mCheck.setDisabled(true);
mThread.start();
}
}
void MainWindow::CheckDone()
{
mCheck.setDisabled(false);
}

106
gui/mainwindow.h Normal file
View File

@ -0,0 +1,106 @@
/*
* 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 MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include "resultsview.h"
#include <QSettings>
#include <QAction>
#include "../src/settings.h"
#include "checkdialog.h"
#include "checkthread.h"
/**
* @brief Main window for cppcheck-gui
*
*/
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow();
virtual ~MainWindow();
public slots:
/**
* @brief Slot for check menu item
*
*/
void Check();
protected slots:
/**
* @brief Slot for checkthread's done signal
*
*/
void CheckDone();
protected:
/**
* @brief Load program settings
*
*/
void LoadSettings();
/**
* @brief Save program settings
*
*/
void SaveSettings();
/**
* @brief Program settings
*
*/
QSettings mSettings;
/**
* @brief Menu action to exit program
*
*/
QAction mExit;
/**
* @brief Menu action to open checkdialog
*
*/
QAction mCheck;
/**
* @brief Results for checking
*
*/
ResultsView mResults;
/**
* @brief Thread to check files
*
*/
CheckThread mThread;
private:
};
#endif // MAINWINDOW_H

96
gui/resultstree.cpp Normal file
View File

@ -0,0 +1,96 @@
/*
* 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/
*/
#include "resultstree.h"
ResultsTree::ResultsTree(QSettings &settings) :
mSettings(settings)
{
setModel(&mModel);
QStringList labels;
labels << "Filename && severity" << "Message";
mModel.setHorizontalHeaderLabels(labels);
LoadSettings();
}
ResultsTree::~ResultsTree()
{
SaveSettings();
}
QStandardItem *ResultsTree::CreateItem(const QString &name)
{
QStandardItem *item = new QStandardItem(name);
item->setEditable(false);
return item;
}
void ResultsTree::AddErrorItem(const QString &file,
const QString &severity,
const QString &error)
{
QStandardItem *fileitem = FindFileItem(file);
if (!fileitem)
{
fileitem = CreateItem(file);
}
QList<QStandardItem*> list;
list << CreateItem(severity);
list << CreateItem(error);
fileitem->appendRow(list);
mModel.appendRow(fileitem);
}
QStandardItem *ResultsTree::FindFileItem(const QString &name)
{
QList<QStandardItem *> list = mModel.findItems(name);
if (list.size() > 0)
return list[0];
return 0;
}
void ResultsTree::Clear()
{
mModel.removeRows(0, mModel.rowCount());
}
void ResultsTree::LoadSettings()
{
for (int i = 0;i < mModel.columnCount();i++)
{
//mFileTree.columnWidth(i);
QString temp = QString("Result column %1 width").arg(i);
setColumnWidth(i, mSettings.value(temp, 800 / mModel.columnCount()).toInt());
}
}
void ResultsTree::SaveSettings()
{
for (int i = 0;i < mModel.columnCount();i++)
{
QString temp = QString("Result column %1 width").arg(i);
mSettings.setValue(temp, columnWidth(i));
}
}

99
gui/resultstree.h Normal file
View File

@ -0,0 +1,99 @@
/*
* 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 RESULTSTREE_H
#define RESULTSTREE_H
#include <QTreeView>
#include <QStandardItemModel>
#include <QStandardItem>
#include <QSettings>
/**
* @brief Cppcheck's results are shown in this tree
*
*/
class ResultsTree : public QTreeView
{
public:
ResultsTree(QSettings &settings);
virtual ~ResultsTree();
/**
* @brief Add a new item to the tree
*
* @param file filename
* @param severity error severity
* @param error error message
*/
void AddErrorItem(const QString &file,
const QString &severity,
const QString &error);
/**
* @brief Clear all errors from the tree
*
*/
void Clear();
protected:
/**
* @brief Load all settings
* Colum widths
*/
void LoadSettings();
/**
* @brief Save all settings
* Colum widths
*/
void SaveSettings();
/**
* @brief Create a new QStandardItem
*
* @param name name for the item
* @return new QStandardItem
*/
QStandardItem *CreateItem(const QString &name);
/**
* @brief Finds a file item
*
* @param name name of the file item to find
* @return pointer to file item or null if none found
*/
QStandardItem *FindFileItem(const QString &name);
/**
* @brief Item model for tree
*
*/
QStandardItemModel mModel;
/**
* @brief Program settings
*
*/
QSettings &mSettings;
private:
};
#endif // RESULTSTREE_H

68
gui/resultsview.cpp Normal file
View File

@ -0,0 +1,68 @@
/*
* 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/
*/
#include "resultsview.h"
#include <QDebug>
#include <QVBoxLayout>
ResultsView::ResultsView(QSettings &settings)
{
QVBoxLayout *layout = new QVBoxLayout();
setLayout(layout);
mProgress = new QProgressBar();
layout->addWidget(mProgress);
mProgress->setMinimum(0);
mTree = new ResultsTree(settings);
layout->addWidget(mTree);
}
ResultsView::~ResultsView()
{
//dtor
}
void ResultsView::Clear()
{
mTree->Clear();
}
void ResultsView::CurrentFile(const QString &filename)
{
mProgress->setFormat(filename);
}
void ResultsView::Progress(int value, int max)
{
mProgress->setMaximum(max);
mProgress->setValue(value);
}
void ResultsView::Error(const QString &filename,
const QString &severity,
const QString &message)
{
qDebug() << "Error" << filename << severity << message;
mTree->AddErrorItem(filename, severity, message);
}

71
gui/resultsview.h Normal file
View File

@ -0,0 +1,71 @@
/*
* 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 RESULTSVIEW_H
#define RESULTSVIEW_H
#include <QWidget>
#include <QProgressBar>
#include "../src/errorlogger.h"
#include "resultstree.h"
/**
* @brief Widget to show cppcheck progressbar and result
*
*/
class ResultsView : public QWidget
{
Q_OBJECT
public:
ResultsView(QSettings &settings);
virtual ~ResultsView();
/**
* @brief Clear results
*
*/
void Clear();
public slots:
/**
* Slots for CheckThread's signals
*/
void CurrentFile(const QString &filename);
void Progress(int value, int max);
void Error(const QString &filename,
const QString &severity,
const QString &message);
protected:
/**
* @brief Tree to show cppcheck's results
*
*/
ResultsTree *mTree;
/**
* @brief Progressbar to show cppcheck's progress
*
*/
QProgressBar *mProgress;
private:
};
#endif // RESULTSVIEW_H

31
gui/settingsdialog.cpp Normal file
View File

@ -0,0 +1,31 @@
/*
* 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/
*/
#include "settingsdialog.h"
SettingsDialog::SettingsDialog()
{
//ctor
}
SettingsDialog::~SettingsDialog()
{
//dtor
}

39
gui/settingsdialog.h Normal file
View File

@ -0,0 +1,39 @@
/*
* 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 SETTINGSDIALOG_H
#define SETTINGSDIALOG_H
#include <QDialog>
/**
* @brief Settings dialog
*
*/
class SettingsDialog : public QDialog
{
public:
SettingsDialog();
virtual ~SettingsDialog();
protected:
private:
};
#endif // SETTINGSDIALOG_H

View File

@ -2,6 +2,8 @@
astyle --style=ansi --min-conditional-indent=0 --pad=oper --unpad=paren src/*.cpp
astyle --style=ansi --min-conditional-indent=0 --pad=oper --unpad=paren src/*.h
astyle --style=ansi --min-conditional-indent=0 --pad=oper --unpad=paren gui/*.cpp
astyle --style=ansi --min-conditional-indent=0 --pad=oper --unpad=paren gui/*.h
astyle --style=ansi --min-conditional-indent=0 --pad=oper --unpad=paren test/*.cpp
astyle --style=ansi --min-conditional-indent=0 --pad=oper --unpad=paren test/*.h

View File

@ -1,6 +1,8 @@
astyle --style=ansi --min-conditional-indent=0 --pad=oper --unpad=paren src/*.cpp
astyle --style=ansi --min-conditional-indent=0 --pad=oper --unpad=paren src/*.h
astyle --style=ansi --min-conditional-indent=0 --pad=oper --unpad=paren gui/*.cpp
astyle --style=ansi --min-conditional-indent=0 --pad=oper --unpad=paren gui/*.h
astyle --style=ansi --min-conditional-indent=0 --pad=oper --unpad=paren test/*.cpp
astyle --style=ansi --min-conditional-indent=0 --pad=oper --unpad=paren test/*.h
astyle --style=ansi --min-conditional-indent=0 --pad=oper --unpad=paren tools/*.cpp