Now adds directory contents to list of files to check.
Only adds proper (.cpp,.c,.cpp,...) files to the list of files to check. Modified checkthread to clear results after each file.
This commit is contained in:
parent
20390ce655
commit
e629db6818
|
@ -27,6 +27,9 @@
|
|||
#include <QFileDialog>
|
||||
#include <QDirIterator>
|
||||
#include <QDebug>
|
||||
#include <QFileInfo>
|
||||
#include <QDirIterator>
|
||||
#include "../src/filelister.h"
|
||||
|
||||
CheckDialog::CheckDialog(QSettings &programSettings) :
|
||||
mSettings(programSettings)
|
||||
|
@ -111,8 +114,54 @@ CheckDialog::~CheckDialog()
|
|||
}
|
||||
|
||||
|
||||
QStringList CheckDialog::RemoveUnacceptedFiles(const QStringList &list)
|
||||
{
|
||||
QStringList result;
|
||||
QString str;
|
||||
foreach(str, list)
|
||||
{
|
||||
if (FileLister::AcceptFile(str.toStdString()))
|
||||
{
|
||||
result << str;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
QStringList CheckDialog::GetFiles(QModelIndex index)
|
||||
{
|
||||
QFileInfo info(mModel.filePath(index));
|
||||
QStringList list;
|
||||
|
||||
if (info.isDir())
|
||||
{
|
||||
QDirIterator it(mModel.filePath(index), QDirIterator::Subdirectories);
|
||||
|
||||
while (it.hasNext())
|
||||
{
|
||||
list << it.next();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
list << mModel.filePath(index);
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
QStringList CheckDialog::RemoveDuplicates(const QStringList &list)
|
||||
{
|
||||
QHash<QString, int> hash;
|
||||
QString str;
|
||||
foreach(str, list)
|
||||
{
|
||||
hash[str] = 0;
|
||||
}
|
||||
|
||||
return QStringList(hash.uniqueKeys());
|
||||
}
|
||||
|
||||
QStringList CheckDialog::GetSelectedFiles()
|
||||
{
|
||||
|
@ -124,11 +173,13 @@ QStringList CheckDialog::GetSelectedFiles()
|
|||
{
|
||||
if (!mModel.filePath(index).isEmpty())
|
||||
{
|
||||
list << mModel.filePath(index);
|
||||
list << GetFiles(index);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
QString str;
|
||||
|
||||
return RemoveUnacceptedFiles(RemoveDuplicates(list));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -71,6 +71,9 @@ public:
|
|||
*/
|
||||
void SaveCheckboxValues();
|
||||
protected:
|
||||
QStringList RemoveUnacceptedFiles(const QStringList &list);
|
||||
QStringList RemoveDuplicates(const QStringList &list);
|
||||
QStringList GetFiles(QModelIndex index);
|
||||
|
||||
/**
|
||||
* @brief Load saved values
|
||||
|
|
|
@ -46,9 +46,12 @@ void CheckThread::run()
|
|||
|
||||
while (!file.isEmpty())
|
||||
{
|
||||
qDebug() << tr("Checking file") << file;
|
||||
qDebug() << "Checking file" << file;
|
||||
mCppCheck.addFile(file.toStdString());
|
||||
mCppCheck.check();
|
||||
mCppCheck.clearFiles();
|
||||
emit FileChecked(file);
|
||||
|
||||
file = mResult.GetNextFile();
|
||||
}
|
||||
|
||||
|
|
|
@ -57,6 +57,8 @@ signals:
|
|||
*
|
||||
*/
|
||||
void Done();
|
||||
|
||||
void FileChecked(const QString &file);
|
||||
protected:
|
||||
ThreadResult &mResult;
|
||||
/**
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
|
||||
#include "resultstree.h"
|
||||
#include <QDebug>
|
||||
|
||||
ResultsTree::ResultsTree(QSettings &settings) :
|
||||
mSettings(settings)
|
||||
|
@ -61,6 +62,8 @@ void ResultsTree::AddErrorItem(const QString &file,
|
|||
fileitem = CreateItem(file);
|
||||
}
|
||||
|
||||
qDebug() << "Adding error for file" << file << ". Message is" << message;
|
||||
|
||||
QList<QStandardItem*> list;
|
||||
list << CreateItem(severity);
|
||||
list << CreateItem(message);
|
||||
|
|
|
@ -51,7 +51,7 @@ void ResultsView::Clear()
|
|||
|
||||
void ResultsView::Progress(int value, int max)
|
||||
{
|
||||
qDebug() << tr("Progress:") << value << tr("/") << max;
|
||||
qDebug() << "Progress:" << value << "/" << max;
|
||||
mProgress->setMaximum(max);
|
||||
mProgress->setValue(value);
|
||||
}
|
||||
|
|
|
@ -21,21 +21,14 @@
|
|||
#include "threadhandler.h"
|
||||
#include <QDebug>
|
||||
|
||||
ThreadHandler::ThreadHandler() : mThreadCount(1), mRunningThreadCount(0)
|
||||
ThreadHandler::ThreadHandler() : mRunningThreadCount(0)
|
||||
{
|
||||
SetThreadCount(1);
|
||||
}
|
||||
|
||||
ThreadHandler::~ThreadHandler()
|
||||
{
|
||||
Stop();
|
||||
|
||||
for (int i = 0;i < mThreads.size();i++)
|
||||
{
|
||||
delete mThreads[i];
|
||||
}
|
||||
|
||||
mThreads.clear();
|
||||
RemoveThreads();
|
||||
}
|
||||
|
||||
void ThreadHandler::ClearFiles()
|
||||
|
@ -50,23 +43,23 @@ void ThreadHandler::SetFiles(const QStringList &files)
|
|||
|
||||
void ThreadHandler::Check(Settings settings)
|
||||
{
|
||||
if (mResults.GetFileCount() == 0 || mRunningThreadCount > 0)
|
||||
if (mResults.GetFileCount() == 0 || mRunningThreadCount > 0 || settings._jobs <= 0)
|
||||
{
|
||||
qDebug() << tr("Can't start checking if there's no files to check or if check is in progress.");
|
||||
qDebug() << "Can't start checking if there's no files to check or if check is in progress.";
|
||||
return;
|
||||
}
|
||||
|
||||
SetThreadCount(settings._jobs);
|
||||
|
||||
|
||||
mRunningThreadCount = mThreadCount;
|
||||
mRunningThreadCount = mThreads.size();
|
||||
|
||||
if (mResults.GetFileCount() < mRunningThreadCount)
|
||||
{
|
||||
mRunningThreadCount = mResults.GetFileCount();
|
||||
}
|
||||
|
||||
qDebug() << tr("Starting") << mRunningThreadCount << tr("threads");
|
||||
qDebug() << "Starting" << mRunningThreadCount << "threads";
|
||||
qDebug() << mThreads.size();
|
||||
for (int i = 0;i < mRunningThreadCount;i++)
|
||||
{
|
||||
mThreads[i]->Check(settings);
|
||||
|
@ -76,41 +69,51 @@ void ThreadHandler::Check(Settings settings)
|
|||
void ThreadHandler::SetThreadCount(const int count)
|
||||
{
|
||||
if (mRunningThreadCount > 0 ||
|
||||
count == mThreadCount ||
|
||||
count == mThreads.size() ||
|
||||
count <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug() << tr("Setting thead count to") << count;
|
||||
qDebug() << "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
|
||||
{
|
||||
RemoveThreads();
|
||||
//Create new threads
|
||||
for (int i = mThreads.size();i < count;i++)
|
||||
{
|
||||
mThreads << new CheckThread(mResults);
|
||||
connect(mThreads.last(), SIGNAL(Done()),
|
||||
this, SLOT(ThreadDone()));
|
||||
connect(mThreads.last(), SIGNAL(FileChecked(const QString &)),
|
||||
&mResults, SLOT(FileChecked(const QString &)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
void ThreadHandler::RemoveThreads()
|
||||
{
|
||||
for (int i = 0;i < mThreads.size();i++)
|
||||
{
|
||||
mThreads[i]->terminate();
|
||||
disconnect(mThreads.last(), SIGNAL(Done()),
|
||||
this, SLOT(ThreadDone()));
|
||||
disconnect(mThreads.last(), SIGNAL(FileChecked(const QString &)),
|
||||
&mResults, SLOT(FileChecked(const QString &)));
|
||||
|
||||
delete mThreads[i];
|
||||
}
|
||||
|
||||
mThreads.clear();
|
||||
}
|
||||
|
||||
void ThreadHandler::ThreadDone()
|
||||
{
|
||||
mRunningThreadCount--;
|
||||
qDebug() << "Thread done" << mRunningThreadCount << "threads left";
|
||||
|
||||
if (mRunningThreadCount == 0)
|
||||
{
|
||||
emit Done();
|
||||
|
@ -153,6 +156,6 @@ void ThreadHandler::LoadSettings(QSettings &settings)
|
|||
|
||||
void ThreadHandler::SaveSettings(QSettings &settings)
|
||||
{
|
||||
settings.setValue(tr("Check threads"), mThreadCount);
|
||||
settings.setValue(tr("Check threads"), mThreads.size());
|
||||
}
|
||||
|
||||
|
|
|
@ -65,8 +65,8 @@ protected slots:
|
|||
void Stop();
|
||||
void ThreadDone();
|
||||
protected:
|
||||
void RemoveThreads();
|
||||
ThreadResult mResults;
|
||||
int mThreadCount;
|
||||
QList<CheckThread *> mThreads;
|
||||
int mRunningThreadCount;
|
||||
private:
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
|
||||
#include "threadresult.h"
|
||||
#include <QDebug>
|
||||
|
||||
ThreadResult::ThreadResult() : mMaxProgress(0), mProgress(0)
|
||||
{
|
||||
|
@ -32,10 +33,16 @@ ThreadResult::~ThreadResult()
|
|||
|
||||
void ThreadResult::reportOut(const std::string &outmsg)
|
||||
{
|
||||
//emit CurrentFile(QString(outmsg.c_str()));
|
||||
Q_UNUSED(outmsg);
|
||||
}
|
||||
|
||||
void ThreadResult::FileChecked(const QString &file)
|
||||
{
|
||||
Q_UNUSED(file); //For later use maybe?
|
||||
mProgress++;
|
||||
emit Progress(mProgress, mMaxProgress);
|
||||
}
|
||||
|
||||
void ThreadResult::reportErr(const ErrorLogger::ErrorMessage &msg)
|
||||
{
|
||||
QMutexLocker locker(&mutex);
|
||||
|
@ -50,6 +57,7 @@ void ThreadResult::reportErr(const ErrorLogger::ErrorMessage &msg)
|
|||
files << QString((*tok).file.c_str());
|
||||
lines << (*tok).line;
|
||||
}
|
||||
qDebug() << "Got error for file" << QString(callStackToString(msg._callStack).c_str()) << QString(msg._msg.c_str());
|
||||
|
||||
emit Error(QString(callStackToString(msg._callStack).c_str()),
|
||||
QString(msg._severity.c_str()),
|
||||
|
@ -57,9 +65,7 @@ void ThreadResult::reportErr(const ErrorLogger::ErrorMessage &msg)
|
|||
files,
|
||||
lines);
|
||||
|
||||
mProgress++;
|
||||
|
||||
emit Progress(mProgress, mMaxProgress);
|
||||
|
||||
}
|
||||
|
||||
|
@ -83,8 +89,7 @@ void ThreadResult::reportStatus(unsigned int index, unsigned int 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
|
||||
QMutexLocker locker(&mutex);
|
||||
mFiles = files;
|
||||
mProgress = 0;
|
||||
mMaxProgress = files.size();
|
||||
|
@ -92,11 +97,13 @@ void ThreadResult::SetFiles(const QStringList &files)
|
|||
|
||||
void ThreadResult::ClearFiles()
|
||||
{
|
||||
QMutexLocker locker(&mutex);
|
||||
mFiles.clear();
|
||||
}
|
||||
|
||||
int ThreadResult::GetFileCount()
|
||||
{
|
||||
QMutexLocker locker(&mutex);
|
||||
return mFiles.size();
|
||||
}
|
||||
|
||||
|
|
|
@ -47,6 +47,8 @@ public:
|
|||
void reportOut(const std::string &outmsg);
|
||||
void reportErr(const ErrorLogger::ErrorMessage &msg);
|
||||
void reportStatus(unsigned int index, unsigned int max);
|
||||
public slots:
|
||||
void FileChecked(const QString &file);
|
||||
signals:
|
||||
void Progress(int value, int max);
|
||||
void Error(const QString &file,
|
||||
|
|
|
@ -42,8 +42,9 @@ public:
|
|||
static void RecursiveAddFiles(std::vector<std::string> &filenames, const std::string &path, bool recursive);
|
||||
static std::string simplifyPath(const char *originalPath);
|
||||
static bool SameFileName(const char fname1[], const char fname2[]);
|
||||
private:
|
||||
static bool AcceptFile(const std::string &filename);
|
||||
private:
|
||||
|
||||
};
|
||||
|
||||
#endif // #ifndef FILELISTER_H
|
||||
|
|
Loading…
Reference in New Issue