Cppcheck
resultsview.h
Go to the documentation of this file.
1 /*
2  * Cppcheck - A tool for static C/C++ code analysis
3  * Copyright (C) 2007-2024 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 RESULTSVIEW_H
21 #define RESULTSVIEW_H
22 
23 #include "report.h"
24 #include "showtypes.h"
25 
26 #include <QObject>
27 #include <QString>
28 #include <QStringList>
29 #include <QWidget>
30 
31 class ErrorItem;
32 class Settings;
33 class ApplicationList;
34 class ThreadHandler;
35 class QModelIndex;
36 class QPrinter;
37 class QSettings;
38 class CheckStatistics;
39 class QPoint;
40 namespace Ui {
41  class ResultsView;
42 }
43 
44 /// @addtogroup GUI
45 /// @{
46 
47 /**
48  * @brief Widget to show cppcheck progressbar and result
49  *
50  */
51 class ResultsView : public QWidget {
52  Q_OBJECT
53 public:
54 
55  explicit ResultsView(QWidget * parent = nullptr);
56  void initialize(QSettings *settings, ApplicationList *list, ThreadHandler *checkThreadHandler);
57  ResultsView(const ResultsView &) = delete;
58  ~ResultsView() override;
59  ResultsView &operator=(const ResultsView &) = delete;
60 
61  /**
62  * @brief Clear results and statistics and reset progressinfo.
63  * @param results Remove all the results from view?
64  */
65  void clear(bool results);
66 
67  /**
68  * @brief Remove a file from the results.
69  */
70  void clear(const QString &filename);
71 
72  /**
73  * @brief Remove a recheck file from the results.
74  */
75  void clearRecheckFile(const QString &filename);
76 
77  /**
78  * @brief Write statistics in file
79  *
80  * @param filename Filename to save statistics to
81  */
82  void saveStatistics(const QString &filename) const;
83 
84  /**
85  * @brief Save results to a file
86  *
87  * @param filename Filename to save results to
88  * @param type Type of the report.
89  * @param productName Custom product name
90  */
91  void save(const QString &filename, Report::Type type, const QString& productName) const;
92 
93  /**
94  * @brief Update results from old report (tag, sinceDate)
95  */
96  void updateFromOldReport(const QString &filename) const;
97 
98  /**
99  * @brief Update tree settings
100  *
101  * @param showFullPath Show full path of files in the tree
102  * @param saveFullPath Save full path of files in reports
103  * @param saveAllErrors Save all visible errors
104  * @param showNoErrorsMessage Show "no errors"?
105  * @param showErrorId Show error id?
106  * @param showInconclusive Show inconclusive?
107  */
108  void updateSettings(bool showFullPath,
109  bool saveFullPath,
110  bool saveAllErrors,
111  bool showNoErrorsMessage,
112  bool showErrorId,
113  bool showInconclusive);
114 
115  /**
116  * @brief Update Code Editor Style
117  *
118  * Function will read updated Code Editor styling from
119  * stored program settings.
120  *
121  * @param settings Pointer to QSettings Object
122  */
123  void updateStyleSetting(QSettings *settings);
124 
125  /**
126  * @brief Set the directory we are checking
127  *
128  * This is used to split error file path to relative if necessary
129  * @param dir Directory we are checking
130  */
131  void setCheckDirectory(const QString &dir);
132 
133  /**
134  * @brief Get the directory we are checking
135  *
136  * @return Directory containing source files
137  */
138 
139  QString getCheckDirectory();
140 
141  /**
142  * Set settings used in checking
143  */
144  void setCheckSettings(const Settings& settings);
145 
146  /**
147  * @brief Inform the view that checking has started
148  *
149  * @param count Count of files to be checked.
150  */
151  void checkingStarted(int count);
152 
153  /**
154  * @brief Inform the view that checking finished.
155  *
156  */
157  void checkingFinished();
158 
159  /**
160  * @brief Do we have visible results to show?
161  *
162  * @return true if there is at least one warning/error to show.
163  */
164  bool hasVisibleResults() const;
165 
166  /**
167  * @brief Do we have results from check?
168  *
169  * @return true if there is at least one warning/error, hidden or visible.
170  */
171  bool hasResults() const;
172 
173  /**
174  * @brief Save View's settings
175  *
176  * @param settings program settings.
177  */
178  void saveSettings(QSettings *settings);
179 
180  /**
181  * @brief Translate this view
182  *
183  */
184  void translate();
185 
186  /**
187  * @brief This function should be called when analysis is stopped
188  */
189  void stopAnalysis();
190 
191  /**
192  * @brief Are there successful results?
193  * @return true if analysis finished without critical errors etc
194  */
195  bool isSuccess() const;
196 
197  void disableProgressbar();
198 
199  /**
200  * @brief Read errors from report XML file.
201  * @param filename Report file to read.
202  *
203  */
204  void readErrorsXml(const QString &filename);
205 
206  /**
207  * @brief Return checking statistics.
208  * @return Pointer to checking statistics.
209  */
211  return mStatistics;
212  }
213 
214  /**
215  * @brief Return Showtypes.
216  * @return Pointer to Showtypes.
217  */
218  const ShowTypes & getShowTypes() const;
219 
220 signals:
221 
222  /**
223  * @brief Signal to be emitted when we have results
224  *
225  */
226  void gotResults();
227 
228  /**
229  * @brief Signal that results have been hidden or shown
230  *
231  * @param hidden true if there are some hidden results, or false if there are not
232  */
233  // NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
234  void resultsHidden(bool hidden);
235 
236  /**
237  * @brief Signal to perform recheck of selected files
238  *
239  * @param selectedFilesList list of selected files
240  */
241  // NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
242  void checkSelected(QStringList selectedFilesList);
243 
244  /** Suppress Ids */
245  // NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
246  void suppressIds(QStringList ids);
247 
248  /**
249  * @brief Show/hide certain type of errors
250  * Refreshes the tree.
251  *
252  * @param type Type of error to show/hide
253  * @param show Should specified errors be shown (true) or hidden (false)
254  */
255  // NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
256  void showResults(ShowTypes::ShowType type, bool show);
257 
258  /**
259  * @brief Show/hide cppcheck errors.
260  * Refreshes the tree.
261  *
262  * @param show Should specified errors be shown (true) or hidden (false)
263  */
264  // NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
265  void showCppcheckResults(bool show);
266 
267  /**
268  * @brief Show/hide clang-tidy/clang-analyzer errors.
269  * Refreshes the tree.
270  *
271  * @param show Should specified errors be shown (true) or hidden (false)
272  */
273  // NOLINTNEXTLINE(readability-inconsistent-declaration-parameter-name) - caused by generated MOC code
274  void showClangResults(bool show);
275 
276  /**
277  * @brief Collapse all results in the result list.
278  */
280 
281  /**
282  * @brief Expand all results in the result list.
283  */
285 
286  /**
287  * @brief Show hidden results in the result list.
288  */
290 
291 public slots:
292 
293  /**
294  * @brief Slot for updating the checking progress
295  *
296  * @param value Current progress value
297  * @param description Description to accompany the progress
298  */
299  void progress(int value, const QString& description);
300 
301  /**
302  * @brief Slot for new error to be displayed
303  *
304  * @param item Error data
305  */
306  void error(const ErrorItem &item);
307 
308  /**
309  * @brief Filters the results in the result list.
310  */
311  void filterResults(const QString& filter);
312 
313  /**
314  * @brief Update detailed message when selected item is changed.
315  *
316  * @param index Position of new selected item.
317  */
318  void updateDetails(const QModelIndex &index);
319 
320  /**
321  * @brief Slot opening a print dialog to print the current report
322  */
323  void print();
324 
325  /**
326  * @brief Slot printing the current report to the printer.
327  * @param printer The printer used for printing the report.
328  */
329  void print(QPrinter* printer);
330 
331  /**
332  * @brief Slot opening a print preview dialog
333  */
334  void printPreview();
335 
336  /**
337  * \brief Log message
338  */
339  void log(const QString &str);
340 
341  /**
342  * \brief debug message
343  */
344  void debugError(const ErrorItem &item);
345 
346  /**
347  * \brief Clear log messages
348  */
349  void logClear();
350 
351  /**
352  * \brief Copy selected log message entry
353  */
354  void logCopyEntry();
355 
356  /**
357  * \brief Copy all log messages
358  */
359  void logCopyComplete();
360 
361 private:
362 
363  /**
364  * If provided ErrorItem is a critical error then display warning message
365  * in the resultsview
366  */
367  void handleCriticalError(const ErrorItem& item);
368 
369  /**
370  * @brief Should we show a "No errors found dialog" every time no errors were found?
371  */
372  bool mShowNoErrorsMessage = true;
373 
374  Ui::ResultsView *mUI;
375 
377 
379 
380  /**
381  * Set to true when checking finish successfully. Set to false whenever analysis starts.
382  */
383  bool mSuccess = false;
384 
385  /** Critical error ids */
387 
388 private slots:
389  /**
390  * @brief Custom context menu for Analysis Log
391  * @param pos Mouse click position
392  */
393  void on_mListLog_customContextMenuRequested(const QPoint &pos);
394 };
395 /// @}
396 #endif // RESULTSVIEW_H
List of applications user has specified to open errors with.
A class for check statistics.
A class containing error data for one error.
Definition: erroritem.h:72
Type
Definition: report.h:36
Widget to show cppcheck progressbar and result.
Definition: resultsview.h:51
void progress(int value, const QString &description)
Slot for updating the checking progress.
void logClear()
Clear log messages.
bool isSuccess() const
Are there successful results?
bool hasResults() const
Do we have results from check?
void updateSettings(bool showFullPath, bool saveFullPath, bool saveAllErrors, bool showNoErrorsMessage, bool showErrorId, bool showInconclusive)
Update tree settings.
bool hasVisibleResults() const
Do we have visible results to show?
void showResults(ShowTypes::ShowType type, bool show)
Show/hide certain type of errors Refreshes the tree.
void checkSelected(QStringList selectedFilesList)
Signal to perform recheck of selected files.
void setCheckSettings(const Settings &settings)
Set settings used in checking.
void suppressIds(QStringList ids)
Suppress Ids.
bool mShowNoErrorsMessage
Should we show a "No errors found dialog" every time no errors were found?
Definition: resultsview.h:372
void save(const QString &filename, Report::Type type, const QString &productName) const
Save results to a file.
void updateStyleSetting(QSettings *settings)
Update Code Editor Style.
void setCheckDirectory(const QString &dir)
Set the directory we are checking.
Ui::ResultsView * mUI
Definition: resultsview.h:374
void showCppcheckResults(bool show)
Show/hide cppcheck errors.
QString mCriticalErrors
Critical error ids.
Definition: resultsview.h:386
void collapseAllResults()
Collapse all results in the result list.
void readErrorsXml(const QString &filename)
Read errors from report XML file.
ResultsView(QWidget *parent=nullptr)
Definition: resultsview.cpp:76
void updateDetails(const QModelIndex &index)
Update detailed message when selected item is changed.
void printPreview()
Slot opening a print preview dialog.
CheckStatistics * mStatistics
Definition: resultsview.h:376
void checkingFinished()
Inform the view that checking finished.
void print()
Slot opening a print dialog to print the current report.
void clear(bool results)
Clear results and statistics and reset progressinfo.
void disableProgressbar()
void showHiddenResults()
Show hidden results in the result list.
void showClangResults(bool show)
Show/hide clang-tidy/clang-analyzer errors.
void resultsHidden(bool hidden)
Signal that results have been hidden or shown.
ResultsView(const ResultsView &)=delete
void error(const ErrorItem &item)
Slot for new error to be displayed.
Settings * mCheckSettings
Definition: resultsview.h:378
void gotResults()
Signal to be emitted when we have results.
~ResultsView() override
void on_mListLog_customContextMenuRequested(const QPoint &pos)
Custom context menu for Analysis Log.
void expandAllResults()
Expand all results in the result list.
bool mSuccess
Set to true when checking finish successfully.
Definition: resultsview.h:383
void translate()
Translate this view.
void logCopyComplete()
Copy all log messages.
void log(const QString &str)
Log message.
void clearRecheckFile(const QString &filename)
Remove a recheck file from the results.
void checkingStarted(int count)
Inform the view that checking has started.
void saveSettings(QSettings *settings)
Save View's settings.
void debugError(const ErrorItem &item)
debug message
void updateFromOldReport(const QString &filename) const
Update results from old report (tag, sinceDate)
const CheckStatistics * getStatistics() const
Return checking statistics.
Definition: resultsview.h:210
const ShowTypes & getShowTypes() const
Return Showtypes.
void saveStatistics(const QString &filename) const
Write statistics in file.
void logCopyEntry()
Copy selected log message entry.
ResultsView & operator=(const ResultsView &)=delete
void stopAnalysis()
This function should be called when analysis is stopped.
void filterResults(const QString &filter)
Filters the results in the result list.
QString getCheckDirectory()
Get the directory we are checking.
void handleCriticalError(const ErrorItem &item)
If provided ErrorItem is a critical error then display warning message in the resultsview.
void initialize(QSettings *settings, ApplicationList *list, ThreadHandler *checkThreadHandler)
Definition: resultsview.cpp:97
This is just a container for general settings so that we don't need to pass individual values to func...
Definition: settings.h:95
A class for different show types we have.
Definition: showtypes.h:38
ShowType
Show types we have (i.e.
Definition: showtypes.h:44
This class handles creating threadresult and starting threads.
Definition: threadhandler.h:50
Definition: aboutdialog.h:27