diff --git a/src/common/KReportItemLine.cpp b/src/common/KReportItemLine.cpp index 03c4bebd..71f78386 100644 --- a/src/common/KReportItemLine.cpp +++ b/src/common/KReportItemLine.cpp @@ -1,159 +1,159 @@ /* 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 "KReportItemLine.h" #include "KReportRenderObjects.h" #include "kreport_debug.h" #include #include #include KReportItemLine::KReportItemLine() { createProperties(); } KReportItemLine::KReportItemLine(const QDomNode & element) { createProperties(); QDomNodeList nl = element.childNodes(); QString n; QDomNode node; QPointF _s, _e; nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name"))); setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); _s.setX(KReportUnit::parseValue(element.toElement().attribute(QLatin1String("svg:x1"), QLatin1String("1cm")))); _s.setY(KReportUnit::parseValue(element.toElement().attribute(QLatin1String("svg:y1"), QLatin1String("1cm")))); _e.setX(KReportUnit::parseValue(element.toElement().attribute(QLatin1String("svg:x2"), QLatin1String("1cm")))); _e.setY(KReportUnit::parseValue(element.toElement().attribute(QLatin1String("svg:y2"), QLatin1String("2cm")))); m_start->setValue(_s); m_end->setValue(_e); for (int i = 0; i < nl.count(); i++) { node = nl.item(i); n = node.nodeName(); if (n == QLatin1String("report:line-style")) { KReportLineStyle ls; if (parseReportLineStyleData(node.toElement(), &ls)) { m_lineWeight->setValue(ls.weight()); m_lineColor->setValue(ls.color()); m_lineStyle->setValue(int(ls.penStyle())); } } else { kreportWarning() << "while parsing line element encountered unknown element: " << n; } } } KReportItemLine::~KReportItemLine() { } void KReportItemLine::createProperties() { m_start = new KProperty("startposition", QPointF(), QCoreApplication::translate("StartPosition", "Start Position")); m_end = new KProperty("endposition", QPointF(), QCoreApplication::translate("EndPosition", "End Position")); m_lineWeight = new KProperty("line-weight", 1.0, tr("Line Weight")); m_lineWeight->setOption("step", 1.0); m_lineColor = new KProperty("line-color", QColor(Qt::black), tr("Line Color")); - m_lineStyle = new KProperty("line-style", (int)Qt::SolidLine, tr("Line Style"), tr("Line Style"), KProperty::LineStyle); + m_lineStyle = new KProperty("line-style", (int)Qt::SolidLine, tr("Line Style"), QString(), KProperty::LineStyle); //Remove the unused properies from KReportItemBase propertySet()->removeProperty("size"); propertySet()->removeProperty("position"); propertySet()->addProperty(m_start); propertySet()->addProperty(m_end); propertySet()->addProperty(m_lineWeight); propertySet()->addProperty(m_lineColor); propertySet()->addProperty(m_lineStyle); } KReportLineStyle KReportItemLine::lineStyle() const { KReportLineStyle ls; ls.setWeight(m_lineWeight->value().toReal()); ls.setColor(m_lineColor->value().value()); ls.setPenStyle((Qt::PenStyle)m_lineStyle->value().toInt()); return ls; } qreal KReportItemLine::weight() const { return m_lineWeight->value().toReal(); } void KReportItemLine::setWeight(qreal w) { m_lineWeight->setValue(w); } QString KReportItemLine::typeName() const { return QLatin1String("line"); } int KReportItemLine::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) { Q_UNUSED(script) Q_UNUSED(data) OROLine * ln = new OROLine(); QPointF s = scenePosition(m_start->value().toPointF()); QPointF e = scenePosition(m_end->value().toPointF()); s += offset; e += offset; ln->setStartPoint(s); ln->setEndPoint(e); ln->setLineStyle(lineStyle()); if (page) page->insertPrimitive(ln); OROLine *l2 = dynamic_cast(ln->clone()); if (l2) { l2->setStartPoint(m_start->value().toPointF()); l2->setEndPoint(m_end->value().toPointF()); if (section) section->addPrimitive(l2); } return 0; } void KReportItemLine::setUnit(const KReportUnit &u) { m_start->setOption("unit", u.symbol()); m_end->setOption("unit", u.symbol()); } QPointF KReportItemLine::startPosition() const { return m_start->value().toPointF(); } QPointF KReportItemLine::endPosition() const { return m_end->value().toPointF(); } diff --git a/src/items/check/KReportItemCheck.cpp b/src/items/check/KReportItemCheck.cpp index 496b31b9..34295bcd 100644 --- a/src/items/check/KReportItemCheck.cpp +++ b/src/items/check/KReportItemCheck.cpp @@ -1,195 +1,195 @@ /* This file is part of the KDE project * Copyright (C) 2009-2010 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 "KReportItemCheck.h" #include "KReportRenderObjects.h" #include "kreportplugin_debug.h" #ifdef KREPORT_SCRIPTING #include "renderer/scripting/KReportScriptHandler.h" #endif #include #include #include KReportItemCheckBox::KReportItemCheckBox() { createProperties(); } KReportItemCheckBox::KReportItemCheckBox(const QDomNode &element) { createProperties(); QDomNodeList nl = element.childNodes(); QString n; QDomNode node; nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name"))); m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source"))); setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); m_foregroundColor->setValue(QColor(element.toElement().attribute(QLatin1String("fo:foreground-color")))); m_checkStyle->setValue(element.toElement().attribute(QLatin1String("report:check-style"))); m_staticValue->setValue(QVariant(element.toElement().attribute(QLatin1String("report:value"))).toBool()); parseReportRect(element.toElement()); for (int i = 0; i < nl.count(); i++) { node = nl.item(i); n = node.nodeName(); if (n == QLatin1String("report:line-style")) { KReportLineStyle ls; if (parseReportLineStyleData(node.toElement(), &ls)) { m_lineWeight->setValue(ls.weight()); m_lineColor->setValue(ls.color()); m_lineStyle->setValue(static_cast(ls.penStyle())); } } else { kreportpluginWarning() << "while parsing check element encountered unknown element: " << n; } } } KReportItemCheckBox::~KReportItemCheckBox() { } void KReportItemCheckBox::createProperties() { QStringList keys, strings; keys << QLatin1String("Cross") << QLatin1String("Tick") << QLatin1String("Dot"); strings << tr("Cross") << tr("Tick") << tr("Dot"); m_checkStyle = new KProperty("check-style", keys, strings, QLatin1String("Cross"), tr("Style")); m_controlSource = new KProperty("item-data-source", QStringList(), QStringList(), QString(), tr("Data Source")); m_controlSource->setOption("extraValueAllowed", QLatin1String("true")); m_foregroundColor = new KProperty("foreground-color", QColor(Qt::black), tr("Foreground Color")); m_lineWeight = new KProperty("line-weight", 1.0, tr("Line Weight")); m_lineWeight->setOption("step", 1.0); m_lineColor = new KProperty("line-color", QColor(Qt::black), tr("Line Color")); - m_lineStyle = new KProperty("line-style", static_cast(Qt::SolidLine), tr("Line Style"), tr("Line Style"), KProperty::LineStyle); + m_lineStyle = new KProperty("line-style", static_cast(Qt::SolidLine), tr("Line Style"), QString(), KProperty::LineStyle); m_staticValue = new KProperty("value", QVariant(false), tr("Value"), tr("Value used if not bound to a field")); propertySet()->addProperty(m_controlSource); propertySet()->addProperty(m_staticValue); propertySet()->addProperty(m_checkStyle); propertySet()->addProperty(m_foregroundColor); propertySet()->addProperty(m_lineWeight); propertySet()->addProperty(m_lineColor); propertySet()->addProperty(m_lineStyle); } KReportLineStyle KReportItemCheckBox::lineStyle() { KReportLineStyle ls; ls.setWeight(m_lineWeight->value().toReal()); ls.setColor(m_lineColor->value().value()); ls.setPenStyle((Qt::PenStyle)m_lineStyle->value().toInt()); return ls; } QString KReportItemCheckBox::itemDataSource() const { return m_controlSource->value().toString(); } // RTTI QString KReportItemCheckBox::typeName() const { return QLatin1String("check"); } int KReportItemCheckBox::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) { OROCheckBox *chk = new OROCheckBox(); chk->setPosition(scenePosition(position()) + offset); chk->setSize(sceneSize(size())); chk->setLineStyle(lineStyle()); chk->setForegroundColor(m_foregroundColor->value().value()); if (m_checkStyle->value().toString() == QLatin1String("Cross")) { chk->setCheckType(OROCheckBox::Cross); } else if (m_checkStyle->value().toString() == QLatin1String("Dot")) { chk->setCheckType(OROCheckBox::Dot); } else { chk->setCheckType(OROCheckBox::Tick); } QString str; bool v = false; QString cs = itemDataSource(); //kreportpluginDebug() << "ControlSource:" << cs; if (!cs.isEmpty()) { #ifdef KREPORT_SCRIPTING if (cs.left(1) == QLatin1String("=") && script) { str = script->evaluate(cs.mid(1)).toString(); } else #else Q_UNUSED(script); #endif { str = data.toString(); } str = str.toLower(); //kreportpluginDebug() << "Check Value:" << str; if (str == QLatin1String("t") || str == QLatin1String("y") || str == QLatin1String("true") || str == QLatin1String("1")) v = true; } else { v = value(); } chk->setValue(v); if (page) { page->insertPrimitive(chk); } if (section) { OROCheckBox *chk2 = dynamic_cast(chk->clone()); if (chk2) { chk2->setPosition(scenePosition(position())); section->addPrimitive(chk2); } } if (!page) { delete chk; } return 0; //Item doesn't stretch the section height } bool KReportItemCheckBox::value() const { return m_staticValue->value().toBool(); } void KReportItemCheckBox::setValue(bool v) { m_staticValue->setValue(v); } diff --git a/src/items/field/KReportItemField.cpp b/src/items/field/KReportItemField.cpp index 823beb4b..d516e2a6 100644 --- a/src/items/field/KReportItemField.cpp +++ b/src/items/field/KReportItemField.cpp @@ -1,288 +1,288 @@ /* 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 "KReportItemField.h" #include "KReportRenderObjects.h" #include "kreportplugin_debug.h" #ifdef KREPORT_SCRIPTING #include "renderer/scripting/KReportScriptHandler.h" #endif #include #include #include #include #include KReportItemField::KReportItemField() { createProperties(); } KReportItemField::KReportItemField(const QDomNode & element) { createProperties(); QDomNodeList nl = element.childNodes(); QString n; QDomNode node; nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name"))); m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source"))); m_itemValue->setValue(element.toElement().attribute(QLatin1String("report:value"))); setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); m_horizontalAlignment->setValue(element.toElement().attribute(QLatin1String("report:horizontal-align"))); m_verticalAlignment->setValue(element.toElement().attribute(QLatin1String("report:vertical-align"))); m_canGrow->setValue(element.toElement().attribute(QLatin1String("report:can-grow"))); m_wordWrap->setValue(element.toElement().attribute(QLatin1String("report:word-wrap"))); parseReportRect(element.toElement()); for (int i = 0; i < nl.count(); i++) { node = nl.item(i); n = node.nodeName(); if (n == QLatin1String("report:text-style")) { KRTextStyleData ts; if (parseReportTextStyleData(node.toElement(), &ts)) { m_backgroundColor->setValue(ts.backgroundColor); m_foregroundColor->setValue(ts.foregroundColor); m_backgroundOpacity->setValue(ts.backgroundOpacity); m_font->setValue(ts.font); } } else if (n == QLatin1String("report:line-style")) { KReportLineStyle ls; if (parseReportLineStyleData(node.toElement(), &ls)) { m_lineWeight->setValue(ls.weight()); m_lineColor->setValue(ls.color()); m_lineStyle->setValue(static_cast(ls.penStyle())); } } else { kreportpluginWarning() << "while parsing field element encountered unknown element: " << n; } } } KReportItemField::~KReportItemField() { } void KReportItemField::createProperties() { QStringList keys, strings; m_controlSource = new KProperty("item-data-source", QStringList(), QStringList(), QString(), tr("Data Source")); m_controlSource->setOption("extraValueAllowed", QLatin1String("true")); m_itemValue = new KProperty("value", QString(), tr("Value"), tr("Value used if not bound to a field")); keys << QLatin1String("left") << QLatin1String("center") << QLatin1String("right"); strings << tr("Left") << tr("Center") << tr("Right"); m_horizontalAlignment = new KProperty("horizontal-align", keys, strings, QLatin1String("left"), tr("Horizontal Alignment")); keys.clear(); strings.clear(); keys << QLatin1String("top") << QLatin1String("center") << QLatin1String("bottom"); strings << tr("Top") << tr("Center") << tr("Bottom"); m_verticalAlignment = new KProperty("vertical-align", keys, strings, QLatin1String("center"), tr("Vertical Alignment")); m_font = new KProperty("font", QApplication::font(), tr("Font")); m_backgroundColor = new KProperty("background-color", QColor(Qt::white), tr("Background Color")); m_foregroundColor = new KProperty("foreground-color", QColor(Qt::black), tr("Foreground Color")); m_backgroundOpacity = new KProperty("background-opacity", QVariant(0), tr("Background Opacity")); m_backgroundOpacity->setOption("max", 100); m_backgroundOpacity->setOption("min", 0); m_backgroundOpacity->setOption("unit", QLatin1String("%")); m_lineWeight = new KProperty("line-weight", 1.0, tr("Line Weight")); m_lineWeight->setOption("step", 1.0); m_lineColor = new KProperty("line-color", QColor(Qt::black), tr("Line Color")); - m_lineStyle = new KProperty("line-style", static_cast(Qt::NoPen), tr("Line Style"), tr("Line Style"), KProperty::LineStyle); + m_lineStyle = new KProperty("line-style", static_cast(Qt::NoPen), tr("Line Style"), QString(), KProperty::LineStyle); m_wordWrap = new KProperty("word-wrap", QVariant(false), tr("Word Wrap")); m_canGrow = new KProperty("can-grow", QVariant(false), tr("Can Grow")); //! @todo I do not think we need these #if 0 //Field Totals m_trackTotal = new KProperty("trackTotal", QVariant(false), futureI18n("Track Total")); m_trackBuiltinFormat = new KProperty("trackBuiltinFormat", QVariant(false), futureI18n("Track Builtin Format")); _useSubTotal = new KProperty("useSubTotal", QVariant(false), futureI18n("Use Sub Total"_)); _trackTotalFormat = new KProperty("trackTotalFormat", QString(), futureI18n("Track Total Format")); #endif propertySet()->addProperty(m_controlSource); propertySet()->addProperty(m_itemValue); propertySet()->addProperty(m_horizontalAlignment); propertySet()->addProperty(m_verticalAlignment); propertySet()->addProperty(m_font); propertySet()->addProperty(m_backgroundColor); propertySet()->addProperty(m_foregroundColor); propertySet()->addProperty(m_backgroundOpacity); propertySet()->addProperty(m_lineWeight); propertySet()->addProperty(m_lineColor); propertySet()->addProperty(m_lineStyle); propertySet()->addProperty(m_wordWrap); propertySet()->addProperty(m_canGrow); //_set->addProperty ( _trackTotal ); //_set->addProperty ( _trackBuiltinFormat ); //_set->addProperty ( _useSubTotal ); //_set->addProperty ( _trackTotalFormat ); } int KReportItemField::textFlags() const { int flags; QString t; t = m_horizontalAlignment->value().toString(); if (t == QLatin1String("center")) flags = Qt::AlignHCenter; else if (t == QLatin1String("right")) flags = Qt::AlignRight; else flags = Qt::AlignLeft; t = m_verticalAlignment->value().toString(); if (t == QLatin1String("center")) flags |= Qt::AlignVCenter; else if (t == QLatin1String("bottom")) flags |= Qt::AlignBottom; else flags |= Qt::AlignTop; if (m_wordWrap->value().toBool() == true) { flags |= Qt::TextWordWrap; } return flags; } KRTextStyleData KReportItemField::textStyle() const { KRTextStyleData d; d.backgroundColor = m_backgroundColor->value().value(); d.foregroundColor = m_foregroundColor->value().value(); d.font = m_font->value().value(); d.backgroundOpacity = m_backgroundOpacity->value().toInt(); return d; } QString KReportItemField::itemDataSource() const { return m_controlSource->value().toString(); } void KReportItemField::setItemDataSource(const QString& t) { if (m_controlSource->value() != t) { m_controlSource->setValue(t); } //kreportpluginDebug() << "Field: " << entityName() << "is" << itemDataSource(); } KReportLineStyle KReportItemField::lineStyle() const { KReportLineStyle ls; ls.setWeight(m_lineWeight->value().toReal()); ls.setColor(m_lineColor->value().value()); ls.setPenStyle((Qt::PenStyle)m_lineStyle->value().toInt()); return ls; } // RTTI QString KReportItemField::typeName() const { return QLatin1String("field"); } int KReportItemField::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) { OROTextBox * tb = new OROTextBox(); tb->setPosition(scenePosition(position()) + offset); tb->setSize(sceneSize(size())); tb->setFont(font()); tb->setFlags(textFlags()); tb->setTextStyle(textStyle()); tb->setLineStyle(lineStyle()); tb->setCanGrow(m_canGrow->value().toBool()); tb->setWordWrap(m_wordWrap->value().toBool()); QString str; QString ids = itemDataSource(); if (!ids.isEmpty()) { #ifdef KREPORT_SCRIPTING if (ids.left(1) == QLatin1String("=") && script) { //Everything after = is treated as code if (!ids.contains(QLatin1String("PageTotal()"))) { QVariant v = script->evaluate(ids.mid(1)); str = v.toString(); } else { str = ids.mid(1); tb->setRequiresPostProcessing(true); } } else #else Q_UNUSED(script); #endif if (ids.left(1) == QLatin1String("$")) { //Everything past $ is treated as a string str = ids.mid(1); } else { str = data.toString(); } } else { str = m_itemValue->value().toString(); } tb->setText(str); //Work out the size of the text if (tb->canGrow()) { QRect r; if (tb->wordWrap()) { //Grow vertically QFontMetrics metrics(font()); QRect temp(tb->position().x(), tb->position().y(), tb->size().width(), 5000); // a large vertical height r = metrics.boundingRect(temp, tb->flags(), str); } else { //Grow Horizontally QFontMetrics metrics(font()); QRect temp(tb->position().x(), tb->position().y(), 5000, tb->size().height()); // a large vertical height r = metrics.boundingRect(temp, tb->flags(), str); } tb->setSize(r.size() + QSize(4,4)); } if (page) { page->insertPrimitive(tb); } if (section) { OROPrimitive *clone = tb->clone(); clone->setPosition(scenePosition(position())); section->addPrimitive(clone); } int height = scenePosition(position()).y() + tb->size().height(); //If there is no page to add the item to, delete it now because it wont be deleted later if (!page) { delete tb; } return height; } diff --git a/src/items/label/KReportItemLabel.cpp b/src/items/label/KReportItemLabel.cpp index 2cf47cf4..a2ba567c 100644 --- a/src/items/label/KReportItemLabel.cpp +++ b/src/items/label/KReportItemLabel.cpp @@ -1,209 +1,209 @@ /* 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 "KReportItemLabel.h" #include "KReportRenderObjects.h" #include "kreportplugin_debug.h" #include #include #include #include KReportItemLabel::KReportItemLabel() { createProperties(); } KReportItemLabel::KReportItemLabel(const QDomNode & element) { createProperties(); QDomNodeList nl = element.childNodes(); QString n; QDomNode node; nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name"))); m_text->setValue(element.toElement().attribute(QLatin1String("report:caption"))); setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); m_horizontalAlignment->setValue(element.toElement().attribute(QLatin1String("report:horizontal-align"))); m_verticalAlignment->setValue(element.toElement().attribute(QLatin1String("report:vertical-align"))); parseReportRect(element.toElement()); for (int i = 0; i < nl.count(); i++) { node = nl.item(i); n = node.nodeName(); if (n == QLatin1String("report:text-style")) { KRTextStyleData ts; if (parseReportTextStyleData(node.toElement(), &ts)) { m_backgroundColor->setValue(ts.backgroundColor); m_foregroundColor->setValue(ts.foregroundColor); m_backgroundOpacity->setValue(ts.backgroundOpacity); m_font->setValue(ts.font); } } else if (n == QLatin1String("report:line-style")) { KReportLineStyle ls; if (parseReportLineStyleData(node.toElement(), &ls)) { m_lineWeight->setValue(ls.weight()); m_lineColor->setValue(ls.color()); m_lineStyle->setValue(static_cast(ls.penStyle())); } } else { kreportpluginWarning() << "while parsing label element encountered unknown element: " << n; } } } KReportItemLabel::~KReportItemLabel() { } QString KReportItemLabel::text() const { return m_text->value().toString(); } void KReportItemLabel::setText(const QString& t) { m_text->setValue(t); } void KReportItemLabel::createProperties() { m_text = new KProperty("caption", QLatin1String("Label"), tr("Caption")); QStringList keys, strings; keys << QLatin1String("left") << QLatin1String("center") << QLatin1String("right"); strings << tr("Left") << tr("Center") << tr("Right"); m_horizontalAlignment = new KProperty("horizontal-align", keys, strings, QLatin1String("left"), tr("Horizontal Alignment")); keys.clear(); strings.clear(); keys << QLatin1String("top") << QLatin1String("center") << QLatin1String("bottom"); strings << tr("Top") << tr("Center") << tr("Bottom"); m_verticalAlignment = new KProperty("vertical-align", keys, strings, QLatin1String("center"), tr("Vertical Alignment")); m_font = new KProperty("font", QFontDatabase::systemFont(QFontDatabase::GeneralFont), tr("Font"), tr("Font")); m_backgroundColor = new KProperty("background-color", QColor(Qt::white), tr("Background Color")); m_foregroundColor = new KProperty("foreground-color", QColor(Qt::black), tr("Foreground Color")); m_backgroundOpacity = new KProperty("background-opacity", QVariant(0), tr("Background Opacity")); m_backgroundOpacity->setOption("max", 100); m_backgroundOpacity->setOption("min", 0); m_backgroundOpacity->setOption("unit", QLatin1String("%")); m_lineWeight = new KProperty("line-weight", 1.0, tr("Line Weight")); m_lineWeight->setOption("step", 1.0); m_lineColor = new KProperty("line-color", QColor(Qt::black), tr("Line Color")); - m_lineStyle = new KProperty("line-style", static_cast(Qt::NoPen), tr("Line Style"), tr("Line Style"), KProperty::LineStyle); + m_lineStyle = new KProperty("line-style", static_cast(Qt::NoPen), tr("Line Style"), QString(), KProperty::LineStyle); propertySet()->addProperty(m_text); propertySet()->addProperty(m_horizontalAlignment); propertySet()->addProperty(m_verticalAlignment); propertySet()->addProperty(m_font); propertySet()->addProperty(m_backgroundColor); propertySet()->addProperty(m_foregroundColor); propertySet()->addProperty(m_backgroundOpacity); propertySet()->addProperty(m_lineWeight); propertySet()->addProperty(m_lineColor); propertySet()->addProperty(m_lineStyle); } Qt::Alignment KReportItemLabel::textFlags() const { Qt::Alignment align; QString t; t = m_horizontalAlignment->value().toString(); if (t == QLatin1String("center")) align = Qt::AlignHCenter; else if (t == QLatin1String("right")) align = Qt::AlignRight; else align = Qt::AlignLeft; t = m_verticalAlignment->value().toString(); if (t == QLatin1String("center")) align |= Qt::AlignVCenter; else if (t == QLatin1String("bottom")) align |= Qt::AlignBottom; else align |= Qt::AlignTop; return align; } KRTextStyleData KReportItemLabel::textStyle() const { KRTextStyleData d; d.backgroundColor = m_backgroundColor->value().value(); d.foregroundColor = m_foregroundColor->value().value(); d.font = m_font->value().value(); d.backgroundOpacity = m_backgroundOpacity->value().toInt(); return d; } KReportLineStyle KReportItemLabel::lineStyle() const { KReportLineStyle ls; ls.setWeight(m_lineWeight->value().toReal()); ls.setColor(m_lineColor->value().value()); ls.setPenStyle((Qt::PenStyle)m_lineStyle->value().toInt()); return ls; } // RTTI QString KReportItemLabel::typeName() const { return QLatin1String("label"); } int KReportItemLabel::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) { Q_UNUSED(data) Q_UNUSED(script) OROTextBox * tb = new OROTextBox(); tb->setPosition(scenePosition(position()) + offset); tb->setSize(sceneSize(size())); tb->setFont(font()); tb->setText(text()); tb->setFlags(textFlags()); tb->setTextStyle(textStyle()); tb->setLineStyle(lineStyle()); if (page) { page->insertPrimitive(tb); } if (section) { OROPrimitive *clone = tb->clone(); clone->setPosition(scenePosition(position())); section->addPrimitive(clone); } if (!page) { delete tb; } return 0; //Item doesn't stretch the section height } diff --git a/src/items/text/KReportItemText.cpp b/src/items/text/KReportItemText.cpp index 327279e9..43b51804 100644 --- a/src/items/text/KReportItemText.cpp +++ b/src/items/text/KReportItemText.cpp @@ -1,320 +1,320 @@ /* 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 "KReportItemText.h" #include "KReportRenderObjects.h" #include "kreportplugin_debug.h" #include #include #include #include #include #include #include KReportItemText::KReportItemText() : KReportItemText(QDomNode()) { } KReportItemText::KReportItemText(const QDomNode & element) : m_bottomPadding(0.0) { QDomNodeList nl = element.childNodes(); QString n; QDomNode node; createProperties(); nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name"))); m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source"))); m_itemValue->setValue(element.toElement().attribute(QLatin1String("report:value"))); setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); m_horizontalAlignment->setValue(element.toElement().attribute(QLatin1String("report:horizontal-align"))); m_verticalAlignment->setValue(element.toElement().attribute(QLatin1String("report:vertical-align"))); m_bottomPadding = element.toElement().attribute(QLatin1String("report:bottom-padding")).toDouble(); parseReportRect(element.toElement()); for (int i = 0; i < nl.count(); i++) { node = nl.item(i); n = node.nodeName(); if (n == QLatin1String("report:text-style")) { KRTextStyleData ts; if (parseReportTextStyleData(node.toElement(), &ts)) { m_backgroundColor->setValue(ts.backgroundColor); m_foregroundColor->setValue(ts.foregroundColor); m_backgroundOpacity->setValue(ts.backgroundOpacity); m_font->setValue(ts.font); } } else if (n == QLatin1String("report:line-style")) { KReportLineStyle ls; if (parseReportLineStyleData(node.toElement(), &ls)) { m_lineWeight->setValue(ls.weight()); m_lineColor->setValue(ls.color()); m_lineStyle->setValue(static_cast(ls.penStyle())); } } else { kreportpluginWarning() << "while parsing field element encountered unknown element: " << n; } } } KReportItemText::~KReportItemText() { } Qt::Alignment KReportItemText::textFlags() const { Qt::Alignment align; QString t; t = m_horizontalAlignment->value().toString(); if (t == QLatin1String("center")) align = Qt::AlignHCenter; else if (t == QLatin1String("right")) align = Qt::AlignRight; else align = Qt::AlignLeft; t = m_verticalAlignment->value().toString(); if (t == QLatin1String("center")) align |= Qt::AlignVCenter; else if (t == QLatin1String("bottom")) align |= Qt::AlignBottom; else align |= Qt::AlignTop; return align; } void KReportItemText::createProperties() { //connect ( set, SIGNAL ( propertyChanged ( KPropertySet &, KProperty & ) ), this, SLOT ( propertyChanged ( KPropertySet &, KProperty & ) ) ); QStringList keys, strings; //_query = new KProperty ( "Query", QStringList(), QStringList(), "Data Source", "Query" ); m_controlSource = new KProperty("item-data-source", QStringList(), QStringList(), QString(), tr("Data Source")); m_itemValue = new KProperty("value", QString(), tr("Value"), tr("Value used if not bound to a field")); keys << QLatin1String("left") << QLatin1String("center") << QLatin1String("right"); strings << tr("Left") << tr("Center") << tr("Right"); m_horizontalAlignment = new KProperty("horizontal-align", keys, strings, QLatin1String("left"), tr("Horizontal Alignment")); keys.clear(); strings.clear(); keys << QLatin1String("top") << QLatin1String("center") << QLatin1String("bottom"); strings << tr("Top") << tr("Center") << tr("Bottom"); m_verticalAlignment = new KProperty("vertical-align", keys, strings, QLatin1String("center"), tr("Vertical Alignment")); m_font = new KProperty("font", QApplication::font(), tr("Font")); m_backgroundColor = new KProperty("background-color", QColor(Qt::white), tr("Background Color")); m_foregroundColor = new KProperty("foreground-color", QColor(Qt::black), tr("Foreground Color")); m_lineWeight = new KProperty("line-weight", 1.0, tr("Line Weight")); m_lineWeight->setOption("step", 1.0); m_lineColor = new KProperty("line-color", QColor(Qt::black), tr("Line Color")); - m_lineStyle = new KProperty("line-style", static_cast(Qt::NoPen), tr("Line Style"), tr("Line Style"), KProperty::LineStyle); + m_lineStyle = new KProperty("line-style", static_cast(Qt::NoPen), tr("Line Style"), QString(), KProperty::LineStyle); m_backgroundOpacity = new KProperty("background-opacity", QVariant(0), tr("Background Opacity")); m_backgroundOpacity->setOption("max", 100); m_backgroundOpacity->setOption("min", 0); m_backgroundOpacity->setOption("unit", QLatin1String("%")); propertySet()->addProperty(m_controlSource); propertySet()->addProperty(m_itemValue); propertySet()->addProperty(m_horizontalAlignment); propertySet()->addProperty(m_verticalAlignment); propertySet()->addProperty(m_font); propertySet()->addProperty(m_backgroundColor); propertySet()->addProperty(m_foregroundColor); propertySet()->addProperty(m_backgroundOpacity); propertySet()->addProperty(m_lineWeight); propertySet()->addProperty(m_lineColor); propertySet()->addProperty(m_lineStyle); } QString KReportItemText::itemDataSource() const { return m_controlSource->value().toString(); } qreal KReportItemText::bottomPadding() const { return m_bottomPadding; } void KReportItemText::setBottomPadding(qreal bp) { if (m_bottomPadding != bp) { m_bottomPadding = bp; } } KRTextStyleData KReportItemText::textStyle() const { KRTextStyleData d; d.backgroundColor = m_backgroundColor->value().value(); d.foregroundColor = m_foregroundColor->value().value(); d.font = m_font->value().value(); d.backgroundOpacity = m_backgroundOpacity->value().toInt(); return d; } KReportLineStyle KReportItemText::lineStyle() const { KReportLineStyle ls; ls.setWeight(m_lineWeight->value().toReal()); ls.setColor(m_lineColor->value().value()); ls.setPenStyle((Qt::PenStyle)m_lineStyle->value().toInt()); return ls; } // RTTI QString KReportItemText::typeName() const { return QLatin1String("text"); } int KReportItemText::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) { Q_UNUSED(script); QString qstrValue; QString cs = itemDataSource(); if (!cs.isEmpty()) { if (cs.left(1) == QLatin1String("$")) { //Everything past $ is treated as a string qstrValue = cs.mid(1); } else { qstrValue = data.toString(); } } else { qstrValue = m_itemValue->value().toString(); } QPointF pos = scenePosition(position()); QSizeF siz = sceneSize(size()); pos += offset; QRectF trf(pos, siz); qreal intStretch = trf.top() - offset.y(); if (qstrValue.length()) { QRectF rect = trf; int pos = 0; QChar separator; QRegularExpression re(QLatin1String("\\s")); QPrinter prnt(QPrinter::HighResolution); QFontMetrics fm(font(), &prnt); // int intRectWidth = (int)(trf.width() * prnt.resolution()) - 10; int intRectWidth = (int)((size().width() / 72) * prnt.resolution()); int intLineCounter = 0; qreal intBaseTop = trf.top(); qreal intRectHeight = trf.height(); while (qstrValue.length()) { QRegularExpressionMatch match = re.match(qstrValue); int idx = match.capturedStart(pos); if (idx == -1) { idx = qstrValue.length(); separator = QLatin1Char('\n'); } else separator = qstrValue.at(idx); if (fm.boundingRect(qstrValue.left(idx)).width() < intRectWidth || pos == 0) { pos = idx + 1; if (separator == QLatin1Char('\n')) { QString line = qstrValue.left(idx); qstrValue.remove(0, idx + 1); pos = 0; rect.setTop(intBaseTop + (intLineCounter * intRectHeight)); rect.setBottom(rect.top() + intRectHeight); OROTextBox * tb = new OROTextBox(); tb->setPosition(rect.topLeft()); tb->setSize(rect.size()); tb->setFont(font()); tb->setText(line); tb->setFlags(textFlags()); tb->setTextStyle(textStyle()); tb->setLineStyle(lineStyle()); if (page) { page->insertPrimitive(tb); } if (section) { OROTextBox *tb2 = dynamic_cast(tb->clone()); if (tb2) { tb2->setPosition(scenePosition(position())); section->addPrimitive(tb2); } } if (!page) { delete tb; } intStretch += intRectHeight; intLineCounter++; } } else { QString line = qstrValue.left(pos - 1); qstrValue.remove(0, pos); pos = 0; rect.setTop(intBaseTop + (intLineCounter * intRectHeight)); rect.setBottom(rect.top() + intRectHeight); OROTextBox * tb = new OROTextBox(); tb->setPosition(rect.topLeft()); tb->setSize(rect.size()); tb->setFont(font()); tb->setText(line); tb->setFlags(textFlags()); tb->setTextStyle(textStyle()); tb->setLineStyle(lineStyle()); if (page) { page->insertPrimitive(tb); } else { delete tb; } intStretch += intRectHeight; intLineCounter++; } } intStretch += (m_bottomPadding / 100.0); } return intStretch; //Item returns its required section height } diff --git a/src/plugins/chart/KReportItemChart.cpp b/src/plugins/chart/KReportItemChart.cpp index 4aee5fb8..5354382a 100644 --- a/src/plugins/chart/KReportItemChart.cpp +++ b/src/plugins/chart/KReportItemChart.cpp @@ -1,435 +1,435 @@ /* This file is part of the KDE project * Copyright (C) 2007-2010 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 "KReportItemChart.h" #include "KReportRenderObjects.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "kreportplugin_debug.h" #include typedef QVector datalist; KReportItemChart::KReportItemChart() { m_reportData = 0; createProperties(); } KReportItemChart::KReportItemChart(QDomNode *element) { m_reportData = 0; createProperties(); QDomNodeList nl = element->childNodes(); QString n; QDomNode node; QDomElement e = element->toElement(); m_name->setValue(e.attribute("report:name")); m_dataSource->setValue(e.attribute("report:data-source")); Z = e.attribute("report:z-index").toDouble(); m_chartType->setValue(e.attribute("report:chart-type").toInt()); m_chartSubType->setValue(e.attribute("report:chart-sub-type").toInt()); m_threeD->setValue(e.attribute("report:three-dimensions")); m_colorScheme->setValue(e.attribute("report:chart-color-scheme")); m_aa->setValue(e.attribute("report:antialiased")); m_xTitle->setValue(e.attribute("report:title-x-axis")); m_yTitle->setValue(e.attribute("report:title-y-axis")); m_backgroundColor->setValue(e.attribute("report:background-color")); m_displayLegend->setValue(e.attribute("report:display-legend")); m_legendPosition->setValue(e.attribute("report:legend-position")); m_legendOrientation->setValue(e.attribute("report:legend-orientation")); m_linkMaster->setValue(e.attribute("report:link-master")); m_linkChild->setValue(e.attribute("report:link-child")); parseReportRect(e, &m_pos, &m_size); } KReportItemChart::~KReportItemChart() { delete m_set; } void KReportItemChart::createProperties() { m_chartWidget = 0; m_set = new KPropertySet; QStringList strings; QList keys; QStringList stringkeys; m_dataSource = new KProperty("data-source", QStringList(), QStringList(), QString(), tr("Data Source")); m_dataSource->setOption("extraValueAllowed", "true"); m_font = new KProperty("font", QFontDatabase::systemFont(QFontDatabase::GeneralFont), tr("Font"), tr("Field Font")); keys << 1 << 2 << 3 << 4 << 5; strings << tr("Bar") << tr("Line") << tr("Pie") << tr("Ring") << tr("Polar"); KProperty::ListData *typeData = new KProperty::ListData(keys, strings); m_chartType = new KProperty("chart-type", typeData, 1, tr("Chart Type")); keys.clear(); strings.clear(); keys << 0 << 1 << 2 << 3; strings << tr("Normal") << tr("Stacked") << tr("Percent") << tr("Rows"); KProperty::ListData *subData = new KProperty::ListData(keys, strings); m_chartSubType = new KProperty("chart-sub-type", subData, 0, tr("Chart Sub Type")); keys.clear(); strings.clear(); stringkeys << "default" << "rainbow" << "subdued"; strings << tr("Default") << tr("Rainbow") << tr("Subdued"); m_colorScheme = new KProperty("chart-color-scheme", stringkeys, strings, "default", tr("Color Scheme")); m_threeD = new KProperty("three-dimensions", QVariant(false), tr("3D", "Three dimensions")); m_aa = new KProperty("antialiased", QVariant(false), tr("Antialiased")); - m_xTitle = new KProperty("title-x-axis", QString(), tr("X Axis Title"), tr("X Axis Title")); - m_yTitle = new KProperty("title-y-axis", QString(), tr("Y Axis Title"), tr("Y Axis Title")); + m_xTitle = new KProperty("title-x-axis", QString(), tr("X Axis Title")); + m_yTitle = new KProperty("title-y-axis", QString(), tr("Y Axis Title")); - m_displayLegend = new KProperty("display-legend", true, tr("Display Legend"), tr("Display Legend")); + m_displayLegend = new KProperty("display-legend", true, tr("Display Legend")); keys.clear(); strings.clear(); keys << (int)KDChartEnums::PositionNorth << (int)KDChartEnums::PositionEast << (int)KDChartEnums::PositionSouth << (int)KDChartEnums::PositionWest; QStringList names = KDChart::Position::printableNames(); foreach (const QVariant &pos, keys) { strings << names[pos.toInt()-1]; } subData = new KProperty::ListData(keys, strings); m_legendPosition = new KProperty("legend-position", subData, (int)KDChartEnums::PositionEast, tr("Legend Position")); keys.clear(); strings.clear(); keys << Qt::Horizontal << Qt::Vertical; strings << tr("Horizontal") << tr("Vertical"); subData = new KProperty::ListData(keys, strings); m_legendOrientation = new KProperty("legend-orientation", subData, Qt::Vertical, tr("Legend Orientation")); m_backgroundColor = new KProperty("background-color", Qt::white, - tr("Background Color"), tr("Background Color")); + tr("Background Color")); m_linkMaster = new KProperty("link-master", QString(), tr("Link Master"), tr("Fields from master data source")); m_linkChild = new KProperty("link-child", QString(), tr("Link Child"), tr("Fields from child data source")); addDefaultProperties(); m_set->addProperty(m_dataSource); m_set->addProperty(m_chartType); m_set->addProperty(m_chartSubType); m_set->addProperty(m_font); m_set->addProperty(m_colorScheme); m_set->addProperty(m_threeD); m_set->addProperty(m_aa); m_set->addProperty(m_xTitle); m_set->addProperty(m_yTitle); m_set->addProperty(m_backgroundColor); m_set->addProperty(m_displayLegend); m_set->addProperty(m_legendPosition); m_set->addProperty(m_legendOrientation); m_set->addProperty(m_linkMaster); m_set->addProperty(m_linkChild); set3D(false); setAA(false); setColorScheme("default"); } void KReportItemChart::set3D(bool td) { if (m_chartWidget && m_chartWidget->barDiagram()) { KDChart::BarDiagram *bar = m_chartWidget->barDiagram(); bar->setPen(QPen(Qt::black)); KDChart::ThreeDBarAttributes threed = bar->threeDBarAttributes(); threed.setEnabled(td); threed.setDepth(10); threed.setAngle(15); threed.setUseShadowColors(true); bar->setThreeDBarAttributes(threed); } } void KReportItemChart::setAA(bool aa) { if (m_chartWidget && m_chartWidget->diagram()) { m_chartWidget->diagram()->setAntiAliasing(aa); } } void KReportItemChart::setColorScheme(const QString &cs) { if (m_chartWidget && m_chartWidget->diagram()) { if (cs == "rainbow") { m_chartWidget->diagram()->useRainbowColors(); } else if (cs == "subdued") { m_chartWidget->diagram()->useSubduedColors(); } else { m_chartWidget->diagram()->useDefaultColors(); } } } void KReportItemChart::setConnection(const KReportData *c) { m_reportData = c; populateData(); } void KReportItemChart::populateData() { QVector data; QStringList labels; QStringList fn; delete m_chartWidget; m_chartWidget = 0; if (m_reportData) { QString src = m_dataSource->value().toString(); if (!src.isEmpty()) { KReportData *curs = m_reportData->create(src); if (curs) { const QStringList keys = m_links.keys(); foreach(const QString& field, keys) { //kreportpluginDebug() << "Adding Expression:" << field << m_links[field]; curs->addExpression(field, m_links[field], '='); } } if (curs && curs->open()) { fn = curs->fieldNames(); //resize the data lists to match the number of columns int cols = fn.count() - 1; if ( cols > 0 ) { data.resize(cols); } m_chartWidget = new KDChart::Widget(); m_chartWidget->setType((KDChart::Widget::ChartType) m_chartType->value().toInt()); m_chartWidget->setSubType((KDChart::Widget::SubType) m_chartSubType->value().toInt()); set3D(m_threeD->value().toBool()); setAA(m_aa->value().toBool()); setColorScheme(m_colorScheme->value().toString()); setBackgroundColor(m_backgroundColor->value().value()); curs->moveFirst(); //bool status = true; do { labels << curs->value(0).toString(); for (int i = 1; i <= cols; ++i) { data[i - 1] << curs->value(i).toDouble(); } } while (curs->moveNext()); for (int i = 1; i <= cols; ++i) { m_chartWidget->setDataset(i - 1, data[i - 1], fn[i]); } setLegend(m_displayLegend->value().toBool(), fn); //Add the axis setAxis(m_xTitle->value().toString(), m_yTitle->value().toString()); //Add the bottom labels if (m_chartWidget->barDiagram() || m_chartWidget->lineDiagram()) { KDChart::AbstractCartesianDiagram *dia = static_cast(m_chartWidget->diagram()); foreach(KDChart::CartesianAxis* axis, dia->axes()) { if (axis->position() == KDChart::CartesianAxis::Bottom) { axis->setLabels(labels); } } } } else { kreportpluginWarning() << "Unable to open data set"; } delete curs; curs = 0; } else { kreportpluginWarning() << "No source set"; } } else { kreportpluginWarning() << "No connection!"; } } QStringList KReportItemChart::masterFields() const { return m_linkMaster->value().toString().split(','); } void KReportItemChart::setLinkData(QString fld, QVariant val) { //kreportpluginDebug() << "Field: " << fld << "is" << val; m_links[fld] = val; } void KReportItemChart::setAxis(const QString& xa, const QString &ya) { if (!m_chartWidget) { return; } Q_ASSERT(m_chartWidget); if (m_chartWidget->barDiagram() || m_chartWidget->lineDiagram()) { KDChart::AbstractCartesianDiagram *dia = static_cast(m_chartWidget->diagram()); KDChart::CartesianAxis *xAxis = 0; KDChart::CartesianAxis *yAxis = 0; //delete existing axis foreach(KDChart::CartesianAxis* axis, dia->axes()) { if (axis->position() == KDChart::CartesianAxis::Bottom) { xAxis = axis; } if (axis->position() == KDChart::CartesianAxis::Left) { yAxis = axis; } } if (!xAxis) { xAxis = new KDChart::CartesianAxis(static_cast(m_chartWidget->diagram())); xAxis->setPosition(KDChart::CartesianAxis::Bottom); dia->addAxis(xAxis); } if (!yAxis) { yAxis = new KDChart::CartesianAxis(static_cast(m_chartWidget->diagram())); yAxis->setPosition(KDChart::CartesianAxis::Left); dia->addAxis(yAxis); } xAxis->setTitleText(xa); yAxis->setTitleText(ya); } } void KReportItemChart::setBackgroundColor(const QColor&) { //Set the background color if (!m_chartWidget) { return; } KDChart::Chart *cht = m_chartWidget->diagram()->coordinatePlane()->parent(); KDChart::BackgroundAttributes ba; ba.setVisible(true); ba.setBrush(m_backgroundColor->value().value()); cht->setBackgroundAttributes(ba); } void KReportItemChart::setLegend(bool le, const QStringList &legends) { //Add the legend if (m_chartWidget) { if (le && ! legends.isEmpty()) { m_chartWidget->addLegend(KDChart::Position((KDChartEnums::PositionValue)m_legendPosition->value().toInt())); m_chartWidget->legend()->setOrientation((Qt::Orientation) m_legendOrientation->value().toInt()); m_chartWidget->legend()->setTitleText("Legend"); for (int i = 1; i < legends.count(); ++i) { m_chartWidget->legend()->setText(i - 1, legends[i]); } m_chartWidget->legend()->setShowLines(true); } else { if (m_chartWidget->legend()) { m_chartWidget->takeLegend(m_chartWidget->legend()); } } } } // RTTI QString KReportItemChart::typeName() const { return "chart"; } int KReportItemChart::renderReportData(OROPage *page, OROSection *section, const QPointF &offset, KReportData *data, KReportScriptHandler *script) { Q_UNUSED(script); setConnection(data); QStringList masters = masterFields(); for (int i = 0; i < masters.size(); ++i) { if (!masters[i].simplified().isEmpty()) { setLinkData(masters[i], data->value(masters[i])); } } populateData(); if (widget()) { OROPicture * pic = new OROPicture(); widget()->setFixedSize(m_size.toScene().toSize()); QPainter p(pic->picture()); widget()->diagram()->coordinatePlane()->parent()->paint(&p, QRect(QPoint(0, 0), m_size.toScene().toSize())); QPointF pos = m_pos.toScene(); QSizeF size = m_size.toScene(); pos += offset; pic->setPosition(pos); pic->setSize(size); if (page) page->addPrimitive(pic); OROPicture *p2 = static_cast(pic->clone()); if (p2) { p2->setPosition(m_pos.toPoint()); if (section) { section->addPrimitive(p2); } } } return 0; } diff --git a/src/plugins/maps/KReportItemMaps.cpp b/src/plugins/maps/KReportItemMaps.cpp index ab3f8d17..a05e2286 100644 --- a/src/plugins/maps/KReportItemMaps.cpp +++ b/src/plugins/maps/KReportItemMaps.cpp @@ -1,228 +1,225 @@ /* * Copyright (C) 2007-2016 by Adam Pigg (adam@piggz.co.uk) * Copyright (C) 2011-2015 by Radoslaw Wicik (radoslaw@wicik.pl) * * 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 "KReportItemMaps.h" #include #include #include #include #define myDebug() if (0) kDebug(44021) //! @todo replace with ReportItemMaps(const QDomNode &element = QDomNode()) KReportItemMaps::KReportItemMaps() : KReportItemMaps(QDomNode()) { } KReportItemMaps::KReportItemMaps(const QDomNode &element) : m_longtitude(0) , m_latitude(0) , m_zoom(1200) , m_pageId(0) , m_sectionId(0) , m_oroPicture(0) , m_longDataSetFromScript(false) , m_latDataSetFromScript(false) , m_zoomDataSetFromScript(false) { createProperties(); nameProperty()->setValue(element.toElement().attribute(QLatin1String("report:name"))); m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source"))); setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble()); m_latitudeProperty->setValue(element.toElement().attribute(QLatin1String("report:latitude")).toDouble()); m_longitudeProperty->setValue(element.toElement().attribute(QLatin1String("report:longitude")).toDouble()); m_zoomProperty->setValue(element.toElement().attribute(QLatin1String("report:zoom")).toInt()); QString themeId(element.toElement().attribute(QLatin1String("report:theme"))); themeId = themeId.isEmpty() ? m_themeManager.mapThemeIds()[0] : themeId; m_themeProperty->setValue(themeId); parseReportRect(element.toElement()); } KReportItemMaps::~KReportItemMaps() { } void KReportItemMaps::createProperties() { m_controlSource = new KProperty("item-data-source", QStringList(), QStringList(), QString(), tr("Data Source")); - m_latitudeProperty = new KProperty("latitude", 0.0, tr("Latitude"), tr("Latitude"), KProperty::Double); + m_latitudeProperty = new KProperty("latitude", 0.0, tr("Latitude"), QString(), KProperty::Double); m_latitudeProperty->setOption("min", -90); m_latitudeProperty->setOption("max", 90); m_latitudeProperty->setOption("unit", QString::fromUtf8("°")); m_latitudeProperty->setOption("precision", 7); - m_longitudeProperty = new KProperty("longitude", 0.0, tr("Longitude"), tr("Longitude"), KProperty::Double); + m_longitudeProperty = new KProperty("longitude", 0.0, tr("Longitude"), QString(), KProperty::Double); m_longitudeProperty->setOption("min", -180); m_longitudeProperty->setOption("max", 180); m_longitudeProperty->setOption("unit", QString::fromUtf8("°")); m_longitudeProperty->setOption("precision", 7); - m_zoomProperty = new KProperty("zoom", 1000, tr("Zoom"), tr("Zoom") ); + m_zoomProperty = new KProperty("zoom", 1000, tr("Zoom") ); m_zoomProperty->setOption("min", 0); m_zoomProperty->setOption("max", 4000); m_zoomProperty->setOption("step", 100); m_zoomProperty->setOption("slider", true); QStringList mapThemIds(m_themeManager.mapThemeIds()); - m_themeProperty = new KProperty("theme", - mapThemIds, - mapThemIds, - mapThemIds[1]); + m_themeProperty = new KProperty("theme", mapThemIds, mapThemIds, mapThemIds[1], tr("Theme")); if (mapThemIds.contains(QLatin1String("earth/srtm/srtm.dgml"))) { m_themeProperty->setValue(QLatin1String("earth/srtm/srtm.dgml"), KProperty::DefaultValueOptions & ~KProperty::ValueOptions(KProperty::ValueOption::RememberOld)); } propertySet()->addProperty(m_controlSource); propertySet()->addProperty(m_latitudeProperty); propertySet()->addProperty(m_longitudeProperty); propertySet()->addProperty(m_zoomProperty); propertySet()->addProperty(m_themeProperty); } void KReportItemMaps::setColumn(const QString &c) { m_controlSource->setValue(c); } QString KReportItemMaps::itemDataSource() const { return m_controlSource->value().toString(); } QString KReportItemMaps::typeName() const { return QLatin1String("maps"); } int KReportItemMaps::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) { Q_UNUSED(script) deserializeData(data); m_pageId = page; m_sectionId = section; m_offset = offset; m_oroPicture = new OROPicture(); m_oroPicture->setPosition(scenePosition(position()) + m_offset); m_oroPicture->setSize(sceneSize(size())); if (m_pageId) { m_pageId->insertPrimitive(m_oroPicture); } if (m_sectionId) { OROPicture *i2 = dynamic_cast(m_oroPicture->clone()); if (i2) { i2->setPosition(scenePosition(position())); } } m_mapRenderer.renderJob(this); return 0; //Item doesn't stretch the section height } void KReportItemMaps::deserializeData(const QVariant& serialized) { //kreportpluginDebug() << "Map data for this record is" << serialized; QStringList dataList = serialized.toString().split(QLatin1Char(';')); if (dataList.size() == 3) { m_latitude = dataList[0].toDouble(); m_longtitude = dataList[1].toDouble(); m_zoom = dataList[2].toInt(); } else { m_latitude = m_latitudeProperty->value().toReal(); m_longtitude = m_longitudeProperty->value().toReal(); m_zoom = m_zoomProperty->value().toInt(); } } void KReportItemMaps::renderFinished() { emit finishedRendering(); } OROPicture* KReportItemMaps::oroImage() { return m_oroPicture; } qreal KReportItemMaps::longtitude() const { return m_longtitude; } qreal KReportItemMaps::latitude() const { return m_latitude; } int KReportItemMaps::zoom() const { return m_zoom; } QString KReportItemMaps::themeId() const { return m_themeProperty->value().toString(); } QVariant KReportItemMaps::realItemData(const QVariant& itemData) const { double lat, lon; int zoom; QStringList dataList = itemData.toString().split(QLatin1Char(';')); if (dataList.size() == 3) { lat = dataList[0].toDouble(); lon = dataList[1].toDouble(); zoom = dataList[2].toInt(); } else if (dataList.size() == 2) { lat = dataList[0].toDouble(); lon = dataList[1].toDouble(); zoom = m_zoomProperty->value().toInt(); } else { lat = m_latitudeProperty->value().toReal(); lon = m_longitudeProperty->value().toReal(); zoom = m_zoomProperty->value().toInt(); } if (m_longDataSetFromScript) { lon = m_longtitude; } if (m_latDataSetFromScript) { lat = m_latitude; } if (m_zoomDataSetFromScript) { zoom = m_zoom; } return QString(QLatin1String("%1;%2;%3")).arg(lat).arg(lon).arg(zoom); }