diff --git a/src/common/KReportDocument.h b/src/common/KReportDocument.h --- a/src/common/KReportDocument.h +++ b/src/common/KReportDocument.h @@ -20,7 +20,6 @@ #define KREPORTDOCUMENT_H #include "config-kreport.h" -#include "kreport_export.h" #include "KReportSectionData.h" #include diff --git a/src/common/KReportSectionData.h b/src/common/KReportSectionData.h --- a/src/common/KReportSectionData.h +++ b/src/common/KReportSectionData.h @@ -1,7 +1,7 @@ /* 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 @@ -36,14 +36,12 @@ 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: @@ -76,53 +74,43 @@ 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; diff --git a/src/common/KReportSectionData.cpp b/src/common/KReportSectionData.cpp --- a/src/common/KReportSectionData.cpp +++ b/src/common/KReportSectionData.cpp @@ -1,7 +1,7 @@ /* 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 @@ -33,35 +33,60 @@ #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; } @@ -88,80 +113,77 @@ } 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) @@ -264,15 +286,55 @@ 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/renderer/scripting/KReportScriptSection.cpp b/src/renderer/scripting/KReportScriptSection.cpp --- a/src/renderer/scripting/KReportScriptSection.cpp +++ b/src/renderer/scripting/KReportScriptSection.cpp @@ -39,13 +39,12 @@ 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 @@ -65,20 +64,20 @@ 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(); } } @@ -88,7 +87,7 @@ 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); } } diff --git a/src/wrtembed/KReportDesignerSection.cpp b/src/wrtembed/KReportDesignerSection.cpp --- a/src/wrtembed/KReportDesignerSection.cpp +++ b/src/wrtembed/KReportDesignerSection.cpp @@ -222,8 +222,8 @@ //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();