Began implementing ThreadExecutor with Qt threads. Still a work in progress.

Added tr to all strings.
This commit is contained in:
Vesa Pikki 2009-03-01 20:44:42 +00:00
parent c936e00191
commit cc6cec091a
15 changed files with 506 additions and 181 deletions

View File

@ -31,8 +31,8 @@
CheckDialog::CheckDialog(QSettings &programSettings) :
mSettings(programSettings)
{
QPushButton *cancel = new QPushButton("Cancel");
QPushButton *ok = new QPushButton("Ok");
QPushButton *cancel = new QPushButton(tr("Cancel"));
QPushButton *ok = new QPushButton(tr("Ok"));
//Main layout
QVBoxLayout *layout = new QVBoxLayout();
@ -42,48 +42,46 @@ CheckDialog::CheckDialog(QSettings &programSettings) :
//File selection tree
layout->addWidget(new QLabel("Select files to check"));
layout->addWidget(new QLabel(tr("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->scrollTo(mModel.index(programSettings.value(tr("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"));
mJobs = new QLineEdit(programSettings.value(tr("Check threads"), 1).toString());
layout->addWidget(new QLabel(tr("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);
mShowAll = AddCheckbox(layout, tr("Show all"), tr("Check show all"), false);
//Check Coding Style
mCheckCodingStyle = AddCheckbox(layout, "Check Coding Style", "Check coding style", false);
mCheckCodingStyle = AddCheckbox(layout, tr("Check Coding Style"), tr("Check coding style"), false);
//Errors only
mErrorsOnly = AddCheckbox(layout, "Errors only", "Check errors only", false);
mErrorsOnly = AddCheckbox(layout, tr("Errors only"), tr("Check errors only"), false);
//Verbose
mVerbose = AddCheckbox(layout, "Verbose", "Check verbose", false);
mVerbose = AddCheckbox(layout, tr("Verbose"), tr("Check verbose"), false);
//Force
mForce = AddCheckbox(layout, "Force", "Check force", false);
mForce = AddCheckbox(layout, tr("Force"), tr("Check force"), false);
//XML
mXml = AddCheckbox(layout, "XML", "Check xml", false);
mXml = AddCheckbox(layout, tr("XML"), tr("Check xml"), false);
//Unused functions
mUnusedFunctions = AddCheckbox(layout, "Unused functions", "Check unused functions", false);
mUnusedFunctions = AddCheckbox(layout, tr("Unused functions"), tr("Check unused functions"), false);
//Security
mSecurity = AddCheckbox(layout, "Security", "Check security", false);
mSecurity = AddCheckbox(layout, tr("Security"), tr("Check security"), false);
//Vcl
mVcl = AddCheckbox(layout, "Vcl", "Check vcl", false);
mVcl = AddCheckbox(layout, tr("Vcl"), tr("Check vcl"), false);
@ -100,7 +98,7 @@ CheckDialog::CheckDialog(QSettings &programSettings) :
connect(cancel, SIGNAL(clicked()),
this, SLOT(reject()));
setWindowTitle("Select files to check");
setWindowTitle(tr("Select files to check"));
setLayout(layout);
LoadSettings();
@ -124,7 +122,10 @@ QStringList CheckDialog::GetSelectedFiles()
foreach(index, indexes)
{
list << mModel.filePath(index);
if (!mModel.filePath(index).isEmpty())
{
list << mModel.filePath(index);
}
}
return list;
@ -166,7 +167,7 @@ QCheckBox* CheckDialog::AddCheckbox(QVBoxLayout *layout,
Settings CheckDialog::GetSettings()
{
Settings result;
result._debug = CheckStateToBool(mDebug->checkState());
result._debug = false;
result._showAll = CheckStateToBool(mShowAll->checkState());
result._checkCodingStyle = CheckStateToBool(mCheckCodingStyle->checkState());
result._errorsOnly = CheckStateToBool(mErrorsOnly->checkState());
@ -212,43 +213,41 @@ void CheckDialog::LoadSettings()
}
else
{*/
resize(mSettings.value("Check dialog width", 800).toInt(), mSettings.value("Check dialog height", 600).toInt());
resize(mSettings.value(tr("Check dialog width"), 800).toInt(), mSettings.value(tr("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);
QString temp = QString(tr("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(tr("Check dialog width"), size().width());
mSettings.setValue(tr("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);
QString temp = QString(tr("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");
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(mXml, tr("Check xml"));
SaveCheckboxValue(mUnusedFunctions, tr("Check unused functions"));
SaveCheckboxValue(mSecurity, tr("Check security"));
}
void CheckDialog::SaveCheckboxValue(QCheckBox *box, const QString &name)

View File

@ -141,12 +141,6 @@ protected:
*/
QLineEdit *mJobs;
/**
* @brief Cppcheck setting
*
*/
QCheckBox *mDebug;
/**
* @brief Cppcheck setting
*

View File

@ -21,7 +21,9 @@
#include "checkthread.h"
#include <QDebug>
CheckThread::CheckThread() : mCppCheck(*this)
CheckThread::CheckThread(ThreadResult &result) :
mResult(result),
mCppCheck(result)
{
//ctor
}
@ -31,49 +33,27 @@ CheckThread::~CheckThread()
//dtor
}
void CheckThread::SetSettings(Settings settings)
void CheckThread::Check(Settings settings)
{
mCppCheck.settings(settings);
}
void CheckThread::AddFile(const QString &file)
{
mCppCheck.addFile(file.toStdString());
}
void CheckThread::ClearFiles()
{
mCppCheck.clearFiles();
start();
}
void CheckThread::run()
{
mCppCheck.check();
QString file;
file = mResult.GetNextFile();
while (!file.isEmpty())
{
qDebug() << tr("Checking file") << file;
mCppCheck.addFile(file.toStdString());
mCppCheck.check();
file = mResult.GetNextFile();
}
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);
}

View File

@ -23,17 +23,17 @@
#include <QThread>
#include "../src/cppcheck.h"
#include "../src/errorlogger.h"
#include "threadresult.h"
/**
* @brief Thread to run cppcheck
*
*/
class CheckThread : public QThread, public ErrorLogger
class CheckThread : public QThread
{
Q_OBJECT
public:
CheckThread();
CheckThread(ThreadResult &result);
virtual ~CheckThread();
/**
@ -41,20 +41,7 @@ public:
*
* @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);
void Check(Settings settings);
/**
* @brief method that is run in a thread
@ -62,39 +49,8 @@ public:
*/
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
@ -102,7 +58,7 @@ signals:
*/
void Done();
protected:
ThreadResult &mResult;
/**
* @brief CppCheck itself
*

View File

@ -8,6 +8,7 @@ DEPENDPATH += .
INCLUDEPATH += .
MOC_DIR = temp
OBJECTS_DIR = temp
CONFIG += warn_on debug
# Input
HEADERS += mainwindow.h \
@ -16,6 +17,8 @@ HEADERS += mainwindow.h \
resultsview.h \
resultstree.h \
settingsdialog.h \
threadresult.h \
threadhandler.h \
../src/checkbufferoverrun.h \
../src/checkclass.h \
../src/checkdangerousfunctions.h \
@ -42,6 +45,8 @@ SOURCES += main.cpp \
checkthread.cpp \
resultsview.cpp \
resultstree.cpp \
threadresult.cpp \
threadhandler.cpp \
settingsdialog.cpp \
../src/checkbufferoverrun.cpp \
../src/checkclass.cpp \

View File

@ -24,9 +24,9 @@
#include <QMenuBar>
MainWindow::MainWindow() :
mSettings("CppCheck", "CppCheck-GUI"),
mExit("E&xit", this),
mCheck("&Check", this),
mSettings(tr("CppCheck"), tr("CppCheck-GUI")),
mExit(tr("E&xit"), this),
mCheck(tr("&Check"), this),
mResults(mSettings)
{
QMenu *menu = menuBar()->addMenu(tr("&File"));
@ -40,14 +40,8 @@ MainWindow::MainWindow() :
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();
mThread.Initialize(&mResults);
}
MainWindow::~MainWindow()
@ -57,21 +51,22 @@ MainWindow::~MainWindow()
void MainWindow::LoadSettings()
{
if (mSettings.value("Window maximized", false).toBool())
if (mSettings.value(tr("Window maximized"), false).toBool())
{
showMaximized();
}
else
{
resize(mSettings.value("Window width", 800).toInt(), mSettings.value("Window height", 600).toInt());
resize(mSettings.value(tr("Window width"), 800).toInt(),
mSettings.value(tr("Window height"), 600).toInt());
}
}
void MainWindow::SaveSettings()
{
mSettings.setValue("Window width", size().width());
mSettings.setValue("Window height", size().height());
mSettings.setValue("Window maximized", isMaximized());
mSettings.setValue(tr("Window width"), size().width());
mSettings.setValue(tr("Window height"), size().height());
mSettings.setValue(tr("Window maximized"), isMaximized());
}
@ -82,22 +77,11 @@ void MainWindow::Check()
{
mResults.Clear();
mThread.ClearFiles();
QString str;
qDebug("Selected files:");
foreach(str, dialog.GetSelectedFiles())
{
qDebug() << str;
mThread.AddFile(str);
}
mSettings.setValue("Check path", dialog.GetDefaultPath());
mThread.SetFiles(dialog.GetSelectedFiles());
mSettings.setValue(tr("Check path"), dialog.GetDefaultPath());
dialog.SaveCheckboxValues();
mThread.SetSettings(dialog.GetSettings());
mCheck.setDisabled(true);
mThread.start();
mThread.Check(dialog.GetSettings());
}
}

View File

@ -28,7 +28,7 @@
#include "../src/settings.h"
#include "checkdialog.h"
#include "checkthread.h"
#include "threadhandler.h"
/**
* @brief Main window for cppcheck-gui
@ -88,17 +88,17 @@ protected:
*/
QAction mCheck;
/**
* @brief Results for checking
*
/**
* @brief Results for checking
*
*/
ResultsView mResults;
/**
* @brief Thread to check files
*
/**
* @brief Thread to check files
*
*/
CheckThread mThread;
ThreadHandler mThread;
private:
};

View File

@ -25,7 +25,7 @@ ResultsTree::ResultsTree(QSettings &settings) :
{
setModel(&mModel);
QStringList labels;
labels << "Filename && severity" << "Message";
labels << tr("Filename && severity") << tr("Message");
mModel.setHorizontalHeaderLabels(labels);
LoadSettings();
@ -48,8 +48,13 @@ QStandardItem *ResultsTree::CreateItem(const QString &name)
void ResultsTree::AddErrorItem(const QString &file,
const QString &severity,
const QString &error)
const QString &message,
const QStringList &files,
const QList<int> &lines)
{
Q_UNUSED(files);
Q_UNUSED(lines);
QStandardItem *fileitem = FindFileItem(file);
if (!fileitem)
{
@ -58,7 +63,7 @@ void ResultsTree::AddErrorItem(const QString &file,
QList<QStandardItem*> list;
list << CreateItem(severity);
list << CreateItem(error);
list << CreateItem(message);
fileitem->appendRow(list);
mModel.appendRow(fileitem);
}
@ -81,7 +86,7 @@ void ResultsTree::LoadSettings()
for (int i = 0;i < mModel.columnCount();i++)
{
//mFileTree.columnWidth(i);
QString temp = QString("Result column %1 width").arg(i);
QString temp = QString(tr("Result column %1 width")).arg(i);
setColumnWidth(i, mSettings.value(temp, 800 / mModel.columnCount()).toInt());
}
}
@ -90,7 +95,7 @@ void ResultsTree::SaveSettings()
{
for (int i = 0;i < mModel.columnCount();i++)
{
QString temp = QString("Result column %1 width").arg(i);
QString temp = QString(tr("Result column %1 width")).arg(i);
mSettings.setValue(temp, columnWidth(i));
}
}

View File

@ -46,7 +46,9 @@ public:
*/
void AddErrorItem(const QString &file,
const QString &severity,
const QString &error);
const QString &message,
const QStringList &files,
const QList<int> &lines);
/**
* @brief Clear all errors from the tree

View File

@ -48,21 +48,19 @@ void ResultsView::Clear()
}
void ResultsView::CurrentFile(const QString &filename)
{
mProgress->setFormat(filename);
}
void ResultsView::Progress(int value, int max)
{
qDebug() << tr("Progress:") << value << tr("/") << max;
mProgress->setMaximum(max);
mProgress->setValue(value);
}
void ResultsView::Error(const QString &filename,
void ResultsView::Error(const QString &file,
const QString &severity,
const QString &message)
const QString &message,
const QStringList &files,
const QList<int> &lines)
{
qDebug() << "Error" << filename << severity << message;
mTree->AddErrorItem(filename, severity, message);
mTree->AddErrorItem(file, severity, message, files, lines);
}

View File

@ -47,11 +47,12 @@ public slots:
/**
* Slots for CheckThread's signals
*/
void CurrentFile(const QString &filename);
void Progress(int value, int max);
void Error(const QString &filename,
void Error(const QString &file,
const QString &severity,
const QString &message);
const QString &message,
const QStringList &files,
const QList<int> &lines);
protected:
/**
* @brief Tree to show cppcheck's results

158
gui/threadhandler.cpp Normal file
View File

@ -0,0 +1,158 @@
/*
* 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 "threadhandler.h"
#include <QDebug>
ThreadHandler::ThreadHandler() : mThreadCount(1), mRunningThreadCount(0)
{
SetThreadCount(1);
}
ThreadHandler::~ThreadHandler()
{
Stop();
for (int i = 0;i < mThreads.size();i++)
{
delete mThreads[i];
}
mThreads.clear();
}
void ThreadHandler::ClearFiles()
{
mResults.ClearFiles();
}
void ThreadHandler::SetFiles(const QStringList &files)
{
mResults.SetFiles(files);
}
void ThreadHandler::Check(Settings settings)
{
if (mResults.GetFileCount() == 0 || mRunningThreadCount > 0)
{
qDebug() << tr("Can't start checking if there's no files to check or if check is in progress.");
return;
}
SetThreadCount(settings._jobs);
mRunningThreadCount = mThreadCount;
if (mResults.GetFileCount() < mRunningThreadCount)
{
mRunningThreadCount = mResults.GetFileCount();
}
qDebug() << tr("Starting") << mRunningThreadCount << tr("threads");
for (int i = 0;i < mRunningThreadCount;i++)
{
mThreads[i]->Check(settings);
}
}
void ThreadHandler::SetThreadCount(const int count)
{
if (mRunningThreadCount > 0 ||
count == mThreadCount ||
count <= 0)
{
return;
}
qDebug() << tr("Setting thead count to") << count;
mThreadCount = count;
//Remove unused old threads
if (mThreads.size() > count)
{
for (int i = count;i < mThreads.size();i++)
{
disconnect(mThreads.last(), SIGNAL(Done()),
this, SLOT(ThreadDone()));
delete mThreads.takeLast();
}
}
else
{
//Create new threads
for (int i = mThreads.size();i < count;i++)
{
mThreads << new CheckThread(mResults);
connect(mThreads.last(), SIGNAL(Done()),
this, SLOT(ThreadDone()));
}
}
}
void ThreadHandler::ThreadDone()
{
mRunningThreadCount--;
if (mRunningThreadCount == 0)
{
emit Done();
}
}
void ThreadHandler::Stop()
{
for (int i = 0;i < mThreads.size();i++)
{
mThreads[i]->terminate();
}
mResults.ClearFiles();
}
void ThreadHandler::Initialize(ResultsView *view)
{
connect(&mResults, SIGNAL(Progress(int, int)),
view, SLOT(Progress(int, int)));
connect(&mResults, SIGNAL(Error(const QString &,
const QString &,
const QString &,
const QStringList &,
const QList<int> &)),
view, SLOT(Error(const QString &,
const QString &,
const QString &,
const QStringList &,
const QList<int> &)));
}
void ThreadHandler::LoadSettings(QSettings &settings)
{
SetThreadCount(settings.value(tr("Check threads"), 1).toInt());
}
void ThreadHandler::SaveSettings(QSettings &settings)
{
settings.setValue(tr("Check threads"), mThreadCount);
}

75
gui/threadhandler.h Normal file
View File

@ -0,0 +1,75 @@
/*
* 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 THREADHANDLER_H
#define THREADHANDLER_H
#include <QObject>
#include <QStringList>
#include "../src/cppcheck.h"
#include "threadresult.h"
#include "checkthread.h"
#include "resultsview.h"
/**
* @brief This class handles creating threadresult and starting threads
*
*/
class ThreadHandler : public QObject
{
Q_OBJECT
public:
ThreadHandler();
virtual ~ThreadHandler();
void SetThreadCount(const int count);
void Initialize(ResultsView *view);
void LoadSettings(QSettings &settings);
void SaveSettings(QSettings &settings);
/**
* @brief Clear all files from cppcheck
*
*/
void ClearFiles();
/**
* @brief Set files to check
*
* @param files files to check
*/
void SetFiles(const QStringList &files);
void Check(Settings settings);
signals:
void Done();
protected slots:
void Stop();
void ThreadDone();
protected:
ThreadResult mResults;
int mThreadCount;
QList<CheckThread *> mThreads;
int mRunningThreadCount;
private:
};
#endif // THREADHANDLER_H

102
gui/threadresult.cpp Normal file
View File

@ -0,0 +1,102 @@
/*
* 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 "threadresult.h"
ThreadResult::ThreadResult() : mMaxProgress(0), mProgress(0)
{
//ctor
}
ThreadResult::~ThreadResult()
{
//dtor
}
void ThreadResult::reportOut(const std::string &outmsg)
{
//emit CurrentFile(QString(outmsg.c_str()));
Q_UNUSED(outmsg);
}
void ThreadResult::reportErr(const ErrorLogger::ErrorMessage &msg)
{
QMutexLocker locker(&mutex);
QList<int> lines;
QStringList files;
for (std::list<ErrorLogger::ErrorMessage::FileLocation>::const_iterator tok = msg._callStack.begin();
tok != msg._callStack.end();
++tok)
{
files << QString((*tok).file.c_str());
lines << (*tok).line;
}
emit Error(QString(callStackToString(msg._callStack).c_str()),
QString(msg._severity.c_str()),
QString(msg._msg.c_str()),
files,
lines);
mProgress++;
emit Progress(mProgress, mMaxProgress);
}
QString ThreadResult::GetNextFile()
{
QMutexLocker locker(&mutex);
if (mFiles.size() == 0)
{
return "";
}
return mFiles.takeFirst();
}
void ThreadResult::reportStatus(unsigned int index, unsigned int max)
{
Q_UNUSED(index);
Q_UNUSED(max);
}
void ThreadResult::SetFiles(const QStringList &files)
{
//TODO we should check which of the strings in files is actually a path
//and add the path's contents
mFiles = files;
mProgress = 0;
mMaxProgress = files.size();
}
void ThreadResult::ClearFiles()
{
mFiles.clear();
}
int ThreadResult::GetFileCount()
{
return mFiles.size();
}

66
gui/threadresult.h Normal file
View File

@ -0,0 +1,66 @@
/*
* 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 THREADRESULT_H
#define THREADRESULT_H
#include <QMutex>
#include <QObject>
#include <QStringList>
#include "../src/errorlogger.h"
/**
* @brief Threads use this class to obtain new files to process and to publish results
*
*/
class ThreadResult : public QObject, public ErrorLogger
{
Q_OBJECT
public:
ThreadResult();
virtual ~ThreadResult();
QString GetNextFile();
void SetFiles(const QStringList &files);
void ClearFiles();
int GetFileCount();
/**
* ErrorLogger methods
*/
void reportOut(const std::string &outmsg);
void reportErr(const ErrorLogger::ErrorMessage &msg);
void reportStatus(unsigned int index, unsigned int max);
signals:
void Progress(int value, int max);
void Error(const QString &file,
const QString &severity,
const QString &message,
const QStringList &files,
const QList<int> &lines);
protected:
mutable QMutex mutex;
QStringList mFiles;
int mMaxProgress;
int mProgress;
private:
};
#endif // THREADRESULT_H