KReport

KReportItemBase.h
1 /* This file is part of the KDE project
2  * Copyright (C) 2007-2010 by Adam Pigg ([email protected])
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library 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 GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef KREPORTITEMBASE_H
19 #define KREPORTITEMBASE_H
20 
21 #include "config-kreport.h"
22 #include "kreport_export.h"
23 #include "KReportUnit.h"
24 
25 #include <QObject>
26 #include <QFont>
27 #include <QColor>
28 
29 class OROPage;
30 class OROSection;
31 class KReportDataSource;
32 class KReportLineStyle;
33 
34 #ifdef KREPORT_SCRIPTING
35 class KReportScriptHandler;
36 #else
37 #define KReportScriptHandler void
38 #endif
39 
40 class KProperty;
41 class KPropertySet;
42 
43 class QDomElement;
44 
45 class KReportTextStyleData
46 {
47 public:
48  QFont font;
49  Qt::Alignment alignment;
50  QColor backgroundColor;
51  QColor foregroundColor;
52  int backgroundOpacity;
53 
54 };
55 
56 /*!
57  * @brief Base class for items that are drawn syncronously.
58  */
59 class KREPORT_EXPORT KReportItemBase : public QObject
60 {
61  Q_OBJECT
62 public:
63 
65  ~KReportItemBase() override;
66 
67  /**
68  @brief Return the item type as a string. Required by all items
69  @return Item type
70  */
71  virtual QString typeName() const = 0;
72 
73  /**
74  @brief Render the item into a primitive which is used by the second stage renderer
75  @return the height required by the object
76  */
77  virtual int renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script);
78 
79  /**
80  @brief Render a complex item that uses a sub query as a data source
81  @return the height required by the object
82  */
83  virtual int renderReportData(OROPage *page, OROSection *section, const QPointF &offset, KReportDataSource *dataSource, KReportScriptHandler *script);
84 
85  /**
86  @return The field name or expression for the data source
87  */
88  QString itemDataSource() const;
89 
90  void setItemDataSource(const QString &source);
91 
92  /**
93  @brief Override if the item uses a sub query and linked fields, such as a chart or sub-report
94  @return True if uses a sub query
95  */
96  virtual bool supportsSubQuery() const;
97 
98  KPropertySet* propertySet();
99  const KPropertySet* propertySet() const;
100 
101  void setEntityName(const QString& n);
102  QString entityName() const;
103 
104  KReportUnit unit() const;
105 
106  //! Sets unit to @a a and converts values of position and size property from the old
107  //! unit to new if needed.
108  virtual void setUnit(const KReportUnit &u);
109 
110  /**
111  * @brief Return the size in points
112  */
113  QSizeF size() const;
114 
115  /**
116  * @brief Return the position in points
117  */
118  QPointF position() const;
119 
120  /**
121  * @brief Sets position for the element
122  * @param ptPos Position in points
123  */
124  void setPosition(const QPointF &ptPos);
125 
126  /**
127  * @brief Sets size for the element
128  * @param ptSize Size in points
129  */
130  void setSize(const QSizeF &ptSize);
131 
132  /**
133  * @brief Return the z-value in points
134  */
135  qreal z() const;
136 
137  /**
138  * @brief Sets the z-value for the element
139  * @param z Z-value in points
140  */
141  void setZ(qreal z);
142 
143  //! Helper function mapping to screen units (pixels), @a ptPos is in points
144  static QPointF scenePosition(const QPointF &ptPos);
145 
146  //! Helper function mapping to screen units (pixels), @a ptSize is in points
147  static QSizeF sceneSize(const QSizeF &ptSize);
148 
149  //! Helper function mapping from screen units to points, @a pos is in pixels
150  static QPointF positionFromScene(const QPointF &pos);
151 
152  //! Helper function mapping from screen units to points, @a size is in pixels
153  static QSizeF sizeFromScene(const QSizeF &size);
154 
155 protected:
156  virtual void createProperties() = 0;
157  void createDataSourceProperty();
158  bool parseReportRect(const QDomElement &elem);
159  static bool parseReportTextStyleData(const QDomElement &, KReportTextStyleData*);
160  static bool parseReportLineStyleData(const QDomElement &, KReportLineStyle*);
161 
162  KProperty *nameProperty();
163  QString oldName() const;
164  void setOldName(const QString &old);
165  KProperty* dataSourceProperty();
166 
167  Q_SLOT virtual void propertyChanged(KPropertySet &s, KProperty &p);
168 
169 private:
171  class Private;
172  Private * const d;
173  Q_SLOT void aboutToDeleteProperty(KPropertySet& set, KProperty& property);
174 
175  friend class KReportDesignerItemRectBase;
176 };
177 
178 #endif
Base class for items that are drawn syncronously.
typedef Alignment
Converts between different units.
Definition: KReportUnit.h:70
The KReportLineStyle class represents line style.
Represents a single page in a document and may contain zero or more OROPrimitive objects all of which...
Abstraction of report data source.
Represents a single a single row in a document and may contain zero or more OROPrimitives.
Base class for rectangular report items used within the designer GUI.
Q_DISABLE_COPY(Class)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Fri Dec 1 2023 04:09:47 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.