GUI: Renamed methods in ThreadHandler

This commit is contained in:
Daniel Marjamäki 2017-07-28 12:39:28 +02:00
parent 90dd04d317
commit 98803bb14c
7 changed files with 113 additions and 113 deletions

View File

@ -69,17 +69,17 @@ void CheckThread::run()
return;
}
QString file = mResult.GetNextFile();
QString file = mResult.getNextFile();
while (!file.isEmpty() && mState == Running) {
qDebug() << "Checking file" << file;
mCppcheck.check(file.toStdString());
emit FileChecked(file);
if (mState == Running)
file = mResult.GetNextFile();
file = mResult.getNextFile();
}
ImportProject::FileSettings fileSettings = mResult.GetNextFileSettings();
ImportProject::FileSettings fileSettings = mResult.getNextFileSettings();
while (!fileSettings.filename.empty() && mState == Running) {
file = QString::fromStdString(fileSettings.filename);
qDebug() << "Checking file" << file;
@ -87,7 +87,7 @@ void CheckThread::run()
emit FileChecked(file);
if (mState == Running)
fileSettings = mResult.GetNextFileSettings();
fileSettings = mResult.getNextFileSettings();
}
if (mState == Running)

View File

@ -121,7 +121,7 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
connect(mUI.mActionToolBarFilter, SIGNAL(toggled(bool)), this, SLOT(toggleFilterToolBar()));
connect(mUI.mActionAuthors, SIGNAL(triggered()), this, SLOT(showAuthors()));
connect(mThread, SIGNAL(Done()), this, SLOT(checkDone()));
connect(mThread, SIGNAL(done()), this, SLOT(checkDone()));
connect(mUI.mResults, SIGNAL(gotResults()), this, SLOT(resultsAdded()));
connect(mUI.mResults, SIGNAL(resultsHidden(bool)), mUI.mActionShowHidden, SLOT(setEnabled(bool)));
connect(mUI.mResults, SIGNAL(checkSelected(QStringList)), this, SLOT(performSelectedFilesCheck(QStringList)));
@ -138,7 +138,7 @@ MainWindow::MainWindow(TranslationHandler* th, QSettings* settings) :
loadSettings();
mThread->Initialize(mUI.mResults);
mThread->initialize(mUI.mResults);
formatAndSetTitle();
enableCheckButtons(true);
@ -371,7 +371,7 @@ void MainWindow::doCheckProject(ImportProject p)
}
mUI.mResults->clear(true);
mThread->ClearFiles();
mThread->clearFiles();
mUI.mResults->checkingStarted(p.fileSettings.size());
@ -394,8 +394,8 @@ void MainWindow::doCheckProject(ImportProject p)
}
//mThread->SetCheckProject(true);
mThread->SetProject(p);
mThread->Check(checkSettings, true);
mThread->setProject(p);
mThread->check(checkSettings, true);
}
void MainWindow::doCheckFiles(const QStringList &files)
@ -416,7 +416,7 @@ void MainWindow::doCheckFiles(const QStringList &files)
QStringList fileNames = pathList.getFileList();
mUI.mResults->clear(true);
mThread->ClearFiles();
mThread->clearFiles();
if (fileNames.isEmpty()) {
QMessageBox msg(QMessageBox::Warning,
@ -430,7 +430,7 @@ void MainWindow::doCheckFiles(const QStringList &files)
mUI.mResults->checkingStarted(fileNames.count());
mThread->SetFiles(fileNames);
mThread->setFiles(fileNames);
QDir inf(mCurrentDirectory);
const QString checkPath = inf.canonicalPath();
setPath(SETTINGS_LAST_CHECK_PATH, checkPath);
@ -450,15 +450,15 @@ void MainWindow::doCheckFiles(const QStringList &files)
AnalyzerInformation::writeFilesTxt(checkSettings.buildDir, sourcefiles, checkSettings.project.fileSettings);
}
mThread->SetCheckFiles(true);
mThread->Check(checkSettings, true);
mThread->setCheckFiles(true);
mThread->check(checkSettings, true);
}
void MainWindow::checkCode(const QString& code, const QString& filename)
{
// Initialize dummy ThreadResult as ErrorLogger
ThreadResult result;
result.SetFiles(QStringList(filename));
result.setFiles(QStringList(filename));
connect(&result, SIGNAL(Progress(int, const QString&)),
mUI.mResults, SLOT(Progress(int, const QString&)));
connect(&result, SIGNAL(Error(const ErrorItem &)),
@ -921,7 +921,7 @@ void MainWindow::reCheckSelected(QStringList files, bool all)
{
if (files.empty())
return;
if (mThread->IsChecking())
if (mThread->isChecking())
return;
// Clear details, statistics and progress
@ -937,19 +937,19 @@ void MainWindow::reCheckSelected(QStringList files, bool all)
QStringList fileNames = pathList.getFileList();
checkLockDownUI(); // lock UI while checking
mUI.mResults->checkingStarted(fileNames.size());
mThread->SetCheckFiles(fileNames);
mThread->setCheckFiles(fileNames);
// Saving last check start time, otherwise unchecked modified files will not be
// considered in "Modified Files Check" performed after "Selected Files Check"
// TODO: Should we store per file CheckStartTime?
QDateTime saveCheckStartTime = mThread->GetCheckStartTime();
mThread->Check(getCppcheckSettings(), all);
mThread->SetCheckStartTime(saveCheckStartTime);
QDateTime saveCheckStartTime = mThread->getCheckStartTime();
mThread->check(getCppcheckSettings(), all);
mThread->setCheckStartTime(saveCheckStartTime);
}
void MainWindow::reCheck(bool all)
{
const QStringList files = mThread->GetReCheckFiles(all);
const QStringList files = mThread->getReCheckFiles(all);
if (files.empty())
return;
@ -966,8 +966,8 @@ void MainWindow::reCheck(bool all)
if (mProject)
qDebug() << "Rechecking project file" << mProject->getProjectFile()->getFilename();
mThread->SetCheckFiles(all);
mThread->Check(getCppcheckSettings(), all);
mThread->setCheckFiles(all);
mThread->check(getCppcheckSettings(), all);
}
void MainWindow::clearResults()
@ -1036,7 +1036,7 @@ void MainWindow::enableCheckButtons(bool enable)
mUI.mActionStop->setEnabled(!enable);
mUI.mActionCheckFiles->setEnabled(enable);
if (!enable || mThread->HasPreviousFiles()) {
if (!enable || mThread->hasPreviousFiles()) {
mUI.mActionRecheckModified->setEnabled(enable);
mUI.mActionRecheckAll->setEnabled(enable);
}
@ -1087,7 +1087,7 @@ void MainWindow::uncheckAll()
void MainWindow::closeEvent(QCloseEvent *event)
{
// Check that we aren't checking files
if (!mThread->IsChecking()) {
if (!mThread->isChecking()) {
saveSettings();
event->accept();
} else {
@ -1105,7 +1105,7 @@ void MainWindow::closeEvent(QCloseEvent *event)
if (rv == QMessageBox::Yes) {
// This isn't really very clean way to close threads but since the app is
// exiting it doesn't matter.
mThread->Stop();
mThread->stop();
saveSettings();
mExiting = true;
}
@ -1253,7 +1253,7 @@ void MainWindow::aboutToShowViewMenu()
void MainWindow::stopChecking()
{
mThread->Stop();
mThread->stop();
mUI.mResults->disableProgressbar();
}
@ -1432,8 +1432,8 @@ void MainWindow::showStatistics()
statsDialog.setProject(*mProject);
}
statsDialog.setPathSelected(mCurrentDirectory);
statsDialog.setNumberOfFilesScanned(mThread->GetPreviousFilesCount());
statsDialog.setScanDuration(mThread->GetPreviousScanDuration() / 1000.0);
statsDialog.setNumberOfFilesScanned(mThread->getPreviousFilesCount());
statsDialog.setScanDuration(mThread->getPreviousScanDuration() / 1000.0);
statsDialog.setStatistics(mUI.mResults->getStatistics());
statsDialog.exec();

View File

@ -580,7 +580,7 @@ void ResultsTree::contextMenuEvent(QContextMenuEvent * e)
hideallid->setDisabled(true);
opencontainingfolder->setDisabled(true);
}
if (mThread->IsChecking())
if (mThread->isChecking())
recheckSelectedFiles->setDisabled(true);
else
recheckSelectedFiles->setDisabled(false);

View File

@ -33,7 +33,7 @@ ThreadHandler::ThreadHandler(QObject *parent) :
mAnalyseWholeProgram(false)
{
SetThreadCount(1);
setThreadCount(1);
}
ThreadHandler::~ThreadHandler()
@ -41,53 +41,53 @@ ThreadHandler::~ThreadHandler()
RemoveThreads();
}
void ThreadHandler::ClearFiles()
void ThreadHandler::clearFiles()
{
mLastFiles.clear();
mResults.ClearFiles();
mResults.clearFiles();
mAnalyseWholeProgram = false;
}
void ThreadHandler::SetFiles(const QStringList &files)
void ThreadHandler::setFiles(const QStringList &files)
{
mResults.SetFiles(files);
mResults.setFiles(files);
mLastFiles = files;
}
void ThreadHandler::SetProject(const ImportProject &prj)
void ThreadHandler::setProject(const ImportProject &prj)
{
mResults.SetProject(prj);
mResults.setProject(prj);
mLastFiles.clear();
}
void ThreadHandler::SetCheckFiles(bool all)
void ThreadHandler::setCheckFiles(bool all)
{
if (mRunningThreadCount == 0) {
mResults.SetFiles(GetReCheckFiles(all));
mResults.setFiles(getReCheckFiles(all));
}
}
void ThreadHandler::SetCheckFiles(QStringList files)
void ThreadHandler::setCheckFiles(QStringList files)
{
if (mRunningThreadCount == 0) {
mResults.SetFiles(files);
mResults.setFiles(files);
}
}
void ThreadHandler::Check(const Settings &settings, bool all)
void ThreadHandler::check(const Settings &settings, bool all)
{
if (mResults.GetFileCount() == 0 || mRunningThreadCount > 0 || settings.jobs == 0) {
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();
emit done();
return;
}
SetThreadCount(settings.jobs);
setThreadCount(settings.jobs);
mRunningThreadCount = mThreads.size();
if (mResults.GetFileCount() < mRunningThreadCount) {
mRunningThreadCount = mResults.GetFileCount();
if (mResults.getFileCount() < mRunningThreadCount) {
mRunningThreadCount = mResults.getFileCount();
}
for (int i = 0; i < mRunningThreadCount; i++) {
@ -102,12 +102,12 @@ void ThreadHandler::Check(const Settings &settings, bool all)
mTime.start();
}
bool ThreadHandler::IsChecking() const
bool ThreadHandler::isChecking() const
{
return mRunningThreadCount > 0;
}
void ThreadHandler::SetThreadCount(const int count)
void ThreadHandler::setThreadCount(const int count)
{
if (mRunningThreadCount > 0 ||
count == mThreads.size() ||
@ -121,9 +121,9 @@ void ThreadHandler::SetThreadCount(const int count)
for (int i = mThreads.size(); i < count; i++) {
mThreads << new CheckThread(mResults);
connect(mThreads.last(), SIGNAL(Done()),
this, SLOT(ThreadDone()));
this, SLOT(threadDone()));
connect(mThreads.last(), SIGNAL(FileChecked(const QString &)),
&mResults, SLOT(FileChecked(const QString &)));
&mResults, SLOT(fileChecked(const QString &)));
}
}
@ -145,7 +145,7 @@ void ThreadHandler::RemoveThreads()
mAnalyseWholeProgram = false;
}
void ThreadHandler::ThreadDone()
void ThreadHandler::threadDone()
{
if (mRunningThreadCount == 1 && mAnalyseWholeProgram) {
mThreads[0]->analyseWholeProgram(mLastFiles);
@ -155,7 +155,7 @@ void ThreadHandler::ThreadDone()
mRunningThreadCount--;
if (mRunningThreadCount == 0) {
emit Done();
emit done();
mScanDuration = mTime.elapsed();
@ -167,7 +167,7 @@ void ThreadHandler::ThreadDone()
}
}
void ThreadHandler::Stop()
void ThreadHandler::stop()
{
mCheckStartTime = QDateTime();
mAnalyseWholeProgram = false;
@ -176,47 +176,47 @@ void ThreadHandler::Stop()
}
}
void ThreadHandler::Initialize(ResultsView *view)
void ThreadHandler::initialize(ResultsView *view)
{
connect(&mResults, SIGNAL(Progress(int, const QString&)),
connect(&mResults, SIGNAL(progress(int, const QString&)),
view, SLOT(progress(int, const QString&)));
connect(&mResults, SIGNAL(Error(const ErrorItem &)),
connect(&mResults, SIGNAL(error(const ErrorItem &)),
view, SLOT(error(const ErrorItem &)));
connect(&mResults, SIGNAL(Log(const QString &)),
connect(&mResults, SIGNAL(log(const QString &)),
parent(), SLOT(log(const QString &)));
connect(&mResults, SIGNAL(DebugError(const ErrorItem &)),
connect(&mResults, SIGNAL(debugError(const ErrorItem &)),
parent(), SLOT(debugError(const ErrorItem &)));
}
void ThreadHandler::LoadSettings(QSettings &settings)
void ThreadHandler::loadSettings(QSettings &settings)
{
SetThreadCount(settings.value(SETTINGS_CHECK_THREADS, 1).toInt());
setThreadCount(settings.value(SETTINGS_CHECK_THREADS, 1).toInt());
}
void ThreadHandler::SaveSettings(QSettings &settings) const
void ThreadHandler::saveSettings(QSettings &settings) const
{
settings.setValue(SETTINGS_CHECK_THREADS, mThreads.size());
}
bool ThreadHandler::HasPreviousFiles() const
bool ThreadHandler::hasPreviousFiles() const
{
return !mLastFiles.isEmpty();
}
int ThreadHandler::GetPreviousFilesCount() const
int ThreadHandler::getPreviousFilesCount() const
{
return mLastFiles.size();
}
int ThreadHandler::GetPreviousScanDuration() const
int ThreadHandler::getPreviousScanDuration() const
{
return mScanDuration;
}
QStringList ThreadHandler::GetReCheckFiles(bool all) const
QStringList ThreadHandler::getReCheckFiles(bool all) const
{
if (mLastCheckTime.isNull() || all)
return mLastFiles;
@ -226,13 +226,13 @@ QStringList ThreadHandler::GetReCheckFiles(bool all) const
QStringList files;
for (int i = 0; i < mLastFiles.size(); ++i) {
if (NeedsReCheck(mLastFiles[i], modified, unmodified))
if (needsReCheck(mLastFiles[i], modified, unmodified))
files.push_back(mLastFiles[i]);
}
return files;
}
bool ThreadHandler::NeedsReCheck(const QString &filename, std::set<QString> &modified, std::set<QString> &unmodified) const
bool ThreadHandler::needsReCheck(const QString &filename, std::set<QString> &modified, std::set<QString> &unmodified) const
{
if (modified.find(filename) != modified.end())
return true;
@ -261,7 +261,7 @@ bool ThreadHandler::NeedsReCheck(const QString &filename, std::set<QString> &mod
if (i > 0) {
line.remove(i,line.length());
line = QFileInfo(filename).absolutePath() + "/" + line;
if (NeedsReCheck(line, modified, unmodified)) {
if (needsReCheck(line, modified, unmodified)) {
modified.insert(line);
return true;
}
@ -272,12 +272,12 @@ bool ThreadHandler::NeedsReCheck(const QString &filename, std::set<QString> &mod
return false;
}
QDateTime ThreadHandler::GetCheckStartTime() const
QDateTime ThreadHandler::getCheckStartTime() const
{
return mCheckStartTime;
}
void ThreadHandler::SetCheckStartTime(QDateTime checkStartTime)
void ThreadHandler::setCheckStartTime(QDateTime checkStartTime)
{
mCheckStartTime = checkStartTime;
}

View File

@ -50,46 +50,46 @@ public:
* @brief Set the number of threads to use
* @param count The number of threads to use
*/
void SetThreadCount(const int count);
void setThreadCount(const int count);
/**
* @brief Initialize the threads (connect all signals to resultsview's slots)
*
* @param view View to show error results
*/
void Initialize(ResultsView *view);
void initialize(ResultsView *view);
/**
* @brief Load settings
* @param settings QSettings to load settings from
*/
void LoadSettings(QSettings &settings);
void loadSettings(QSettings &settings);
/**
* @brief Save settings
* @param settings QSettings to save settings to
*/
void SaveSettings(QSettings &settings) const;
void saveSettings(QSettings &settings) const;
/**
* @brief Clear all files from cppcheck
*
*/
void ClearFiles();
void clearFiles();
/**
* @brief Set files to check
*
* @param files files to check
*/
void SetFiles(const QStringList &files);
void setFiles(const QStringList &files);
/**
* @brief Set project to check
*
* @param prj project to check
*/
void SetProject(const ImportProject &prj);
void setProject(const ImportProject &prj);
/**
* @brief Start the threads to check the files
@ -97,76 +97,76 @@ public:
* @param settings Settings for checking
* @param all true if all files, false if modified files
*/
void Check(const Settings &settings, bool all);
void check(const Settings &settings, bool all);
/**
* @brief Set files to check
*
* @param all true if all files, false if modified files
*/
void SetCheckFiles(bool all);
void setCheckFiles(bool all);
/**
* @brief Set selected files to check
*
* @param files list of files to be checked
*/
void SetCheckFiles(QStringList files);
void setCheckFiles(QStringList files);
/**
* @brief Is checking running?
*
* @return true if check is running, false otherwise.
*/
bool IsChecking() const;
bool isChecking() const;
/**
* @brief Have we checked files already?
*
* @return true check has been previously run and recheck can be done
*/
bool HasPreviousFiles() const;
bool hasPreviousFiles() const;
/**
* @brief Return count of files we checked last time.
*
* @return count of files that were checked last time.
*/
int GetPreviousFilesCount() const;
int getPreviousFilesCount() const;
/**
* @brief Return the time elapsed while scanning the previous time.
*
* @return the time elapsed in milliseconds.
*/
int GetPreviousScanDuration() const;
int getPreviousScanDuration() const;
/**
* @brief Get files that should be rechecked because they have been
* changed.
*/
QStringList GetReCheckFiles(bool all) const;
QStringList getReCheckFiles(bool all) const;
/**
* @brief Get start time of last check
*
* @return start time of last check
*/
QDateTime GetCheckStartTime() const;
QDateTime getCheckStartTime() const;
/**
* @brief Set start time of check
*
* @param checkStartTime saved start time of the last check
*/
void SetCheckStartTime(QDateTime checkStartTime);
void setCheckStartTime(QDateTime checkStartTime);
signals:
/**
* @brief Signal that all threads are done
*
*/
void Done();
void done();
public slots:
@ -174,7 +174,7 @@ public slots:
* @brief Slot to stop all threads
*
*/
void Stop();
void stop();
protected slots:
@ -183,7 +183,7 @@ protected slots:
* @brief Slot that a single thread is done
*
*/
void ThreadDone();
void threadDone();
protected:
/**
* @brief List of files checked last time (used when rechecking)
@ -242,7 +242,7 @@ private:
* @brief Check if a file needs to be rechecked. Recursively checks
* included headers. Used by GetReCheckFiles()
*/
bool NeedsReCheck(const QString &filename, std::set<QString> &modified, std::set<QString> &unmodified) const;
bool needsReCheck(const QString &filename, std::set<QString> &modified, std::set<QString> &unmodified) const;
};
/// @}
#endif // THREADHANDLER_H

View File

@ -39,10 +39,10 @@ ThreadResult::~ThreadResult()
void ThreadResult::reportOut(const std::string &outmsg)
{
emit Log(QString::fromStdString(outmsg));
emit log(QString::fromStdString(outmsg));
}
void ThreadResult::FileChecked(const QString &file)
void ThreadResult::fileChecked(const QString &file)
{
QMutexLocker locker(&mutex);
@ -53,7 +53,7 @@ void ThreadResult::FileChecked(const QString &file)
const int value = static_cast<int>(PROGRESS_MAX * mProgress / mMaxProgress);
const QString description = tr("%1 of %2 files checked").arg(mFilesChecked).arg(mTotalFiles);
emit Progress(value, description);
emit progress(value, description);
}
}
@ -62,12 +62,12 @@ void ThreadResult::reportErr(const ErrorLogger::ErrorMessage &msg)
QMutexLocker locker(&mutex);
const ErrorItem item(msg);
if (msg._severity != Severity::debug)
emit Error(item);
emit error(item);
else
emit DebugError(item);
emit debugError(item);
}
QString ThreadResult::GetNextFile()
QString ThreadResult::getNextFile()
{
QMutexLocker locker(&mutex);
if (mFiles.isEmpty()) {
@ -77,7 +77,7 @@ QString ThreadResult::GetNextFile()
return mFiles.takeFirst();
}
ImportProject::FileSettings ThreadResult::GetNextFileSettings()
ImportProject::FileSettings ThreadResult::getNextFileSettings()
{
QMutexLocker locker(&mutex);
if (mFileSettings.empty()) {
@ -88,7 +88,7 @@ ImportProject::FileSettings ThreadResult::GetNextFileSettings()
return fs;
}
void ThreadResult::SetFiles(const QStringList &files)
void ThreadResult::setFiles(const QStringList &files)
{
QMutexLocker locker(&mutex);
mFiles = files;
@ -105,7 +105,7 @@ void ThreadResult::SetFiles(const QStringList &files)
mMaxProgress = sizeOfFiles;
}
void ThreadResult::SetProject(const ImportProject &prj)
void ThreadResult::setProject(const ImportProject &prj)
{
QMutexLocker locker(&mutex);
mFiles.clear();
@ -123,7 +123,7 @@ void ThreadResult::SetProject(const ImportProject &prj)
mMaxProgress = sizeOfFiles;
}
void ThreadResult::ClearFiles()
void ThreadResult::clearFiles()
{
QMutexLocker locker(&mutex);
mFiles.clear();
@ -132,7 +132,7 @@ void ThreadResult::ClearFiles()
mTotalFiles = 0;
}
int ThreadResult::GetFileCount() const
int ThreadResult::getFileCount() const
{
QMutexLocker locker(&mutex);
return mFiles.size() + mFileSettings.size();

View File

@ -45,29 +45,29 @@ public:
* @brief Get next unprocessed file
* @return File path
*/
QString GetNextFile();
QString getNextFile();
ImportProject::FileSettings GetNextFileSettings();
ImportProject::FileSettings getNextFileSettings();
/**
* @brief Set list of files to check
* @param files List of files to check
*/
void SetFiles(const QStringList &files);
void setFiles(const QStringList &files);
void SetProject(const ImportProject &prj);
void setProject(const ImportProject &prj);
/**
* @brief Clear files to check
*
*/
void ClearFiles();
void clearFiles();
/**
* @brief Get the number of files to check
*
*/
int GetFileCount() const;
int getFileCount() const;
/**
* ErrorLogger methods
@ -81,35 +81,35 @@ public slots:
* @brief Slot threads use to signal this class that a specific file is checked
* @param file File that is checked
*/
void FileChecked(const QString &file);
void fileChecked(const QString &file);
signals:
/**
* @brief Progress signal
* @param value Current progress
* @param description Description of the current stage
*/
void Progress(int value, const QString& description);
void progress(int value, const QString& description);
/**
* @brief Signal of a new error
*
* @param item Error data
*/
void Error(const ErrorItem &item);
void error(const ErrorItem &item);
/**
* @brief Signal of a new log message
*
* @param logline Log line
*/
void Log(const QString &logline);
void log(const QString &logline);
/**
* @brief Signal of a debug error
*
* @param item Error data
*/
void DebugError(const ErrorItem &item);
void debugError(const ErrorItem &item);
protected: