KReport

KReportItemBase.cpp
1/* This file is part of the KDE project
2 * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
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#include "KReportItemBase.h"
19
20#include "KReportUtils.h"
21#include "KReportUtils_p.h"
22
23#include <KPropertySet>
24#include <KPropertyListData>
25#include <QApplication>
26#include <QDomElement>
27
28class Q_DECL_HIDDEN KReportItemBase::Private
29{
30public:
31 Private();
32 ~Private();
33
34 void setUnit(const KReportUnit& u, bool force)
35 {
36 if (!force && unit == u) {
37 return;
38 }
39 const QSignalBlocker blocker(set);
40 KReportUnit oldunit = unit;
41 unit = u;
42 // convert values
43
44 if (positionProperty) {
45 positionProperty->setValue(KReportUnit::convertFromUnitToUnit(
46 positionProperty->value().toPointF(), oldunit, u),
47 KProperty::ValueOption::IgnoreOld);
48
49 positionProperty->setOption("suffix", u.symbol());
50
51 }
52 if (sizeProperty) {
53 sizeProperty->setValue(
54 KReportUnit::convertFromUnitToUnit(sizeProperty->value().toSizeF(), oldunit, u),
55 KProperty::ValueOption::IgnoreOld);
56
57 sizeProperty->setOption("suffix", u.symbol());
58 }
59
60 }
61
62 KPropertySet *set;
63 KProperty *nameProperty;
64 KProperty *sizeProperty;
65 KProperty *positionProperty;
66 KProperty *dataSourceProperty = nullptr;
67 QString oldName;
68 qreal z = 0;
69 KReportUnit unit;
70};
71
72KReportItemBase::Private::Private()
73{
74 set = new KPropertySet();
75 nameProperty = new KProperty("name", QString(), tr("Name"), tr("Object Name"));
76 nameProperty->setValueSyncPolicy(KProperty::ValueSyncPolicy::FocusOut);
77
78 positionProperty = new KProperty("position", QPointF(), QCoreApplication::translate("ItemPosition", "Position"));
79 sizeProperty = new KProperty("size", QSizeF(), QCoreApplication::translate("ItemSize", "Size"));
80 setUnit(DEFAULT_UNIT, true);
81
82 set->addProperty(nameProperty);
83 set->addProperty(positionProperty);
84 set->addProperty(sizeProperty);
85}
86
87KReportItemBase::Private::~Private()
88{
89 delete set;
90}
91
92
93KReportItemBase::KReportItemBase() : d(new Private())
94{
96 this, &KReportItemBase::propertyChanged);
97
98 connect(propertySet(), &KPropertySet::aboutToDeleteProperty, this, &KReportItemBase::aboutToDeleteProperty);
99}
100
101KReportItemBase::~KReportItemBase()
102{
103 delete d;
104}
105
106void KReportItemBase::createDataSourceProperty()
107{
108 if (d->dataSourceProperty) {
109 return;
110 }
111 d->dataSourceProperty
112 = new KProperty("item-data-source", new KPropertyListData, QVariant(), tr("Data Source"));
113 d->dataSourceProperty->setOption("extraValueAllowed", true);
114 d->set->addProperty(d->dataSourceProperty);
115}
116
117bool KReportItemBase::parseReportTextStyleData(const QDomElement & elemSource, KReportTextStyleData *ts)
118{
119 return KReportUtils::parseReportTextStyleData(elemSource, ts);
120}
121
122bool KReportItemBase::parseReportLineStyleData(const QDomElement & elemSource, KReportLineStyle *ls)
123{
124 return KReportUtils::parseReportLineStyleData(elemSource, ls);
125}
126
127
128bool KReportItemBase::parseReportRect(const QDomElement & elemSource)
129{
130 const QRectF r(KReportUtils::readRectAttributes(elemSource, DEFAULT_ELEMENT_RECT_PT));
131 setPosition(r.topLeft());
132 setSize(r.size());
133 return true;
134}
135
136KReportUnit KReportItemBase::unit() const
137{
138 return d->unit;
139}
140
142{
143 d->setUnit(u, false);
144}
145
147 const QVariant &data, KReportScriptHandler* script)
148{
149 Q_UNUSED(page)
150 Q_UNUSED(section)
151 Q_UNUSED(offset)
152 Q_UNUSED(data)
153 Q_UNUSED(script)
154 return 0;
155}
156
158 KReportDataSource *dataSource, KReportScriptHandler* script)
159{
160 Q_UNUSED(page)
161 Q_UNUSED(section)
162 Q_UNUSED(offset)
163 Q_UNUSED(dataSource)
164 Q_UNUSED(script)
165 return 0;
166}
167
169{
170 return d->dataSourceProperty ? d->dataSourceProperty->value().toString() : QString();
171}
172
173void KReportItemBase::setItemDataSource(const QString& source)
174{
175 if (d->dataSourceProperty && d->dataSourceProperty->value() != source) {
176 d->dataSourceProperty->setValue(source);
177 }
178}
179
180KPropertySet* KReportItemBase::propertySet()
181{
182 return d->set;
183}
184
186{
187 return false;
188}
189
190QString KReportItemBase::entityName() const
191{
192 return d->nameProperty->value().toString();
193}
194
195void KReportItemBase::setEntityName(const QString& n)
196{
197 d->nameProperty->setValue(n);
198}
199
200KProperty* KReportItemBase::nameProperty()
201{
202 return d->nameProperty;
203}
204
205QString KReportItemBase::oldName() const
206{
207 return d->oldName;
208}
209
210void KReportItemBase::setOldName(const QString& old)
211{
212 d->oldName = old;
213}
214
215KProperty* KReportItemBase::dataSourceProperty()
216{
217 return d->dataSourceProperty;
218}
219
221{
222 return d->unit.convertToPoint(d->positionProperty->value().toPointF());
223}
224
226{
227 return d->unit.convertToPoint(d->sizeProperty->value().toSizeF());
228}
229
230const KPropertySet * KReportItemBase::propertySet() const
231{
232 return d->set;
233}
234
236{
237 const qreal x = POINT_TO_INCH(ptPos.x()) * KReportPrivate::dpiX();
238 const qreal y = POINT_TO_INCH(ptPos.y()) * KReportPrivate::dpiY();
239 return QPointF(x, y);
240}
241
243{
244 const qreal w = POINT_TO_INCH(ptSize.width()) * KReportPrivate::dpiX();
245 const qreal h = POINT_TO_INCH(ptSize.height()) * KReportPrivate::dpiY();
246 return QSizeF(w, h);
247}
248
250{
251 return d->z;
252}
253
255{
256 d->z = z;
257}
258
260{
261 d->positionProperty->setValue(d->unit.convertFromPoint(ptPos));
262}
263
265{
266 d->sizeProperty->setValue(d->unit.convertFromPoint(ptSize));
267}
268
270{
271 const qreal x = INCH_TO_POINT(pos.x() / KReportPrivate::dpiX());
272 const qreal y = INCH_TO_POINT(pos.y() / KReportPrivate::dpiY());
273 return QPointF(x, y);
274}
275
277{
278 qreal w = INCH_TO_POINT(size.width() / KReportPrivate::dpiX());
279 qreal h = INCH_TO_POINT(size.height() / KReportPrivate::dpiY());
280 return QSizeF(w, h);
281}
282
283void KReportItemBase::propertyChanged(KPropertySet& s, KProperty& p)
284{
285 Q_UNUSED(s)
286 Q_UNUSED(p)
287}
288
289void KReportItemBase::aboutToDeleteProperty(KPropertySet& set, KProperty& property)
290{
291 Q_UNUSED(set)
292 if (property.name() == "size") {
293 d->sizeProperty = nullptr;
294 }
295 else if (property.name() == "position") {
296 d->positionProperty = nullptr;
297 }
298}
void aboutToDeleteProperty(KPropertySet &set, KProperty &property)
void addProperty(KProperty *property, const QByteArray &group="common")
void propertyChanged(KPropertySet &set, KProperty &property)
QVariant value() const
void setValueSyncPolicy(ValueSyncPolicy policy)
bool setValue(const QVariant &value, ValueOptions options=ValueOptions())
void setOption(const char *name, const QVariant &val)
Abstraction of report data source.
Base class for items that are drawn syncronously.
static QPointF scenePosition(const QPointF &ptPos)
Helper function mapping to screen units (pixels), ptPos is in points.
void setSize(const QSizeF &ptSize)
Sets size for the element.
virtual int renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script)
Render the item into a primitive which is used by the second stage renderer.
QPointF position() const
Return the position in points.
void setZ(qreal z)
Sets the z-value for the element.
static QSizeF sceneSize(const QSizeF &ptSize)
Helper function mapping to screen units (pixels), ptSize is in points.
virtual bool supportsSubQuery() const
Override if the item uses a sub query and linked fields, such as a chart or sub-report.
void setPosition(const QPointF &ptPos)
Sets position for the element.
qreal z() const
Return the z-value in points.
QSizeF size() const
Return the size in points.
static QPointF positionFromScene(const QPointF &pos)
Helper function mapping from screen units to points, pos is in pixels.
static QSizeF sizeFromScene(const QSizeF &size)
Helper function mapping from screen units to points, size is in pixels.
virtual void setUnit(const KReportUnit &u)
Sets unit to a and converts values of position and size property from the old unit to new if needed.
virtual int renderReportData(OROPage *page, OROSection *section, const QPointF &offset, KReportDataSource *dataSource, KReportScriptHandler *script)
Render a complex item that uses a sub query as a data source.
QString itemDataSource() const
The KReportLineStyle class represents line style.
Converts between different units.
Definition KReportUnit.h:71
qreal convertFromPoint(qreal ptValue) const
static qreal convertFromUnitToUnit(qreal value, const KReportUnit &fromUnit, const KReportUnit &toUnit, qreal factor=1.0)
convert the given value directly from one unit to another with high accuracy
static QString symbol(KReportUnit::Type type)
Returns the symbol string of given unit type Symbol for Invalid type is empty string.
qreal convertToPoint(qreal value) const
Represents a single page in a document and may contain zero or more OROPrimitive objects all of which...
Represents a single a single row in a document and may contain zero or more OROPrimitives.
QString translate(const char *context, const char *sourceText, const char *disambiguation, int n)
QVariant property(const char *name) const const
QString tr(const char *sourceText, const char *disambiguation, int n)
qreal x() const const
qreal y() const const
qreal height() const const
qreal width() const const
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
QPointF toPointF() const const
QSizeF toSizeF() const const
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri May 24 2024 11:52:58 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.