MyBooks
reportcore.h
Go to the documentation of this file.
1 /***************************************************************************
2  * This file is part of the CuteReport project *
3  * Copyright (C) 2012-2017 by Alexander Mikhalov *
4  * alexander.mikhalov@gmail.com *
5  * *
6  ** GNU General Public License Usage **
7  * *
8  * This library is free software: you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation, either version 3 of the License, or *
11  * (at your option) any later version. *
12  * You should have received a copy of the GNU General Public License *
13  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
14  * *
15  ** GNU Lesser General Public License **
16  * *
17  * This library is free software: you can redistribute it and/or modify *
18  * it under the terms of the GNU Lesser General Public License as *
19  * published by the Free Software Foundation, either version 3 of the *
20  * License, or (at your option) any later version. *
21  * You should have received a copy of the GNU Lesser General Public *
22  * License along with this library. *
23  * If not, see <http://www.gnu.org/licenses/>. *
24  * *
25  * This library is distributed in the hope that it will be useful, *
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
28  * GNU General Public License for more details. *
29  ****************************************************************************/
30 #ifndef REPORTCORE_H
31 #define REPORTCORE_H
32 
33 #include <QObject>
34 #include <QMap>
35 #include "cutereport_globals.h"
36 #include "cutereport_types.h"
37 
38 
39 namespace CuteReport
40 {
41 
42 class DatasetInterface;
43 class PageInterface;
44 class BaseItemInterface;
45 class StorageInterface;
46 class StorageOptionsInterface;
47 class RendererInterface;
48 class RenderedPageInterface;
49 class PrinterInterface;
50 class FormInterface;
51 class SerializerInterface;
52 class ImportInterface;
53 class ExportInterface;
54 class Log;
55 class ReportInterface;
56 class RenderedReportInterface;
57 class ReportPluginInterface;
58 class ScriptExtensionInterface;
59 class DesignerItemInterface;
60 
63 
64 struct QueueReport {
65  explicit QueueReport();
66  virtual ~QueueReport();
68  QString url;
70  QString rendererName;
71  QString destinationName;
72  bool success;
73 };
74 
75 
76 struct QueueReportExport: public QueueReport {
77  QString format;
78  QString outputUrl;
79  QStringList options;
80 };
81 
82 
83 class CUTEREPORT_EXPORTS ReportCore : public QObject
84 {
85  Q_OBJECT
86 
87 public:
88  explicit ReportCore(QObject *parent = 0, QSettings *settings = 0, bool interactive = true, bool initLogSytem = true);
89  explicit ReportCore(QSettings *settings, bool interactive = true);
90  ~ReportCore();
91 
92  int versionMajor() const;
93  int versionMinor() const;
94  QString license() const;
95 
103  bool interactive() const;
104 
110  void finish();
111 
125  void restoreState(bool cleanRestore = true);
126  void storeState();
127 
132  bool setDefaultStorage(const QString &objectName);
133  QString defaultStorageName() const;
134 
135  bool setDefaultPrinter(const QString objectName);
136  QString defaultPrinterName() const;
137 
138  bool setDefaultRenderer(const QString &objectName);
139  QString defaultRendererName() const;
140 
144  void setRootWidget(QWidget * widget);
145  QWidget * rootWidget();
146 
152  const QList<ReportPluginInterface *> modules(ModuleType moduleType) const;
153 
157  const ReportPluginInterface * module(ModuleType moduleType, const QString &moduleName) const;
158 
160  QStringList moduleNames(ModuleType moduleType, bool shortName = false) const;
161 
163  QString moduleTypeToString(ModuleType type) const;
164  ModuleType moduleTypeFromString(const QString & type) const;
165 
175  QStringList moduleOptions(ReportPluginInterface * module, bool includeObjectName = true);
176  void setModuleOptions(ReportPluginInterface * module, const QStringList & options, bool setObjectNameIfDefined = true);
177  QString moduleOptionsStr(ReportPluginInterface * module, bool includeObjectName = true, const QString & delimiter = QString());
178  void setModuleOptionsStr(ReportPluginInterface * module, const QString & options, bool setObjectNameIfDefined = true);
179 
182  QList<StorageInterface *> storageList(ReportInterface * report = 0) const;
183  QStringList storageNameList(ReportInterface * report = 0) const;
184  StorageInterface * storage(const QString & objectName, ReportInterface * report = 0) const;
185  StorageInterface * storageByUrl(const QString & urlString, ReportInterface * report = 0) const;
186  void setStorage(StorageInterface * storage);
187  void deleteStorage(const QString & objectName);
188 
189  QList<RendererInterface *> rendererList(ReportInterface * report = 0) const;
190  QStringList rendererNameList(ReportInterface * report = 0) const;
191  RendererInterface * renderer(const QString &objectName) const;
192  RendererInterface * renderer(ReportInterface * report, const QString &objectName = QString()) const;
193  void setRenderer(RendererInterface * renderer);
194  void deleteRenderer(const QString & objectName);
195 
196  QList<PrinterInterface *> printerList(ReportInterface * report = 0) const;
197  QStringList printerNameList(ReportInterface * report = 0) const;
198  PrinterInterface * printer(const QString & objectName, ReportInterface * report = 0) const;
199  void setPrinter(PrinterInterface * printer);
200  void deletePrinter(const QString & objectName);
201 
202  PageInterface * pageByName(const QString & pageName, CuteReport::ReportInterface * report) const;
203  BaseItemInterface * itemByName(const QString & itemName, CuteReport::PageInterface * page = 0) const; //if page is 0, look at all pages
204  BaseItemInterface * itemByName(const QString & itemName, const QString & pageName, CuteReport::ReportInterface * report) const;
205  DatasetInterface * datasetByName(const QString & datasetName, CuteReport::ReportInterface * report) const;
206  FormInterface * formByName(const QString & formName, CuteReport::ReportInterface * report) const;
207 
208  QList<ReportInterface *> reports() const;
209  CuteReport::ReportInterface * createReport();
210  void deleteReport(CuteReport::ReportInterface * report);
211 
217  CuteReport::PageInterface * createPageObject(const QString & moduleName, CuteReport::ReportInterface *report = 0);
218  CuteReport::DatasetInterface * createDatasetObject(const QString & moduleName, CuteReport::ReportInterface *report = 0);
219  CuteReport::BaseItemInterface * createItemObject(const QString & moduleName, CuteReport::ReportInterface *report = 0, QObject * parent = 0);
220  CuteReport::PrinterInterface * createPrinterObject(const QString & moduleName, CuteReport::ReportInterface *report = 0);
221  CuteReport::StorageInterface * createStorageObject(const QString & moduleName, CuteReport::ReportInterface *report = 0);
222  CuteReport::RendererInterface * createRendererObject(const QString & moduleName, CuteReport::ReportInterface *report = 0);
223  CuteReport::FormInterface * createFormObject(const QString & moduleName, CuteReport::ReportInterface *report = 0);
224  CuteReport::ExportInterface * createExportObject(const QString & moduleName, CuteReport::ReportInterface *report = 0);
225  ScriptExtensionInterface * createScriptExtentionObject(const QString & moduleName, CuteReport::ReportInterface *report = 0, QObject * parent = 0);
226 
227  QByteArray serialize(const QObject * object, bool *ok = 0, QString * error = 0, const QString & moduleName = QString());
228  QObject * deserialize(const QByteArray &data, bool *ok = 0, QString * error = 0, const QString & moduleName = QString());
229 
230 
231  bool saveReport(const QString & urlString, CuteReport::ReportInterface * report, QString * errorText = 0);
232 
233  bool reportExists(const QString & urlString);
234 
235  CuteReport::ReportInterface * loadReport(const QString & urlString,
236  QString * errorText = 0);
237 
238  bool saveObject(const QString & urlString,
240  const QByteArray &objectData,
241  QString * errorText = 0);
242 
243  QByteArray loadObject(const QString & urlString,
245  QString * errorText = 0);
246 
247  QString localCachedFileName(const QString & url, CuteReport::ReportInterface * report);
248  QList<StorageObjectInfo> objectsList(const QString & url, CuteReport::ReportInterface * report, QString *errorText = 0);
249  QList<StorageObjectInfo> objectsList(const QString & url, ReportInterface *report, const QStringList & nameFilters, QDir::Filters filters,
250  QDir::SortFlags sort, QString *errorText = 0);
251 
253 // const QList<QString> renderers();
254  bool render(ReportInterface* report, const QString &rendererName = QString());
255  bool render(const QString & reportUrl, const QString &rendererName = QString());
256  void stopRendering(ReportInterface *report, bool silent = false); // silent = true if we don't know if report rendering or not, to prevent warnings
257  bool isRendered(ReportInterface *report);
258  int rendererTotalPages(ReportInterface *report) const;
259  RenderedPageInterface * rendererGetPage(ReportInterface *report, int number) const;
260  void renderDataClear(ReportInterface * report);
261  void renderDataclearAll();
262 
264  void print(ReportInterface* report, const QString & printerName = QString());
265  void print(const QString url, const QString & printerName = QString());
266 
268  QStringList importExtensions() const;
269  bool canImport(const QString &reportUrl) const;
270  QStringList importModulesForFile(const QString &reportUrl) const;
271  ReportInterface *import(const QString &reportUrl, const QString & moduleName = QString()) const;
272 
276  void exportTo(ReportInterface* report, const QString & format, const QString & outputUrl = QString(), const QStringList & options = QStringList());
277  void exportTo(const QString &reportUrl, const QString & format, const QString & outputUrl = QString(), const QStringList & options = QStringList());
278 
279  static void log(LogLevel level, const QString & sender, const QString & message);
280  static void log(LogLevel level, const QString & sender, const QString & shortMessage, const QString & fullMessage);
281 
282  static bool isNameUnique(QObject *object, const QString &name, QObject * rootObject);
283  static QString uniqueName(QObject * object, const QString &proposedName, QObject *rootObject);
284 
285  int maxRenderingThreads() const;
286  void setMaxRenderingThreads(int maxRenderingThreads);
287 
288  ScriptString processString(ScriptString & scriptString);
289  ScriptString processString(const ScriptString &scriptString);
290 
291  QSet<QString> getReportParameters(ReportInterface *report, QString *error = 0);
292 
293  QSettings * settings();
294 
296  QString resourcesPath() const;
297  QString imagesPath() const;
298  QString pluginsPath() const;
299  QString settingsPath() const;
300 
301  bool inheritReport(ReportInterface * report, const QString & baseReportUrl);
302  bool inheritReport(ReportInterface * report, const QString & baseReportFileName, const QString &baseReportPath);
303  bool detachReport(ReportInterface * report, bool ownInheritedItems = false);
304 
305 
306 public slots:
307  void sendMetric(CuteReport::MetricType type, const QVariant &value);
308 
309 signals:
310  void finished(bool);
311  void syncMessage(const QString & moduleName, const QString & message);
312 
313  void rendererStarted(CuteReport::ReportInterface * report);
314  void rendererDone(CuteReport::ReportInterface * report, bool success);
315  void rendererDone(const QString & reportUrl, bool success);
316  void rendererMessage(CuteReport::ReportInterface * report, int logLevel, QString message);
317  void rendererProcessingPage(CuteReport::ReportInterface * report, int page, int total, int pass, int passTotal);
318  void rendererProcessedPage(CuteReport::ReportInterface * report, CuteReport::RenderedPageInterface * page, int pageNumber);
319 
320  void printingDone(CuteReport::ReportInterface * report, bool successfully);
321  void printingDone(const QString & reportUrl, bool successfully);
322 
323  void exportDone(CuteReport::ReportInterface * report, bool successfully);
324  void exportDone(const QString & reportUrl, bool successfully);
325 
326  void reportObjectCreated(CuteReport::ReportInterface * report);
327  void reportObjectDestroyed(CuteReport::ReportInterface * report);
328  void metricUpdated(CuteReport::MetricType type, const QVariant &value);
329 
330 private slots:
331  void _rendererStarted();
332  void _rendererDone(bool successful);
333  void _rendererMessage(int logLevel, QString message);
334  void _rendererProcessingPage(int page, int total, int pass, int passTotal);
335 
336  void _reportObjectCreated(CuteReport::ReportInterface * report);
337 
338 private:
339  static bool loadPlugins(QSettings *settings);
340  static void processModuleList(QList<ReportPluginInterface *> &list);
341  static void fixLoadedReportIssues(ReportInterface * report);
342  ReportPluginInterface * getOriginalModuleByName(const QString & moduleName, const QList<ReportPluginInterface *> &list) const;
343  ReportPluginInterface * getExtendedModuleByName(const QString & origModuleName, const QList<ReportPluginInterface *> &list) const;
344  ReportPluginInterface * getModuleByName(const QString & moduleName, const QList<ReportPluginInterface *> &list);
345  void saveObjectsOptions(const QString & prefix, const QList<ReportPluginInterface*> & objects, bool clearPrefix = true);
346  void loadObjectsOptions(const QString & prefix, QList<ReportPluginInterface*> & objects, const QList<ReportPluginInterface*> * plugins);
347  bool removeObject(const QString & objectName, QList<ReportPluginInterface*> & objects);
348  bool replaceObject(ReportPluginInterface* object, QList<ReportPluginInterface*> & objects, QPointer<ReportPluginInterface> defaultObject);
349  QStringList objectNames(const QList<ReportPluginInterface *> &objects) const;
350  ReportPluginInterface * getObjectByName(const QString & objectName, const QList<ReportPluginInterface *> &list) const;
351  void createLocalObjects(QList<ReportPluginInterface*> & objects, const QList<ReportPluginInterface*> * plugins);
352  ReportPluginInterface * findDefaultObject(const QString &type, const QString &fullModuleNameList, QList<ReportPluginInterface*> & objects);
353  RendererInterface * getRendererForReport(ReportInterface *report, QString *error);
354 
355  void init(QSettings * settings, bool initLogSystem);
356  inline bool checkReportPointer(CuteReport::ReportInterface * report, QString * errorText = 0) const;
357  bool _render(QueueReport *queueReport);
358  void _renderDone(QueueReport *queueReport);
359  void _export(QueueReport *queueReport);
360  void _exportDone(QueueReport *queueReport);
361  void _print(QueueReport *queueReport);
362  void _printDone(QueueReport *queueReport);
363 
364 private:
365  static int m_refCount;
366 
367  static QList<ReportPluginInterface*> * m_itemPlugins;
368  static QList<ReportPluginInterface*> * m_pagePlugins;
369  static QList<ReportPluginInterface*> * m_datasetPlugins;
370  static QList<ReportPluginInterface*> * m_storagePlugins;
371  static QList<ReportPluginInterface*> * m_serializePlugins;
372  static QList<ReportPluginInterface*> * m_rendererPlugins;
373  static QList<ReportPluginInterface*> * m_printerPlugins;
374  static QList<ReportPluginInterface*> * m_formPlugins;
375  static QList<ReportPluginInterface*> * m_importPlugins;
376  static QList<ReportPluginInterface*> * m_exportPlugins;
377  static QList<ReportPluginInterface*> * m_scriptExtensionPlugins;
378 
379  QPointer<ReportPluginInterface> m_defaultStorage;
380  QPointer<ReportPluginInterface> m_defaultRenderer;
381  QPointer<ReportPluginInterface> m_defaultPrinter;
382  QPointer<ReportPluginInterface> m_defaultSerializer;
383 
384  QWidget* m_rootWidget;
385  QList<ReportPluginInterface*> m_storages;
386  QList<ReportPluginInterface*> m_renderers;
387  QList<ReportPluginInterface*> m_printers;
388  QList<ReportPluginInterface*> m_serializers;
389  QList<ReportPluginInterface*> m_exporters;
390 
391  QSettings * m_settings;
392  bool m_interactive;
393 
394  QList<QueueReport*> m_waitingQueue;
395  QHash<RendererInterface*, QueueReport*> m_renderingQueue;
396  int m_maxRenderingThreads;
397 };
398 
399 }
400 #endif // REPORTCORE_H
Definition: forminterface.h:45
Definition: reportcore.h:76
Definition: abstractpainterdelegate.h:42
RenderingDestination destination
Definition: reportcore.h:69
Definition: datasetinterface.h:56
Definition: pageinterface.h:74
Definition: printerinterface.h:44
TODO v2: rename to ReportObject.
Definition: reportinterface.h:71
ReportInterface * report
Definition: reportcore.h:67
RenderingDestination
Definition: reportcore.h:62
Definition: reportcore.h:62
Definition: reportplugininterface.h:53
Definition: reportcore.h:62
Definition: reportcore.h:64
ModuleType
Definition: cutereport_types.h:127
Definition: cutereport_types.h:310
bool success
Definition: reportcore.h:72
BaseType
Definition: reportcore.h:61
Definition: reportcore.h:62
LogLevel
Definition: cutereport_types.h:146
Definition: reportcore.h:61
Definition: reportcore.h:61
QString rendererName
Definition: reportcore.h:70
Definition: pageinterface.h:305
Definition: scriptextensioninterface.h:44
#define CUTEREPORT_EXPORTS
Definition: cutereport_globals.h:47
QString url
Definition: reportcore.h:68
Definition: rendererinterface.h:49
Definition: exportinterface.h:44
MetricType
Definition: cutereport_types.h:166
Definition: baseiteminterface.h:107
QString destinationName
Definition: reportcore.h:71
Definition: storageinterface.h:56