diff --git a/src/common/KReportAsyncItemBase.cpp b/src/common/KReportAsyncItemBase.cpp index c5e5cfb4..fb16b47c 100644 --- a/src/common/KReportAsyncItemBase.cpp +++ b/src/common/KReportAsyncItemBase.cpp @@ -1,25 +1,41 @@ /* This file is part of the KDE project Copyright (C) 2011 Adam Pigg This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "KReportAsyncItemBase.h" +class Q_DECL_HIDDEN KReportAsyncItemBase::Private +{ +public: + bool dummy = true; +}; + +KReportAsyncItemBase::KReportAsyncItemBase() : d(new Private) +{ +} + +KReportAsyncItemBase::~KReportAsyncItemBase() +{ + delete d; +} + + QVariant KReportAsyncItemBase::realItemData(const QVariant& itemData) const { return itemData; } diff --git a/src/common/KReportAsyncItemBase.h b/src/common/KReportAsyncItemBase.h index 10c775fa..c0450b4c 100644 --- a/src/common/KReportAsyncItemBase.h +++ b/src/common/KReportAsyncItemBase.h @@ -1,36 +1,42 @@ /* This file is part of the KDE project Copyright (C) 2011 Adam Pigg This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef KREPORTASYNCITEMBASE_H #define KREPORTASYNCITEMBASE_H #include "KReportItemBase.h" class KREPORT_EXPORT KReportAsyncItemBase : public KReportItemBase { Q_OBJECT public: + KReportAsyncItemBase(); + ~KReportAsyncItemBase(); int renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) override = 0; virtual QVariant realItemData(const QVariant& itemData) const; Q_SIGNALS: void finishedRendering(); + +private: + class Private; + Private * const d; }; #endif // KREPORTASYNCITEMBASE_H diff --git a/src/common/KReportDocument.cpp b/src/common/KReportDocument.cpp index aa223622..cc99d47c 100644 --- a/src/common/KReportDocument.cpp +++ b/src/common/KReportDocument.cpp @@ -1,388 +1,400 @@ /* This file is part of the KDE project * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportDocument.h" #include "KReportUnit.h" #include "KReportDetailSectionData.h" #include "KReportItemBase.h" #include "KReportUtils_p.h" #include "KReportPageSize.h" #include #include #include "kreport_debug.h" class Q_DECL_HIDDEN KReportDocument::Private { public: bool valid; QString title; QString name; QString query; #ifdef KREPORT_SCRIPTING QString script; QString interpreter; #endif bool externalData; KReportPrivate::PageLayout pageLayout; QString pageSize; QString labelType; + + KReportSectionData * pageHeaderFirst = nullptr; + KReportSectionData * pageHeaderOdd = nullptr; + KReportSectionData * pageHeaderEven = nullptr; + KReportSectionData * pageHeaderLast = nullptr; + KReportSectionData * pageHeaderAny = nullptr; + + KReportSectionData * reportHeader = nullptr; + KReportSectionData * reportFooter = nullptr; + + KReportSectionData * pageFooterFirst = nullptr; + KReportSectionData * pageFooterOdd = nullptr; + KReportSectionData * pageFooterEven = nullptr; + KReportSectionData * pageFooterLast = nullptr; + KReportSectionData * pageFooterAny = nullptr; + + KReportDetailSectionData* detailSection = nullptr; }; -void KReportDocument::init() -{ - m_pageHeaderFirst = m_pageHeaderOdd = m_pageHeaderEven = m_pageHeaderLast = m_pageHeaderAny = nullptr; - m_pageFooterFirst = m_pageFooterOdd = m_pageFooterEven = m_pageFooterLast = m_pageFooterAny = nullptr; - m_reportHeader = m_reportFooter = nullptr; -} - KReportDocument::KReportDocument(QObject *parent) : QObject(parent), - m_detailSection(nullptr), - d(new Private()) + d(new Private) { - init(); d->valid = true; } KReportDocument::KReportDocument(const QDomElement & elemSource, QObject *parent) : QObject(parent), - m_detailSection(nullptr), - d(new Private()) + d(new Private) { d->valid = false; - init(); - //kreportDebug(); + if (elemSource.tagName() != QLatin1String("report:content")) { kreportWarning() << "QDomElement is not tag" << elemSource.text(); return; } QDomNodeList sections = elemSource.childNodes(); for (int nodeCounter = 0; nodeCounter < sections.count(); nodeCounter++) { QDomElement elemThis = sections.item(nodeCounter).toElement(); if (elemThis.tagName() == QLatin1String("report:title")) { d->title = elemThis.text(); #ifdef KREPORT_SCRIPTING } else if (elemThis.tagName() == QLatin1String("report:script")) { d->script = elemThis.text(); d->interpreter = elemThis.attribute(QLatin1String("report:script-interpreter")); #endif } else if (elemThis.tagName() == QLatin1String("report:page-style")) { QString pagetype = elemThis.firstChild().nodeValue(); //Full page mode is required to allow margins to be set to whatever the user has specified d->pageLayout.setMode(QPageLayout::FullPageMode); if (pagetype == QLatin1String("predefined")) { setPageSize(elemThis.attribute(QLatin1String("report:page-size"), QLatin1String("A4"))); d->pageLayout.setPageSize(QPageSize(KReportPageSize::pageSize(pageSize()))); } else if (pagetype == QLatin1String("custom")) { kreportDebug() << "Setting custom page size in document to " << KReportUnit::parseValue(elemThis.attribute(QLatin1String("report:custom-page-width"), QLatin1String("5.0cm"))) << KReportUnit::parseValue(elemThis.attribute(QLatin1String("report:custom-page-height"), QLatin1String("5.0cm"))) ; QPageSize custom(QSize(KReportUnit::parseValue(elemThis.attribute(QLatin1String("report:custom-page-width"), QLatin1String("5.0cm"))) , KReportUnit::parseValue(elemThis.attribute(QLatin1String("report:custom-page-height"), QLatin1String("5.0cm"))) ), QString(), QPageSize::ExactMatch); d->pageLayout.setPageSize(custom); } else if (pagetype == QLatin1String("label")) { setLabelType(elemThis.firstChild().nodeValue()); } //! @todo add config for default margins or add within templates support d->pageLayout.setUnits(QPageLayout::Point); d->pageLayout.setLeftMargin(KReportUnit::parseValue(elemThis.attribute(QLatin1String("fo:margin-left"), QLatin1String("1.0cm")))); d->pageLayout.setRightMargin(KReportUnit::parseValue(elemThis.attribute(QLatin1String("fo:margin-right"), QLatin1String("1.0cm")))); d->pageLayout.setTopMargin(KReportUnit::parseValue(elemThis.attribute(QLatin1String("fo:margin-top"), QLatin1String("1.0cm")))); d->pageLayout.setBottomMargin(KReportUnit::parseValue(elemThis.attribute(QLatin1String("fo:margin-bottom"), QLatin1String("1.0cm")))); d->pageLayout.setOrientation(elemThis.attribute(QLatin1String("report:print-orientation"), QLatin1String("portrait")) == QLatin1String("portrait") ? QPageLayout::Portrait : QPageLayout::Landscape); } else if (elemThis.tagName() == QLatin1String("report:body")) { QDomNodeList sectionlist = elemThis.childNodes(); QDomNode sec; for (int s = 0; s < sectionlist.count(); ++s) { sec = sectionlist.item(s); if (sec.isElement()) { QString sn = sec.nodeName().toLower(); //kreportDebug() << sn; if (sn == QLatin1String("report:section")) { KReportSectionData * sd = new KReportSectionData(sec.toElement(), this); if (!sd->isValid()) { kreportDebug() << "Invalid section"; delete sd; } else { //kreportDebug() << "Adding section of type " << sd->type(); switch (sd->type()) { case KReportSectionData::Type::PageHeaderFirst: - m_pageHeaderFirst = sd; + d->pageHeaderFirst = sd; break; case KReportSectionData::Type::PageHeaderOdd: - m_pageHeaderOdd = sd; + d->pageHeaderOdd = sd; break; case KReportSectionData::Type::PageHeaderEven: - m_pageHeaderEven = sd; + d->pageHeaderEven = sd; break; case KReportSectionData::Type::PageHeaderLast: - m_pageHeaderLast = sd; + d->pageHeaderLast = sd; break; case KReportSectionData::Type::PageHeaderAny: - m_pageHeaderAny = sd; + d->pageHeaderAny = sd; break; case KReportSectionData::Type::ReportHeader: - m_reportHeader = sd; + d->reportHeader = sd; break; case KReportSectionData::Type::ReportFooter: - m_reportFooter = sd; + d->reportFooter = sd; break; case KReportSectionData::Type::PageFooterFirst: - m_pageFooterFirst = sd; + d->pageFooterFirst = sd; break; case KReportSectionData::Type::PageFooterOdd: - m_pageFooterOdd = sd; + d->pageFooterOdd = sd; break; case KReportSectionData::Type::PageFooterEven: - m_pageFooterEven = sd; + d->pageFooterEven = sd; break; case KReportSectionData::Type::PageFooterLast: - m_pageFooterLast = sd; + d->pageFooterLast = sd; break; case KReportSectionData::Type::PageFooterAny: - m_pageFooterAny = sd; + d->pageFooterAny = sd; break; default: ; } } } else if (sn == QLatin1String("report:detail")) { KReportDetailSectionData * dsd = new KReportDetailSectionData(sec.toElement(), this); if (dsd->isValid()) { - m_detailSection = dsd; + d->detailSection = dsd; } else { kreportDebug() << "Invalid detail section"; delete dsd; } } } else { kreportWarning() << "Encountered an unknown Element: " << elemThis.tagName(); } } } d->valid = true; } } KReportDocument::~KReportDocument() { delete d; } QList KReportDocument::objects() const { QList obs; for (int i = static_cast(KReportSectionData::Type::PageHeaderFirst); i <= static_cast(KReportSectionData::Type::PageFooterAny); i++) { KReportSectionData *sec = section(static_cast(i)); if (sec) { obs << sec->objects(); } } - if (m_detailSection) { + if (d->detailSection) { //kreportDebug() << "Number of groups: " << m_detailSection->m_groupList.count(); - foreach(KReportDetailGroupSectionData* g, m_detailSection->groupList) { + foreach(KReportDetailGroupSectionData* g, d->detailSection->groupList) { if (g->groupHeader) { obs << g->groupHeader->objects(); } if (g->groupFooter) { obs << g->groupFooter->objects(); } } - if (m_detailSection->detailSection) - obs << m_detailSection->detailSection->objects(); + if (d->detailSection->detailSection) + obs << d->detailSection->detailSection->objects(); } /*kreportDebug() << "Object List:"; foreach(KReportItemBase* o, obs) { kreportDebug() << o->entityName(); }*/ return obs; } KReportItemBase* KReportDocument::object(const QString& n) const { QList obs = objects(); foreach(KReportItemBase* o, obs) { if (o->entityName() == n) { return o; } } return nullptr; } QList KReportDocument::sections() const { QList secs; for (int i = static_cast(KReportSectionData::Type::PageHeaderFirst); i <= static_cast(KReportSectionData::Type::PageFooterAny); i++) { KReportSectionData *sec = section(static_cast(i)); if (sec) { secs << sec; } } - if (m_detailSection) { + if (d->detailSection) { //kreportDebug() << "Number of groups: " << m_detailSection->m_groupList.count(); - foreach(KReportDetailGroupSectionData* g, m_detailSection->groupList) { + foreach(KReportDetailGroupSectionData* g, d->detailSection->groupList) { if (g->groupHeader) { secs << g->groupHeader; } if (g->groupFooter) { secs << g->groupFooter; } } - if (m_detailSection->detailSection) - secs << m_detailSection->detailSection; + if (d->detailSection->detailSection) + secs << d->detailSection->detailSection; } return secs; } KReportSectionData* KReportDocument::section(const QString& sn) const { QList secs = sections(); foreach(KReportSectionData *sec, secs) { if (sec->name() == sn) { return sec; } } return nullptr; } KReportSectionData* KReportDocument::section(KReportSectionData::Type type) const { KReportSectionData *sec; switch (type) { case KReportSectionData::Type::PageHeaderAny: - sec = m_pageHeaderAny; + sec = d->pageHeaderAny; break; case KReportSectionData::Type::PageHeaderEven: - sec = m_pageHeaderEven; + sec = d->pageHeaderEven; break; case KReportSectionData::Type::PageHeaderOdd: - sec = m_pageHeaderOdd; + sec = d->pageHeaderOdd; break; case KReportSectionData::Type::PageHeaderFirst: - sec = m_pageHeaderFirst; + sec = d->pageHeaderFirst; break; case KReportSectionData::Type::PageHeaderLast: - sec = m_pageHeaderLast; + sec = d->pageHeaderLast; break; case KReportSectionData::Type::PageFooterAny: - sec = m_pageFooterAny; + sec = d->pageFooterAny; break; case KReportSectionData::Type::PageFooterEven: - sec = m_pageFooterEven; + sec = d->pageFooterEven; break; case KReportSectionData::Type::PageFooterOdd: - sec = m_pageFooterOdd; + sec = d->pageFooterOdd; break; case KReportSectionData::Type::PageFooterFirst: - sec = m_pageFooterFirst; + sec = d->pageFooterFirst; break; case KReportSectionData::Type::PageFooterLast: - sec = m_pageFooterLast; + sec = d->pageFooterLast; break; case KReportSectionData::Type::ReportHeader: - sec = m_reportHeader; + sec = d->reportHeader; break; case KReportSectionData::Type::ReportFooter: - sec = m_reportFooter; + sec = d->reportFooter; break; default: sec = nullptr; } return sec; } QPageLayout KReportDocument::pageLayout() const { return d->pageLayout; } bool KReportDocument::isValid() const { return d->valid; } QString KReportDocument::title() const { return d->title; } bool KReportDocument::externalData() const { return d->externalData; } QString KReportDocument::interpreter() const { return d->interpreter; } QString KReportDocument::name() const { return d->name; } void KReportDocument::setName(const QString& n) { d->name = n; } QString KReportDocument::query() const { return d->query; } QString KReportDocument::script() const { return d->script; } QString KReportDocument::pageSize() { return d->pageSize; } void KReportDocument::setPageSize(const QString& size) { d->pageSize = size; } QString KReportDocument::labelType() const { return d->labelType; } void KReportDocument::setLabelType(const QString& label) { d->labelType = label; } + +KReportDetailSectionData * KReportDocument::detail() const +{ + return d->detailSection; +} + diff --git a/src/common/KReportDocument.h b/src/common/KReportDocument.h index a74cf727..73c09676 100644 --- a/src/common/KReportDocument.h +++ b/src/common/KReportDocument.h @@ -1,136 +1,112 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #ifndef KREPORTDOCUMENT_H #define KREPORTDOCUMENT_H #include "config-kreport.h" #include "kreport_export.h" #include "KReportSectionData.h" #include class KReportDetailSectionData; #ifdef KREPORT_SCRIPTING namespace Scripting { class Report; } #endif /** */ class KREPORT_EXPORT KReportDocument : public QObject { Q_OBJECT public: explicit KReportDocument(const QDomElement &elemSource, QObject *parent = nullptr); explicit KReportDocument(QObject *parent = nullptr); ~KReportDocument() override; bool isValid() const; /** \return a list of all objects in the report */ QList objects() const; /** \return a report object given its name */ KReportItemBase* object(const QString&) const; /** \return all the sections, including groups and detail */ QList sections() const; /** \return a sectiondata given a section type */ KReportSectionData* section(KReportSectionData::Type type) const; /** \return a sectiondata given its name */ KReportSectionData* section(const QString &name) const; QString query() const; #ifdef KREPORT_SCRIPTING QString script() const; QString interpreter() const; #endif bool externalData() const; - KReportDetailSectionData* detail() const { - return m_detailSection; - } + KReportDetailSectionData* detail() const; void setName(const QString&n); QString name() const; QString title() const; QPageLayout pageLayout() const; QString pageSize(); void setPageSize(const QString &size); - -protected: - - - KReportSectionData * m_pageHeaderFirst; - KReportSectionData * m_pageHeaderOdd; - KReportSectionData * m_pageHeaderEven; - KReportSectionData * m_pageHeaderLast; - KReportSectionData * m_pageHeaderAny; - - KReportSectionData * m_reportHeader; - KReportSectionData * m_reportFooter; - KReportSectionData * m_pageFooterFirst; - KReportSectionData * m_pageFooterOdd; - KReportSectionData * m_pageFooterEven; - KReportSectionData * m_pageFooterLast; - KReportSectionData * m_pageFooterAny; - - KReportDetailSectionData* m_detailSection; - -private: - void init(); - +private: friend class KReportPreRendererPrivate; friend class KReportPreRenderer; #ifdef KREPORT_SCRIPTING friend class KReportScriptHandler; friend class Scripting::Report; #endif //! TODO add support for labels QString labelType() const; void setLabelType(const QString &label); class Private; Private * const d; }; #endif diff --git a/src/plugins/barcode/KReportDesignerItemBarcode.cpp b/src/plugins/barcode/KReportDesignerItemBarcode.cpp index 916c849c..15cd3ba8 100644 --- a/src/plugins/barcode/KReportDesignerItemBarcode.cpp +++ b/src/plugins/barcode/KReportDesignerItemBarcode.cpp @@ -1,173 +1,173 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportDesignerItemBarcode.h" #include "KReportDesignerItemBase.h" #include "KReportDesigner.h" #include "barcodepaint.h" #include #include #include #include #include #include #include "kreportplugin_debug.h" void KReportDesignerItemBarcode::init(QGraphicsScene *scene) { if (scene) scene->addItem(this); connect(propertySet(), SIGNAL(propertyChanged(KPropertySet&,KProperty&)), this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); setMaxLength(5); setZ(z()); updateRenderText(m_itemValue->value().toString().isEmpty() ? m_format->value().toString() : QString(), m_itemValue->value().toString(), QString()); } // methods (constructors) KReportDesignerItemBarcode::KReportDesignerItemBarcode(KReportDesigner * rw, QGraphicsScene* scene, const QPointF &pos) : KReportDesignerItemRectBase(rw, this) { Q_UNUSED(pos); init(scene); - setSceneRect(properRect(*rw, m_minWidthTotal*m_dpiX, m_minHeight*m_dpiY)); + setSceneRect(properRect(*rw, m_minWidthTotal*dpiX(), m_minHeight*dpiY())); nameProperty()->setValue(designer()->suggestEntityName(typeName())); } KReportDesignerItemBarcode::KReportDesignerItemBarcode(const QDomNode & element, KReportDesigner * rw, QGraphicsScene* scene) : KReportItemBarcode(element), KReportDesignerItemRectBase(rw, this) { init(scene); setSceneRect(KReportItemBase::scenePosition(item()->position()), KReportItemBase::sceneSize(item()->size())); } KReportDesignerItemBarcode* KReportDesignerItemBarcode::clone() { QDomDocument d; QDomElement e = d.createElement(QLatin1String("clone")); QDomNode n; buildXML(&d, &e); n = e.firstChild(); return new KReportDesignerItemBarcode(n, designer(), nullptr); } // methods (deconstructor) KReportDesignerItemBarcode::~KReportDesignerItemBarcode() {} QRect KReportDesignerItemBarcode::getTextRect() { QFont fnt = QFont(); return QFontMetrics(fnt) .boundingRect(int (x()), int (y()), 0, 0, 0, dataSourceAndObjectTypeName(itemDataSource(), QLatin1String("barcode"))); } void KReportDesignerItemBarcode::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget) { Q_UNUSED(option); Q_UNUSED(widget); // store any values we plan on changing so we can restore them QPen p = painter->pen(); painter->setBackground(Qt::white); //Draw a border so user knows the object edge painter->setPen(QPen(QColor(224, 224, 224))); painter->drawRect(rect()); drawHandles(painter); QByteArray fmt = m_format->value().toByteArray(); if (fmt == "i2of5") { renderI2of5(rect().toRect(), renderText(), alignment(), painter); } else if (fmt == "3of9") { render3of9(rect().toRect(), renderText(), alignment(), painter); } else if (fmt == "3of9+") { renderExtended3of9(rect().toRect(), renderText(), alignment(), painter); } else if (fmt == "128") { renderCode128(rect().toRect(), renderText(), alignment(), painter); } else if (fmt == "upc-a") { renderCodeUPCA(rect().toRect(), renderText(), alignment(), painter); } else if (fmt == "upc-e") { renderCodeUPCE(rect().toRect(), renderText(), alignment(), painter); } else if (fmt == "ean13") { renderCodeEAN13(rect().toRect(), renderText(), alignment(), painter); } else if (fmt == "ean8") { renderCodeEAN8(rect().toRect(), renderText(), alignment(), painter); } painter->setPen(Qt::black); painter->drawText(rect(), 0, dataSourceAndObjectTypeName(itemDataSource(), QLatin1String("barcode"))); // restore an values before we started just in case painter->setPen(p); } void KReportDesignerItemBarcode::buildXML(QDomDocument *doc, QDomElement *parent) { //kreportpluginDebug(); QDomElement entity = doc->createElement(QLatin1String("report:") + typeName()); // properties addPropertyAsAttribute(&entity, nameProperty()); addPropertyAsAttribute(&entity, m_controlSource); addPropertyAsAttribute(&entity, m_horizontalAlignment); addPropertyAsAttribute(&entity, m_format); addPropertyAsAttribute(&entity, m_maxLength); entity.setAttribute(QLatin1String("report:z-index"), zValue()); addPropertyAsAttribute(&entity, m_itemValue); // bounding rect buildXMLRect(doc, &entity, this); parent->appendChild(entity); } void KReportDesignerItemBarcode::slotPropertyChanged(KPropertySet &s, KProperty &p) { if (p.name() == "name") { //For some reason p.oldValue returns an empty string if (!designer()->isEntityNameUnique(p.value().toString(), this)) { p.setValue(oldName()); } else { setOldName(p.value().toString()); } } updateRenderText(m_itemValue->value().toString().isEmpty() ? m_format->value().toString() : QString(), m_itemValue->value().toString(), QString()); KReportDesignerItemRectBase::propertyChanged(s, p); if (designer()) designer()->setModified(true); } void KReportDesignerItemBarcode::mousePressEvent(QGraphicsSceneMouseEvent * event) { m_controlSource->setListData(designer()->fieldKeys(), designer()->fieldNames()); KReportDesignerItemRectBase::mousePressEvent(event); } diff --git a/src/renderer/KReportPreRenderer.cpp b/src/renderer/KReportPreRenderer.cpp index 56bf0732..c404b618 100644 --- a/src/renderer/KReportPreRenderer.cpp +++ b/src/renderer/KReportPreRenderer.cpp @@ -1,702 +1,702 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportPreRenderer.h" #include "KReportPreRenderer_p.h" #include "KReportAsyncItemManager_p.h" #include "KReportOneRecordDataSource_p.h" #include "KReportRenderObjects.h" #include "KReportDataSource.h" #include "KReportItemBase.h" #include "KReportDocument.h" #include "KReportDetailSectionData.h" #include "KReportLabelSizeInfo.h" #include "KReportPageSize.h" #include "KReportUtils_p.h" #ifdef KREPORT_SCRIPTING #include "scripting/KReportScriptHandler.h" #include "scripting/KReportGroupTracker.h" #endif #include #include #include "kreport_debug.h" KReportPreRendererPrivate::KReportPreRendererPrivate(KReportPreRenderer *preRenderer) : m_preRenderer(preRenderer) { m_valid = false; m_document = nullptr; m_reportDocument = nullptr; m_page = nullptr; m_yOffset = 0.0; m_topMargin = m_bottomMargin = 0.0; m_leftMargin = m_rightMargin = 0.0; m_pageCounter = 0; m_maxHeight = m_maxWidth = 0.0; m_oneRecord = new KReportPrivate::OneRecordDataSource(); m_dataSource = nullptr; #ifdef KREPORT_SCRIPTING m_scriptHandler = nullptr; #endif asyncManager = new KReportPrivate::AsyncItemManager(this); connect(asyncManager, SIGNAL(finished()), this, SLOT(asyncItemsFinished())); } KReportPreRendererPrivate::~KReportPreRendererPrivate() { delete m_reportDocument; delete m_document; delete m_oneRecord; m_postProcText.clear(); } void KReportPreRendererPrivate::createNewPage() { //kreportDebug(); if (m_pageCounter > 0) finishCurPage(false); m_pageCounter++; #ifdef KREPORT_SCRIPTING //Update the page count script value m_scriptHandler->setPageNumber(m_pageCounter); m_scriptHandler->newPage(); #endif m_page = new OROPage(nullptr); m_document->addPage(m_page); //! @todo calculate past page bool lastPage = false; m_yOffset = m_topMargin; - if (m_pageCounter == 1 && m_reportDocument->m_pageHeaderFirst) - renderSection(*(m_reportDocument->m_pageHeaderFirst)); - else if (lastPage == true && m_reportDocument->m_pageHeaderLast) - renderSection(*(m_reportDocument->m_pageHeaderLast)); - else if ((m_pageCounter % 2) == 1 && m_reportDocument->m_pageHeaderOdd) - renderSection(*(m_reportDocument->m_pageHeaderOdd)); - else if ((m_pageCounter % 2) == 0 && m_reportDocument->m_pageHeaderAny) - renderSection(*(m_reportDocument->m_pageHeaderAny)); - else if (m_reportDocument->m_pageHeaderAny) - renderSection(*(m_reportDocument->m_pageHeaderAny)); + if (m_pageCounter == 1 && m_reportDocument->section(KReportSectionData::Type::PageHeaderFirst)) + renderSection(*(m_reportDocument->section(KReportSectionData::Type::PageHeaderFirst))); + else if (lastPage == true && m_reportDocument->section(KReportSectionData::Type::PageHeaderLast)) + renderSection(*(m_reportDocument->section(KReportSectionData::Type::PageHeaderLast))); + else if ((m_pageCounter % 2) == 1 && m_reportDocument->section(KReportSectionData::Type::PageHeaderOdd)) + renderSection(*(m_reportDocument->section(KReportSectionData::Type::PageHeaderOdd))); + else if ((m_pageCounter % 2) == 0 && m_reportDocument->section(KReportSectionData::Type::PageHeaderEven)) + renderSection(*(m_reportDocument->section(KReportSectionData::Type::PageHeaderEven))); + else if (m_reportDocument->section(KReportSectionData::Type::PageHeaderAny)) + renderSection(*(m_reportDocument->section(KReportSectionData::Type::PageHeaderAny))); } qreal KReportPreRendererPrivate::finishCurPageSize(bool lastPage) { qreal retval = 0.0; - if (lastPage && m_reportDocument->m_pageFooterLast) - retval = renderSectionSize(* (m_reportDocument->m_pageFooterLast)); - else if (m_pageCounter == 1 && m_reportDocument->m_pageFooterFirst) - retval = renderSectionSize(* (m_reportDocument->m_pageFooterFirst)); - else if ((m_pageCounter % 2) == 1 && m_reportDocument->m_pageFooterOdd) - retval = renderSectionSize(* (m_reportDocument->m_pageFooterOdd)); - else if ((m_pageCounter % 2) == 0 && m_reportDocument->m_pageFooterEven) - retval = renderSectionSize(* (m_reportDocument->m_pageFooterEven)); - else if (m_reportDocument->m_pageFooterAny) - retval = renderSectionSize(* (m_reportDocument->m_pageFooterAny)); + if (lastPage && m_reportDocument->section(KReportSectionData::Type::PageFooterLast)) + retval = renderSectionSize(* (m_reportDocument->section(KReportSectionData::Type::PageFooterLast))); + else if (m_pageCounter == 1 && m_reportDocument->section(KReportSectionData::Type::PageFooterFirst)) + retval = renderSectionSize(* (m_reportDocument->section(KReportSectionData::Type::PageFooterFirst))); + else if ((m_pageCounter % 2) == 1 && m_reportDocument->section(KReportSectionData::Type::PageFooterOdd)) + retval = renderSectionSize(* (m_reportDocument->section(KReportSectionData::Type::PageFooterOdd))); + else if ((m_pageCounter % 2) == 0 && m_reportDocument->section(KReportSectionData::Type::PageFooterEven)) + retval = renderSectionSize(* (m_reportDocument->section(KReportSectionData::Type::PageFooterEven))); + else if (m_reportDocument->section(KReportSectionData::Type::PageFooterAny)) + retval = renderSectionSize(* (m_reportDocument->section(KReportSectionData::Type::PageFooterAny))); //kreportDebug() << retval; return retval; } qreal KReportPreRendererPrivate::finishCurPage(bool lastPage) { qreal offset = m_maxHeight - m_bottomMargin; qreal retval = 0.0; //kreportDebug() << offset; - if (lastPage && m_reportDocument->m_pageFooterLast) { + if (lastPage && m_reportDocument->section(KReportSectionData::Type::PageFooterLast)) { //kreportDebug() << "Last Footer"; - m_yOffset = offset - renderSectionSize(* (m_reportDocument->m_pageFooterLast)); - retval = renderSection(* (m_reportDocument->m_pageFooterLast)); - } else if (m_pageCounter == 1 && m_reportDocument->m_pageFooterFirst) { + m_yOffset = offset - renderSectionSize(* (m_reportDocument->section(KReportSectionData::Type::PageFooterLast))); + retval = renderSection(* (m_reportDocument->section(KReportSectionData::Type::PageFooterLast))); + } else if (m_pageCounter == 1 && m_reportDocument->section(KReportSectionData::Type::PageFooterFirst)) { //kreportDebug() << "First Footer"; - m_yOffset = offset - renderSectionSize(* (m_reportDocument->m_pageFooterFirst)); - retval = renderSection(* (m_reportDocument->m_pageFooterFirst)); - } else if ((m_pageCounter % 2) == 1 && m_reportDocument->m_pageFooterOdd) { + m_yOffset = offset - renderSectionSize(* (m_reportDocument->section(KReportSectionData::Type::PageFooterLast))); + retval = renderSection(* (m_reportDocument->section(KReportSectionData::Type::PageFooterFirst))); + } else if ((m_pageCounter % 2) == 1 && m_reportDocument->section(KReportSectionData::Type::PageFooterOdd)) { //kreportDebug() << "Odd Footer"; - m_yOffset = offset - renderSectionSize(* (m_reportDocument->m_pageFooterOdd)); - retval = renderSection(* (m_reportDocument->m_pageFooterOdd)); - } else if ((m_pageCounter % 2) == 0 && m_reportDocument->m_pageFooterEven) { + m_yOffset = offset - renderSectionSize(* (m_reportDocument->section(KReportSectionData::Type::PageFooterOdd))); + retval = renderSection(* (m_reportDocument->section(KReportSectionData::Type::PageFooterOdd))); + } else if ((m_pageCounter % 2) == 0 && m_reportDocument->section(KReportSectionData::Type::PageFooterEven)) { //kreportDebug() << "Even Footer"; - m_yOffset = offset - renderSectionSize(* (m_reportDocument->m_pageFooterEven)); - retval = renderSection(* (m_reportDocument->m_pageFooterEven)); - } else if (m_reportDocument->m_pageFooterAny) { + m_yOffset = offset - renderSectionSize(* (m_reportDocument->section(KReportSectionData::Type::PageFooterEven))); + retval = renderSection(* (m_reportDocument->section(KReportSectionData::Type::PageFooterEven))); + } else if (m_reportDocument->section(KReportSectionData::Type::PageFooterAny)) { //kreportDebug() << "Any Footer"; - m_yOffset = offset - renderSectionSize(* (m_reportDocument->m_pageFooterAny)); - retval = renderSection(* (m_reportDocument->m_pageFooterAny)); + m_yOffset = offset - renderSectionSize(* (m_reportDocument->section(KReportSectionData::Type::PageFooterAny))); + retval = renderSection(* (m_reportDocument->section(KReportSectionData::Type::PageFooterAny))); } return retval; } void KReportPreRendererPrivate::renderDetailSection(KReportDetailSectionData *detailData) { if (detailData->detailSection) { if (m_dataSource/* && !curs->eof()*/) { QStringList keys; QStringList keyValues; QList shownGroups; KReportDetailGroupSectionData * grp = nullptr; bool status = m_dataSource->moveFirst(); int recordCount = m_dataSource->recordCount(); //kreportDebug() << "Record Count:" << recordCount; for (int i = 0; i < (int) detailData->groupList.count(); ++i) { grp = detailData->groupList[i]; //If the group has a header or footer, then emit a change of group value if(grp->groupFooter || grp->groupHeader) { // we get here only if group is *shown* shownGroups << i; keys.append(grp->column); if (!keys.last().isEmpty()) keyValues.append(m_dataSource->value(m_dataSource->fieldNumber(keys.last())).toString()); else keyValues.append(QString()); //Tell interested parties we're about to render a header emit(enteredGroup(keys.last(), keyValues.last())); } if (grp->groupHeader) renderSection(*(grp->groupHeader)); } while (status) { const qint64 pos = m_dataSource->at(); //kreportDebug() << "At:" << l << "Y:" << m_yOffset << "Max Height:" << m_maxHeight; if ((renderSectionSize(*detailData->detailSection) + finishCurPageSize((pos + 1 == recordCount)) + m_bottomMargin + m_yOffset) >= m_maxHeight) { //kreportDebug() << "Next section is too big for this page"; if (pos > 0) { m_dataSource->movePrevious(); createNewPage(); m_dataSource->moveNext(); } } renderSection(*(detailData->detailSection)); status = m_dataSource->moveNext(); if (status == true && keys.count() > 0) { // check to see where it is we need to start int pos = -1; // if it's still -1 by the time we are done then no keyValues changed for (int i = 0; i < keys.count(); ++i) { if (keyValues[i] != m_dataSource->value(m_dataSource->fieldNumber(keys[i])).toString()) { pos = i; break; } } // don't bother if nothing has changed if (pos != -1) { // roll back the query and go ahead if all is good status = m_dataSource->movePrevious(); if (status == true) { // print the footers as needed // any changes made in this for loop need to be duplicated // below where the footers are finished. bool do_break = false; for (int i = shownGroups.count() - 1; i >= 0; i--) { if (do_break) createNewPage(); do_break = false; grp = detailData->groupList[shownGroups.at(i)]; if (grp->groupFooter) { if (renderSectionSize(*(grp->groupFooter)) + finishCurPageSize(false) + m_bottomMargin + m_yOffset >= m_maxHeight) createNewPage(); renderSection(*(grp->groupFooter)); } if (KReportDetailGroupSectionData::PageBreak::AfterGroupFooter == grp->pagebreak) do_break = true; } // step ahead to where we should be and print the needed headers // if all is good status = m_dataSource->moveNext(); if (do_break) createNewPage(); if (status == true) { for (int i = 0; i < shownGroups.count(); ++i) { grp = detailData->groupList[shownGroups.at(i)]; if (grp->groupHeader) { if (renderSectionSize(*(grp->groupHeader)) + finishCurPageSize(false) + m_bottomMargin + m_yOffset >= m_maxHeight) { m_dataSource->movePrevious(); createNewPage(); m_dataSource->moveNext(); } if (!keys[i].isEmpty()) keyValues[i] = m_dataSource->value(m_dataSource->fieldNumber(keys[i])).toString(); //Tell interested parties thak key values changed renderSection(*(grp->groupHeader)); } } } } } } } if (keys.size() > 0 && m_dataSource->movePrevious()) { // finish footers // duplicated changes from above here for (int i = shownGroups.count() - 1; i >= 0; i--) { grp = detailData->groupList[shownGroups.at(i)]; if (grp->groupFooter) { if (renderSectionSize(*(grp->groupFooter)) + finishCurPageSize(false) + m_bottomMargin + m_yOffset >= m_maxHeight) createNewPage(); renderSection(*(grp->groupFooter)); emit(exitedGroup(keys[i], keyValues[i])); } } } } if (KReportDetailSectionData::PageBreak::AtEnd == detailData->pageBreak) createNewPage(); } } qreal KReportPreRendererPrivate::renderSectionSize(const KReportSectionData & sectionData) { qreal intHeight = POINT_TO_INCH(sectionData.height()) * KReportPrivate::dpiX(); if (sectionData.objects().count() == 0) return intHeight; QList objects = sectionData.objects(); foreach(KReportItemBase *ob, objects) { QPointF offset(m_leftMargin, m_yOffset); //ASync objects cannot alter the section height KReportAsyncItemBase *async_ob = qobject_cast(ob); if (!async_ob) { QVariant itemData; if (m_dataSource) { itemData = m_dataSource->value(ob->itemDataSource()); } const int itemHeight = ob->renderSimpleData(nullptr, nullptr, offset, itemData, m_scriptHandler); if (itemHeight > intHeight) { intHeight = itemHeight; } } } return intHeight; } qreal KReportPreRendererPrivate::renderSection(const KReportSectionData & sectionData) { qreal sectionHeight = POINT_TO_INCH(sectionData.height()) * KReportPrivate::dpiX(); int itemHeight = 0; //kreportDebug() << "Name: " << sectionData.name() << " Height: " << sectionHeight // << "Objects: " << sectionData.objects().count(); emit(renderingSection(const_cast(§ionData), m_page, QPointF(m_leftMargin, m_yOffset))); //Create a pre-rendered section for this section and add it to the document OROSection *sec = new OROSection(m_document); sec->setHeight(sectionData.height()); sec->setBackgroundColor(sectionData.backgroundColor()); sec->setType(sectionData.type()); m_document->addSection(sec); //Render section background ORORect* bg = new ORORect(); bg->setPen(QPen(Qt::NoPen)); bg->setBrush(sectionData.backgroundColor()); qreal w = m_page->document()->pageLayout().fullRectPixels(KReportPrivate::dpiX()).width() - m_page->document()->pageLayout().marginsPixels(KReportPrivate::dpiX()).right() - m_leftMargin; bg->setRect(QRectF(m_leftMargin, m_yOffset, w, sectionHeight)); m_page->insertPrimitive(bg, true); QList objects = sectionData.objects(); foreach(KReportItemBase *ob, objects) { QPointF offset(m_leftMargin, m_yOffset); QVariant itemData = m_dataSource->value(ob->itemDataSource()); if (ob->supportsSubQuery()) { itemHeight = ob->renderReportData(m_page, sec, offset, m_dataSource, m_scriptHandler); } else { KReportAsyncItemBase *async_ob = qobject_cast(ob); if (async_ob){ //kreportDebug() << "async object"; asyncManager->addItem(async_ob, m_page, sec, offset, async_ob->realItemData(itemData), m_scriptHandler); } else { //kreportDebug() << "sync object"; itemHeight = ob->renderSimpleData(m_page, sec, offset, itemData, m_scriptHandler); } } if (itemHeight > sectionHeight) { sectionHeight = itemHeight; } } for (int i = 0; i < m_page->primitiveCount(); ++i) { OROPrimitive *prim = m_page->primitive(i); if (OROTextBox *text = dynamic_cast(prim)) { if (text->requiresPostProcessing()) { m_postProcText.append(text); } } } m_yOffset += sectionHeight; return sectionHeight; } #ifdef KREPORT_SCRIPTING void KReportPreRendererPrivate::initEngine() { delete m_scriptHandler; m_scriptHandler = new KReportScriptHandler(m_dataSource, scriptSource, m_reportDocument); connect(this, SIGNAL(enteredGroup(QString,QVariant)), m_scriptHandler, SLOT(slotEnteredGroup(QString,QVariant))); connect(this, SIGNAL(exitedGroup(QString,QVariant)), m_scriptHandler, SLOT(slotExitedGroup(QString,QVariant))); connect(this, SIGNAL(renderingSection(KReportSectionData*,OROPage*,QPointF)), m_scriptHandler, SLOT(slotEnteredSection(KReportSectionData*,OROPage*,QPointF))); } #endif void KReportPreRendererPrivate::asyncItemsFinished() { //kreportDebug() << "Finished rendering async items"; asyncManager->deleteLater(); emit finishedAllASyncItems(); } bool KReportPreRendererPrivate::generateDocument() { if (!m_dataSource) { m_dataSource = m_oneRecord; } if (!m_valid || !m_reportDocument) { return false; } // Do this check now so we don't have to undo a lot of work later if it fails KReportLabelSizeInfo label; if (m_reportDocument->pageSize() == QLatin1String("Labels")) { label = KReportLabelSizeInfo::find(m_reportDocument->labelType()); if (label.isNull()) { return false; } } //kreportDebug() << "Creating Document"; m_document = new ORODocument(m_reportDocument->title()); m_pageCounter = 0; m_yOffset = 0.0; //kreportDebug() << "Calculating Margins"; if (!label.isNull()) { if (m_reportDocument->pageLayout().orientation() == QPageLayout::Portrait) { m_topMargin = (label.startY() / 100.0); m_bottomMargin = 0; m_rightMargin = 0; m_leftMargin = (label.startX() / 100.0); } else { m_topMargin = (label.startX() / 100.0); m_bottomMargin = 0; m_rightMargin = 0; m_leftMargin = (label.startY() / 100.0); } } else { m_topMargin = m_reportDocument->pageLayout().marginsPoints().top(); m_bottomMargin = m_reportDocument->pageLayout().marginsPoints().bottom(); m_rightMargin = m_reportDocument->pageLayout().marginsPoints().right(); m_leftMargin = m_reportDocument->pageLayout().marginsPoints().left(); //kreportDebug() << "Margins:" << m_topMargin << m_bottomMargin << m_rightMargin << m_leftMargin; } //kreportDebug() << "Calculating Page Size"; QPageLayout layout = m_reportDocument->pageLayout(); // This should reflect the information of the report page size if (m_reportDocument->pageSize() == QLatin1String("Custom")) { m_maxWidth = m_reportDocument->pageLayout().fullRectPoints().width(); m_maxHeight = m_reportDocument->pageLayout().fullRectPoints().height(); } else { if (!label.isNull()) { m_maxWidth = label.width(); m_maxHeight = label.height(); m_reportDocument->pageLayout().setPageSize(QPageSize(KReportPageSize::pageSize(label.paper()))); } else { // lookup the correct size information for the specified size paper QSizeF pageSizePx = m_reportDocument->pageLayout().fullRectPixels(KReportPrivate::dpiX()).size(); m_maxWidth = pageSizePx.width(); m_maxHeight = pageSizePx.height(); } } if (m_reportDocument->pageLayout().orientation() == QPageLayout::Landscape) { qreal tmp = m_maxWidth; m_maxWidth = m_maxHeight; m_maxHeight = tmp; } //kreportDebug() << "Page Size:" << m_maxWidth << m_maxHeight; m_document->setPageLayout(m_reportDocument->pageLayout()); - m_dataSource->setSorting(m_reportDocument->m_detailSection->sortedFields); + m_dataSource->setSorting(m_reportDocument->detail()->sortedFields); if (!m_dataSource->open()) { return false; } #ifdef KREPORT_SCRIPTING initEngine(); connect(m_scriptHandler, SIGNAL(groupChanged(QMap)), m_preRenderer, SIGNAL(groupChanged(QMap))); //Loop through all abjects that have been registered, and register them with the script handler if (m_scriptHandler) { QMapIterator i(m_scriptObjects); while (i.hasNext()) { i.next(); m_scriptHandler->registerScriptObject(i.value(), i.key()); } //execute the script, if it fails, abort and return the empty document if (!m_scriptHandler->trigger()) { m_scriptHandler->displayErrors(); return m_document; } } #endif createNewPage(); if (!label.isNull()) { // Label Print Run // remember the initial margin setting as we will be modifying // the value and restoring it as we move around qreal margin = m_leftMargin; m_yOffset = m_topMargin; qreal w = (label.width() / 100.0); qreal wg = (label.xGap() / 100.0); qreal h = (label.height() / 100.0); qreal hg = (label.yGap() / 100.0); int numCols = label.columns(); int numRows = label.rows(); qreal tmp; // flip the value around if we are printing landscape - if (!m_reportDocument->pageLayout().orientation() == QPageLayout::Portrait) { + if (!(m_reportDocument->pageLayout().orientation() == QPageLayout::Portrait)) { w = (label.height() / 100.0); wg = (label.yGap() / 100.0); h = (label.width() / 100.0); hg = (label.xGap() / 100.0); numCols = label.rows(); numRows = label.columns(); } - KReportDetailSectionData * detailData = m_reportDocument->m_detailSection; + KReportDetailSectionData * detailData = m_reportDocument->detail(); if (detailData->detailSection) { KReportDataSource *mydata = m_dataSource; if (mydata && mydata->recordCount() > 0) { /* && !((query = orqThis->getQuery())->eof()))*/ if (!mydata->moveFirst()) { return false; } int row = 0; int col = 0; do { tmp = m_yOffset; // store the value as renderSection changes it renderSection(*(detailData->detailSection)); m_yOffset = tmp; // restore the value that renderSection modified col++; m_leftMargin += w + wg; if (col >= numCols) { m_leftMargin = margin; // reset back to original value col = 0; row++; m_yOffset += h + hg; if (row >= numRows) { m_yOffset = m_topMargin; row = 0; createNewPage(); } } } while (mydata->moveNext()); } } } else { // Normal Print Run - if (m_reportDocument->m_reportHeader) { - renderSection(*(m_reportDocument->m_reportHeader)); + if (m_reportDocument->section(KReportSectionData::Type::ReportHeader)) { + renderSection(*(m_reportDocument->section(KReportSectionData::Type::ReportHeader))); } - if (m_reportDocument->m_detailSection) { - renderDetailSection(m_reportDocument->m_detailSection); + if (m_reportDocument->detail()) { + renderDetailSection(m_reportDocument->detail()); } - if (m_reportDocument->m_reportFooter) { - if (renderSectionSize(*(m_reportDocument->m_reportFooter)) + finishCurPageSize(true) + m_bottomMargin + m_yOffset >= m_maxHeight) { + if (m_reportDocument->section(KReportSectionData::Type::ReportFooter)) { + if (renderSectionSize(*(m_reportDocument->section(KReportSectionData::Type::ReportFooter))) + finishCurPageSize(true) + m_bottomMargin + m_yOffset >= m_maxHeight) { createNewPage(); } - renderSection(*(m_reportDocument->m_reportFooter)); + renderSection(*(m_reportDocument->section(KReportSectionData::Type::ReportFooter))); } } finishCurPage(true); #ifdef KREPORT_SCRIPTING // _postProcText contains those text boxes that need to be updated // with information that wasn't available at the time it was added to the document m_scriptHandler->setPageTotal(m_document->pageCount()); for (int i = 0; i < m_postProcText.size(); i++) { OROTextBox * tb = m_postProcText.at(i); m_scriptHandler->setPageNumber(tb->page()->pageNumber() + 1); tb->setText(m_scriptHandler->evaluate(tb->text()).toString()); } #endif asyncManager->startRendering(); #ifdef KREPORT_SCRIPTING m_scriptHandler->displayErrors(); #endif if (!m_dataSource->close()) { return false; } #ifdef KREPORT_SCRIPTING delete m_scriptHandler; m_scriptHandler = nullptr; #endif if (m_dataSource != m_oneRecord) { delete m_dataSource; m_dataSource = nullptr; } m_postProcText.clear(); return true; } //===========================KReportPreRenderer=============================== KReportPreRenderer::KReportPreRenderer(const QDomElement &document) : d(new KReportPreRendererPrivate(this)) { setDocument(document); connect(d, &KReportPreRendererPrivate::finishedAllASyncItems, this, &KReportPreRenderer::finishedAllASyncItems); } KReportPreRenderer::~KReportPreRenderer() { delete d; } void KReportPreRenderer::setName(const QString &n) { d->m_reportDocument->setName(n); } bool KReportPreRenderer::isValid() const { if (d && d->m_valid) return true; return false; } ORODocument* KReportPreRenderer::document() { return d->m_document; } bool KReportPreRenderer::generateDocument() { // delete d->m_document; if (!d->generateDocument()) { delete d->m_document; d->m_document = nullptr; } return d->m_document; } void KReportPreRenderer::setSourceData(KReportDataSource *dataSource) { if (d && dataSource != d->m_dataSource) { delete d->m_dataSource; d->m_dataSource = dataSource; } } void KReportPreRenderer::setScriptSource(KReportScriptSource *source) { if (d) { d->scriptSource = source; } } bool KReportPreRenderer::setDocument(const QDomElement &document) { delete d->m_document; d->m_valid = false; if (document.tagName() != QLatin1String("report:content")) { kreportWarning() << "report schema is invalid"; return false; } d->m_reportDocument = new KReportDocument(document); d->m_valid = d->m_reportDocument->isValid(); return isValid(); } #ifdef KREPORT_SCRIPTING void KReportPreRenderer::registerScriptObject(QObject* obj, const QString& name) { //kreportDebug() << name; d->m_scriptObjects[name] = obj; } KReportScriptHandler *KReportPreRenderer::scriptHandler() { return d->m_scriptHandler; } #endif const KReportDocument* KReportPreRenderer::reportData() const { return d->m_reportDocument; } diff --git a/src/wrtembed/KReportDesignerItemRectBase.cpp b/src/wrtembed/KReportDesignerItemRectBase.cpp index 52d44f15..1f9b163d 100644 --- a/src/wrtembed/KReportDesignerItemRectBase.cpp +++ b/src/wrtembed/KReportDesignerItemRectBase.cpp @@ -1,397 +1,404 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include "KReportDesignerItemRectBase.h" #include "KReportDesignerSectionView.h" #include "KReportDesigner.h" #include "KReportDesignerSectionScene.h" #include "KReportUtils_p.h" #include #include #include class Q_DECL_HIDDEN KReportDesignerItemRectBase::Private { public: Private(); ~Private(); int grabAction = 0; + int dpiX = KReportPrivate::dpiX(); + int dpiY = KReportPrivate::dpiY(); }; KReportDesignerItemRectBase::Private::Private() { } KReportDesignerItemRectBase::Private::~Private() { } KReportDesignerItemRectBase::KReportDesignerItemRectBase(KReportDesigner *r, KReportItemBase *b) : QGraphicsRectItem(), KReportDesignerItemBase(r, b), d(new KReportDesignerItemRectBase::Private) { - m_dpiX = KReportPrivate::dpiX(); - m_dpiY = KReportPrivate::dpiY(); - - d->grabAction = 0; setAcceptHoverEvents(true); - setFlags(ItemIsSelectable | ItemIsMovable | ItemSendsGeometryChanges); } KReportDesignerItemRectBase::~KReportDesignerItemRectBase() { delete d; } QRectF KReportDesignerItemRectBase::sceneRect() { return QRectF(KReportItemBase::scenePosition(item()->position()), KReportItemBase::sceneSize(item()->size())); } QRectF KReportDesignerItemRectBase::pointRect() const { return QRectF(item()->position(), item()->size()); } void KReportDesignerItemRectBase::setSceneRect(const QPointF& topLeft, const QSizeF& size, SceneRectFlag update) { setSceneRect(QRectF(topLeft, size), update); } void KReportDesignerItemRectBase::setSceneRect(const QRectF& rect, SceneRectFlag update) { QGraphicsRectItem::setPos(rect.x(), rect.y()); setRect(0, 0, rect.width(), rect.height()); if (update == SceneRectFlag::UpdateProperty) { item()->setPosition(KReportItemBase::positionFromScene(QPointF(rect.x(), rect.y()))); item()->setSize(KReportItemBase::sizeFromScene(QSizeF(rect.width(), rect.height()))); } this->update(); } void KReportDesignerItemRectBase::mousePressEvent(QGraphicsSceneMouseEvent * event) { //Update and show properties item()->setPosition(KReportItemBase::positionFromScene(QPointF(sceneRect().x(), sceneRect().y()))); designer()->changeSet(item()->propertySet()); setSelected(true); scene()->update(); QGraphicsItem::mousePressEvent(event); } void KReportDesignerItemRectBase::mouseReleaseEvent(QGraphicsSceneMouseEvent * event) { //Keep the size and position in sync item()->setPosition(KReportItemBase::positionFromScene(pos())); item()->setSize(KReportItemBase::sizeFromScene(QSizeF(rect().width(), rect().height()))); QGraphicsItem::mouseReleaseEvent(event); } void KReportDesignerItemRectBase::mouseMoveEvent(QGraphicsSceneMouseEvent * event) { //kreportDebug() << m_grabAction; qreal w, h; KReportDesignerSectionScene *section = qobject_cast(scene()); if (!section) { return; } QPointF p = section->gridPoint(event->scenePos()); w = p.x() - scenePos().x(); h = p.y() - scenePos().y(); //! @todo use an enum for the directions switch (d->grabAction) { case 1: if (sceneRect().y() - p.y() + rect().height() > 0 && sceneRect().x() - p.x() + rect().width() >= 0) setSceneRect(QPointF(p.x(), p.y()), QSizeF(sceneRect().x() - p.x() + rect().width(), sceneRect().y() - p.y() + rect().height())); break; case 2: if (sceneRect().y() - p.y() + rect().height() >= 0) setSceneRect(QPointF(sceneRect().x(), p.y()), QSizeF(rect().width(), sceneRect().y() - p.y() + rect().height())); break; case 3: if (sceneRect().y() - p.y() + rect().height() >= 0 && w >= 0) setSceneRect(QPointF(sceneRect().x(), p.y()), QSizeF(w, sceneRect().y() - p.y() + rect().height())); break; case 4: if (w >= 0) setSceneRect(QPointF(sceneRect().x(), sceneRect().y()), QSizeF(w, (rect().height()))); break; case 5: if (h >= 0 && w >= 0) setSceneRect(QPointF(sceneRect().x(), sceneRect().y()), QSizeF(w, h)); break; case 6: if (h >= 0) setSceneRect(QPointF(sceneRect().x(), sceneRect().y()), QSizeF((rect().width()), h)); break; case 7: if (sceneRect().x() - p.x() + rect().width() >= 0 && h >= 0) setSceneRect(QPointF(p.x(), sceneRect().y()), QSizeF(sceneRect().x() - p.x() + rect().width(), h)); break; case 8: if (sceneRect().x() - p.x() + rect().width() >= 0) setSceneRect(QPointF(p.x(), sceneRect().y()), QSizeF(sceneRect().x() - p.x() + rect().width(), rect().height())); break; default: QGraphicsItem::mouseMoveEvent(event); } } void KReportDesignerItemRectBase::hoverMoveEvent(QGraphicsSceneHoverEvent * event) { //m_grabAction = 0; if (isSelected()) { d->grabAction = grabHandle(event->pos()); switch (d->grabAction) { case 1: setCursor(Qt::SizeFDiagCursor); break; case 2: setCursor(Qt::SizeVerCursor); break; case 3: setCursor(Qt::SizeBDiagCursor); break; case 4: setCursor(Qt::SizeHorCursor); break; case 5: setCursor(Qt::SizeFDiagCursor); break; case 6: setCursor(Qt::SizeVerCursor); break; case 7: setCursor(Qt::SizeBDiagCursor); break; case 8: setCursor(Qt::SizeHorCursor); break; default: unsetCursor(); } } //kreportDebug() << m_grabAction; } void KReportDesignerItemRectBase::drawHandles(QPainter *painter) { if (isSelected()) { // draw a selected border for visual purposes painter->setPen(QPen(QColor(128, 128, 255), 0, Qt::DotLine)); painter->drawRect(rect()); const QRectF r = rect(); double halfW = (r.width() / 2); double halfH = (r.height() / 2); QPointF center = r.center(); center += QPointF(0.75,0.75); painter->fillRect(center.x() - halfW, center.y() - halfH , 5, 5, QColor(128, 128, 255)); painter->fillRect(center.x() - 2, center.y() - halfH , 5, 5, QColor(128, 128, 255)); painter->fillRect(center.x() + halfW - 4, center.y() - halfH, 5, 5, QColor(128, 128, 255)); painter->fillRect(center.x() + (halfW - 4), center.y() - 2, 5, 5, QColor(128, 128, 255)); painter->fillRect(center.x() + halfW - 4 , center.y() + halfH - 4 , 5, 5, QColor(128, 128, 255)); painter->fillRect(center.x() - 2, center.y() + halfH - 4, 5, 5, QColor(128, 128, 255)); painter->fillRect(center.x() - halfW, center.y() + halfH - 4 , 5, 5, QColor(128, 128, 255)); painter->fillRect(center.x() - halfW, center.y() - 2, 5, 5, QColor(128, 128, 255)); } } /** @return 1 2 3 8 0 4 7 6 5 */ int KReportDesignerItemRectBase::grabHandle(const QPointF &pos) { QRectF r = boundingRect(); int halfW = (int)(r.width() / 2); int halfH = (int)(r.height() / 2); QPointF center = r.center(); if (QRectF(center.x() - (halfW), center.y() - (halfH), 5, 5).contains(pos)) { // we are over the top-left handle return 1; } else if (QRectF(center.x() - 2, center.y() - (halfH), 5, 5).contains(pos)) { // top-middle handle return 2; } else if (QRectF(center.x() + (halfW - 4), center.y() - (halfH), 5, 5).contains(pos)) { // top-right return 3; } else if (QRectF(center.x() + (halfW - 4), center.y() - 2, 5, 5).contains(pos)) { // middle-right return 4; } else if (QRectF(center.x() + (halfW - 4), center.y() + (halfH - 4), 5, 5).contains(pos)) { // bottom-left return 5; } else if (QRectF(center.x() - 2, center.y() + (halfH - 4), 5, 5).contains(pos)) { // bottom-middle return 6; } else if (QRectF(center.x() - (halfW), center.y() + (halfH - 4), 5, 5).contains(pos)) { // bottom-right return 7; } else if (QRectF(center.x() - (halfW), center.y() - 2, 5, 5).contains(pos)) { // middle-right return 8; } return 0; } QVariant KReportDesignerItemRectBase::itemChange(GraphicsItemChange change, const QVariant &value) { KReportDesignerSectionScene *section = qobject_cast(scene()); if (section) { if (change == ItemPositionChange) { QPointF newPos = value.toPointF(); newPos = section->gridPoint(newPos); if (newPos.x() < 0) newPos.setX(0); else if (newPos.x() > (scene()->width() - rect().width())) newPos.setX(scene()->width() - rect().width()); if (newPos.y() < 0) newPos.setY(0); else if (newPos.y() > (scene()->height() - rect().height())) newPos.setY(scene()->height() - rect().height()); return newPos; } else if (change == ItemPositionHasChanged) { setSceneRect(value.toPointF(), KReportItemBase::sceneSize(item()->size()), SceneRectFlag::DontUpdateProperty); } else if (change == ItemSceneHasChanged && item()) { QPointF newPos = pos(); newPos = section->gridPoint(newPos); if (newPos.x() < 0) newPos.setX(0); else if (newPos.x() > (scene()->width() - rect().width())) newPos.setX(scene()->width() - rect().width()); if (newPos.y() < 0) newPos.setY(0); else if (newPos.y() > (scene()->height() - rect().height())) newPos.setY(scene()->height() - rect().height()); setSceneRect(newPos, KReportItemBase::sceneSize(item()->size()), KReportDesignerItemRectBase::SceneRectFlag::DontUpdateProperty); } } return QGraphicsItem::itemChange(change, value); } void KReportDesignerItemRectBase::propertyChanged(const KPropertySet &s, const KProperty &p) { Q_UNUSED(s) Q_UNUSED(p) #if 0 if (p.name() == "position") { item()->setPosition(item()->unit().convertToPoint(p.value().toPointF())); //TODO dont update property } else if (p.name() == "size") { item()->setSize(item()->unit().convertToPoint(p.value().toSizeF())); //TODO dont update property } #endif setSceneRect(KReportItemBase::scenePosition(item()->position()), KReportItemBase::sceneSize(item()->size()), SceneRectFlag::DontUpdateProperty); } void KReportDesignerItemRectBase::move(const QPointF& /*m*/) { //! @todo } QPointF KReportDesignerItemRectBase::properPressPoint(const KReportDesigner &d) const { const QPointF pressPoint = d.getPressPoint(); const QPointF releasePoint = d.getReleasePoint(); if (releasePoint.x() < pressPoint.x() && releasePoint.y() < pressPoint.y()) { return releasePoint; } if (releasePoint.x() < pressPoint.x() && releasePoint.y() > pressPoint.y()) { return QPointF(releasePoint.x(), pressPoint.y()); } if (releasePoint.x() > pressPoint.x() && releasePoint.y() < pressPoint.y()) { return QPointF(pressPoint.x(), releasePoint.y()); } return QPointF(pressPoint); } QRectF KReportDesignerItemRectBase::properRect(const KReportDesigner &d, qreal minWidth, qreal minHeight) const { QPointF tempPressPoint = properPressPoint(d); qreal currentPressX = tempPressPoint.x(); qreal currentPressY = tempPressPoint.y(); const qreal width = qMax(d.countSelectionWidth(), minWidth); const qreal height = qMax(d.countSelectionHeight(), minHeight); qreal tempReleasePointX = tempPressPoint.x() + width; qreal tempReleasePointY = tempPressPoint.y() + height; if (tempReleasePointX > scene()->width()) { int offsetWidth = tempReleasePointX - scene()->width(); currentPressX = tempPressPoint.x() - offsetWidth; } if (tempReleasePointY > scene()->height()) { int offsetHeight = tempReleasePointY - scene()->height(); currentPressY = tempPressPoint.y() - offsetHeight; } return (QRectF(QPointF(currentPressX, currentPressY), QSizeF(width, height))); } void KReportDesignerItemRectBase::enterInlineEditingMode() { } void KReportDesignerItemRectBase::exitInlineEditingMode() { } void KReportDesignerItemBase::updateRenderText(const QString &itemDataSource, const QString &itemStaticValue, const QString &itemType) { if (itemDataSource.isEmpty()) { if (itemType.isEmpty()) { setRenderText(itemStaticValue); } else { setRenderText(dataSourceAndObjectTypeName(itemStaticValue, itemType)); } } else { if (itemType.isEmpty()) { setRenderText(itemDataSource); } else { setRenderText(dataSourceAndObjectTypeName(itemDataSource, itemType)); } } } + +int KReportDesignerItemRectBase::dpiX() const +{ + return d->dpiX; +} + +int KReportDesignerItemRectBase::dpiY() const +{ + return d->dpiY; +} diff --git a/src/wrtembed/KReportDesignerItemRectBase.h b/src/wrtembed/KReportDesignerItemRectBase.h index de1605ce..18edfed9 100644 --- a/src/wrtembed/KReportDesignerItemRectBase.h +++ b/src/wrtembed/KReportDesignerItemRectBase.h @@ -1,83 +1,84 @@ /* This file is part of the KDE project * Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com) * Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #ifndef KREPORTDESIGNERITEMRECTBASE_H #define KREPORTDESIGNERITEMRECTBASE_H #include #include "KReportDesignerItemBase.h" #include "kreport_export.h" class KReportDesigner; class KPropertySet; const int KREPORT_ITEM_RECT_DEFAULT_WIDTH = 100; const int KREPORT_ITEM_RECT_DEFAULT_HEIGHT = 100; /** */ class KREPORT_EXPORT KReportDesignerItemRectBase : public QGraphicsRectItem, public KReportDesignerItemBase { public: explicit KReportDesignerItemRectBase(KReportDesigner *r, KReportItemBase *b); ~KReportDesignerItemRectBase() override; QRectF pointRect() const; virtual void enterInlineEditingMode(); virtual void exitInlineEditingMode(); protected: - int m_dpiX; - int m_dpiY; enum class SceneRectFlag { UpdateProperty, DontUpdateProperty }; void setSceneRect(const QPointF &topLeft, const QSizeF &size, SceneRectFlag update = SceneRectFlag::UpdateProperty); void setSceneRect(const QRectF &rect, SceneRectFlag update = SceneRectFlag::UpdateProperty); void drawHandles(QPainter*); QRectF sceneRect(); void mousePressEvent(QGraphicsSceneMouseEvent * event) override; void mouseReleaseEvent(QGraphicsSceneMouseEvent * event) override; void mouseMoveEvent(QGraphicsSceneMouseEvent * event) override; void hoverMoveEvent(QGraphicsSceneHoverEvent * event) override; QVariant itemChange(GraphicsItemChange change, const QVariant &value) override; void propertyChanged(const KPropertySet &s, const KProperty &p); void move(const QPointF&) override; QRectF properRect(const KReportDesigner &d, qreal minWidth, qreal minHeight) const; + int dpiX() const; + int dpiY() const; private: + Q_DISABLE_COPY(KReportDesignerItemRectBase) int grabHandle(const QPointF &pos); QPointF properPressPoint(const KReportDesigner &d) const; class Private; Private * const d; }; #endif