Cppcheck
threadresult.h
Go to the documentation of this file.
1 /*
2  * Cppcheck - A tool for static C/C++ code analysis
3  * Copyright (C) 2007-2023 Cppcheck team.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 
20 #ifndef THREADRESULT_H
21 #define THREADRESULT_H
22 
23 #include "color.h"
24 #include "errorlogger.h"
25 #include "filesettings.h"
26 
27 #include <list>
28 #include <mutex>
29 #include <string>
30 
31 #include <QObject>
32 #include <QString>
33 #include <QStringList>
34 #include <QtGlobal>
35 
36 class ErrorItem;
37 class ImportProject;
38 
39 /// @addtogroup GUI
40 /// @{
41 
42 /**
43  * @brief Threads use this class to obtain new files to process and to publish results
44  *
45  */
46 class ThreadResult : public QObject, public ErrorLogger {
47  Q_OBJECT
48 public:
49  ThreadResult() = default;
50 
51  /**
52  * @brief Get next unprocessed file
53  * @return File path
54  */
55  QString getNextFile();
56 
58 
59  /**
60  * @brief Set list of files to check
61  * @param files List of files to check
62  */
63  void setFiles(const QStringList &files);
64 
65  void setProject(const ImportProject &prj);
66 
67  /**
68  * @brief Clear files to check
69  *
70  */
71  void clearFiles();
72 
73  /**
74  * @brief Get the number of files to check
75  *
76  */
77  int getFileCount() const;
78 
79  /**
80  * ErrorLogger methods
81  */
82  void reportOut(const std::string &outmsg, Color c = Color::Reset) override;
83  void reportErr(const ErrorMessage &msg) override;
84 
85 public slots:
86 
87  /**
88  * @brief Slot threads use to signal this class that a specific file is checked
89  * @param file File that is checked
90  */
91  void fileChecked(const QString &file);
92 signals:
93  /**
94  * @brief Progress signal
95  * @param value Current progress
96  * @param description Description of the current stage
97  */
98  // NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
99  void progress(int value, const QString& description);
100 
101  /**
102  * @brief Signal of a new error
103  *
104  * @param item Error data
105  */
106  // NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
107  void error(const ErrorItem &item);
108 
109  /**
110  * @brief Signal of a new log message
111  *
112  * @param logline Log line
113  */
114  // NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
115  void log(const QString &logline);
116 
117  /**
118  * @brief Signal of a debug error
119  *
120  * @param item Error data
121  */
122  // NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
123  void debugError(const ErrorItem &item);
124 
125 protected:
126 
127  /**
128  * @brief Mutex
129  *
130  */
131  mutable std::mutex mutex;
132 
133  /**
134  * @brief List of files to check
135  *
136  */
137  QStringList mFiles;
138 
139  std::list<FileSettings> mFileSettings;
140 
141  /**
142  * @brief Max progress
143  *
144  */
145  quint64 mMaxProgress{};
146 
147  /**
148  * @brief Current progress
149  *
150  */
151  quint64 mProgress{};
152 
153  /**
154  * @brief Current number of files checked
155  *
156  */
157  unsigned long mFilesChecked{};
158 
159  /**
160  * @brief Total number of files
161  *
162  */
163  unsigned long mTotalFiles{};
164 };
165 /// @}
166 #endif // THREADRESULT_H
A class containing error data for one error.
Definition: erroritem.h:72
This is an interface, which the class responsible of error logging should implement.
Definition: errorlogger.h:214
Wrapper for error messages, provided by reportErr()
Definition: errorlogger.h:48
Importing project settings.
Definition: importproject.h:52
Threads use this class to obtain new files to process and to publish results.
Definition: threadresult.h:46
quint64 mMaxProgress
Max progress.
Definition: threadresult.h:145
ThreadResult()=default
QStringList mFiles
List of files to check.
Definition: threadresult.h:137
void clearFiles()
Clear files to check.
std::mutex mutex
Mutex.
Definition: threadresult.h:131
unsigned long mTotalFiles
Total number of files.
Definition: threadresult.h:163
FileSettings getNextFileSettings()
void error(const ErrorItem &item)
Signal of a new error.
quint64 mProgress
Current progress.
Definition: threadresult.h:151
void setProject(const ImportProject &prj)
QString getNextFile()
Get next unprocessed file.
void debugError(const ErrorItem &item)
Signal of a debug error.
void reportErr(const ErrorMessage &msg) override
Information about found errors and warnings is directed here.
void log(const QString &logline)
Signal of a new log message.
void fileChecked(const QString &file)
Slot threads use to signal this class that a specific file is checked.
unsigned long mFilesChecked
Current number of files checked.
Definition: threadresult.h:157
std::list< FileSettings > mFileSettings
Definition: threadresult.h:139
void progress(int value, const QString &description)
Progress signal.
void reportOut(const std::string &outmsg, Color c=Color::Reset) override
ErrorLogger methods.
void setFiles(const QStringList &files)
Set list of files to check.
int getFileCount() const
Get the number of files to check.
Color
Definition: color.h:27
File settings.
Definition: filesettings.h:57