Cppcheck
Public Slots | Signals | Public Member Functions | Protected Slots | Protected Member Functions | Protected Attributes | Private Member Functions | List of all members
ThreadHandler Class Reference

This class handles creating threadresult and starting threads. More...

#include <threadhandler.h>

Inheritance diagram for ThreadHandler:

Public Slots

void stop ()
 Slot to stop all threads. More...
 

Signals

void done ()
 Signal that all threads are done. More...
 
void log (const QString &msg)
 
void debugError (const ErrorItem &item)
 

Public Member Functions

 ThreadHandler (QObject *parent=nullptr)
 
 ~ThreadHandler () override
 
void setThreadCount (const int count)
 Set the number of threads to use. More...
 
void initialize (const ResultsView *view)
 Initialize the threads (connect all signals to resultsview's slots) More...
 
void loadSettings (const QSettings &settings)
 Load settings. More...
 
void saveSettings (QSettings &settings) const
 Save settings. More...
 
void setAddonsAndTools (const QStringList &addonsAndTools)
 
void setSuppressions (const QList< SuppressionList::Suppression > &s)
 
void setClangIncludePaths (const QStringList &s)
 
void clearFiles ()
 Clear all files from cppcheck. More...
 
void setFiles (const QStringList &files)
 Set files to check. More...
 
void setProject (const ImportProject &prj)
 Set project to check. More...
 
void check (const Settings &settings)
 Start the threads to check the files. More...
 
void setCheckFiles (bool all)
 Set files to check. More...
 
void setCheckFiles (const QStringList &files)
 Set selected files to check. More...
 
bool isChecking () const
 Is checking running? More...
 
bool hasPreviousFiles () const
 Have we checked files already? More...
 
int getPreviousFilesCount () const
 Return count of files we checked last time. More...
 
int getPreviousScanDuration () const
 Return the time elapsed while scanning the previous time. More...
 
QStringList getReCheckFiles (bool all) const
 Get files that should be rechecked because they have been changed. More...
 
QDateTime getCheckStartTime () const
 Get start time of last check. More...
 
void setCheckStartTime (QDateTime checkStartTime)
 Set start time of check. More...
 

Protected Slots

void threadDone ()
 Slot that a single thread is done. More...
 

Protected Member Functions

void removeThreads ()
 Function to delete all threads. More...
 

Protected Attributes

QStringList mLastFiles
 List of files checked last time (used when rechecking) More...
 
QDateTime mCheckStartTime
 date and time when current checking started More...
 
QDateTime mLastCheckTime
 when was the files checked the last time (used when rechecking) More...
 
QElapsedTimer mTimer
 Timer used for measuring scan duration. More...
 
int mScanDuration {}
 The previous scan duration in milliseconds. More...
 
ThreadResult mResults
 Thread results are stored here. More...
 
QList< CheckThread * > mThreads
 List of threads currently in use. More...
 
int mRunningThreadCount {}
 The amount of threads currently running. More...
 
bool mAnalyseWholeProgram {}
 
QStringList mAddonsAndTools
 
QList< SuppressionList::SuppressionmSuppressions
 
QStringList mClangIncludePaths
 

Private Member Functions

bool needsReCheck (const QString &filename, std::set< QString > &modified, std::set< QString > &unmodified) const
 Check if a file needs to be rechecked. More...
 

Detailed Description

This class handles creating threadresult and starting threads.

Definition at line 50 of file threadhandler.h.

Constructor & Destructor Documentation

◆ ThreadHandler()

ThreadHandler::ThreadHandler ( QObject *  parent = nullptr)
explicit

Definition at line 38 of file threadhandler.cpp.

References setThreadCount().

◆ ~ThreadHandler()

ThreadHandler::~ThreadHandler ( )
override

Definition at line 44 of file threadhandler.cpp.

References removeThreads().

Member Function Documentation

◆ check()

void ThreadHandler::check ( const Settings settings)

◆ clearFiles()

void ThreadHandler::clearFiles ( )

◆ debugError

void ThreadHandler::debugError ( const ErrorItem item)
signal

◆ done

void ThreadHandler::done ( )
signal

Signal that all threads are done.

Referenced by check(), MainWindow::MainWindow(), and threadDone().

◆ getCheckStartTime()

QDateTime ThreadHandler::getCheckStartTime ( ) const

Get start time of last check.

Returns
start time of last check

Definition at line 293 of file threadhandler.cpp.

References mCheckStartTime.

Referenced by MainWindow::reAnalyzeSelected().

◆ getPreviousFilesCount()

int ThreadHandler::getPreviousFilesCount ( ) const

Return count of files we checked last time.

Returns
count of files that were checked last time.

Definition at line 227 of file threadhandler.cpp.

References mLastFiles.

Referenced by MainWindow::showStatistics().

◆ getPreviousScanDuration()

int ThreadHandler::getPreviousScanDuration ( ) const

Return the time elapsed while scanning the previous time.

Returns
the time elapsed in milliseconds.

Definition at line 232 of file threadhandler.cpp.

References mScanDuration.

Referenced by MainWindow::showStatistics().

◆ getReCheckFiles()

QStringList ThreadHandler::getReCheckFiles ( bool  all) const

Get files that should be rechecked because they have been changed.

Definition at line 237 of file threadhandler.cpp.

References mLastCheckTime, mLastFiles, and needsReCheck().

Referenced by MainWindow::reAnalyze(), and setCheckFiles().

◆ hasPreviousFiles()

bool ThreadHandler::hasPreviousFiles ( ) const

Have we checked files already?

Returns
true check has been previously run and recheck can be done

Definition at line 222 of file threadhandler.cpp.

References mLastFiles.

Referenced by MainWindow::enableCheckButtons().

◆ initialize()

void ThreadHandler::initialize ( const ResultsView view)

Initialize the threads (connect all signals to resultsview's slots)

Parameters
viewView to show error results

Definition at line 197 of file threadhandler.cpp.

References debugError(), ThreadResult::debugError(), ResultsView::error(), ThreadResult::error(), ThreadResult::log(), log(), mResults, ResultsView::progress(), and ThreadResult::progress().

Referenced by MainWindow::MainWindow().

◆ isChecking()

bool ThreadHandler::isChecking ( ) const

Is checking running?

Returns
true if check is running, false otherwise.

Definition at line 122 of file threadhandler.cpp.

References mRunningThreadCount.

Referenced by MainWindow::closeEvent(), ResultsTree::contextMenuEvent(), and MainWindow::reAnalyzeSelected().

◆ loadSettings()

void ThreadHandler::loadSettings ( const QSettings &  settings)

Load settings.

Parameters
settingsQSettings to load settings from

Definition at line 212 of file threadhandler.cpp.

References setThreadCount(), and SETTINGS_CHECK_THREADS.

◆ log

void ThreadHandler::log ( const QString &  msg)
signal

◆ needsReCheck()

bool ThreadHandler::needsReCheck ( const QString &  filename,
std::set< QString > &  modified,
std::set< QString > &  unmodified 
) const
private

Check if a file needs to be rechecked.

Recursively checks included headers. Used by GetReCheckFiles()

Definition at line 253 of file threadhandler.cpp.

References mLastCheckTime.

Referenced by getReCheckFiles().

◆ removeThreads()

void ThreadHandler::removeThreads ( )
protected

◆ saveSettings()

void ThreadHandler::saveSettings ( QSettings &  settings) const

Save settings.

Parameters
settingsQSettings to save settings to

Definition at line 217 of file threadhandler.cpp.

References mThreads, and SETTINGS_CHECK_THREADS.

◆ setAddonsAndTools()

void ThreadHandler::setAddonsAndTools ( const QStringList &  addonsAndTools)
inline

◆ setCheckFiles() [1/2]

void ThreadHandler::setCheckFiles ( bool  all)

Set files to check.

Parameters
alltrue if all files, false if modified files

Definition at line 70 of file threadhandler.cpp.

References getReCheckFiles(), mResults, mRunningThreadCount, and ThreadResult::setFiles().

Referenced by MainWindow::doAnalyzeFiles(), MainWindow::reAnalyze(), and MainWindow::reAnalyzeSelected().

◆ setCheckFiles() [2/2]

void ThreadHandler::setCheckFiles ( const QStringList &  files)

Set selected files to check.

Parameters
fileslist of files to be checked

Definition at line 77 of file threadhandler.cpp.

References mResults, mRunningThreadCount, and ThreadResult::setFiles().

◆ setCheckStartTime()

void ThreadHandler::setCheckStartTime ( QDateTime  checkStartTime)

Set start time of check.

Parameters
checkStartTimesaved start time of the last check

Definition at line 298 of file threadhandler.cpp.

References mCheckStartTime.

Referenced by MainWindow::reAnalyzeSelected().

◆ setClangIncludePaths()

void ThreadHandler::setClangIncludePaths ( const QStringList &  s)
inline

Definition at line 89 of file threadhandler.h.

References mClangIncludePaths.

Referenced by MainWindow::doAnalyzeProject().

◆ setFiles()

void ThreadHandler::setFiles ( const QStringList &  files)

Set files to check.

Parameters
filesfiles to check

Definition at line 58 of file threadhandler.cpp.

References mLastFiles, mResults, and ThreadResult::setFiles().

Referenced by MainWindow::doAnalyzeFiles().

◆ setProject()

void ThreadHandler::setProject ( const ImportProject prj)

Set project to check.

Parameters
prjproject to check

Definition at line 64 of file threadhandler.cpp.

References mLastFiles, mResults, and ThreadResult::setProject().

Referenced by MainWindow::doAnalyzeProject().

◆ setSuppressions()

void ThreadHandler::setSuppressions ( const QList< SuppressionList::Suppression > &  s)
inline

Definition at line 85 of file threadhandler.h.

References mSuppressions.

Referenced by MainWindow::doAnalyzeFiles(), and MainWindow::doAnalyzeProject().

◆ setThreadCount()

void ThreadHandler::setThreadCount ( const int  count)

Set the number of threads to use.

Parameters
countThe number of threads to use

Definition at line 127 of file threadhandler.cpp.

References CheckThread::done(), CheckThread::fileChecked(), ThreadResult::fileChecked(), mResults, mRunningThreadCount, mThreads, removeThreads(), and threadDone().

Referenced by check(), loadSettings(), and ThreadHandler().

◆ stop

void ThreadHandler::stop ( )
slot

Slot to stop all threads.

Definition at line 188 of file threadhandler.cpp.

References mAnalyseWholeProgram, mCheckStartTime, and mThreads.

Referenced by MainWindow::closeEvent(), and MainWindow::stopAnalysis().

◆ threadDone

void ThreadHandler::threadDone ( )
protectedslot

Slot that a single thread is done.

Definition at line 166 of file threadhandler.cpp.

References done(), mAnalyseWholeProgram, mCheckStartTime, mLastCheckTime, mLastFiles, mRunningThreadCount, mScanDuration, mThreads, and mTimer.

Referenced by removeThreads(), and setThreadCount().

Member Data Documentation

◆ mAddonsAndTools

QStringList ThreadHandler::mAddonsAndTools
protected

Definition at line 261 of file threadhandler.h.

Referenced by check(), clearFiles(), and setAddonsAndTools().

◆ mAnalyseWholeProgram

bool ThreadHandler::mAnalyseWholeProgram {}
protected

Definition at line 259 of file threadhandler.h.

Referenced by check(), clearFiles(), removeThreads(), stop(), and threadDone().

◆ mCheckStartTime

QDateTime ThreadHandler::mCheckStartTime
protected

date and time when current checking started

Definition at line 216 of file threadhandler.h.

Referenced by check(), getCheckStartTime(), setCheckStartTime(), stop(), and threadDone().

◆ mClangIncludePaths

QStringList ThreadHandler::mClangIncludePaths
protected

Definition at line 263 of file threadhandler.h.

Referenced by check(), and setClangIncludePaths().

◆ mLastCheckTime

QDateTime ThreadHandler::mLastCheckTime
protected

when was the files checked the last time (used when rechecking)

Definition at line 221 of file threadhandler.h.

Referenced by getReCheckFiles(), needsReCheck(), and threadDone().

◆ mLastFiles

QStringList ThreadHandler::mLastFiles
protected

List of files checked last time (used when rechecking)

Definition at line 213 of file threadhandler.h.

Referenced by clearFiles(), getPreviousFilesCount(), getReCheckFiles(), hasPreviousFiles(), setFiles(), setProject(), and threadDone().

◆ mResults

ThreadResult ThreadHandler::mResults
protected

Thread results are stored here.

Definition at line 245 of file threadhandler.h.

Referenced by check(), clearFiles(), initialize(), removeThreads(), setCheckFiles(), setFiles(), setProject(), and setThreadCount().

◆ mRunningThreadCount

int ThreadHandler::mRunningThreadCount {}
protected

The amount of threads currently running.

Definition at line 257 of file threadhandler.h.

Referenced by check(), isChecking(), setCheckFiles(), setThreadCount(), and threadDone().

◆ mScanDuration

int ThreadHandler::mScanDuration {}
protected

The previous scan duration in milliseconds.

Definition at line 233 of file threadhandler.h.

Referenced by getPreviousScanDuration(), and threadDone().

◆ mSuppressions

QList<SuppressionList::Suppression> ThreadHandler::mSuppressions
protected

Definition at line 262 of file threadhandler.h.

Referenced by check(), clearFiles(), and setSuppressions().

◆ mThreads

QList<CheckThread *> ThreadHandler::mThreads
protected

List of threads currently in use.

Definition at line 251 of file threadhandler.h.

Referenced by check(), removeThreads(), saveSettings(), setThreadCount(), stop(), and threadDone().

◆ mTimer

QElapsedTimer ThreadHandler::mTimer
protected

Timer used for measuring scan duration.

Definition at line 227 of file threadhandler.h.

Referenced by check(), and threadDone().


The documentation for this class was generated from the following files: