Cppcheck
report.h
Go to the documentation of this file.
1 /*
2  * Cppcheck - A tool for static C/C++ code analysis
3  * Copyright (C) 2007-2022 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 #ifndef REPORT_H
20 #define REPORT_H
21 
22 #include <QFile>
23 #include <QObject>
24 #include <QString>
25 
26 class ErrorItem;
27 
28 /// @addtogroup GUI
29 /// @{
30 
31 /**
32  * @brief A base class for reports.
33  */
34 class Report : public QObject {
35 public:
36  enum Type {
37  TXT,
39  CSV,
40  };
41 
42  explicit Report(QString filename);
43  ~Report() override;
44 
45  /**
46  * @brief Create the report (file).
47  * @return true if succeeded, false if file could not be created.
48  */
49  virtual bool create();
50 
51  /**
52  * @brief Open the existing report (file).
53  * @return true if succeeded, false if file could not be created.
54  */
55  virtual bool open();
56 
57  /**
58  * @brief Close the report (file).
59  */
60  void close();
61 
62  /**
63  * @brief Write report header.
64  */
65  virtual void writeHeader() = 0;
66 
67  /**
68  * @brief Write report footer.
69  */
70  virtual void writeFooter() = 0;
71 
72  /**
73  * @brief Write error to report.
74  * @param error Error data.
75  */
76  virtual void writeError(const ErrorItem &error) = 0;
77 
78 protected:
79 
80  /**
81  * @brief Get the file object where the report is written to.
82  */
83  QFile* getFile();
84 
85 private:
86 
87  /**
88  * @brief Filename of the report.
89  */
90  QString mFilename;
91 
92  /**
93  * @brief Fileobject for the report file.
94  */
95  QFile mFile;
96 };
97 /// @}
98 #endif // REPORT_H
A class containing error data for one error.
Definition: erroritem.h:72
A base class for reports.
Definition: report.h:34
virtual void writeError(const ErrorItem &error)=0
Write error to report.
virtual void writeHeader()=0
Write report header.
~Report() override
Definition: report.cpp:29
virtual void writeFooter()=0
Write report footer.
QFile * getFile()
Get the file object where the report is written to.
Definition: report.cpp:60
@ CSV
Definition: report.h:39
@ XMLV2
Definition: report.h:38
@ TXT
Definition: report.h:37
void close()
Close the report (file).
Definition: report.cpp:54
Report(QString filename)
Definition: report.cpp:25
virtual bool open()
Open the existing report (file).
Definition: report.cpp:44
virtual bool create()
Create the report (file).
Definition: report.cpp:34
QString mFilename
Filename of the report.
Definition: report.h:90
QFile mFile
Fileobject for the report file.
Definition: report.h:95
Information about a class type.
@ error
Programming error.