MyBooks
reportinterface.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 REPORTINTERFACE_H
31 #define REPORTINTERFACE_H
32 
33 #include <QObject>
34 #include <QPointer>
35 #include <QPointF>
36 #include <QHash>
37 #include <QVariant>
38 #include <QSet>
39 
40 #include "cutereport_globals.h"
41 
42 namespace CuteReport
43 {
44 
45 class ReportCore;
46 class BaseItemInterface;
47 class DatasetInterface;
48 class PageInterface;
49 class RendererInterface;
50 class PrinterInterface;
51 class FormInterface;
52 class StorageInterface;
53 class RenderedReportInterface;
54 class RendererPublicInterface;
55 class ScriptEngineInterface;
56 class InheritanceDataContainer;
57 
58 typedef QPointer<QObject> ObjectPointer;
59 
61 public:
63  QString baseReportPath;
64  QString baseReportName;
65  QHash<QString, QHash<QString, QVariant> > itemData; //itemName, <propertyName, changedValue>
66 // QHash<QString, QHash<QString, QPair<QVariant, QVariant> > > itemData; //itemName, <propertyName, pair(changedValue, origValue) >
67 };
68 
70 
71 class CUTEREPORT_EXPORTS ReportInterface : public QObject
72 {
73 
74  Q_OBJECT
75 
76  Q_PROPERTY(QString name READ name WRITE setName NOTIFY nameChanged)
77  Q_PROPERTY(QString author READ author WRITE setAuthor NOTIFY authorChanged)
78  Q_PROPERTY(QString description READ description WRITE setDescription NOTIFY descriptionChanged)
79  Q_PROPERTY(QString script READ script WRITE setScript DESIGNABLE false NOTIFY scriptChanged)
80  Q_PROPERTY(int version READ version WRITE setVersion DESIGNABLE false)
81  Q_PROPERTY(QString fileUrl READ fileUrl WRITE setFileUrl NOTIFY fileUrlChanged STORED false)
82  Q_PROPERTY(QString defaultStorage READ defaultStorageName WRITE setDefaultStorageName NOTIFY defaultStorageChanged)
83  Q_PROPERTY(QString defaultRenderer READ defaultRendererName WRITE setDefaultRendererName NOTIFY defaultRendererChanged)
84  Q_PROPERTY(QString defaultPrinter READ defaultPrinterName WRITE setDefaultPrinterName NOTIFY defaultPrinterChanged)
85  Q_PROPERTY(QVariantHash variables READ variables WRITE setVariables NOTIFY variablesChanged DESIGNABLE false)
86  Q_PROPERTY(QVariantHash customData READ customDataAll WRITE setCustomDataAll NOTIFY customDataChanged DESIGNABLE false)
87  Q_PROPERTY(QVariantHash inheritanceData READ inheritanceDataHash WRITE setInheritanceDataHash NOTIFY inheritanceDataChanged DESIGNABLE false)
88 
89 public:
90 
91  enum ReportFlag {
92  VariablesAutoUpdate = 0x01,
93  DirtynessAutoUpdate = 0x02
94  };
95  Q_DECLARE_FLAGS(ReportFlags, ReportFlag)
96  // WARNING do not include QScriptEngine: all custom application will need to add it to pro
97 // struct FunctionValue
98 // {
99 // QScriptEngine::FunctionSignature function;
100 // int args;
101 // QScriptValue::PropertyFlags flags;
102 // };
103 
104 // typedef QMap<QString, FunctionValue> FunctionValues;
105 
106 // struct ReportValue
107 // {
108 // QVariant value;
109 // QScriptValue::PropertyFlags flags;
110 // };
111 
112 // typedef QMap<QString, ReportValue> ReportValues;
113 
114  ~ReportInterface();
115 
116  ReportInterface * clone(bool withChildren = true, bool init = true);
117 
118  void init();
119 
120  QString name();
121  void setName(const QString & name);
122 
123  QString author();
124  void setAuthor(const QString & author);
125 
126  virtual QString script();
127  virtual void setScript(const QString & script);
128 
129  double version();
130  void setVersion(double tVersion);
131 
132  QString description();
133  void setDescription(const QString & description);
134 
135  QString fileUrl();
136  void setFileUrl(const QString & fileUrl);
137 
138  QList<CuteReport::BaseItemInterface *> items(const QString & pageObjectName = QString());
139  CuteReport::BaseItemInterface * item (const QString & itemName);
140  QStringList itemNames(const QString &pageObjectName = QString());
141 
142  QList<CuteReport::PageInterface *> pages();
143  QStringList pageNames();
144  CuteReport::PageInterface * page(const QString & pageName);
145  void addPage (CuteReport::PageInterface * page);
146  void deletePage(CuteReport::PageInterface * page);
147  void deletePage(const QString & pageName);
148 
149  QList<CuteReport::DatasetInterface *> datasets();
150  QStringList datasetNames();
151  CuteReport::DatasetInterface * dataset(const QString & datasetName);
152  void addDatasets(QList<CuteReport::DatasetInterface *> datasets);
153  void addDataset(CuteReport::DatasetInterface* dataset);
154  void deleteDataset(CuteReport::DatasetInterface* dataset);
155  void deleteDataset(const QString & datasetName);
156 
157  QList<CuteReport::RendererInterface *> renderers();
158  QStringList rendererNames();
159  CuteReport::RendererInterface * renderer(const QString & rendererName = QString());
160  void addRenderer(RendererInterface * renderer);
161  void deleteRenderer(CuteReport::RendererInterface * renderer);
162  void deleteRenderer(const QString & rendererName);
163  QString defaultRendererName() const;
164  void setDefaultRendererName(const QString &name);
165 
166  QList<CuteReport::PrinterInterface *> printers();
167  QStringList printerNames();
168  CuteReport::PrinterInterface * printer(const QString & printerName = QString());
169  void addPrinter(CuteReport::PrinterInterface *printer);
170  void deletePrinter(CuteReport::PrinterInterface * printer);
171  void deletePrinter(const QString & printerName);
172  QString defaultPrinterName() const;
173  void setDefaultPrinterName(const QString &name);
174 
175  CuteReport::StorageInterface * storage(const QString & objectName) const;
176  QStringList storageNames() const;
177  CuteReport::StorageInterface * storageByUrl(const QString & url) const;
178  QList<CuteReport::StorageInterface*> storageListByScheme(const QString & scheme) const;
179  QList<CuteReport::StorageInterface*> storageListByModuleName(const QString & moduleName) const;
180  QList<StorageInterface *> storages() const;
181  void addStorage(CuteReport::StorageInterface *storage);
182  void deleteStorage(const QString & storageName);
183  void deleteStorage(StorageInterface * storage);
184  bool hasStorageModule(const QString & moduleName);
185  QString defaultStorageName() const;
186  void setDefaultStorageName(const QString &name);
187 
188  QList<CuteReport::FormInterface*> forms();
189  CuteReport::FormInterface* form(const QString & formName);
190  void addForm(CuteReport::FormInterface * form );
191  void deleteForm(CuteReport::FormInterface * form );
192 
193  virtual int suitId();
194 
195  const QVariantHash & variables();
196  void setVariables(const QVariantHash &vars);
197  void setVariableValue(const QString & name, const QVariant & value);
198  QVariant variableValue(const QString & name);
199  bool variableExists(const QString & name);
200  void renameVariable(const QString & oldName, const QString & newName);
201  void removeVariable(const QString & name);
202 
204  QStringList variableObjectsNames();
205  void setVariableObject(const QString & name, QObject * object);
206  QObject *variableObject(const QString & name);
207 
208  QVariant customData(const QString & dataName) const;
209  void setCustomData(const QString & dataName, const QVariant &customData);
210  void setCustomData(const QVariantHash &customData);
211  void clearCustomData(const QString & dataName);
212  QVariantHash customDataAll() const;
213  void setCustomDataAll(const QVariantHash &customData);
214 
215  void setFlags(ReportFlags flags);
216  void setFlag(ReportFlag flag, bool enable);
217  bool isFlagSet(ReportFlag flag);
218  ReportFlags flags();
219 
220  bool isDirty() const;
221  bool isValid() const;
222 
223  void rendererInit(CuteReport::ScriptEngineInterface *scriptEngine);
224  void rendererReset();
225  bool isBeingRendered();
226  RenderedReportInterface *renderedReport() const;
227  void setRenderedReport(RenderedReportInterface *renderedReport);
228  void clearRenderedReport();
229 
231  void setModuleVariable(const QString & var, const QString & fullModuleName);
232  void removeModuleVariable(const QString & var, const QString & fullModuleName);
233  void setModuleVariables(const QSet<QString> & vars);
234  void removeModuleVariables(const QSet<QString> & vars);
235 
236  void setLocaleName(const QString & localeName);
237  QString localeName() const;
238 
239  QVariantHash inheritanceDataHash() const;
240  void setInheritanceDataHash(const QVariantHash & data);
241 
242  const InheritanceDataContainer & inheritanceData() const;
243  void setInheritanceData(const InheritanceDataContainer &data);
244 
245 public slots:
246  void updateVariables();
247  void setDirty(bool b = true);
248  void setValid(bool b = true);
249  void setInvalid();
250 
251 signals:
252  void nameChanged(QString);
253  void authorChanged(QString);
254  void descriptionChanged(QString);
255  void scriptChanged(QString);
256  void fileUrlChanged(QString);
257  void rendererAdded(CuteReport::RendererInterface*);
258  void rendererDeleted(CuteReport::RendererInterface*);
259  void rendererDeleted(QString rendererName);
260  void printerAdded(CuteReport::PrinterInterface*);
261  void printerDeleted(CuteReport::PrinterInterface*);
262  void printerDeleted(QString printerName);
263  void storageAdded(CuteReport::StorageInterface*);
264  void storageDeleted(CuteReport::StorageInterface*);
265  void storageDeleted(QString storageName);
266  void datasetAdded(CuteReport::DatasetInterface * dataset);
267  void datasetDeleted(CuteReport::DatasetInterface * dataset);
268  void datasetDeleted(QString datasetName);
269  void formAdded(CuteReport::FormInterface*);
270  void formDeleted(CuteReport::FormInterface*);
271  void pageAdded(CuteReport::PageInterface*);
272  void pageDeleted(CuteReport::PageInterface*);
273  void itemAdded(CuteReport::BaseItemInterface*);
274  void itemDeleted(CuteReport::BaseItemInterface*, bool);
275  void defaultStorageChanged(QString);
276  void defaultRendererChanged(QString);
277  void defaultPrinterChanged(QString);
278  void variablesChanged();
279  void dirtynessChanged(bool);
280  void validityChanged(bool);
281  void changed();
282  void propertyChanged();
283  void customDataChanged();
284  void customDataByNameChanged(QString dataName);
285  void baseReportPathChanged(QString path);
286  void baseReportNameChanged(QString path);
287  void inheritanceDataChanged();
288 
289 private slots:
290  void childDestroyed(QObject * object);
291  void slotItemAdded(CuteReport::BaseItemInterface *item);
292  void slotItemRemoved(CuteReport::BaseItemInterface* item, QString, bool directDeletion);
293  void slotScriptStringsChanged();
294  void slotNewItemAdded(CuteReport::BaseItemInterface* item);
295 
296 protected:
297  explicit ReportInterface(CuteReport::ReportCore *reportCore);
298  explicit ReportInterface(const ReportInterface & dd, CuteReport::ReportCore *reportCore);
299 
300  void precessFlags(ReportInterface::ReportFlags previousFlags);
301  void setUniqueName(QObject * object, const QString &proposedName = QString());
302 
303  QString m_name;
304  QString m_author;
305  QString m_script;
306  double m_version;
307  QString m_description;
308  QString m_fileUrl;
312  QVariantHash m_variables;
313  QHash<QString, ObjectPointer> m_variableObjects;
314  ReportFlags m_flags;
315  bool m_isDirty;
316  bool m_isValid;
317  QVariantHash m_customData;
318  QSet<QString> m_moduleVariables;
319  QString m_localeName;
320  InheritanceDataContainer * m_inheritanceData;
321 
322  RenderedReportInterface * m_renderedReport;
323 
324  // TODO: implement as shared private class to copy data
325  QVariantHash _m_variables;
326  QHash<QString, ObjectPointer> _m_variableObjects;
327  ReportFlags _m_flags;
329 
330  friend class ReportCore;
331 };
332 
333 
334 } //namespace
335 
336 Q_DECLARE_OPERATORS_FOR_FLAGS(CuteReport::ReportInterface::ReportFlags)
337 
338 
339 #endif
QString m_defaultRendererName
Definition: reportinterface.h:310
Definition: forminterface.h:45
QString m_name
Definition: reportinterface.h:303
Definition: abstractpainterdelegate.h:42
InheritanceData()
Definition: reportinterface.h:62
QString m_author
Definition: reportinterface.h:304
QVariantHash m_customData
Definition: reportinterface.h:317
Definition: reportinterface.h:60
Definition: datasetinterface.h:56
double m_version
Definition: reportinterface.h:306
bool m_isDirty
Definition: reportinterface.h:315
QVariantHash _m_variables
Definition: reportinterface.h:325
Definition: pageinterface.h:74
bool m_isValid
Definition: reportinterface.h:316
Definition: printerinterface.h:44
TODO v2: rename to ReportObject.
Definition: reportinterface.h:71
ReportFlag
Definition: reportinterface.h:91
QString m_fileUrl
Definition: reportinterface.h:308
ReportFlags m_flags
Definition: reportinterface.h:314
QString baseReportPath
Definition: reportinterface.h:63
QSet< QString > m_moduleVariables
Definition: reportinterface.h:318
QString baseReportName
Definition: reportinterface.h:64
InheritanceDataContainer * m_inheritanceData
Definition: reportinterface.h:320
QString m_description
Definition: reportinterface.h:307
QString m_localeName
Definition: reportinterface.h:319
QVariantHash m_variables
Definition: reportinterface.h:312
RenderedReportInterface * m_renderedReport
Definition: reportinterface.h:322
QString m_defaultPrinterName
Definition: reportinterface.h:311
QHash< QString, ObjectPointer > m_variableObjects
Definition: reportinterface.h:313
ReportFlags _m_flags
Definition: reportinterface.h:327
#define CUTEREPORT_EXPORTS
Definition: cutereport_globals.h:47
QHash< QString, ObjectPointer > _m_variableObjects
Definition: reportinterface.h:326
Definition: rendererinterface.h:49
QPointer< QObject > ObjectPointer
Definition: reportinterface.h:56
bool m_isBeingRendered
Definition: reportinterface.h:328
QString m_defaultStorageName
Definition: reportinterface.h:309
Definition: baseiteminterface.h:107
QString m_script
Definition: reportinterface.h:305
Definition: reportcore.h:83
QHash< QString, QHash< QString, QVariant > > itemData
Definition: reportinterface.h:65
Definition: storageinterface.h:56