MyBooks
baseiteminterface.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 BASEITEMINTERFACE_H
31 #define BASEITEMINTERFACE_H
32 
33 #include <QObject>
34 #include <QtCore>
35 #include <QGraphicsWidget>
36 #include <QPen>
37 #include <QWidget>
38 #include <QPolygonF>
39 #include <QIcon>
40 
41 #include "reportplugininterface.h"
42 #include "cutereport_types.h"
43 #include "cutereport_functions.h"
44 #include "cutereport_globals.h"
45 
46 #define ITEMVIEWTYPE QGraphicsItem::UserType + 101
47 
48 #define SAVEIFCHANGED(OLD, NEW) \
49  if (d-> OLD == NEW) \
50  return; \
51  d-> OLD = NEW;
52 
53 #define PROCESS_NEW_PROPERTY_VALUE(PropertyName, VALUE) \
54  if (d-> PropertyName == VALUE) \
55  return; \
56  d-> PropertyName = VALUE; \
57  if (d->state == CuteReport::NormalState) { \
58  emit PropertyName##Changed ( d-> PropertyName ); \
59  emit changed(); \
60  }
61 
62 #define PROCESS_NEW_PROPERTY_VALUE_WITH_GUI_UPDATE(PropertyName, VALUE) \
63  if (d-> PropertyName == VALUE) \
64  return; \
65  d-> PropertyName = VALUE; \
66  update_gui(); \
67  if (d->state == CuteReport::NormalState) { \
68  emit PropertyName##Changed ( d-> PropertyName ); \
69  emit changed(); \
70  }
71 
72 #define PROPERTY_CHANGE_SIGNALS(PropertyName) \
73  if (d->state == CuteReport::NormalState) { \
74  emit PropertyName##Changed ( d-> PropertyName ); \
75  emit changed(); \
76  }
77 
78 #define NOTPROPERTY_CHANGE_SIGNALS(SIGNALNAME, VARIABLE) \
79  if (d->state == NormalState) { \
80  emit SIGNALNAME ( VARIABLE ); \
81  emit changed(); \
82  }
83 
84 
85 
86 
87 
88 class QScriptEngine;
89 
90 namespace CuteReport
91 {
92 
93 class DesignerItemInterface;
94 class PageInterface;
95 class BaseItemHelperInterface;
96 class BaseItemInterfacePrivate;
97 class RenderedItemInterfacePrivate;
98 class ItemInterfaceView;
99 class RendererInterface;
100 class RenderedItemInterface;
101 class RendererPublicInterface;
102 class ReportInterface;
103 class ItemExternalDataInterface;
104 class ScriptEngineInterface;
105 
106 
108 {
109  Q_OBJECT
111 
112  Q_FLAGS(Frames)
114 
115  Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged)
116  Q_PROPERTY(QRectF geometry READ geometry WRITE setGeometry NOTIFY geometryChanged)
117 // Q_PROPERTY(QRectF boundingRect READ boundingRect NOTIFY boundingRectChanged) //if rotated
118  Q_PROPERTY(Frames frame READ frame WRITE setFrame NOTIFY frameChanged)
119  Q_PROPERTY(qreal opacity READ opacity WRITE setOpacity NOTIFY opacityChanged)
120  Q_PROPERTY(qreal rotation READ rotation WRITE setRotation NOTIFY rotationChanged)
121  Q_PROPERTY(QPen borderPen READ borderPen WRITE setBorderPen NOTIFY borderPenChanged)
122  Q_PROPERTY(QString borderType READ borderTypeStr WRITE setBorderTypeStr NOTIFY borderTypeChanged)
123  Q_PROPERTY(QBrush backgroundBrush READ backgroundBrush WRITE setBackgroundBrush NOTIFY backgroundBrushChanged)
124  Q_PROPERTY(int order READ order WRITE setOrder NOTIFY orderChanged)
125  Q_PROPERTY(int baseItemFlags READ baseItemFlags WRITE setBaseItemFlags NOTIFY baseItemFlagsChanged DESIGNABLE false)
126 
127  Q_PROPERTY(BorderType borderType READ borderType WRITE setBorderType NOTIFY borderTypeChanged DESIGNABLE false STORED false)
128  Q_PROPERTY(QStringList _borderType_variants READ _borderType_variants DESIGNABLE false STORED false)
129 
130  Q_PROPERTY(int _current_property READ _currentProperty WRITE _setCurrentProperty DESIGNABLE false STORED false)
131  Q_PROPERTY(QString _current_property_description READ _current_property_description DESIGNABLE false STORED false)
132  Q_PROPERTY(int _current_property_precision READ _current_property_precision DESIGNABLE false STORED false)
133  Q_PROPERTY(QIcon _icon READ itemIcon DESIGNABLE false STORED false)
134 
135 public:
140  };
141  Q_DECLARE_FLAGS(Frames, Frame)
142 
143  enum ResizeFlags {Fixed = 0,
144  ResizeLeft = 1,
145  ResizeRight = 2,
146  ResizeTop = 4,
147  ResizeBottom = 8,
148  FixedPos = 16
149  };
150 
151  enum BorderType { Middle = 0, Inner = 1, Outer = 2 };
152 
154  BaseReportItem = 0x0001,
155  LockedItem = 0x0002,
156  AutoRenamedFromBaseReport = 0x0004
157 // CanExtendWidthOnRendering = 0x0004,
158 // CanExtendHeightOnRendering = 0x0008,
159  };
160 
161  explicit BaseItemInterface(QObject * parent);
162  virtual ~BaseItemInterface();
163 
165  virtual bool moduleInit();
166 
168  virtual void init();
169 
170  virtual void check_gui();
171  virtual void update_gui();
172  virtual void init_gui() = 0;
173 
174  virtual BaseItemInterface * createInstance(QObject * parent) const = 0;
175  virtual BaseItemInterface * clone(bool withChildren = true, bool init = true) const;
176  virtual ItemExternalDataInterface * createDataObjectByTypeName(const QString & className) {Q_UNUSED(className); return 0;}
177 
178  virtual PageInterface * page() const;
179  virtual void setPage(PageInterface * page);
180  virtual BaseItemInterface * parentItem() const;
181  virtual void setParentItem(BaseItemInterface *parentItem);
182  CuteReport::ReportInterface * reportObject();
183  virtual int childLevel();
184  CuteReport::BandInterface * carrierBand();
185 
186  virtual BaseItemInterface * topmostChildAt(const QPointF & localPos);
187  virtual QList<BaseItemInterface *> childrenAt(const QPointF & localPos);
188  QList<BaseItemInterface *> allChildrenAt(const QPointF & localPos);
189 
190  virtual BaseItemHelperInterface * createHelper(CuteReport::DesignerItemInterface * designer) { Q_UNUSED(designer); return 0; }
191  virtual QByteArray serialize();
192  virtual void deserialize(QByteArray &data);
193 
194  virtual bool canContain(QObject * object);
195  virtual ItemInterfaceView * view();
196 // virtual void updateView();
197 
198  virtual void saveState();
199  virtual void restoreState();
200 
202  virtual void renderInit(CuteReport::ScriptEngineInterface *scriptEngine, CuteReport::InitFlags flags) = 0;
203 
205  virtual void renderReset();
206 
211  virtual bool renderBegin() = 0;
212 
214  virtual RenderedItemInterface * renderView(quint32 id) = 0;
215 
219  virtual bool renderEnd();
220 
221  virtual void renderPassStart() {}
222  virtual void renderPassEnd() {}
223  virtual void renderCannotFitToPage() {}
224 
226  virtual void renderSiblingsBefore(QList<BaseItemInterface*> siblings) {Q_UNUSED(siblings);}
228  virtual void renderSiblingsAfter(QList<BaseItemInterface*> siblings) {Q_UNUSED(siblings);}
229 
231  virtual bool selfRendering();
232 
234  virtual bool childrenSelfRendering();
235 
236  virtual QIcon itemIcon() const = 0;
237  virtual QString itemGroup() const = 0;
238  virtual int itemSortOrderInGroup() const {return 0;}
239 
240  virtual Unit unit() const;
241  virtual void setUnit(Unit unit);
242 
243  virtual QRectF geometry(Unit unit = UnitNotDefined) const;
244  virtual void setGeometry(const QRectF & rect, Unit unit = UnitNotDefined);
245  virtual qreal height(Unit unit = UnitNotDefined) const;
246  virtual void setHeight(qreal height, Unit unit = UnitNotDefined);
247  virtual qreal width(Unit unit = UnitNotDefined) const;
248  virtual void setWidth(qreal width, Unit unit = UnitNotDefined);
249  virtual QSizeF minSize(Unit unit = UnitNotDefined) const;
250  virtual QRectF boundingRect(Unit unit = UnitNotDefined, bool withTransformation = true, bool withBorder = true) const;
251  virtual QPolygonF polygon(Unit unit = UnitNotDefined) const;
252 
253  virtual qint8 frame() const;
254  virtual void setFrame(Frames frame);
255  virtual qreal opacity() const;
256  virtual void setOpacity(qreal opacity);
257  virtual qreal rotation() const;
258  virtual void setRotation(qreal angle);
259 
260  virtual QPen borderPen() const;
261  virtual void setBorderPen(const QPen & pen);
262  virtual QBrush backgroundBrush() const;
263  virtual void setBackgroundBrush(const QBrush & brush);
264 
265  virtual BorderType borderType() const;
266  virtual void setBorderType(BaseItemInterface::BorderType borderType);
267  virtual QString borderTypeStr() const;
268  virtual void setBorderTypeStr(const QString & borderType);
269 
270  int resizeFlags() const;
271 
272  int baseItemFlags() const;
273  void setBaseItemFlags(int flags, bool value = true);
274 // void setBaseItemFlag(int flag, bool value = true);
275  bool isBaseItemFlagSet(int flag);
276 
277  virtual bool enabled() const;
278  virtual void setEnabled(bool b = true);
279 
280  virtual int order() const;
281  virtual void setOrder(int order);
282 
283  virtual void setDpi(int dpi);
284  virtual int dpi() const;
285 
286  virtual bool isSplitAllowed() const {return false;}
287 
288  virtual QList<CuteReport::InternalStringData> renderingStrings(){return QList<InternalStringData>();}
289 
290  // common painter
291  static void paintBegin(QPainter * painter, const QStyleOptionGraphicsItem *option, BaseItemInterfacePrivate * data, const QRectF &boundingRect = QRectF(), RenderingType type = RenderingTemplate);
292  static void paintEnd(QPainter * painter, const QStyleOptionGraphicsItem *option, BaseItemInterfacePrivate *data, const QRectF &boundingRect = QRectF(), RenderingType type = RenderingTemplate);
293  static QRectF paintArea(const BaseItemInterfacePrivate * data, const QRectF &boundingRect = QRectF());
294  static qreal borderWidth(const BaseItemInterfacePrivate * data, Unit unit = UnitNotDefined, qreal *insideWidth = 0, qreal *outsideWidth = 0);
295 
296  virtual QTransform transform() const;
297 
298  // values in local unit
299  // NotDefined = default item meassure
300  QRectF mapFromPage(const QRectF & rect, Unit inputUnit = UnitNotDefined, Unit outputUnit = UnitNotDefined) const;
301  QPointF mapFromPage(const QPointF & point, Unit inputUnit = UnitNotDefined, Unit outputUnit = UnitNotDefined) const;
302  QRectF mapToPage(const QRectF & rect, Unit inputUnit = UnitNotDefined, Unit outputUnit = UnitNotDefined) const;
303  QPointF mapToPage(const QPointF & point, Unit inputUnit = UnitNotDefined, Unit outputUnit = UnitNotDefined) const;
304  QRectF mapToParent(const QRectF & rect, Unit inputUnit = UnitNotDefined, Unit outputUnit = UnitNotDefined) const ;
305  QPointF mapToParent(const QPointF & point, Unit inputUnit = UnitNotDefined, Unit outputUnit = UnitNotDefined) const;
306  QRectF mapFromParent(const QRectF & rect, Unit inputUnit = UnitNotDefined, Unit outputUnit = UnitNotDefined) const ;
307  QPointF mapFromParent(const QPointF & point, Unit inputUnit = UnitNotDefined, Unit outputUnit = UnitNotDefined) const;
308  QRectF absoluteGeometry(Unit outputUnit = UnitNotDefined) const;
309  void setAbsoluteGeometry(const QRectF & rect, Unit inputUnit = UnitNotDefined);
310  QRectF absoluteBoundingRect(Unit unit = UnitNotDefined, bool withTransformation = true, bool withBorder = true) const;
311  QPolygonF absolutePolygon(Unit unit = UnitNotDefined) const;
312 
314  static QFont fontPrepared(const QFont & font, qint16 dpi);
315  static QPen penPrepared(const QPen & pen, qint16 dpi);
316  static QTransform transform(const BaseItemInterfacePrivate *d);
317  static QPointF transformedPos(const BaseItemInterfacePrivate *d, const QRectF &rect);
318 
319  static BorderType borderTypeFromString(const QString & bType);
320  static QString borderTypeToString(BorderType bType);
321 
322  virtual StdEditorPropertyList stdEditorList() const;
323 
324  QStringList _borderType_variants();
325 
326  virtual void _setCurrentProperty(int num) {m_currentProperty = num;}
327  virtual int _currentProperty() { return m_currentProperty;}
328  virtual QString _current_property_description() const;
329  virtual int _current_property_precision() const;
330 
331  virtual TemplateItemDetailLevel templateDetailLevel();
332  virtual void setTemplateDetailLevel(const TemplateItemDetailLevel &value);
333 
334  static TemplateItemDetailLevel defaultTemplateDetailLevel();
335  static void setDefaultTemplateDetailLevel(const TemplateItemDetailLevel &value);
336 
337  void aboutToBeDeleted();
338 
339 signals:
340  void unitChanged(Unit);
341  void geometryChanged(QRectF newGeometry);
342  void opacityChanged(qreal newOpacity);
343  void frameChanged(Frames);
344  void rotationChanged(qreal angle);
345  void borderPenChanged(QPen pen);
346  void backgroundBrushChanged(QBrush brush);
347  void dpiChanged(int dpi);
348  void enabledChanged(bool);
349  void orderChanged(int);
350  void parentItemChanged(CuteReport::BaseItemInterface * parent);
351  void renderingStringsChanged();
352  void stdEditorListChanded(StdEditorPropertyList);
353  void borderTypeChanged(BorderType);
354  void borderTypeChanged(QString);
355  void baseItemFlagsChanged(int);
356 
357  void boundingRectChanged();
358 
360  void printInit();
361 
363  void printReset();
364 
368  void printCreateBefore();
369 
374  void printDataBefore();
375 
380  void printBefore();
381 
385  void printAfter();
386 
387 public slots:
388 // void updateViewIfExists();
389 
390 protected:
391  BaseItemInterface(BaseItemInterfacePrivate *dd, QObject * parent);
392  virtual BaseItemInterface * itemClone() const = 0;
393  void pushContext(BaseItemInterfacePrivate * r);
394  void popContext();
395 
396  virtual void childAdded(BaseItemInterface * item) { Q_UNUSED(item); }
397  virtual void childRemoved(BaseItemInterface * item) { Q_UNUSED(item); }
398 
399  void setResizeFlags(int resizeFlags);
400  static const QRectF adjustRect(QRectF & rect, const QPen & pen);
401  virtual void adjustOrder();
402  virtual void updateMeassure();
403 
404 protected:
405  void renderInitBase(CuteReport::ScriptEngineInterface *scriptEngine, CuteReport::InitFlags flags);
406  void rendererBeginBaseStart(BaseItemInterfacePrivate *p);
407  void rendererBeginBaseEnd();
408  void renderResetBase();
409 
410  BaseItemInterfacePrivate * d_ptr;
411  BaseItemInterfacePrivate * orig_ptr;
412  QList <BaseItemInterfacePrivate*> dataStack;
413  ItemInterfaceView * m_gui;
416 // bool m_inited;
419 
421 
422 private:
423  void initMe();
424  Q_DECLARE_PRIVATE(BaseItemInterface)
425 
426  friend class ReportCore;
427  friend class BaseRenderedItemInterface;
428  friend class ItemInterfaceView;
429 };
430 
431 
433 {
434 public:
435  virtual void sync(){}
436  virtual bool screenBack(bool accept = true){Q_UNUSED(accept); return false;} //only one screen by default;
437 };
438 
439 
440 Q_DECLARE_OPERATORS_FOR_FLAGS(BaseItemInterface::Frames)
441 //Q_DECLARE_OPERATORS_FOR_FLAGS(BaseItemInterface::BaseItemFlags)
442 } // namespace
443 
444 Q_DECLARE_INTERFACE(CuteReport::BaseItemInterface, "CuteReport.BaseItemInterface/1.0")
445 Q_DECLARE_METATYPE(CuteReport::BaseItemInterface*)
446 Q_DECLARE_METATYPE(CuteReport::BaseItemInterface::Frame)
450 
451 #endif // BASEITEMINTERFACE_H
Definition: abstractpainterdelegate.h:42
virtual void childRemoved(BaseItemInterface *item)
Definition: baseiteminterface.h:397
virtual ItemExternalDataInterface * createDataObjectByTypeName(const QString &className)
Definition: baseiteminterface.h:176
virtual bool screenBack(bool accept=true)
Definition: baseiteminterface.h:436
QList< StdEditorProperty > StdEditorPropertyList
Definition: cutereport_types.h:262
virtual QList< CuteReport::InternalStringData > renderingStrings()
Definition: baseiteminterface.h:288
Definition: cutereport_types.h:111
Definition: bandinterface.h:44
Definition: cutereport_types.h:109
RenderingType
Definition: cutereport_types.h:177
Definition: cutereport_types.h:178
Definition: pageinterface.h:74
TODO v2: rename to ReportObject.
Definition: reportinterface.h:71
virtual void renderSiblingsBefore(QList< BaseItemInterface *> siblings)
Definition: baseiteminterface.h:226
virtual void _setCurrentProperty(int num)
Definition: baseiteminterface.h:326
TemplateItemDetailLevel
for Designer
Definition: cutereport_types.h:268
BaseItemFlag
Definition: baseiteminterface.h:153
int m_currentProperty
Definition: baseiteminterface.h:417
virtual void renderCannotFitToPage()
Definition: baseiteminterface.h:223
Definition: cutereport_types.h:103
ResizeFlags
Definition: baseiteminterface.h:143
Frame
Definition: baseiteminterface.h:136
Definition: baseiteminterface.h:432
Definition: reportplugininterface.h:53
Definition: cutereport_types.h:110
BorderType
Definition: baseiteminterface.h:151
ItemInterfaceView * m_gui
Definition: baseiteminterface.h:413
BaseItemInterface * m_parentItem
Definition: baseiteminterface.h:415
virtual void renderSiblingsAfter(QList< BaseItemInterface *> siblings)
Definition: baseiteminterface.h:228
BaseItemInterfacePrivate * orig_ptr
Definition: baseiteminterface.h:411
BaseItemInterfacePrivate * d_ptr
Definition: baseiteminterface.h:410
virtual void childAdded(BaseItemInterface *item)
Definition: baseiteminterface.h:396
virtual BaseItemHelperInterface * createHelper(CuteReport::DesignerItemInterface *designer)
Definition: baseiteminterface.h:190
virtual int _currentProperty()
Definition: baseiteminterface.h:327
static TemplateItemDetailLevel g_templateDetailLevel
Definition: baseiteminterface.h:420
#define CUTEREPORT_EXPORTS
Definition: cutereport_globals.h:47
virtual void sync()
Definition: baseiteminterface.h:435
TemplateItemDetailLevel m_templateDetailLevel
Definition: baseiteminterface.h:418
QList< BaseItemInterfacePrivate * > dataStack
Definition: baseiteminterface.h:412
virtual void renderPassStart()
Definition: baseiteminterface.h:221
Unit
Definition: cutereport_types.h:95
virtual int itemSortOrderInGroup() const
Definition: baseiteminterface.h:238
Definition: cutereport_types.h:108
Definition: baseiteminterface.h:107
virtual bool isSplitAllowed() const
Definition: baseiteminterface.h:286
Definition: reportcore.h:83
virtual void renderPassEnd()
Definition: baseiteminterface.h:222
PageInterface * m_page
Definition: baseiteminterface.h:414