diff --git a/src/common/KReportDocument.h b/src/common/KReportDocument.h index 72f9e028..5fbf1f75 100644 --- a/src/common/KReportDocument.h +++ b/src/common/KReportDocument.h @@ -1,115 +1,114 @@ /* 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 /*! * @brief Top level report document definition. * A KReportDocment defines the design of a document, and is composed of multiple * sections. */ 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; void setName(const QString&n); QString name() const; QString title() const; QPageLayout pageLayout() const; QString pageSize(); void setPageSize(const QString &size); 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/common/KReportSectionData.cpp b/src/common/KReportSectionData.cpp index dfdc3ea2..37565b20 100644 --- a/src/common/KReportSectionData.cpp +++ b/src/common/KReportSectionData.cpp @@ -1,278 +1,340 @@ /* 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) - * Copyright (C) 2010 Jarosław Staniek + * Copyright (C) 2010-2018 Jarosław Staniek * * 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 "KReportSectionData.h" #include "KReportDesigner.h" #include "KReportDocument.h" #include "KReportItemLine.h" #include "KReportPluginInterface.h" #include "KReportPluginManager.h" #include "KReportItemLine.h" #include "KReportDesigner.h" #include "KReportUtils.h" #include "KReportUtils_p.h" #include "kreport_debug.h" #include #include -KReportSectionData::KReportSectionData(QObject *parent) : KReportSectionData(QDomElement(), parent) +class Q_DECL_HIDDEN KReportSectionData::Private { -} +public: + explicit Private(KReportSectionData *data, const QDomElement &elemSource) : q(data) + { + if (!elemSource.isNull()) { + q->setObjectName(elemSource.tagName()); + type = sectionTypeFromString(KReportUtils::readSectionTypeNameAttribute(elemSource)); + } + createProperties(elemSource); + if (!elemSource.isNull()) { + loadXml(elemSource); + } + set.clearModifiedFlags(); + } -KReportSectionData::KReportSectionData(const QDomElement & elemSource, QObject *parent) - : QObject(parent) - , m_unit(DEFAULT_UNIT_TYPE) -{ - if (elemSource.isNull()) { - m_type = Type::None; - } else { - setObjectName(elemSource.tagName()); - m_type = sectionTypeFromString(KReportUtils::readSectionTypeNameAttribute(elemSource)); + ~Private() + { + qDeleteAll(objects); } - createProperties(elemSource); + void setHeight(qreal ptHeight, KProperty::ValueOptions options); - if (elemSource.isNull()) { - m_valid = true; - } else { - loadXml(elemSource); - } - m_set->clearModifiedFlags(); + static bool zLessThan(KReportItemBase* s1, KReportItemBase* s2); + static bool xLessThan(KReportItemBase* s1, KReportItemBase* s2); + + KReportSectionData * const q; + KPropertySet set; + KProperty *backgroundColor; + KProperty *height; + QList objects; + KReportUnit unit = KReportUnit(DEFAULT_UNIT_TYPE); + Type type = Type::None; + bool valid = true; + +private: + void createProperties(const QDomElement &elemSource); + void loadXml(const QDomElement &elemSource); +}; + +KReportSectionData::KReportSectionData(QObject *parent) + : KReportSectionData(QDomElement(), parent) +{ +} + +KReportSectionData::KReportSectionData(const QDomElement & elemSource, QObject *parent) + : QObject(parent), d(new Private(this, elemSource)) +{ } -void KReportSectionData::loadXml(const QDomElement &elemSource) +void KReportSectionData::Private::loadXml(const QDomElement &elemSource) { - if (objectName() != QLatin1String("report:section") || m_type == KReportSectionData::Type::None) { - m_valid = false; + if (q->objectName() != QLatin1String("report:section") || type == KReportSectionData::Type::None) { + valid = false; return; } KReportPluginManager* manager = KReportPluginManager::self(); QDomNodeList section = elemSource.childNodes(); for (int nodeCounter = 0; nodeCounter < section.count(); nodeCounter++) { QDomElement elemThis = section.item(nodeCounter).toElement(); QString n = elemThis.tagName(); if (n.startsWith(QLatin1String("report:"))) { KReportItemBase *krobj = nullptr; QString reportItemName = n.mid(qstrlen("report:")); if (reportItemName == QLatin1String("line")) { KReportItemLine * line = new KReportItemLine(elemThis); krobj = line; } else { KReportPluginInterface *plugin = manager->plugin(reportItemName); if (plugin) { QObject *obj = plugin->createRendererInstance(elemThis); if (obj) { krobj = dynamic_cast(obj); } } } if (krobj) { krobj->propertySet()->clearModifiedFlags(); - m_objects.append(krobj); + objects.append(krobj); } else { kreportWarning() << "Could not create element of type" << reportItemName; } } else { kreportWarning() << "While parsing section encountered an unknown element:" << n; } } - qSort(m_objects.begin(), m_objects.end(), zLessThan); - m_valid = true; + qSort(objects.begin(), objects.end(), zLessThan); + valid = true; } KReportSectionData::~KReportSectionData() { - delete m_set; - qDeleteAll(m_objects); + delete d; } KReportUnit KReportSectionData::unit() const { - return m_unit; + return d->unit; } void KReportSectionData::setUnit(const KReportUnit &u) { - if (m_unit == u) { + if (d->unit == u) { return; } // convert values - KReportUnit oldunit = m_unit; - m_unit = u; + KReportUnit oldunit = d->unit; + d->unit = u; - m_height->setValue(KReportUnit::convertFromUnitToUnit(m_height->value().toReal(), oldunit, u), + d->height->setValue(KReportUnit::convertFromUnitToUnit(d->height->value().toReal(), oldunit, u), KProperty::ValueOption::IgnoreOld); - m_height->setOption("suffix", u.symbol()); + d->height->setOption("suffix", u.symbol()); } -bool KReportSectionData::zLessThan(KReportItemBase* s1, KReportItemBase* s2) +bool KReportSectionData::Private::zLessThan(KReportItemBase* s1, KReportItemBase* s2) { return s1->z() < s2->z(); } -bool KReportSectionData::xLessThan(KReportItemBase* s1, KReportItemBase* s2) +bool KReportSectionData::Private::xLessThan(KReportItemBase* s1, KReportItemBase* s2) { return s1->position().toPoint().x() < s2->position().toPoint().x(); } -void KReportSectionData::createProperties(const QDomElement & elemSource) +void KReportSectionData::Private::createProperties(const QDomElement & elemSource) { - m_set = new KPropertySet(this); - KReportDesigner::addMetaProperties(m_set, - tr("Section", "Report section"), QLatin1String("kreport-section-element")); - - m_height = new KProperty("height", 0.0, tr("Height")); - m_backgroundColor = new KProperty( + KReportDesigner::addMetaProperties(&set, KReportSectionData::tr("Section", "Report section"), + QLatin1String("kreport-section-element")); + height = new KProperty("height", 0.0, tr("Height")); + backgroundColor = new KProperty( "background-color", KReportUtils::attr(elemSource, QLatin1String("fo:background-color"), QColor(Qt::white)), tr("Background Color")); - m_height->setOption("unit", QLatin1String("cm")); + height->setOption("unit", QLatin1String("cm")); if (!elemSource.isNull()) { - m_height->setValue(m_unit.convertFromPoint( + height->setValue(unit.convertFromPoint( KReportUtils::readSizeAttributes( elemSource, QSizeF(DEFAULT_SECTION_SIZE_PT, DEFAULT_SECTION_SIZE_PT)) .height())); } - m_set->addProperty(m_height); - m_set->addProperty(m_backgroundColor); - m_set->clearModifiedFlags(); + set.addProperty(height); + set.addProperty(backgroundColor); + set.clearModifiedFlags(); } QString KReportSectionData::name() const { - return (objectName() + QLatin1Char('-') + sectionTypeString(m_type)); + return (objectName() + QLatin1Char('-') + sectionTypeString(d->type)); } QString KReportSectionData::sectionTypeString(KReportSectionData::Type type) { //! @todo use QMap QString sectiontype; switch (type) { case KReportSectionData::Type::PageHeaderAny: sectiontype = QLatin1String("header-page-any"); break; case KReportSectionData::Type::PageHeaderEven: sectiontype = QLatin1String("header-page-even"); break; case KReportSectionData::Type::PageHeaderOdd: sectiontype = QLatin1String("header-page-odd"); break; case KReportSectionData::Type::PageHeaderFirst: sectiontype = QLatin1String("header-page-first"); break; case KReportSectionData::Type::PageHeaderLast: sectiontype = QLatin1String("header-page-last"); break; case KReportSectionData::Type::PageFooterAny: sectiontype = QLatin1String("footer-page-any"); break; case KReportSectionData::Type::PageFooterEven: sectiontype = QLatin1String("footer-page-even"); break; case KReportSectionData::Type::PageFooterOdd: sectiontype = QLatin1String("footer-page-odd"); break; case KReportSectionData::Type::PageFooterFirst: sectiontype = QLatin1String("footer-page-first"); break; case KReportSectionData::Type::PageFooterLast: sectiontype = QLatin1String("footer-page-last"); break; case KReportSectionData::Type::ReportHeader: sectiontype = QLatin1String("header-report"); break; case KReportSectionData::Type::ReportFooter: sectiontype = QLatin1String("footer-report"); break; case KReportSectionData::Type::GroupHeader: sectiontype = QLatin1String("group-header"); break; case KReportSectionData::Type::GroupFooter: sectiontype = QLatin1String("group-footer"); break; case KReportSectionData::Type::Detail: sectiontype = QLatin1String("detail"); break; default: break; } return sectiontype; } KReportSectionData::Type KReportSectionData::sectionTypeFromString(const QString& s) { //! @todo use QMap KReportSectionData::Type type; //kreportDebug() << "Determining section type for " << s; if (s == QLatin1String("header-page-any")) type = KReportSectionData::Type::PageHeaderAny; else if (s == QLatin1String("header-page-even")) type = KReportSectionData::Type::PageHeaderEven; else if (s == QLatin1String("header-page-odd")) type = KReportSectionData::Type::PageHeaderOdd; else if (s == QLatin1String("header-page-first")) type = KReportSectionData::Type::PageHeaderFirst; else if (s == QLatin1String("header-page-last")) type = KReportSectionData::Type::PageHeaderLast; else if (s == QLatin1String("header-report")) type = KReportSectionData::Type::ReportHeader; else if (s == QLatin1String("footer-page-any")) type = KReportSectionData::Type::PageFooterAny; else if (s == QLatin1String("footer-page-even")) type = KReportSectionData::Type::PageFooterEven; else if (s == QLatin1String("footer-page-odd")) type = KReportSectionData::Type::PageFooterOdd; else if (s == QLatin1String("footer-page-first")) type = KReportSectionData::Type::PageFooterFirst; else if (s == QLatin1String("footer-page-last")) type = KReportSectionData::Type::PageFooterLast; else if (s == QLatin1String("footer-report")) type = KReportSectionData::Type::ReportFooter; else if (s == QLatin1String("group-header")) type = KReportSectionData::Type::GroupHeader; else if (s == QLatin1String("group-footer")) type = KReportSectionData::Type::GroupFooter; else if (s == QLatin1String("detail")) type = KReportSectionData::Type::Detail; else type = KReportSectionData::Type::None; return type; } qreal KReportSectionData::height() const { - return m_unit.convertToPoint(m_height->value().toReal()); + return d->unit.convertToPoint(d->height->value().toReal()); } void KReportSectionData::setHeight(qreal ptHeight, KProperty::ValueOptions options) { - m_height->setValue(m_unit.convertFromPoint(ptHeight), options); + d->height->setValue(d->unit.convertFromPoint(ptHeight), options); } void KReportSectionData::setHeight(qreal ptHeight) { setHeight(ptHeight, KProperty::ValueOptions()); } + +KPropertySet* KReportSectionData::propertySet() +{ + return &d->set; +} + +const KPropertySet* KReportSectionData::propertySet() const +{ + return &d->set; +} + +bool KReportSectionData::isValid() const +{ + return d->valid; +} + +QList KReportSectionData::objects() const +{ + return d->objects; +} + +QColor KReportSectionData::backgroundColor() const +{ + return d->backgroundColor->value().value(); +} + +void KReportSectionData::setBackgroundColor(const QColor &color) +{ + d->backgroundColor->setValue(color); +} + +KReportSectionData::Type KReportSectionData::type() const +{ + return d->type; +} + +KReportItemBase* KReportSectionData::object(int index) +{ + return d->objects.value(index); +} diff --git a/src/common/KReportSectionData.h b/src/common/KReportSectionData.h index 85fd1b7e..f2e04a93 100644 --- a/src/common/KReportSectionData.h +++ b/src/common/KReportSectionData.h @@ -1,131 +1,119 @@ /* 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) - * Copyright (C) 2010 Jarosław Staniek + * Copyright (C) 2010-2018 Jarosław Staniek * * 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 KREPORTSECTIONDATA_H #define KREPORTSECTIONDATA_H #include "KReportUnit.h" #include #include class KReportItemBase; class KReportDocument; class QDomElement; namespace Scripting { class Section; } -// -// KReportSectionData is used to store the information about a specific -// section. -// A section has a name and optionally extra data. `name' -// reportheader, reportfooter, pageheader, pagefooter, groupheader, groupfooter or detail. -// In the case of pghead and pgfoot extra would contain the page -// designation (firstpage, odd, even or lastpage). -class KReportSectionData : public QObject +/** + * KReportSectionData is used to store the information about a specific report section + * + * A section has a name, type, unit and optionally extra data. + */ +class KREPORT_EXPORT KReportSectionData : public QObject { Q_OBJECT public: enum class Type { None, PageHeaderFirst, PageHeaderOdd, PageHeaderEven, PageHeaderLast, PageHeaderAny, ReportHeader, ReportFooter, PageFooterFirst, PageFooterOdd, PageFooterEven, PageFooterLast, PageFooterAny, GroupHeader, GroupFooter, Detail }; explicit KReportSectionData(QObject* parent = nullptr); explicit KReportSectionData(const QDomElement &elemSource, QObject *parent = nullptr); ~KReportSectionData() override; KReportUnit unit() const; void setUnit(const KReportUnit &u); - KPropertySet* propertySet() const { - return m_set; - } + /** + * Returns property set for this section + * + * @since 3.1 + */ + KPropertySet* propertySet(); + + /** + * @overload + */ + const KPropertySet* propertySet() const; - bool isValid() const { - return m_valid; - } + bool isValid() const; qreal height() const; void setHeight(qreal ptHeight); - QList objects() const { - return m_objects; - } + QList objects() const; QString name() const; - QColor backgroundColor() const { - return m_backgroundColor->value().value(); - } + QColor backgroundColor() const; - Type type() const { - return m_type; - } + Type type() const; static KReportSectionData::Type sectionTypeFromString(const QString& s); static QString sectionTypeString(KReportSectionData::Type type); -protected: - KPropertySet *m_set; - KProperty *m_backgroundColor; private: - void createProperties(const QDomElement & elemSource); - void loadXml(const QDomElement &elemSource); + void setBackgroundColor(const QColor &color); void setHeight(qreal ptHeight, KProperty::ValueOptions options); + KReportItemBase* object(int index); - KProperty *m_height; - QList m_objects; - KReportUnit m_unit; - - Type m_type; - - static bool zLessThan(KReportItemBase* s1, KReportItemBase* s2); - static bool xLessThan(KReportItemBase* s1, KReportItemBase* s2); - - bool m_valid; + Q_DISABLE_COPY(KReportSectionData) + class Private; + Private * const d; friend class Scripting::Section; friend class KReportDesignerSection; }; #endif diff --git a/src/renderer/scripting/KReportScriptSection.cpp b/src/renderer/scripting/KReportScriptSection.cpp index 9807e938..a0527edd 100644 --- a/src/renderer/scripting/KReportScriptSection.cpp +++ b/src/renderer/scripting/KReportScriptSection.cpp @@ -1,108 +1,107 @@ /* 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 "KReportScriptSection.h" #include "KReportScriptLine.h" #include "KReportItemBase.h" #include "KReportPluginManager.h" #include "KReportPluginInterface.h" #include "KReportItemLine.h" #include "KReportSectionData.h" #include "kreport_debug.h" namespace Scripting { Section::Section(KReportSectionData* sec) { m_section = sec; m_scriptObject = 0; } Section::~Section() { } QColor Section::backgroundColor() const { - return m_section->m_backgroundColor->value().value(); + return m_section->backgroundColor(); } -void Section::setBackgroundColor(const QColor &c) +void Section::setBackgroundColor(const QColor &c) { - //kreportDebug() << c.name(); - m_section->m_backgroundColor->setValue(c); + m_section->setBackgroundColor(c); } qreal Section::height() const { return m_section->height(); } void Section::setHeight(qreal h) { m_section->setHeight(h); } QString Section::name() const { return m_section->objectName(); } QObject* Section::objectByNumber(int i) { - if (m_section->m_objects[i]->typeName() == QLatin1String("line")) { - return new Scripting::Line(dynamic_cast(m_section->m_objects[i])); + if (m_section->object(i)->typeName() == QLatin1String("line")) { + return new Scripting::Line(dynamic_cast(m_section->object(i))); } else { KReportPluginManager* manager = KReportPluginManager::self(); - KReportPluginInterface *plugin = manager->plugin(m_section->m_objects[i]->typeName()); + KReportPluginInterface *plugin = manager->plugin(m_section->object(i)->typeName()); if (plugin) { - QObject *obj = plugin->createScriptInstance(m_section->m_objects[i]); + QObject *obj = plugin->createScriptInstance(m_section->object(i)); if (obj) { return obj; } } else { - kreportWarning() << "Encountered unknown node while parsing section: " << m_section->m_objects[i]->typeName(); + kreportWarning() << "Encountered unknown node while parsing section: " << m_section->object(i)->typeName(); } } return new QObject(); } QObject* Section::objectByName(const QString& n) { for (int i = 0; i < m_section->objects().count(); ++i) { - if (m_section->m_objects[i]->entityName() == n) { + if (m_section->object(i)->entityName() == n) { return objectByNumber(i); } } return nullptr; } void Section::initialize(const QJSValue &s) { m_scriptObject = s; } void Section::eventOnRender() { if (m_scriptObject.isObject() && m_scriptObject.hasProperty(QLatin1String("OnRender"))) m_scriptObject.property(QLatin1String("OnRender")).call(); } } diff --git a/src/wrtembed/KReportDesignerSection.cpp b/src/wrtembed/KReportDesignerSection.cpp index 975d8c94..2a246adc 100644 --- a/src/wrtembed/KReportDesignerSection.cpp +++ b/src/wrtembed/KReportDesignerSection.cpp @@ -1,453 +1,453 @@ /* 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) * Copyright (C) 2014 Jarosław Staniek * * 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 "KReportDesignerSection.h" #include "KReportDesignerSectionScene.h" #include "KReportDesignerSectionView.h" #include "KReportDesigner.h" #include "KReportDesignerItemBase.h" #include "KReportUtils.h" #include "KReportPluginInterface.h" #include "KReportPluginManager.h" #include "KReportDesignerItemRectBase.h" #include "KReportDesignerItemLine.h" #include "KReportRuler_p.h" #include "KReportZoomHandler_p.h" #include "KReportUtils_p.h" #include "KReportPluginMetaData.h" #include "kreport_debug.h" #include #include #include #include #include #include #include #include #include //! @internal class ReportResizeBar : public QFrame { Q_OBJECT public: explicit ReportResizeBar(QWidget * parent = nullptr, Qt::WindowFlags f = nullptr); Q_SIGNALS: void barDragged(int delta); protected: void mouseMoveEvent(QMouseEvent * e) override; }; //! @internal class KReportDesignerSectionTitle : public QLabel { Q_OBJECT public: explicit KReportDesignerSectionTitle(QWidget *parent = nullptr); ~KReportDesignerSectionTitle() override; Q_SIGNALS: void clicked(); protected: void paintEvent(QPaintEvent* event) override; void mousePressEvent(QMouseEvent *event) override; }; //! @internal class Q_DECL_HIDDEN KReportDesignerSection::Private { public: explicit Private() {} ~Private() {} KReportDesignerSectionTitle *title; KReportDesignerSectionScene *scene; ReportResizeBar *resizeBar; KReportDesignerSectionView *sceneView; KReportDesigner*reportDesigner; KReportRuler *sectionRuler; KReportSectionData *sectionData; int dpiY; bool slotPropertyChangedEnabled = true; }; KReportDesignerSection::KReportDesignerSection(KReportDesigner * rptdes, const KReportZoomHandler &zoomHandler) : QWidget(rptdes) , d(new Private()) { Q_ASSERT(rptdes); d->sectionData = new KReportSectionData(this); connect(d->sectionData->propertySet(), SIGNAL(propertyChanged(KPropertySet&,KProperty&)), this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&))); d->dpiY = KReportPrivate::dpiY(); d->reportDesigner = rptdes; setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); QGridLayout * glayout = new QGridLayout(this); glayout->setSpacing(0); glayout->setMargin(0); glayout->setColumnStretch(1, 1); glayout->setRowStretch(1, 1); glayout->setSizeConstraint(QLayout::SetFixedSize); // ok create the base interface d->title = new KReportDesignerSectionTitle(this); d->title->setObjectName(QLatin1String("detail")); d->title->setText(tr("Detail")); d->sectionRuler = new KReportRuler(this, Qt::Vertical, zoomHandler); d->sectionRuler->setUnit(d->reportDesigner->pageUnit()); d->scene = new KReportDesignerSectionScene(d->reportDesigner->pageWidthPx(), d->dpiY, rptdes); d->scene->setBackgroundBrush(d->sectionData->backgroundColor()); d->sceneView = new KReportDesignerSectionView(rptdes, d->scene, this); d->sceneView->setObjectName(QLatin1String("scene view")); d->sceneView->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); d->resizeBar = new ReportResizeBar(this); connect(d->resizeBar, SIGNAL(barDragged(int)), this, SLOT(slotResizeBarDragged(int))); connect(d->reportDesigner, &KReportDesigner::pagePropertyChanged, this, &KReportDesignerSection::slotPageOptionsChanged); connect(d->scene, &KReportDesignerSectionScene::clicked, this, &KReportDesignerSection::slotSceneClicked); connect(d->scene, SIGNAL(lostFocus()), d->title, SLOT(update())); connect(d->title, &KReportDesignerSectionTitle::clicked, this, &KReportDesignerSection::slotSceneClicked); glayout->addWidget(d->title, 0, 0, 1, 2); glayout->addWidget(d->sectionRuler, 1, 0); glayout->addWidget(d->sceneView , 1, 1); glayout->addWidget(d->resizeBar, 2, 0, 1, 2); d->sectionRuler->setFixedWidth(d->sectionRuler->sizeHint().width()); setLayout(glayout); slotResizeBarDragged(0); } KReportDesignerSection::~KReportDesignerSection() { delete d; } void KReportDesignerSection::setTitle(const QString & s) { d->title->setText(s); } void KReportDesignerSection::slotResizeBarDragged(int delta, bool changeSet) { if (d->sceneView->designer() && d->sceneView->designer()->propertySet()->property("page-size").value().toString() == QLatin1String("Labels")) { return; // we don't want to allow this on reports that are for labels } if (changeSet) { slotSceneClicked(); // switches property set to this section } qreal h = d->scene->height() + delta; if (h < 1) h = 1; h = d->scene->gridPoint(QPointF(0, h)).y(); d->slotPropertyChangedEnabled = false; // reduce updates d->sectionData->setHeight(INCH_TO_POINT(h / d->dpiY), delta == 0 ? KProperty::ValueOption::IgnoreOld : KProperty::ValueOption::None); d->slotPropertyChangedEnabled = true; d->sectionRuler->setRulerLength(h); const QRect newSceneRect(0, 0, d->scene->width(), h); if (d->scene->sceneRect() != newSceneRect) { d->scene->setSceneRect(newSceneRect); } d->sceneView->resizeContents(newSceneRect.size()); if (delta != 0) { d->reportDesigner->setModified(true); } } void KReportDesignerSection::buildXML(QDomDocument *doc, QDomElement *section) { KReportUtils::setAttribute(section, QLatin1String("svg:height"), d->sectionData->height()); section->setAttribute(QLatin1String("fo:background-color"), d->sectionData->backgroundColor().name()); // now get a list of all the QGraphicsItems on this scene and output them. QGraphicsItemList list = d->scene->items(); for (QGraphicsItemList::iterator it = list.begin(); it != list.end(); ++it) { KReportDesignerItemBase::buildXML((*it), doc, section); } } void KReportDesignerSection::initFromXML(const QDomNode & section) { QDomNodeList nl = section.childNodes(); QDomNode node; QString n; qreal ptHeight = KReportUtils::readSizeAttributes(section.toElement(), QSizeF(DEFAULT_SECTION_SIZE_PT, DEFAULT_SECTION_SIZE_PT)).height(); d->sectionData->setHeight(ptHeight); qreal h = POINT_TO_INCH(ptHeight) * d->dpiY; //kreportDebug() << "Section Height: " << h; d->scene->setSceneRect(0, 0, d->scene->width(), h); slotResizeBarDragged(0); - - d->sectionData->m_backgroundColor->setValue(QColor(section.toElement().attribute(QLatin1String("fo:background-color"), QLatin1String("#ffffff")))); + d->sectionData->setBackgroundColor(KReportUtils::attr( + section.toElement(), QLatin1String("fo:background-color"), QColor(Qt::white))); d->sectionData->propertySet()->clearModifiedFlags(); KReportPluginManager* manager = KReportPluginManager::self(); for (int i = 0; i < nl.count(); ++i) { node = nl.item(i); n = node.nodeName(); if (n.startsWith(QLatin1String("report:"))) { //Load objects //report:line is a special case as it is not a plugin QObject *obj = nullptr; KReportPluginInterface *plugin = nullptr; QString reportItemName = n.mid(qstrlen("report:")); if (reportItemName == QLatin1String("line")) { obj = new KReportDesignerItemLine(node, d->sceneView->designer(), d->scene); } else { plugin = manager->plugin(reportItemName); if (plugin) { obj = plugin->createDesignerInstance(node, d->reportDesigner, d->scene); } } if (obj) { KReportDesignerItemRectBase *entity = dynamic_cast(obj); if (entity) { entity->setVisible(true); } KReportItemBase *item = dynamic_cast(obj); if (item) { item->setUnit(d->reportDesigner->pageUnit()); if (plugin) { KReportDesigner::addMetaProperties(item->propertySet(), plugin->metaData()->name(), plugin->metaData()->iconName()); } item->propertySet()->clearModifiedFlags(); } } } kreportWarning() << "Encountered unknown node while parsing section: " << n; } } QSize KReportDesignerSection::sizeHint() const { return QSize(d->scene->width() + d->sectionRuler->frameSize().width(), d->title->frameSize().height() + d->sceneView->sizeHint().height() + d->resizeBar->frameSize().height()); } void KReportDesignerSection::slotPageOptionsChanged(KPropertySet &set) { Q_UNUSED(set) KReportUnit unit = d->reportDesigner->pageUnit(); d->sectionData->setUnit(unit); //update items position with unit QList itms = d->scene->items(); for (int i = 0; i < itms.size(); ++i) { KReportItemBase *obj = dynamic_cast(itms[i]); if (obj) { obj->setUnit(unit); } } d->scene->setSceneRect(0, 0, d->reportDesigner->pageWidthPx(), d->scene->height()); d->title->setMinimumWidth(d->reportDesigner->pageWidthPx() + d->sectionRuler->frameSize().width()); d->sectionRuler->setUnit(d->reportDesigner->pageUnit()); //Trigger a redraw of the background d->sceneView->resizeContents(QSize(d->scene->width(), d->scene->height())); d->sceneView->resetCachedContent(); d->sceneView->update(); d->reportDesigner->adjustSize(); d->reportDesigner->repaint(); } void KReportDesignerSection::slotSceneClicked() { d->reportDesigner->setActiveScene(d->scene); d->reportDesigner->changeSet(d->sectionData->propertySet()); } void KReportDesignerSection::slotPropertyChanged(KPropertySet &s, KProperty &p) { Q_UNUSED(s) if (!d->slotPropertyChangedEnabled) { return; } //kreportDebug() << p.name(); //Handle Background Color if (p.name() == "background-color") { d->scene->setBackgroundBrush(p.value().value()); } if (p.name() == "height") { const QRect newSceneRect(0, 0, d->scene->width(), POINT_TO_INCH(d->sectionData->height()) * d->dpiY); if (d->scene->sceneRect() != newSceneRect) { d->scene->setSceneRect(newSceneRect); } d->sceneView->resizeContents(newSceneRect.size()); } if (d->reportDesigner) d->reportDesigner->setModified(true); d->sceneView->resetCachedContent(); d->scene->update(); } void KReportDesignerSection::setSectionCursor(const QCursor& c) { if (d->sceneView) d->sceneView->setCursor(c); } void KReportDesignerSection::unsetSectionCursor() { if (d->sceneView) d->sceneView->unsetCursor(); } QGraphicsItemList KReportDesignerSection::items() const { QGraphicsItemList items; if (d->scene) { foreach (QGraphicsItem *itm, d->scene->items()) { if (itm->parentItem() == nullptr) { items << itm; } } } return items; } // // class ReportResizeBar // ReportResizeBar::ReportResizeBar(QWidget * parent, Qt::WindowFlags f) : QFrame(parent, f) { setCursor(QCursor(Qt::SizeVerCursor)); setFrameStyle(QFrame::HLine); setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum); } void ReportResizeBar::mouseMoveEvent(QMouseEvent * e) { e->accept(); emit barDragged(e->y()); } //============================================================================= KReportDesignerSectionTitle::KReportDesignerSectionTitle(QWidget*parent) : QLabel(parent) { setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed); setAlignment(Qt::AlignLeft | Qt::AlignTop); setMinimumHeight(qMax(fontMetrics().lineSpacing(),16 + 2)); //16 = Small icon size } KReportDesignerSectionTitle::~KReportDesignerSectionTitle() { } //! \return true if \a o has parent \a par. static bool hasParent(QObject* par, QObject* o) { if (!o || !par) return false; while (o && o != par) o = o->parent(); return o == par; } static void replaceColors(QPixmap* original, const QColor& color) { QImage dest(original->toImage()); QPainter p(&dest); p.setCompositionMode(QPainter::CompositionMode_SourceIn); p.fillRect(dest.rect(), color); *original = QPixmap::fromImage(dest); } void KReportDesignerSectionTitle::paintEvent(QPaintEvent * event) { QPainter painter(this); KReportDesignerSection* section = dynamic_cast(parent()); if (section) { const bool current = section->d->scene == section->d->reportDesigner->activeScene(); QPalette::ColorGroup cg = QPalette::Inactive; QWidget *activeWindow = QApplication::activeWindow(); if (activeWindow) { QWidget *par = activeWindow->focusWidget(); if (qobject_cast(par)) { par = par->parentWidget(); // we're close, pick common parent } if (hasParent(par, this)) { cg = QPalette::Active; } } if (current) { painter.fillRect(rect(), palette().brush(cg, QPalette::Highlight)); } painter.setPen(palette().color(cg, current ? QPalette::HighlightedText : QPalette::WindowText)); QPixmap pixmap(QIcon::fromTheme(QLatin1String("arrow-down")).pixmap(16,16)); replaceColors(&pixmap, painter.pen().color()); const int left = 25; painter.drawPixmap(QPoint(left, (height() - pixmap.height()) / 2), pixmap); painter.drawText(rect().adjusted(left + pixmap.width() + 4, 0, 0, 0), Qt::AlignLeft | Qt::AlignVCenter, text()); } QFrame::paintEvent(event); } void KReportDesignerSectionTitle::mousePressEvent(QMouseEvent *event) { QLabel::mousePressEvent(event); if (event->button() == Qt::LeftButton) { emit clicked(); } } #include "KReportDesignerSection.moc"