MyBooks
pageinterface.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 PAGEINTERFACE_H
31 #define PAGEINTERFACE_H
32 
33 #include "reportplugininterface.h"
34 #include "cutereport_types.h"
35 
36 #include <QPointF>
37 #include <QRectF>
38 #include <QMap>
39 #include <QIcon>
40 #include <QString>
41 #include <QGraphicsRectItem>
42 #include <QWidget>
43 #include <QAction>
44 
45 
46 //static int RenderedPageInterfaceType = QGraphicsItem::UserType + 12789;
47 //static int PageViewInterfaceType = QGraphicsItem::UserType + 123754;
48 
49 class QGraphicsView;
50 class QGraphicsScene;
51 class QAction;
52 class QLabel;
53 
54 namespace CuteReport
55 {
56 
57 class BaseItemInterface;
58 class PageManipulatorInterface;
59 class ReportCore;
60 class RenderedPageInterface;
61 class PageViewInterface;
62 class RendererPublicInterface;
63 class DesignerItemInterface;
64 class PageHelperInterface;
65 class ScriptEngineInterface;
66 
67 class CUTEREPORT_EXPORTS PageAction {
68 public:
69  QAction * action;
70  QString name;
71  QString parentName;
72 };
73 
74 class CUTEREPORT_EXPORTS PageInterface : public ReportPluginInterface
75 {
76  Q_OBJECT
78 
79  Q_ENUMS(Unit)
80  Q_ENUMS(Orientation FillDirection PageFlag)
81 
82  Q_PROPERTY(Orientation orientation READ orientation WRITE setOrientation NOTIFY orientationChanged)
83  Q_PROPERTY(QString format READ format WRITE setFormat/* NOTIFY formatChanged*/)
84  Q_PROPERTY(QSizeF paperSize READ paperSize WRITE setPaperSize NOTIFY paperSizeChanged)
85  Q_PROPERTY(QString unit READ unitStr WRITE setUnitStr NOTIFY unitChanged)
86  Q_PROPERTY(int dpi READ dpi WRITE setDpi NOTIFY dpiChanged)
87  Q_PROPERTY(int columns READ columns WRITE setColumns NOTIFY columnsChanged)
88  Q_PROPERTY(FillDirection columnFillDirection READ fillDirection WRITE setFillDirection NOTIFY fillDirectionChanged)
89  Q_PROPERTY(QColor background READ background WRITE setBackground NOTIFY backgroundChanged)
90  Q_PROPERTY(int order READ order WRITE setOrder NOTIFY orderChanged)
91  Q_PROPERTY(QFont font READ font WRITE setFont NOTIFY fontChanged)
92 
93  //deprecated from v1.1 - will be removed in v1.3
94  Q_PROPERTY(qreal marginLeft READ marginLeft WRITE setMarginLeft NOTIFY marginLeftChanged DESIGNABLE false)
95  Q_PROPERTY(qreal marginTop READ marginTop WRITE setMarginTop NOTIFY marginTopChanged DESIGNABLE false)
96  Q_PROPERTY(qreal marginRight READ marginRight WRITE setMarginRight NOTIFY marginRightChanged DESIGNABLE false)
97  Q_PROPERTY(qreal marginBottom READ marginBottom WRITE setMarginBottom NOTIFY marginBottomChanged DESIGNABLE false)
98  // ----------------
99  // use margins instead
100  Q_PROPERTY(CuteReport::Margins margins READ margins WRITE setMargins NOTIFY marginsChanged)
101 
102  Q_PROPERTY(bool printOnPreviousPage READ printOnPreviousPage WRITE setPrintOnPreviousPage NOTIFY printOnPreviousPageChanged)
103  Q_PROPERTY(bool allowMirrorMargins READ allowMirrorMargins WRITE setAllowMirrorMargins NOTIFY allowMirrorMarginsChanged)
104  Q_PROPERTY(bool endlessWidth READ endlessWidth WRITE setEndlessWidth NOTIFY endlessWidthChanged)
105  Q_PROPERTY(bool endlessHeight READ endlessHeight WRITE setEndlessHeight NOTIFY endlessHeightChanged)
106  Q_PROPERTY(int pageFlags READ pageFlags WRITE setPageFlags NOTIFY pageFlagsChanged DESIGNABLE false)
107 
108  Q_PROPERTY(int _current_property READ _currentProperty WRITE _setCurrentProperty DESIGNABLE false STORED false)
109  Q_PROPERTY(QString _current_property_description READ _current_property_description DESIGNABLE false STORED false)
110  Q_PROPERTY(int _current_property_precision READ _current_property_precision DESIGNABLE false STORED false)
111  Q_PROPERTY(QIcon _icon READ icon DESIGNABLE false STORED false)
112 
113 public:
114  enum Orientation { Portrait = 0, Landscape = 1 };
115  enum FillDirection { Vertical = 0, Horizontal = 1 };
116 
117  enum PageFlag {
118  BaseReportPage = 0x0001,
119  };
120 
121  explicit PageInterface(QObject *parent = 0);
122  virtual ~PageInterface();
123 
124  virtual QIcon icon() = 0;
125 
126  virtual void init(){} // work after restoring
127 
128  virtual QList <BaseItemInterface*> items() const = 0;
129  virtual BaseItemInterface* item(const QString & objectName) const = 0;
130 
131  virtual PageHelperInterface * createHelper(CuteReport::DesignerItemInterface * designer) = 0;
132  virtual PageInterface * createInstance( QObject * parent=0) const = 0;
133  virtual PageInterface * clone(bool withChildren = true, bool init = true) const;
134 
135  virtual bool canContain(const QObject * object) = 0;
136 
137  // properties
138  virtual Orientation orientation() const = 0;
139  virtual void setOrientation(const Orientation & orientation) = 0;
140  virtual QString format() const =0;
141  virtual void setFormat(const QString & formatName)=0;
142  virtual QSizeF paperSize(Unit unit = UnitNotDefined) const = 0; // if NotDefined = use current page format
143  virtual void setPaperSize(const QSizeF & size, CuteReport::Unit unit = CuteReport::UnitNotDefined) = 0; // for custom formats
144  virtual QRectF pageRect(CuteReport::Unit unit = UnitNotDefined) = 0;
145  virtual qreal marginLeft(CuteReport::Unit unit = CuteReport::UnitNotDefined) const = 0;
146  virtual qreal marginTop(CuteReport::Unit unit = CuteReport::UnitNotDefined) const = 0;
147  virtual qreal marginRight(CuteReport::Unit unit = CuteReport::UnitNotDefined) const = 0;
148  virtual qreal marginBottom(CuteReport::Unit unit = CuteReport::UnitNotDefined) const = 0;
149  virtual void setMarginLeft(qreal margin, CuteReport::Unit unit = CuteReport::UnitNotDefined) = 0;
150  virtual void setMarginTop(qreal margin, CuteReport::Unit unit = CuteReport::UnitNotDefined) = 0;
151  virtual void setMarginRight(qreal margin, CuteReport::Unit unit = CuteReport::UnitNotDefined) = 0;
152  virtual void setMarginBottom(qreal margin, CuteReport::Unit unit = CuteReport::UnitNotDefined) = 0;
153  virtual void setMargins(const CuteReport::Margins & margins, CuteReport::Unit unit = CuteReport::UnitNotDefined) = 0;
154  virtual CuteReport::Margins margins(CuteReport::Unit unit = CuteReport::UnitNotDefined) const = 0;
155 // virtual CuteReport::Margins margins(CuteReport::Unit unit = CuteReport::UnitNotDefined) const = 0;
156  Q_SCRIPTABLE virtual void setMargins(qreal left, qreal top, qreal right, qreal bottom, CuteReport::Unit unit = CuteReport::UnitNotDefined) = 0;
157  virtual CuteReport::Unit unit() const = 0;
158  virtual void setUnit(const CuteReport::Unit &) = 0;
159  virtual QString unitStr() const = 0;
160  virtual void setUnitStr(const QString &) = 0;
161  virtual int dpi() const = 0;
162  virtual void setDpi(int dpi) = 0;
163  virtual QColor background() const = 0;
164  virtual void setBackground(const QColor & background) = 0;
165  virtual int columns() const {return 1;}
166  virtual void setColumns(int columns) {Q_UNUSED(columns);}
167  virtual FillDirection fillDirection() const {return Vertical;}
168  virtual void setFillDirection(FillDirection value) {Q_UNUSED(value);}
169  virtual int order() const = 0;
170  virtual void setOrder(int order) = 0;
171  virtual QFont font() const = 0;
172  virtual void setFont(const QFont & font) = 0;
173  virtual int pageFlags() const = 0;
174  virtual void setPageFlags(int flags, bool value = true) = 0;
175  virtual bool isPageFlagSet(int flag) = 0;
176 
177  virtual bool printOnPreviousPage() const {return false;}
178  virtual void setPrintOnPreviousPage(bool value) {Q_UNUSED(value)}
179  virtual bool allowMirrorMargins() const { return false;}
180  virtual void setAllowMirrorMargins(bool value) {Q_UNUSED(value)}
181  virtual bool endlessWidth() const {return false;}
182  virtual void setEndlessWidth(bool value) {Q_UNUSED(value)}
183  virtual bool endlessHeight() const {return false;}
184  virtual void setEndlessHeight(bool value) {Q_UNUSED(value)}
185 
186  virtual bool addItem(BaseItemInterface * item, QPointF pagePos, QString * error = 0) = 0;
187  virtual bool addItem(BaseItemInterface * item) = 0;
188  virtual BaseItemInterface * addItem(const QString & className, QPointF pagePos, QString * error = 0) = 0;
189  virtual void deleteItem(BaseItemInterface * item) = 0;
190  virtual void deleteItem(const QString & itemName) = 0;
191 
193 
195  virtual void renderInit(CuteReport::ScriptEngineInterface *scriptEngine) = 0;
197  virtual void renderStart() = 0;
198  virtual CuteReport::RenderedPageInterface * render(int customDPI = 0) = 0;
199  virtual void render(QPainter * /*painter*/, QPointF /*translate*/, const QRectF & /*clipRect*/){}
201  virtual void renderPagePlaced() {}
203  virtual void renderEnd() {}
204  virtual void renderReset(){}
205  virtual void renderPassStart(){}
206 
207  virtual BaseItemInterface * itemAt(QPointF pos) = 0;
208  virtual QList<BaseItemInterface *> itemsAt(QPointF pos) = 0;
209 
210  // GUI
211  virtual PageManipulatorInterface * createManupulator(QObject * parent = 0) = 0;
212  virtual int pageManupilatorID() = 0;
213  virtual QList<BaseItemInterface *> selectedItems() = 0;
214  virtual void setSelectedItems(QList<BaseItemInterface *> selected) = 0;
215  virtual BaseItemInterface * currentItem() = 0;
216  virtual void setCurrentItem(BaseItemInterface * item) = 0;
217  virtual QList <PageViewInterface *> views() = 0;
218  virtual PageViewInterface * createView(QWidget * parent = 0) = 0;
219  virtual CuteReport::PageViewInterface * createSimpleView(QWidget * parent = 0) = 0; // the simplest view without any additional elements like shadow, rulers, etc.
220  virtual QGraphicsItem * pageItem() = 0;
221 
222  // mapping units
223 // virtual QRectF mapFromPixel(QRectF rect, int customDPI = 0) = 0;
224 // virtual QPointF mapFromPixel(QPointF point, int customDPI = 0) = 0;
225 // virtual QRect mapToPixel(QRectF rect, int customDPI = 0) = 0;
226 // virtual QPoint mapToPixel(QPointF point, int customDPI = 0) = 0;
228 
229  virtual void _setCurrentProperty(int num) {m_currentProperty = num;}
230  virtual int _currentProperty() { return m_currentProperty;}
231  virtual QString _current_property_description() const;
232  virtual int _current_property_precision() const;
233 
234 signals:
235  //GUI methods
236  void itemHelperRequest(CuteReport::BaseItemInterface * item);
237  void pageHelperRequest();
238  void activeObjectChanged(QObject * object);
239  void beforeNewItemAdded(CuteReport::BaseItemInterface * item, bool * cancel);
240  void afterNewItemAdded(CuteReport::BaseItemInterface * item);
241  void beforeItemRemoved(CuteReport::BaseItemInterface* item, bool * cancel);
242  void afterItemRemoved(CuteReport::BaseItemInterface* item, QString itemName, bool directDeletion);
243  void itemGeometryChanged(BaseItemInterface * item, QRectF oldGeometry, QRectF newGeometry);
244  void viewCreated(PageViewInterface *);
245  void stdEditorListChanded(StdEditorPropertyList);
246 
247  //properties
248  void orientationChanged(Orientation newOrientation);
249  void formatChanged(QString newFormat);
250  void paperSizeChanged(QSizeF newFormatSize);
251  void pageRectChanged(QRectF newFormatSize);
252  void unitChanged(CuteReport::Unit newUnit);
253  void unitChanged(QString newUnit);
254  void dpiChanged(int newDpi);
255  // deprecated since 1.1
256  void marginLeftChanged(qreal margin);
257  void marginTopChanged(qreal margin);
258  void marginRightChanged(qreal margin);
259  void marginBottomChanged(qreal margin);
260  // ---------------
261  void marginsChanged(CuteReport::Margins);
262  void backgroundChanged(QColor);
263  void columnsChanged(int);
264  void fillDirectionChanged(FillDirection newFillDirection);
265  void orderChanged(int);
266  void fontChanged(const QFont &font);
267  void printOnPreviousPageChanged(bool value);
268  void allowMirrorMarginsChanged(bool value);
269  void endlessWidthChanged(bool value);
270  void endlessHeightChanged(bool value);
271  void pageFlagsChanged(int);
272 
273 protected:
274  PageInterface(const PageInterface &dd, QObject * parent);
275  virtual PageInterface * objectClone() const = 0;
276 
277  int m_currentProperty;
278 
279  friend class ReportCore;
280 };
281 
282 
283 /******************************************************************
284  *
285  * PageManipulatorInterface
286  *
287  ******************************************************************/
288 
289 class CUTEREPORT_EXPORTS PageManipulatorInterface : public QObject
290 {
291  Q_OBJECT
292 public:
293  explicit PageManipulatorInterface(QObject *parent = 0);
295 
296  virtual void setActivePage(PageInterface * page) = 0;
297  virtual PageInterface * activePage() = 0;
298  virtual int pageManupilatorId() = 0;
299 
300  virtual QList<PageAction*> actions() = 0;
301  virtual QList<QLabel*> statusBarLabels() = 0;
302 };
303 
304 
305 class CUTEREPORT_EXPORTS RenderedPageInterface: public QObject, public QGraphicsRectItem
306 {
307 public:
308  enum {Type = QGraphicsItem::UserType + 12789};
309  enum ShowFlag { ShowNothing = 0x00,
310  ShowBackground = 0x01,
311  ShowPaperBorder = 0x04,
312  ShowPageBorder = 0x08,
313  ShowDefaultPreview = ShowBackground | ShowPaperBorder /*| ShowPageBorder*/,
314  ShowDefaultExport = ShowPaperBorder,
315  ShowDefaultPrint = ShowNothing
316  };
317  Q_DECLARE_FLAGS(ShowFlags, ShowFlag)
318 
319  explicit RenderedPageInterface ( QGraphicsItem * parent = 0 ) :
320  QObject(),
321  QGraphicsRectItem(parent),
322  m_showFlags(ShowDefaultPreview)
323  {}
324  virtual ~RenderedPageInterface();
325 
326  virtual void setShowFlags(ShowFlags f) {m_showFlags = f;}
327  virtual ShowFlags showFlags() {return m_showFlags;}
328 
329  virtual CuteReport::PageInterface::Orientation orientation() const = 0;
330  //virtual CuteReport::Margins margins(CuteReport::Unit unit) const = 0;
331  virtual QRectF paperRect(CuteReport::Unit unit) const = 0;
332  virtual QSizeF paperSize(CuteReport::Unit unit) const = 0;
333  virtual QRectF pageRect(CuteReport::Unit unit) const = 0;
334  virtual QSizeF pageSize(CuteReport::Unit unit) const = 0;
335  virtual int dpi() const = 0;
336  virtual void setDpi(int dpi) = 0;
337 
338  virtual void redraw() = 0;
339 
340  virtual int type() const { return Type; }
341 
342 protected:
343  Q_DISABLE_COPY(RenderedPageInterface)
344  ShowFlags m_showFlags;
345 };
346 
347 
348 class CUTEREPORT_EXPORTS PageViewInterface: public QWidget
349 {
350 public:
351  explicit PageViewInterface(QWidget * parent = 0, Qt::WindowFlags f = 0 ):
352  QWidget(parent) { Q_UNUSED(f)}
353  virtual ~PageViewInterface(){}
354 
355  virtual void fit() = 0;
356 
357  //virtual int type() const { return PageViewInterfaceType; }
358 };
359 
360 
361 class CUTEREPORT_EXPORTS PageHelperInterface: public QWidget
362 {
363 public:
365  virtual ~PageHelperInterface() {}
366 
367  virtual void sync(){}
368  virtual bool screenBack(bool accept = true){Q_UNUSED(accept); return false;} //only one screen by default;
369 };
370 
371 
372 
373 } //namespace
374 
375 Q_DECLARE_OPERATORS_FOR_FLAGS( CuteReport::RenderedPageInterface::ShowFlags )
376 Q_DECLARE_METATYPE(CuteReport::PageAction)
377 Q_DECLARE_INTERFACE(CuteReport::PageInterface, "CuteReport.PageInterface/1.0")
378 Q_DECLARE_INTERFACE(CuteReport::RenderedPageInterface, "CuteReport.RenderedPageInterface/1.0")
379 Q_DECLARE_INTERFACE(CuteReport::PageViewInterface, "CuteReport.PageViewInterface/1.0")
380 
381 #endif // PAGEINTERFACE_H
virtual void renderPagePlaced()
called when the empty page is placed and before headers and footers placed
Definition: pageinterface.h:201
PageHelperInterface()
Definition: pageinterface.h:364
virtual void init()
Definition: pageinterface.h:126
virtual FillDirection fillDirection() const
Definition: pageinterface.h:167
Definition: abstractpainterdelegate.h:42
virtual ~PageManipulatorInterface()
Definition: pageinterface.h:294
virtual void sync()
Definition: pageinterface.h:367
QList< StdEditorProperty > StdEditorPropertyList
Definition: cutereport_types.h:262
PageFlag
Definition: pageinterface.h:117
virtual int columns() const
Definition: pageinterface.h:165
virtual bool printOnPreviousPage() const
Definition: pageinterface.h:177
virtual void renderReset()
Definition: pageinterface.h:204
Definition: pageinterface.h:74
virtual void setEndlessHeight(bool value)
Definition: pageinterface.h:184
virtual void setAllowMirrorMargins(bool value)
Definition: pageinterface.h:180
virtual void renderEnd()
called when the page is totally completed
Definition: pageinterface.h:203
virtual void setShowFlags(ShowFlags f)
Definition: pageinterface.h:326
virtual ShowFlags showFlags()
Definition: pageinterface.h:327
virtual void render(QPainter *, QPointF, const QRectF &)
Definition: pageinterface.h:199
Definition: pageinterface.h:361
ShowFlag
Definition: pageinterface.h:309
virtual void renderPassStart()
Definition: pageinterface.h:205
virtual bool screenBack(bool accept=true)
Definition: pageinterface.h:368
Definition: cutereport_types.h:103
virtual ~PageHelperInterface()
Definition: pageinterface.h:365
virtual int _currentProperty()
Definition: pageinterface.h:230
virtual void _setCurrentProperty(int num)
Definition: pageinterface.h:229
Definition: reportplugininterface.h:53
virtual void setColumns(int columns)
Definition: pageinterface.h:166
virtual void setFillDirection(FillDirection value)
Definition: pageinterface.h:168
Definition: pageinterface.h:348
virtual bool endlessWidth() const
Definition: pageinterface.h:181
virtual StdEditorPropertyList stdEditorList() const
Definition: pageinterface.h:227
virtual void setPrintOnPreviousPage(bool value)
Definition: pageinterface.h:178
virtual bool allowMirrorMargins() const
Definition: pageinterface.h:179
Orientation
Definition: cutereport_types.h:125
PageViewInterface(QWidget *parent=0, Qt::WindowFlags f=0)
Definition: pageinterface.h:351
Definition: cutereport_types.h:46
virtual int type() const
Definition: pageinterface.h:340
Definition: pageinterface.h:305
FillDirection
Definition: pageinterface.h:115
Definition: pageinterface.h:67
Orientation
Definition: pageinterface.h:114
#define CUTEREPORT_EXPORTS
Definition: cutereport_globals.h:47
virtual bool endlessHeight() const
Definition: pageinterface.h:183
Definition: cutereport_types.h:125
Unit
Definition: cutereport_types.h:95
Definition: baseiteminterface.h:107
Definition: reportcore.h:83
Definition: cutereport_types.h:125
Definition: pageinterface.h:289
virtual void setEndlessWidth(bool value)
Definition: pageinterface.h:182
virtual ~PageViewInterface()
Definition: pageinterface.h:353