20#include "KReportSectionData.h"
21#include "KReportDesigner.h"
22#include "KReportDocument.h"
23#include "KReportItemLine.h"
24#include "KReportPluginInterface.h"
25#include "KReportPluginManager.h"
26#include "KReportItemLine.h"
27#include "KReportDesigner.h"
28#include "KReportUtils.h"
29#include "KReportUtils_p.h"
30#include "kreport_debug.h"
32#include <KPropertySet>
39 explicit Private(KReportSectionData *data,
const QDomElement &elemSource) : q(data)
41 if (!elemSource.
isNull()) {
42 q->setObjectName(elemSource.tagName());
43 type = sectionTypeFromString(KReportUtils::readSectionTypeNameAttribute(elemSource));
45 createProperties(elemSource);
46 if (!elemSource.
isNull()) {
49 set.clearModifiedFlags();
57 void setHeight(qreal ptHeight, KProperty::ValueOptions options);
59 static bool zLessThan(KReportItemBase* s1, KReportItemBase* s2);
60 static bool xLessThan(KReportItemBase* s1, KReportItemBase* s2);
62 KReportSectionData *
const q;
64 KProperty *backgroundColor;
66 QList<KReportItemBase *> objects;
67 KReportUnit unit = KReportUnit(DEFAULT_UNIT_TYPE);
72 void createProperties(
const QDomElement &elemSource);
73 void loadXml(
const QDomElement &elemSource);
76KReportSectionData::KReportSectionData(
QObject *parent)
82 :
QObject(parent), d(new Private(this, elemSource))
86void KReportSectionData::Private::loadXml(
const QDomElement &elemSource)
88 if (q->objectName() != QLatin1String(
"report:section") || type == KReportSectionData::Type::None) {
93 KReportPluginManager* manager = KReportPluginManager::self();
95 QDomNodeList section = elemSource.
childNodes();
96 for (
int nodeCounter = 0; nodeCounter < section.
count(); nodeCounter++) {
100 KReportItemBase *krobj =
nullptr;
101 QString reportItemName = n.
mid(qstrlen(
"report:"));
102 if (reportItemName == QLatin1String(
"line")) {
103 KReportItemLine * line =
new KReportItemLine(elemThis);
106 KReportPluginInterface *plugin = manager->plugin(reportItemName);
110 krobj =
dynamic_cast<KReportItemBase*
>(obj);
116 objects.append(krobj);
118 kreportWarning() <<
"Could not create element of type" << reportItemName;
121 kreportWarning() <<
"While parsing section encountered an unknown element:" << n;
124 std::sort(objects.begin(), objects.end(), zLessThan);
128KReportSectionData::~KReportSectionData()
133KReportUnit KReportSectionData::unit()
const
138void KReportSectionData::setUnit(
const KReportUnit &u)
144 KReportUnit oldunit = d->unit;
148 KProperty::ValueOption::IgnoreOld);
149 d->height->setOption(
"suffix", u.
symbol());
152bool KReportSectionData::Private::zLessThan(KReportItemBase* s1, KReportItemBase* s2)
154 return s1->
z() < s2->
z();
157bool KReportSectionData::Private::xLessThan(KReportItemBase* s1, KReportItemBase* s2)
162void KReportSectionData::Private::createProperties(
const QDomElement & elemSource)
165 QLatin1String(
"kreport-section-element"));
166 height =
new KProperty(
"height", 0.0,
tr(
"Height"));
167 backgroundColor =
new KProperty(
169 KReportUtils::attr(elemSource, QLatin1String(
"fo:background-color"), QColor(
Qt::white)),
170 tr(
"Background Color"));
171 height->setOption(
"unit", QLatin1String(
"cm"));
172 if (!elemSource.
isNull()) {
173 height->setValue(unit.convertFromPoint(
174 KReportUtils::readSizeAttributes(
175 elemSource, QSizeF(DEFAULT_SECTION_SIZE_PT, DEFAULT_SECTION_SIZE_PT))
179 set.addProperty(height);
180 set.addProperty(backgroundColor);
181 set.clearModifiedFlags();
184QString KReportSectionData::name()
const
194 case KReportSectionData::Type::PageHeaderAny:
197 case KReportSectionData::Type::PageHeaderEven:
200 case KReportSectionData::Type::PageHeaderOdd:
203 case KReportSectionData::Type::PageHeaderFirst:
206 case KReportSectionData::Type::PageHeaderLast:
209 case KReportSectionData::Type::PageFooterAny:
212 case KReportSectionData::Type::PageFooterEven:
215 case KReportSectionData::Type::PageFooterOdd:
218 case KReportSectionData::Type::PageFooterFirst:
221 case KReportSectionData::Type::PageFooterLast:
224 case KReportSectionData::Type::ReportHeader:
227 case KReportSectionData::Type::ReportFooter:
230 case KReportSectionData::Type::GroupHeader:
233 case KReportSectionData::Type::GroupFooter:
236 case KReportSectionData::Type::Detail:
249 KReportSectionData::Type type;
252 type = KReportSectionData::Type::PageHeaderAny;
254 type = KReportSectionData::Type::PageHeaderEven;
256 type = KReportSectionData::Type::PageHeaderOdd;
258 type = KReportSectionData::Type::PageHeaderFirst;
260 type = KReportSectionData::Type::PageHeaderLast;
262 type = KReportSectionData::Type::ReportHeader;
264 type = KReportSectionData::Type::PageFooterAny;
266 type = KReportSectionData::Type::PageFooterEven;
268 type = KReportSectionData::Type::PageFooterOdd;
270 type = KReportSectionData::Type::PageFooterFirst;
272 type = KReportSectionData::Type::PageFooterLast;
274 type = KReportSectionData::Type::ReportFooter;
276 type = KReportSectionData::Type::GroupHeader;
278 type = KReportSectionData::Type::GroupFooter;
280 type = KReportSectionData::Type::Detail;
282 type = KReportSectionData::Type::None;
287qreal KReportSectionData::height()
const
292void KReportSectionData::setHeight(qreal ptHeight, KProperty::ValueOptions options)
294 d->height->setValue(d->unit.convertFromPoint(ptHeight), options);
297void KReportSectionData::setHeight(qreal ptHeight)
299 setHeight(ptHeight, KProperty::ValueOptions());
312bool KReportSectionData::isValid()
const
317QList<KReportItemBase*> KReportSectionData::objects()
const
322QColor KReportSectionData::backgroundColor()
const
324 return d->backgroundColor->
value().value<QColor>();
327void KReportSectionData::setBackgroundColor(
const QColor &color)
329 d->backgroundColor->setValue(color);
332KReportSectionData::Type KReportSectionData::type()
const
337KReportItemBase* KReportSectionData::object(
int index)
339 return d->objects.value(index);
void clearModifiedFlags()
static void addMetaProperties(KPropertySet *set, const QString &classString, const QString &iconName)
Adds meta-properties to the property set set for consumption by property editor.
QPointF position() const
Return the position in points.
qreal z() const
Return the z-value in points.
virtual QObject * createRendererInstance(const QDomNode &element)=0
KReportSectionData is used to store the information about a specific report section.
KPropertySet * propertySet()
Returns property set for this section.
static KReportSectionData::Type sectionTypeFromString(const QString &s)
static QString sectionTypeString(KReportSectionData::Type type)
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
VehicleSection::Type type(QStringView coachNumber, QStringView coachClassification)
QString tagName() const const
QDomNodeList childNodes() const const
bool isNull() const const
QDomElement toElement() const const
QDomNode item(int index) const const
QString tr(const char *sourceText, const char *disambiguation, int n)
QPoint toPoint() const const
QString mid(qsizetype position, qsizetype n) const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
qreal toReal(bool *ok) const const