1 /*
2  * Copyright 2007-2018  Thomas Baumgart <tbaumgart@kde.org>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of
7  * the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef REPORTTABLE_H
19 #define REPORTTABLE_H
20 
21 // ----------------------------------------------------------------------------
22 // QT Includes
23 
24 #include <QObject>
25 
26 // ----------------------------------------------------------------------------
27 // KDE Includes
28 
29 // ----------------------------------------------------------------------------
30 // Project Includes
31 
32 #include "mymoneyreport.h"
33 
34 namespace reports
35 {
36 
37 class KReportChartView;
38 
39 /**
40   * This class serves as base class definition for the concrete report classes
41   * This class is abstract but it contains common code used by all children classes
42   */
43 class ReportTable : public QObject
44 {
45   Q_OBJECT
46 private:
47 
48   /**
49    * Tries to find a css file for the report.
50    *
51    * Search is done in following order:
52    * <ol>
53    *  <li> report specific stylesheet
54    *  <li> configured stylesheet
55    *  <li> installation default of stylesheet
56    * </ol>
57    *
58    * @retval css-filename  if a css-file was found
59    * @retval empty-string  if no css-file was found
60    */
61   QString cssFileNameGet();
62 
63   /**
64    * Subdirectory for html-resources of application.
65    *
66    * @see QStandardPaths
67    */
68   QString m_resourceHtml;
69 
70   /**
71    * Notation of @c reportstylesheet as used by:
72    * @code
73    *  MyMoneyFile::instance()::value();
74    * @endcode
75   */
76   QString m_reportStyleSheet;
77 
78   /**
79    * Filename of default css file.
80    */
81   QString m_cssFileDefault;
82 
83 protected:
84   ReportTable(const MyMoneyReport &_report);
85 
86   /**
87    * Constructs html header.
88    *
89    * @param title html title of report
90    * @param[in] includeCSS  flag, whether the generated html has to include the css inline or whether
91    * the css is referenced as a link to a file
92    * @return  html header
93    */
94   QString renderHeader(const QString& title, const QByteArray &encoding, bool includeCSS);
95 
96   /**
97    * Constructs html footer.
98    *
99    * @return  html footer
100    */
101   QString renderFooter();
102 
103   /**
104    * Constructs the body of the report. Implemented by the concrete classes
105    * @see PivotTable
106    * @see ListTable
107    * @return QString with the html body of the report
108    */
109   virtual QString renderHTML() const = 0;
110 
111   MyMoneyReport m_config;
112   /**
113    * Does the report contain any non-base currency
114    */
115   mutable bool m_containsNonBaseCurrency;
116 
117 public:
~ReportTable()118   virtual ~ReportTable() {}
119 
120   /**
121    * Constructs a comma separated-file of the report. Implemented by the concrete classes
122    * @see PivotTable
123    * @see ListTable
124    */
125   virtual QString renderCSV() const = 0;
126 
127   /**
128    * Renders a graph from the report. Implemented by the concrete classes
129    * @see PivotTable
130    */
131   virtual void drawChart(KReportChartView& view) const = 0;
132   virtual void dump(const QString& file, const QString& context = QString()) const = 0;
133 
134   /**
135    * Creates the complete html document.
136    *
137    * @param widget      parent widget
138    * @param encoding    character set encoding
139    * @param title       html title of report
140    * @param includeCSS  flag, whether the generated html has
141    *                        to include the css inline or whether
142    *                        the css is referenced as a link to a file
143    *
144    * @return complete html document
145    */
146   QString renderReport(const QString &type, const QByteArray& encoding, const QString& title, bool includeCSS = false);
147 };
148 
149 }
150 #endif
151 // REPORTTABLE_H
152