cppcheck/gui/threadresult.cpp

143 lines
3.7 KiB
C++
Raw Normal View History

/*
* Cppcheck - A tool for static C/C++ code analysis
2020-05-10 11:16:32 +02:00
* Copyright (C) 2007-2020 Cppcheck team.
*
* 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"
#include <QFile>
#include "common.h"
#include "erroritem.h"
2010-10-31 12:16:55 +01:00
#include "errorlogger.h"
2020-02-10 20:24:36 +01:00
ThreadResult::ThreadResult() : QObject(), ErrorLogger(), mMaxProgress(0), mProgress(0), mFilesChecked(0), mTotalFiles(0)
{
//ctor
}
ThreadResult::~ThreadResult()
{
//dtor
}
void ThreadResult::reportOut(const std::string &outmsg)
{
2017-07-28 12:39:28 +02:00
emit log(QString::fromStdString(outmsg));
}
2017-07-28 12:39:28 +02:00
void ThreadResult::fileChecked(const QString &file)
{
QMutexLocker locker(&mutex);
mProgress += QFile(file).size();
mFilesChecked ++;
2011-10-13 20:53:06 +02:00
if (mMaxProgress > 0) {
const int value = static_cast<int>(PROGRESS_MAX * mProgress / mMaxProgress);
const QString description = tr("%1 of %2 files checked").arg(mFilesChecked).arg(mTotalFiles);
2017-07-28 12:39:28 +02:00
emit progress(value, description);
}
}
2020-05-23 07:16:49 +02:00
void ThreadResult::reportErr(const ErrorMessage &msg)
{
QMutexLocker locker(&mutex);
2017-05-21 08:25:55 +02:00
const ErrorItem item(msg);
if (msg.severity != Severity::debug)
2017-07-28 12:39:28 +02:00
emit error(item);
else
2017-07-28 12:39:28 +02:00
emit debugError(item);
}
2017-07-28 12:39:28 +02:00
QString ThreadResult::getNextFile()
{
QMutexLocker locker(&mutex);
if (mFiles.isEmpty()) {
2017-08-03 12:39:31 +02:00
return QString();
}
return mFiles.takeFirst();
}
2017-07-28 12:39:28 +02:00
ImportProject::FileSettings ThreadResult::getNextFileSettings()
2016-08-18 21:58:50 +02:00
{
QMutexLocker locker(&mutex);
if (mFileSettings.empty()) {
return ImportProject::FileSettings();
}
const ImportProject::FileSettings fs = mFileSettings.front();
mFileSettings.pop_front();
return fs;
}
2017-07-28 12:39:28 +02:00
void ThreadResult::setFiles(const QStringList &files)
{
QMutexLocker locker(&mutex);
mFiles = files;
mProgress = 0;
mFilesChecked = 0;
mTotalFiles = files.size();
// Determine the total size of all of the files to check, so that we can
// show an accurate progress estimate
quint64 sizeOfFiles = 0;
foreach (const QString& file, files) {
sizeOfFiles += QFile(file).size();
}
mMaxProgress = sizeOfFiles;
}
2017-07-28 12:39:28 +02:00
void ThreadResult::setProject(const ImportProject &prj)
2016-08-18 21:58:50 +02:00
{
QMutexLocker locker(&mutex);
mFiles.clear();
mFileSettings = prj.fileSettings;
mProgress = 0;
mFilesChecked = 0;
mTotalFiles = prj.fileSettings.size();
// Determine the total size of all of the files to check, so that we can
// show an accurate progress estimate
quint64 sizeOfFiles = 0;
foreach (const ImportProject::FileSettings& fs, prj.fileSettings) {
sizeOfFiles += QFile(QString::fromStdString(fs.filename)).size();
}
mMaxProgress = sizeOfFiles;
}
2017-07-28 12:39:28 +02:00
void ThreadResult::clearFiles()
{
QMutexLocker locker(&mutex);
mFiles.clear();
2016-08-18 21:58:50 +02:00
mFileSettings.clear();
mFilesChecked = 0;
mTotalFiles = 0;
}
2017-07-28 12:39:28 +02:00
int ThreadResult::getFileCount() const
{
QMutexLocker locker(&mutex);
2016-08-18 21:58:50 +02:00
return mFiles.size() + mFileSettings.size();
}
2020-02-10 20:24:36 +01:00
void ThreadResult::bughuntingReport(const std::string &str)
{
if (str.empty())
return;
emit bughuntingReportLine(QString::fromStdString(str));
}