diff --git a/src/common/KReportItemBase.cpp b/src/common/KReportItemBase.cpp
index 2002a70f..065bcc38 100644
--- a/src/common/KReportItemBase.cpp
+++ b/src/common/KReportItemBase.cpp
@@ -1,273 +1,298 @@
/* 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 "KReportItemBase.h"
#include "KReportUtils.h"
#include "KReportUtils_p.h"
#include
+#include
#include
#include
class Q_DECL_HIDDEN KReportItemBase::Private
{
public:
Private();
~Private();
void setUnit(const KReportUnit& u, bool force)
{
if (!force && unit == u) {
return;
}
const QSignalBlocker blocker(set);
KReportUnit oldunit = unit;
unit = u;
// convert values
if (positionProperty) {
positionProperty->setValue(KReportUnit::convertFromUnitToUnit(
positionProperty->value().toPointF(), oldunit, u),
KProperty::ValueOption::IgnoreOld);
positionProperty->setOption("suffix", u.symbol());
}
if (sizeProperty) {
sizeProperty->setValue(
KReportUnit::convertFromUnitToUnit(sizeProperty->value().toSizeF(), oldunit, u),
KProperty::ValueOption::IgnoreOld);
sizeProperty->setOption("suffix", u.symbol());
}
}
KPropertySet *set;
KProperty *nameProperty;
KProperty *sizeProperty;
KProperty *positionProperty;
+ KProperty *dataSourceProperty = 0;
QString oldName;
qreal z = 0;
KReportUnit unit;
};
KReportItemBase::Private::Private()
{
set = new KPropertySet();
nameProperty = new KProperty("name", QString(), tr("Name"), tr("Object Name"));
nameProperty->setValueSyncPolicy(KProperty::ValueSyncPolicy::FocusOut);
positionProperty = new KProperty("position", QPointF(), QCoreApplication::translate("ItemPosition", "Position"));
sizeProperty = new KProperty("size", QSizeF(), QCoreApplication::translate("ItemSize", "Size"));
setUnit(DEFAULT_UNIT, true);
set->addProperty(nameProperty);
set->addProperty(positionProperty);
set->addProperty(sizeProperty);
}
KReportItemBase::Private::~Private()
{
delete set;
}
KReportItemBase::KReportItemBase() : d(new Private())
{
connect(propertySet(), &KPropertySet::propertyChanged,
this, &KReportItemBase::propertyChanged);
connect(propertySet(), &KPropertySet::aboutToDeleteProperty, this, &KReportItemBase::aboutToDeleteProperty);
}
KReportItemBase::~KReportItemBase()
{
delete d;
}
+void KReportItemBase::createDataSourceProperty()
+{
+ if (d->dataSourceProperty) {
+ return;
+ }
+ d->dataSourceProperty
+ = new KProperty("item-data-source", new KPropertyListData, QVariant(), tr("Data Source"));
+ d->dataSourceProperty->setOption("extraValueAllowed", true);
+ d->set->addProperty(d->dataSourceProperty);
+}
+
bool KReportItemBase::parseReportTextStyleData(const QDomElement & elemSource, KReportTextStyleData *ts)
{
return KReportUtils::parseReportTextStyleData(elemSource, ts);
}
bool KReportItemBase::parseReportLineStyleData(const QDomElement & elemSource, KReportLineStyle *ls)
{
return KReportUtils::parseReportLineStyleData(elemSource, ls);
}
bool KReportItemBase::parseReportRect(const QDomElement & elemSource)
{
const QRectF r(KReportUtils::readRectAttributes(elemSource, DEFAULT_ELEMENT_RECT_PT));
setPosition(r.topLeft());
setSize(r.size());
return true;
}
KReportUnit KReportItemBase::unit() const
{
return d->unit;
}
void KReportItemBase::setUnit(const KReportUnit& u)
{
d->setUnit(u, false);
}
int KReportItemBase::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset,
const QVariant &data, KReportScriptHandler* script)
{
Q_UNUSED(page)
Q_UNUSED(section)
Q_UNUSED(offset)
Q_UNUSED(data)
Q_UNUSED(script)
return 0;
}
int KReportItemBase::renderReportData(OROPage *page, OROSection *section, const QPointF &offset,
KReportDataSource *dataSource, KReportScriptHandler* script)
{
Q_UNUSED(page)
Q_UNUSED(section)
Q_UNUSED(offset)
Q_UNUSED(dataSource)
Q_UNUSED(script)
return 0;
}
QString KReportItemBase::itemDataSource() const
{
- return QString();
+ return d->dataSourceProperty ? d->dataSourceProperty->value().toString() : QString();
+}
+
+void KReportItemBase::setItemDataSource(const QString& source)
+{
+ if (d->dataSourceProperty && d->dataSourceProperty->value() != source) {
+ d->dataSourceProperty->setValue(source);
+ }
}
KPropertySet* KReportItemBase::propertySet()
{
return d->set;
}
bool KReportItemBase::supportsSubQuery() const
{
return false;
}
QString KReportItemBase::entityName() const
{
return d->nameProperty->value().toString();
}
void KReportItemBase::setEntityName(const QString& n)
{
d->nameProperty->setValue(n);
}
KProperty* KReportItemBase::nameProperty()
{
return d->nameProperty;
}
QString KReportItemBase::oldName() const
{
return d->oldName;
}
void KReportItemBase::setOldName(const QString& old)
{
d->oldName = old;
}
+KProperty* KReportItemBase::dataSourceProperty()
+{
+ return d->dataSourceProperty;
+}
+
QPointF KReportItemBase::position() const
{
return d->unit.convertToPoint(d->positionProperty->value().toPointF());
}
QSizeF KReportItemBase::size() const
{
return d->unit.convertToPoint(d->sizeProperty->value().toSizeF());
}
const KPropertySet * KReportItemBase::propertySet() const
{
return d->set;
}
QPointF KReportItemBase::scenePosition(const QPointF &ptPos)
{
const qreal x = POINT_TO_INCH(ptPos.x()) * KReportPrivate::dpiX();
const qreal y = POINT_TO_INCH(ptPos.y()) * KReportPrivate::dpiY();
return QPointF(x, y);
}
QSizeF KReportItemBase::sceneSize(const QSizeF &ptSize)
{
const qreal w = POINT_TO_INCH(ptSize.width()) * KReportPrivate::dpiX();
const qreal h = POINT_TO_INCH(ptSize.height()) * KReportPrivate::dpiY();
return QSizeF(w, h);
}
qreal KReportItemBase::z() const
{
return d->z;
}
void KReportItemBase::setZ(qreal z)
{
d->z = z;
}
void KReportItemBase::setPosition(const QPointF& ptPos)
{
d->positionProperty->setValue(d->unit.convertFromPoint(ptPos));
}
void KReportItemBase::setSize(const QSizeF &ptSize)
{
d->sizeProperty->setValue(d->unit.convertFromPoint(ptSize));
}
QPointF KReportItemBase::positionFromScene(const QPointF& pos)
{
const qreal x = INCH_TO_POINT(pos.x() / KReportPrivate::dpiX());
const qreal y = INCH_TO_POINT(pos.y() / KReportPrivate::dpiY());
return QPointF(x, y);
}
QSizeF KReportItemBase::sizeFromScene(const QSizeF& size)
{
qreal w = INCH_TO_POINT(size.width() / KReportPrivate::dpiX());
qreal h = INCH_TO_POINT(size.height() / KReportPrivate::dpiY());
return QSizeF(w, h);
}
void KReportItemBase::propertyChanged(KPropertySet& s, KProperty& p)
{
Q_UNUSED(s)
Q_UNUSED(p)
}
void KReportItemBase::aboutToDeleteProperty(KPropertySet& set, KProperty& property)
{
Q_UNUSED(set)
if (property.name() == "size") {
d->sizeProperty = nullptr;
}
else if (property.name() == "position") {
d->positionProperty = nullptr;
}
}
diff --git a/src/common/KReportItemBase.h b/src/common/KReportItemBase.h
index a9c3ee4a..d77b1622 100644
--- a/src/common/KReportItemBase.h
+++ b/src/common/KReportItemBase.h
@@ -1,174 +1,178 @@
/* 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 .
*/
#ifndef KREPORTITEMBASE_H
#define KREPORTITEMBASE_H
#include "config-kreport.h"
#include "kreport_export.h"
#include "KReportUnit.h"
#include
#include
#include
class OROPage;
class OROSection;
class KReportDataSource;
class KReportLineStyle;
#ifdef KREPORT_SCRIPTING
class KReportScriptHandler;
#else
#define KReportScriptHandler void
#endif
class KProperty;
class KPropertySet;
class QDomElement;
class KReportTextStyleData
{
public:
QFont font;
Qt::Alignment alignment;
QColor backgroundColor;
QColor foregroundColor;
int backgroundOpacity;
};
/*!
* @brief Base class for items that are drawn syncronously.
*/
class KREPORT_EXPORT KReportItemBase : public QObject
{
Q_OBJECT
public:
KReportItemBase();
~KReportItemBase() override;
/**
@brief Return the item type as a string. Required by all items
@return Item type
*/
virtual QString typeName() const = 0;
/**
@brief Render the item into a primitive which is used by the second stage renderer
@return the height required by the object
*/
virtual int renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script);
/**
@brief Render a complex item that uses a sub query as a data source
@return the height required by the object
*/
virtual int renderReportData(OROPage *page, OROSection *section, const QPointF &offset, KReportDataSource *dataSource, KReportScriptHandler *script);
/**
- @brief Override if the item supports a simple data source, such as a field
@return The field name or expression for the data source
*/
- virtual QString itemDataSource() const;
+ QString itemDataSource() const;
+
+ void setItemDataSource(const QString &source);
/**
@brief Override if the item uses a sub query and linked fields, such as a chart or sub-report
@return True if uses a sub query
*/
virtual bool supportsSubQuery() const;
KPropertySet* propertySet();
const KPropertySet* propertySet() const;
void setEntityName(const QString& n);
QString entityName() const;
KReportUnit unit() const;
//! Sets unit to @a a and converts values of position and size property from the old
//! unit to new if needed.
virtual void setUnit(const KReportUnit &u);
/**
* @brief Return the size in points
*/
QSizeF size() const;
/**
* @brief Return the position in points
*/
QPointF position() const;
/**
* @brief Sets position for the element
* @param ptPos Position in points
*/
void setPosition(const QPointF &ptPos);
/**
* @brief Sets size for the element
* @param ptSize Size in points
*/
void setSize(const QSizeF &ptSize);
/**
* @brief Return the z-value in points
*/
qreal z() const;
/**
* @brief Sets the z-value for the element
* @param z Z-value in points
*/
void setZ(qreal z);
//! Helper function mapping to screen units (pixels), @a ptPos is in points
static QPointF scenePosition(const QPointF &ptPos);
//! Helper function mapping to screen units (pixels), @a ptSize is in points
static QSizeF sceneSize(const QSizeF &ptSize);
//! Helper function mapping from screen units to points, @a pos is in pixels
static QPointF positionFromScene(const QPointF &pos);
//! Helper function mapping from screen units to points, @a size is in pixels
static QSizeF sizeFromScene(const QSizeF &size);
protected:
virtual void createProperties() = 0;
+ void createDataSourceProperty();
bool parseReportRect(const QDomElement &elem);
static bool parseReportTextStyleData(const QDomElement &, KReportTextStyleData*);
static bool parseReportLineStyleData(const QDomElement &, KReportLineStyle*);
KProperty *nameProperty();
QString oldName() const;
void setOldName(const QString &old);
+ KProperty* dataSourceProperty();
Q_SLOT virtual void propertyChanged(KPropertySet &s, KProperty &p);
private:
Q_DISABLE_COPY(KReportItemBase)
class Private;
Private * const d;
Q_SLOT void aboutToDeleteProperty(KPropertySet& set, KProperty& property);
+ friend class KReportDesignerItemRectBase;
};
#endif
diff --git a/src/items/check/KReportDesignerItemCheckBox.cpp b/src/items/check/KReportDesignerItemCheckBox.cpp
index 2ccc8ec3..d517e756 100644
--- a/src/items/check/KReportDesignerItemCheckBox.cpp
+++ b/src/items/check/KReportDesignerItemCheckBox.cpp
@@ -1,183 +1,177 @@
/* 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 "KReportDesignerItemCheckBox.h"
#include "KReportDesignerItemRectBase.h"
#include "KReportDesigner.h"
#include "KReportLineStyle.h"
#include
#include
#include
#include
//
// class ReportEntityCheck
//
void KReportDesignerItemCheckBox::init(QGraphicsScene *scene)
{
if (scene)
scene->addItem(this);
connect(propertySet(), SIGNAL(propertyChanged(KPropertySet&,KProperty&)),
this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&)));
setZValue(z());
}
// methods (constructors)
KReportDesignerItemCheckBox::KReportDesignerItemCheckBox(KReportDesigner* d, QGraphicsScene * scene, const QPointF &pos)
: KReportDesignerItemRectBase(d, this)
{
Q_UNUSED(pos);
init(scene);
setSceneRect(properRect(*d, KREPORT_ITEM_CHECK_DEFAULT_WIDTH, KREPORT_ITEM_CHECK_DEFAULT_HEIGHT));
nameProperty()->setValue(designer()->suggestEntityName(typeName()));
}
KReportDesignerItemCheckBox::KReportDesignerItemCheckBox(const QDomNode & element, KReportDesigner * d, QGraphicsScene * s)
: KReportItemCheckBox(element), KReportDesignerItemRectBase(d, this)
{
init(s);
setSceneRect(KReportItemBase::scenePosition(item()->position()), KReportItemBase::sceneSize(item()->size()));
}
KReportDesignerItemCheckBox* KReportDesignerItemCheckBox::clone()
{
QDomDocument d;
QDomElement e = d.createElement(QLatin1String("clone"));
QDomNode n;
buildXML(&d, &e);
n = e.firstChild();
return new KReportDesignerItemCheckBox(n, designer(), nullptr);
}
// methods (deconstructor)
KReportDesignerItemCheckBox::~KReportDesignerItemCheckBox()
{}
void KReportDesignerItemCheckBox::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
// store any values we plan on changing so we can restore them
QFont f = painter->font();
QPen p = painter->pen();
QBrush b = painter->brush();
painter->setBackgroundMode(Qt::OpaqueMode);
painter->setRenderHint(QPainter::Antialiasing);
painter->setPen(m_foregroundColor->value().value());
if ((Qt::PenStyle)m_lineStyle->value().toInt() == Qt::NoPen || m_lineWeight->value().toInt() <= 0) {
painter->setPen(QPen(Qt::lightGray));
} else {
painter->setPen(QPen(m_lineColor->value().value(), m_lineWeight->value().toInt(), (Qt::PenStyle)m_lineStyle->value().toInt()));
}
QSizeF sceneSize = this->sceneSize(size());
qreal ox = sceneSize.width() / 5;
qreal oy = sceneSize.height() / 5;
//Checkbox Style
if (m_checkStyle->value().toString() == QLatin1String("Cross")) {
painter->drawRoundedRect(QGraphicsRectItem::rect(), sceneSize.width() / 10 , sceneSize.height() / 10);
QPen lp;
lp.setColor(m_foregroundColor->value().value());
lp.setWidth(ox > oy ? oy : ox);
painter->setPen(lp);
painter->drawLine(ox, oy, sceneSize.width() - ox, sceneSize.height() - oy);
painter->drawLine(ox, sceneSize.height() - oy, sceneSize.width() - ox, oy);
} else if (m_checkStyle->value().toString() == QLatin1String("Dot")) {
//Radio Style
painter->drawEllipse(QGraphicsRectItem::rect());
QBrush lb(m_foregroundColor->value().value());
painter->setBrush(lb);
painter->setPen(Qt::NoPen);
painter->drawEllipse(rect().center(), sceneSize.width() / 2 - ox, sceneSize.height() / 2 - oy);
} else {
//Tickbox Style
painter->drawRoundedRect(QGraphicsRectItem::rect(), sceneSize.width() / 10 , sceneSize.height() / 10);
QPen lp;
lp.setColor(m_foregroundColor->value().value());
lp.setWidth(ox > oy ? oy : ox);
painter->setPen(lp);
painter->drawLine(ox, sceneSize.height() / 2, sceneSize.width() / 2, sceneSize.height() - oy);
painter->drawLine(sceneSize.width() / 2, sceneSize.height() - oy, sceneSize.width() - ox, oy);
}
painter->setBackgroundMode(Qt::TransparentMode);
painter->setPen(m_foregroundColor->value().value());
// restore an values before we started just in case
painter->setFont(f);
painter->setPen(p);
painter->setBrush(b);
drawHandles(painter);
}
void KReportDesignerItemCheckBox::buildXML(QDomDocument *doc, QDomElement *parent)
{
//kreportpluginDebug();
QDomElement entity = doc->createElement(QLatin1String("report:") + typeName());
//properties
addPropertyAsAttribute(&entity, nameProperty());
- addPropertyAsAttribute(&entity, m_controlSource);
+ addPropertyAsAttribute(&entity, dataSourceProperty());
entity.setAttribute(QLatin1String("fo:foreground-color"), m_foregroundColor->value().toString());
addPropertyAsAttribute(&entity, m_checkStyle);
addPropertyAsAttribute(&entity, m_staticValue);
// bounding rect
buildXMLRect(doc, &entity, this);
//Line Style
buildXMLLineStyle(doc, &entity, lineStyle());
parent->appendChild(entity);
}
void KReportDesignerItemCheckBox::slotPropertyChanged(KPropertySet &s, KProperty &p)
{
Q_UNUSED(s)
if (p.name() == "name") {
//For some reason p.oldValue returns an empty string
if (!designer()->isEntityNameUnique(p.value().toString(), this)) {
p.setValue(oldName());
} else {
setOldName(p.value().toString());
}
}
KReportDesignerItemRectBase::propertyChanged(s, p);
if (designer()) designer()->setModified(true);
}
-
-void KReportDesignerItemCheckBox::mousePressEvent(QGraphicsSceneMouseEvent * event)
-{
- m_controlSource->setListData(designer()->fieldKeys(), designer()->fieldNames());
- KReportDesignerItemRectBase::mousePressEvent(event);
-}
diff --git a/src/items/check/KReportDesignerItemCheckBox.h b/src/items/check/KReportDesignerItemCheckBox.h
index 58a96636..fb71d9f5 100644
--- a/src/items/check/KReportDesignerItemCheckBox.h
+++ b/src/items/check/KReportDesignerItemCheckBox.h
@@ -1,57 +1,54 @@
/* 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 .
*/
#ifndef KREPORTDESIGNERITEMCHECK_H
#define KREPORTDESIGNERITEMCHECK_H
#include "KReportDesignerItemRectBase.h"
#include "KReportItemCheck.h"
#include
#include
const int KREPORT_ITEM_CHECK_DEFAULT_WIDTH = 15;
const int KREPORT_ITEM_CHECK_DEFAULT_HEIGHT = 15;
class KReportDesignerItemCheckBox : public KReportItemCheckBox, public KReportDesignerItemRectBase
{
Q_OBJECT
public:
KReportDesignerItemCheckBox(KReportDesigner *designer, QGraphicsScene *scene,
const QPointF &pos);
KReportDesignerItemCheckBox(const QDomNode &element, KReportDesigner *designer,
QGraphicsScene *scene);
~KReportDesignerItemCheckBox() override;
void buildXML(QDomDocument *doc, QDomElement *parent) override;
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr) override;
KReportDesignerItemCheckBox* clone() override;
private:
void init(QGraphicsScene *scene);
private Q_SLOTS:
void slotPropertyChanged(KPropertySet &, KProperty &);
-
-protected:
- void mousePressEvent(QGraphicsSceneMouseEvent * event) override;
};
#endif // KREPORTDESIGNERITEMCHECK_H
diff --git a/src/items/check/KReportItemCheck.cpp b/src/items/check/KReportItemCheck.cpp
index 2c488c46..2ecbc483 100644
--- a/src/items/check/KReportItemCheck.cpp
+++ b/src/items/check/KReportItemCheck.cpp
@@ -1,197 +1,189 @@
/* 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 "KReportUtils.h"
#include "KReportUtils_p.h"
#include "kreportplugin_debug.h"
#ifdef KREPORT_SCRIPTING
#include "KReportScriptHandler.h"
#endif
#include
#include
#include
#include
KReportItemCheckBox::KReportItemCheckBox()
{
createProperties();
}
KReportItemCheckBox::KReportItemCheckBox(const QDomNode &element)
: KReportItemCheckBox()
{
nameProperty()->setValue(KReportUtils::readNameAttribute(element.toElement()));
- m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source")));
+ setItemDataSource(element.toElement().attribute(QLatin1String("report:item-data-source")));
setZ(KReportUtils::readZAttribute(element.toElement()));
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());
QDomNodeList nl = element.childNodes();
QString n;
QDomNode node;
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()
{
KPropertyListData *listData = new KPropertyListData(
QVariantList{ QLatin1String("Cross"), QLatin1String("Tick"), QLatin1String("Dot") },
QVariantList{ tr("Cross"), tr("Tick"), tr("Dot") });
m_checkStyle = new KProperty("check-style", listData, QLatin1String("Cross"), tr("Style"));
- m_controlSource
- = new KProperty("item-data-source", new KPropertyListData, QVariant(), tr("Data Source"));
- m_controlSource->setOption("extraValueAllowed", QLatin1String("true"));
+ createDataSourceProperty();
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"), 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::Type::Cross);
} else if (m_checkStyle->value().toString() == QLatin1String("Dot")) {
chk->setCheckType(OROCheckBox::Type::Dot);
} else {
chk->setCheckType(OROCheckBox::Type::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/check/KReportItemCheck.h b/src/items/check/KReportItemCheck.h
index af7d7e67..cc94a865 100644
--- a/src/items/check/KReportItemCheck.h
+++ b/src/items/check/KReportItemCheck.h
@@ -1,63 +1,59 @@
/* 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 .
*/
#ifndef KREPORTITEMCHECKBOX_H
#define KREPORTITEMCHECKBOX_H
#include "KReportItemBase.h"
class QDomNode;
namespace Scripting
{
class CheckBox;
}
class KReportItemCheckBox : public KReportItemBase
{
Q_OBJECT
public:
KReportItemCheckBox();
explicit KReportItemCheckBox(const QDomNode &element);
~KReportItemCheckBox() override;
QString typeName() const override;
int renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) override;
- QString itemDataSource()const override;
-
protected:
-
- KProperty * m_controlSource;
KProperty* m_checkStyle;
KProperty* m_foregroundColor;
KProperty* m_lineColor;
KProperty* m_lineWeight;
KProperty* m_lineStyle;
KProperty* m_staticValue;
bool value() const;
void setValue(bool v);
KReportLineStyle lineStyle();
private:
void createProperties() override;
friend class Scripting::CheckBox;
};
#endif // KREPORTITEMCHECKBOX_H
diff --git a/src/items/field/KReportDesignerItemField.cpp b/src/items/field/KReportDesignerItemField.cpp
index 2dcd6cea..623ce45e 100644
--- a/src/items/field/KReportDesignerItemField.cpp
+++ b/src/items/field/KReportDesignerItemField.cpp
@@ -1,189 +1,181 @@
/* This file is part of the KDE project
* Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#include "KReportDesignerItemField.h"
#include "KReportItemField.h"
#include "KReportDesigner.h"
#include "kreportplugin_debug.h"
#include "KReportLineStyle.h"
#include
#include
#include
#include
//
// class ReportEntityField
//
void KReportDesignerItemField::init(QGraphicsScene *scene)
{
if (scene)
scene->addItem(this);
connect(propertySet(), SIGNAL(propertyChanged(KPropertySet&,KProperty&)),
this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&)));
+ dataSourceProperty()->setListData(designer()->fieldKeys(), designer()->fieldNames());
setZValue(z());
- updateRenderText(m_controlSource->value().toString(), m_itemValue->value().toString(), QLatin1String("field"));
+ updateRenderText(itemDataSource(), m_itemValue->value().toString(), QLatin1String("field"));
}
// methods (constructors)
KReportDesignerItemField::KReportDesignerItemField(KReportDesigner *rw, QGraphicsScene *scene, const QPointF &pos)
: KReportDesignerItemRectBase(rw, this)
{
Q_UNUSED(pos);
init(scene);
setSceneRect(properRect(*rw, getTextRect().width(), getTextRect().height()));
nameProperty()->setValue(designer()->suggestEntityName(typeName()));
}
KReportDesignerItemField::KReportDesignerItemField(const QDomNode & element, KReportDesigner * d, QGraphicsScene * s)
: KReportItemField(element), KReportDesignerItemRectBase(d, this)
{
init(s);
setSceneRect(KReportItemBase::scenePosition(item()->position()), KReportItemBase::sceneSize(item()->size()));
}
KReportDesignerItemField* KReportDesignerItemField::clone()
{
QDomDocument d;
QDomElement e = d.createElement(QLatin1String("clone"));
QDomNode n;
buildXML(&d, &e);
n = e.firstChild();
return new KReportDesignerItemField(n, designer(), nullptr);
}
// methods (deconstructor)
KReportDesignerItemField::~KReportDesignerItemField()
{}
QRectF KReportDesignerItemField::getTextRect() const
{
return QFontMetricsF(font()).boundingRect(QRectF(x(), y(), 0, 0), textFlags(), renderText());
}
void KReportDesignerItemField::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
// store any values we plan on changing so we can restore them
QFont f = painter->font();
QPen p = painter->pen();
painter->setFont(font());
painter->setBackgroundMode(Qt::TransparentMode);
QColor bg = m_backgroundColor->value().value();
bg.setAlphaF(m_backgroundOpacity->value().toReal() *0.01);
painter->setPen(m_foregroundColor->value().value());
painter->fillRect(QGraphicsRectItem::rect(), bg);
painter->drawText(rect(), textFlags(), renderText());
if ((Qt::PenStyle)m_lineStyle->value().toInt() == Qt::NoPen || m_lineWeight->value().toInt() <= 0) {
painter->setPen(QPen(Qt::lightGray));
} else {
painter->setPen(QPen(m_lineColor->value().value(), m_lineWeight->value().toInt(), (Qt::PenStyle)m_lineStyle->value().toInt()));
}
painter->drawRect(rect());
drawHandles(painter);
// restore an values before we started just in case
painter->setFont(f);
painter->setPen(p);
}
void KReportDesignerItemField::buildXML(QDomDocument *doc, QDomElement *parent)
{
QDomElement entity = doc->createElement(QLatin1String("report:") + typeName());
// properties
addPropertyAsAttribute(&entity, nameProperty());
- addPropertyAsAttribute(&entity, m_controlSource);
+ addPropertyAsAttribute(&entity, dataSourceProperty());
addPropertyAsAttribute(&entity, m_verticalAlignment);
addPropertyAsAttribute(&entity, m_horizontalAlignment);
addPropertyAsAttribute(&entity, m_wordWrap);
addPropertyAsAttribute(&entity, m_canGrow);
addPropertyAsAttribute(&entity, m_itemValue);
entity.setAttribute(QLatin1String("report:z-index"), zValue());
// bounding rect
buildXMLRect(doc, &entity, this);
//text style info
buildXMLTextStyle(doc, &entity, textStyle());
//Line Style
buildXMLLineStyle(doc, &entity, lineStyle());
#if 0 //Field Totals
if (m_trackTotal) {
QDomElement tracktotal = doc->createElement("tracktotal");
if (m_trackBuiltinFormat)
tracktotal.setAttribute("builtin", "true");
if (_useSubTotal)
tracktotal.setAttribute("subtotal", "true");
tracktotal.appendChild(doc.createTextNode(_trackTotalFormat->value().toString()));
entity.appendChild(tracktotal);
}
#endif
parent->appendChild(entity);
}
void KReportDesignerItemField::slotPropertyChanged(KPropertySet &s, KProperty &p)
{
Q_UNUSED(s);
if (p.name() == "name") {
//For some reason p.oldValue returns an empty string
if (!designer()->isEntityNameUnique(p.value().toString(), this)) {
p.setValue(oldName());
} else {
setOldName(p.value().toString());
}
}
- updateRenderText(m_controlSource->value().toString(), m_itemValue->value().toString(), QLatin1String("field"));
+ updateRenderText(itemDataSource(), m_itemValue->value().toString(), QLatin1String("field"));
KReportDesignerItemRectBase::propertyChanged(s, p);
if (designer())designer()->setModified(true);
}
-
-void KReportDesignerItemField::mousePressEvent(QGraphicsSceneMouseEvent * event)
-{
- //kreportpluginDebug() << m_reportDesigner->fieldKeys() << m_reportDesigner->fieldNames();
- m_controlSource->setListData(designer()->fieldKeys(), designer()->fieldNames());
- KReportDesignerItemRectBase::mousePressEvent(event);
-}
-
-
diff --git a/src/items/field/KReportDesignerItemField.h b/src/items/field/KReportDesignerItemField.h
index 5c98a385..9e4a9e99 100644
--- a/src/items/field/KReportDesignerItemField.h
+++ b/src/items/field/KReportDesignerItemField.h
@@ -1,56 +1,53 @@
/* 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 KREPORTDESIGNERITEMFIELD_H
#define KREPORTDESIGNERITEMFIELD_H
#include
#include
#include "KReportItemField.h"
#include "KReportDesignerItemRectBase.h"
class KReportDesignerItemField : public KReportItemField, public KReportDesignerItemRectBase
{
Q_OBJECT
public:
// Used when creating new basic field
KReportDesignerItemField(KReportDesigner *designer, QGraphicsScene *scene, const QPointF &pos);
// Used when loading from file
KReportDesignerItemField(const QDomNode &element, KReportDesigner *designer,
QGraphicsScene *scene);
~KReportDesignerItemField() override;
void buildXML(QDomDocument *doc, QDomElement *parent) override;
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget *widget = nullptr) override;
KReportDesignerItemField* clone() override;
-protected:
- void mousePressEvent(QGraphicsSceneMouseEvent * event) override;
-
private:
void init(QGraphicsScene *scene);
QRectF getTextRect() const;
private Q_SLOTS:
void slotPropertyChanged(KPropertySet &, KProperty &);
};
#endif
diff --git a/src/items/field/KReportItemField.cpp b/src/items/field/KReportItemField.cpp
index b675f3aa..0cc9ae78 100644
--- a/src/items/field/KReportItemField.cpp
+++ b/src/items/field/KReportItemField.cpp
@@ -1,289 +1,270 @@
/* 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 "KReportUtils.h"
#include "kreportplugin_debug.h"
#ifdef KREPORT_SCRIPTING
#include "KReportScriptHandler.h"
#endif
#include
#include
#include
#include
#include
#include
KReportItemField::KReportItemField()
{
createProperties();
}
KReportItemField::KReportItemField(const QDomNode & element)
: KReportItemField()
{
nameProperty()->setValue(KReportUtils::readNameAttribute(element.toElement()));
- m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source")));
+ setItemDataSource(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());
QDomNodeList nl = element.childNodes();
QString n;
QDomNode node;
for (int i = 0; i < nl.count(); i++) {
node = nl.item(i);
n = node.nodeName();
if (n == QLatin1String("report:text-style")) {
KReportTextStyleData 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()
{
- m_controlSource = new KProperty("item-data-source", new KPropertyListData, QVariant(), tr("Data Source"));
- m_controlSource->setOption("extraValueAllowed", QLatin1String("true"));
+ createDataSourceProperty();
m_itemValue = new KProperty("value", QString(), tr("Value"), tr("Value used if not bound to a field"));
KPropertyListData *listData = new KPropertyListData(
{ QLatin1String("left"), QLatin1String("center"), QLatin1String("right") },
QVariantList{ tr("Left"), tr("Center"), tr("Right") });
m_horizontalAlignment = new KProperty("horizontal-align", listData, QLatin1String("left"),
tr("Horizontal Alignment"));
listData = new KPropertyListData(
{ QLatin1String("top"), QLatin1String("center"), QLatin1String("bottom") },
QVariantList{ tr("Top"), tr("Center"), tr("Bottom") });
m_verticalAlignment = new KProperty("vertical-align", listData, 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("suffix", 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"), 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;
}
KReportTextStyleData KReportItemField::textStyle() const
{
KReportTextStyleData 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();
- }
+ str = data.toString();
} else {
- str = m_itemValue->value().toString();
+ str = m_itemValue->value().toString();
}
tb->setText(str);
//Work out the size of the text
if (tb->canGrow()) {
QRectF r;
if (tb->wordWrap()) {
//Grow vertically
QFontMetricsF metrics(font());
QRectF 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
QFontMetricsF metrics(font());
QRectF 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/field/KReportItemField.h b/src/items/field/KReportItemField.h
index 39e57e5a..0dd91e92 100644
--- a/src/items/field/KReportItemField.h
+++ b/src/items/field/KReportItemField.h
@@ -1,87 +1,81 @@
/* 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 .
*/
#ifndef KREPORTITEMFIELD_H
#define KREPORTITEMFIELD_H
#include "KReportItemBase.h"
#include
class QDomNode;
namespace Scripting
{
class Field;
}
class KReportItemField : public KReportItemBase
{
Q_OBJECT
public:
KReportItemField();
explicit KReportItemField(const QDomNode & element);
~KReportItemField() override;
QString typeName() const override;
int renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) override;
- QString itemDataSource() const override;
-
protected:
-
- KProperty * m_controlSource;
KProperty * m_horizontalAlignment;
KProperty * m_verticalAlignment;
KProperty * m_font;
//KProperty * m_trackTotal;
//KProperty * m_trackBuiltinFormat;
//KProperty * _useSubTotal;
//KProperty * _trackTotalFormat;
KProperty * m_foregroundColor;
KProperty * m_backgroundColor;
KProperty* m_backgroundOpacity;
KProperty* m_lineColor;
KProperty* m_lineWeight;
KProperty* m_lineStyle;
KProperty* m_wordWrap;
KProperty* m_canGrow;
KProperty* m_itemValue;
//bool builtinFormat;
//QString format;
QStringList fieldNames(const QString &);
KReportLineStyle lineStyle() const;
KReportTextStyleData textStyle() const;
int textFlags() const;
QFont font() const {
return m_font->value().value();
}
- void setItemDataSource(const QString&);
-
private:
void createProperties() override;
friend class Scripting::Field;
};
#endif
diff --git a/src/items/field/KReportScriptField.h b/src/items/field/KReportScriptField.h
index 6db795f5..21308824 100644
--- a/src/items/field/KReportScriptField.h
+++ b/src/items/field/KReportScriptField.h
@@ -1,125 +1,125 @@
/* 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 .
*/
#ifndef KRSCRIPTFIELD_H
#define KRSCRIPTFIELD_H
#include
#include "KReportItemField.h"
/**
@brief Field item script interface
The user facing interface for scripting report field items
*/
namespace Scripting
{
/**
@brief Field script interface
The user facing interface for scripting report fields
*/
class Field : public QObject
{
Q_OBJECT
public:
explicit Field(KReportItemField*);
~Field() override;
public Q_SLOTS:
- //! @return the source (column) that the field gets its data from*
+ //! @return the data source for the field element
+ //! The source can be a column name or a valid script expression if prefixed with a '='.
QString source() const;
- //! Sets the source (column) for the field.
- //! Valid values include a column name, fixed string if prefixed with '$'
- //! or a valid script expression if prefixed with a '='
- void setSource(const QString&);
+ //! Sets the data source for the field element.
+ //! @see source()
+ void setSource(const QString &s);
//! @return the horizontal alignment as an integer
//! Valid values are left: -1, center: 0, right; 1
int horizontalAlignment() const;
//! Sets the horizontal alignment
//! Valid values for alignment are left: -1, center: 0, right; 1
void setHorizonalAlignment(int);
//! @return the vertical alignment
//! Valid values are top: -1, middle: 0, bottom: 1
int verticalAlignment() const;
//! Sets the vertical alignment
//! Valid values for aligmnt are top: -1, middle: 0, bottom: 1
void setVerticalAlignment(int);
//! @return the background color of the lable
QColor backgroundColor() const;
//! Set the background color of the field to the given color
void setBackgroundColor(const QColor&);
//! @return the foreground (text) color of the field
QColor foregroundColor() const;
//! Sets the foreground (text) color of the field to the given color
void setForegroundColor(const QColor&);
//! @return the opacity of the field
int backgroundOpacity() const;
//! Sets the background opacity of the field
//! Valid values are in the range 0-100
void setBackgroundOpacity(int);
//! @return the border line color of the field
QColor lineColor() const;
//! Sets the border line color of the field to the given color
void setLineColor(const QColor&);
//! @return the border line weight (thickness) of the field
int lineWeight() const;
//! Sets the border line weight (thickness) of the field
void setLineWeight(int);
//! @return the border line style of the field. Values are from Qt::Penstyle range 0-5
int lineStyle() const;
//! Sets the border line style of the field to the given style in the range 0-5
void setLineStyle(int);
//! @returns the position of the field in points
QPointF position() const;
//! Sets the position of the field to the given point coordinates
void setPosition(const QPointF&);
//! @returns the size of the field in points
QSizeF size() const;
//! Sets the size of the field to the given size in points
void setSize(const QSizeF&);
private:
KReportItemField *m_field;
};
}
#endif
diff --git a/src/items/image/KReportDesignerItemImage.cpp b/src/items/image/KReportDesignerItemImage.cpp
index cfae0c3d..2cd2dbba 100644
--- a/src/items/image/KReportDesignerItemImage.cpp
+++ b/src/items/image/KReportDesignerItemImage.cpp
@@ -1,150 +1,144 @@
/* This file is part of the KDE project
* Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#include "KReportDesignerItemImage.h"
#include "KReportDesignerItemBase.h"
#include "KReportDesigner.h"
#include
#include
#include
#include
#include
//
// ReportEntitiesImage
//
// contructors/deconstructors
void KReportDesignerItemImage::init(QGraphicsScene *scene)
{
//kreportpluginDebug();
if (scene)
scene->addItem(this);
connect(propertySet(), SIGNAL(propertyChanged(KPropertySet&,KProperty&)),
this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&)));
- m_controlSource->setListData(designer()->fieldKeys(), designer()->fieldNames());
+ dataSourceProperty()->setListData(designer()->fieldKeys(), designer()->fieldNames());
setZValue(z());
}
KReportDesignerItemImage::KReportDesignerItemImage(KReportDesigner *rw, QGraphicsScene *scene, const QPointF &pos)
: KReportDesignerItemRectBase(rw, this)
{
Q_UNUSED(pos);
//kreportpluginDebug();
init(scene);
setSceneRect(properRect(*rw, KREPORT_ITEM_RECT_DEFAULT_WIDTH, KREPORT_ITEM_RECT_DEFAULT_WIDTH));
nameProperty()->setValue(designer()->suggestEntityName(typeName()));
}
KReportDesignerItemImage::KReportDesignerItemImage(const QDomNode & element, KReportDesigner * rw, QGraphicsScene* scene)
: KReportItemImage(element), KReportDesignerItemRectBase(rw, this)
{
init(scene);
setSceneRect(KReportItemBase::scenePosition(item()->position()), KReportItemBase::sceneSize(item()->size()));
}
KReportDesignerItemImage* KReportDesignerItemImage::clone()
{
QDomDocument d;
QDomElement e = d.createElement(QLatin1String("clone"));
QDomNode n;
buildXML(&d, &e);
n = e.firstChild();
return new KReportDesignerItemImage(n, designer(), nullptr);
}
KReportDesignerItemImage::~KReportDesignerItemImage()
{
// do we need to clean anything up?
}
void KReportDesignerItemImage::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
// store any values we plan on changing so we can restore them
QPen p = painter->pen();
if (isInline()) {
//QImage t_img = _image;
QImage t_img = m_staticImage->value().value().toImage();
if (mode() == QLatin1String("stretch")) {
t_img = t_img.scaled(rect().width(), rect().height(), Qt::KeepAspectRatio);
}
painter->drawImage(rect().left(), rect().top(), t_img, 0, 0, rect().width(), rect().height());
} else {
painter->drawText(rect(), 0, dataSourceAndObjectTypeName(itemDataSource(), QLatin1String("image")));
}
//Draw a border so user knows the object edge
painter->setPen(QPen(Qt::lightGray));
painter->drawRect(rect());
drawHandles(painter);
// restore an values before we started just in case
painter->setPen(p);
}
void KReportDesignerItemImage::buildXML(QDomDocument *doc, QDomElement *parent)
{
QDomElement entity = doc->createElement(QLatin1String("report:") + typeName());
// properties
addPropertyAsAttribute(&entity, nameProperty());
addPropertyAsAttribute(&entity, m_resizeMode);
entity.setAttribute(QLatin1String("report:z-index"), z());
buildXMLRect(doc, &entity, this);
if (isInline()) {
QDomElement map = doc->createElement(QLatin1String("report:inline-image-data"));
map.appendChild(doc->createTextNode(QLatin1String(inlineImageData())));
entity.appendChild(map);
} else {
- addPropertyAsAttribute(&entity, m_controlSource);
+ addPropertyAsAttribute(&entity, dataSourceProperty());
}
parent->appendChild(entity);
}
void KReportDesignerItemImage::slotPropertyChanged(KPropertySet &s, KProperty &p)
{
if (p.name() == "name") {
//For some reason p.oldValue returns an empty string
if (!designer()->isEntityNameUnique(p.value().toString(), this)) {
p.setValue(oldName());
} else {
setOldName(p.value().toString());
}
}
KReportDesignerItemRectBase::propertyChanged(s, p);
if (designer()) designer()->setModified(true);
}
-
-void KReportDesignerItemImage::mousePressEvent(QGraphicsSceneMouseEvent * event)
-{
- m_controlSource->setListData(designer()->fieldKeys(), designer()->fieldNames());
- KReportDesignerItemRectBase::mousePressEvent(event);
-}
diff --git a/src/items/image/KReportDesignerItemImage.h b/src/items/image/KReportDesignerItemImage.h
index e9bf3f87..b7282519 100644
--- a/src/items/image/KReportDesignerItemImage.h
+++ b/src/items/image/KReportDesignerItemImage.h
@@ -1,52 +1,49 @@
/* 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 KREPORTDESIGNERITEMIMAGE_H
#define KREPORTDESIGNERITEMIMAGE_H
#include "KReportDesignerItemRectBase.h"
#include "KReportItemImage.h"
#include
class KReportDesignerItemImage : public KReportItemImage, public KReportDesignerItemRectBase
{
Q_OBJECT
public:
KReportDesignerItemImage(KReportDesigner *designer, QGraphicsScene *scene, const QPointF &pos);
KReportDesignerItemImage(const QDomNode &element, KReportDesigner *designer,
QGraphicsScene *scene);
~KReportDesignerItemImage() override;
void buildXML(QDomDocument *doc, QDomElement *parent) override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget = nullptr) override;
KReportDesignerItemImage *clone() override;
-protected:
- void mousePressEvent(QGraphicsSceneMouseEvent * event) override;
-
private:
void init(QGraphicsScene *scene);
private Q_SLOTS:
void slotPropertyChanged(KPropertySet &, KProperty &);
};
#endif
diff --git a/src/items/image/KReportItemImage.cpp b/src/items/image/KReportItemImage.cpp
index b0b0c3cd..c40161d7 100644
--- a/src/items/image/KReportItemImage.cpp
+++ b/src/items/image/KReportItemImage.cpp
@@ -1,189 +1,177 @@
/* 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 "KReportItemImage.h"
#include "KReportUtils.h"
#include "KReportRenderObjects.h"
#include "kreportplugin_debug.h"
#include
#include
#include
#include
KReportItemImage::KReportItemImage()
{
createProperties();
}
KReportItemImage::KReportItemImage(const QDomNode & element)
: KReportItemImage()
{
nameProperty()->setValue(KReportUtils::readNameAttribute(element.toElement()));
- m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source")));
+ setItemDataSource(element.toElement().attribute(QLatin1String("report:item-data-source")));
m_resizeMode->setValue(element.toElement().attribute(QLatin1String("report:resize-mode"), QLatin1String("stretch")));
setZ(element.toElement().attribute(QLatin1String("report:z-index")).toDouble());
parseReportRect(element.toElement());
QDomNodeList nl = element.childNodes();
QString n;
QDomNode node;
for (int i = 0; i < nl.count(); i++) {
node = nl.item(i);
n = node.nodeName();
if (n == QLatin1String("report:inline-image-data")) {
setInlineImageData(node.firstChild().nodeValue().toLatin1());
} else {
kreportpluginWarning() << "while parsing image element encountered unknown element: " << n;
}
}
}
KReportItemImage::~KReportItemImage()
{
}
bool KReportItemImage::isInline() const
{
return !(inlineImageData().isEmpty());
}
QByteArray KReportItemImage::inlineImageData() const
{
QPixmap pixmap = m_staticImage->value().value();
QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::ReadWrite);
pixmap.save(&buffer, "PNG"); // writes pixmap into ba in PNG format,
//! @todo should I remember the format used, or save as PNG as its lossless?
return buffer.buffer().toBase64();
}
void KReportItemImage::setInlineImageData(const QByteArray &dat, const QString &fn)
{
if (!fn.isEmpty()) {
QPixmap pix(fn);
if (!pix.isNull())
m_staticImage->setValue(pix);
else {
QPixmap blank(1, 1);
blank.fill();
m_staticImage->setValue(blank);
}
} else {
const QByteArray binaryStream(QByteArray::fromBase64(dat));
const QPixmap pix(QPixmap::fromImage(QImage::fromData(binaryStream), Qt::ColorOnly));
m_staticImage->setValue(pix);
}
}
QString KReportItemImage::mode() const
{
return m_resizeMode->value().toString();
}
void KReportItemImage::setMode(const QString &m)
{
if (mode() != m) {
m_resizeMode->setValue(m);
}
}
void KReportItemImage::createProperties()
{
- m_controlSource = new KProperty("item-data-source", new KPropertyListData, QVariant(), tr("Data Source"));
+ createDataSourceProperty();
KPropertyListData *listData = new KPropertyListData(
{ QLatin1String("clip"), QLatin1String("stretch") },
QVariantList{ tr("Clip"), tr("Stretch") });
m_resizeMode = new KProperty("resize-mode", listData, QLatin1String("clip"), tr("Resize Mode"));
m_staticImage = new KProperty("static-image", QPixmap(), tr("Value"), tr("Value used if not bound to a field"));
- propertySet()->addProperty(m_controlSource);
propertySet()->addProperty(m_resizeMode);
propertySet()->addProperty(m_staticImage);
}
-
-void KReportItemImage::setColumn(const QString &c)
-{
- m_controlSource->setValue(c);
-}
-
-QString KReportItemImage::itemDataSource() const
-{
- return m_controlSource->value().toString();
-}
-
QString KReportItemImage::typeName() const
{
return QLatin1String("image");
}
int KReportItemImage::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset,
const QVariant &data, KReportScriptHandler *script)
{
Q_UNUSED(script)
QByteArray uudata;
QByteArray imgdata;
if (!isInline()) {
imgdata = data.toByteArray();
} else {
uudata = inlineImageData();
imgdata = QByteArray::fromBase64(uudata);
}
QImage img;
img.loadFromData(imgdata);
OROImage * id = new OROImage();
id->setImage(img);
if (mode().toLower() == QLatin1String("stretch")) {
id->setScaled(true);
id->setAspectRatioMode(Qt::KeepAspectRatio);
id->setTransformationMode(Qt::SmoothTransformation);
}
id->setPosition(scenePosition(position()) + offset);
id->setSize(sceneSize(size()));
if (page) {
page->insertPrimitive(id);
}
if (section) {
OROImage *i2 = dynamic_cast(id->clone());
if (i2) {
i2->setPosition(scenePosition(position()));
section->addPrimitive(i2);
}
}
if (!page) {
delete id;
}
return 0; //Item doesn't stretch the section height
}
diff --git a/src/items/image/KReportItemImage.h b/src/items/image/KReportItemImage.h
index c174b874..16faad4d 100644
--- a/src/items/image/KReportItemImage.h
+++ b/src/items/image/KReportItemImage.h
@@ -1,62 +1,58 @@
/* 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 .
*/
#ifndef KREPORTITEMIMAGE_H
#define KREPORTITEMIMAGE_H
#include "KReportItemBase.h"
class QDomNode;
namespace Scripting
{
class Image;
}
class KReportItemImage : public KReportItemBase
{
Q_OBJECT
public:
KReportItemImage();
explicit KReportItemImage(const QDomNode & element);
~KReportItemImage() override;
QString typeName() const override;
int renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset,
const QVariant &data, KReportScriptHandler *script) override;
- QString itemDataSource() const override;
-
protected:
- KProperty * m_controlSource;
KProperty* m_resizeMode;
KProperty* m_staticImage;
void setMode(const QString&);
void setInlineImageData(const QByteArray &dat, const QString& = QString());
- void setColumn(const QString&);
QString mode() const;
bool isInline() const;
QByteArray inlineImageData() const;
private:
void createProperties() override;
friend class Scripting::Image;
};
#endif
diff --git a/src/items/image/KReportScriptImage.cpp b/src/items/image/KReportScriptImage.cpp
index ce13fbe4..dce9b1b5 100644
--- a/src/items/image/KReportScriptImage.cpp
+++ b/src/items/image/KReportScriptImage.cpp
@@ -1,78 +1,78 @@
/* 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 "KReportScriptImage.h"
#include "KReportItemImage.h"
#include
namespace Scripting
{
Image::Image(KReportItemImage *i)
{
m_image = i;
}
Image::~Image()
{
}
QPointF Image::position() const
{
return m_image->position();
}
void Image::setPosition(const QPointF& p)
{
m_image->setPosition(p);
}
QSizeF Image::size() const
{
return m_image->size();
}
void Image::setSize(const QSizeF& s)
{
m_image->setSize(s);
}
QString Image::resizeMode() const
{
return m_image->m_resizeMode->value().toString();
}
void Image::setResizeMode(const QString &rm)
{
if (rm == QLatin1String("Stretch")) {
m_image->m_resizeMode->setValue(QLatin1String("Stretch"));
} else {
m_image->m_resizeMode->setValue(QLatin1String("Clip"));
}
}
void Image::setInlineImage(const QByteArray &ba)
{
m_image->setInlineImageData(ba);
}
-void Image::loadFromFile(const QVariant &pth)
+void Image::loadFromFile(const QVariant &path)
{
- QString str = pth.toString();
+ QString str = path.toString();
m_image->setInlineImageData(QByteArray(), str);
}
}
diff --git a/src/items/image/KReportScriptImage.h b/src/items/image/KReportScriptImage.h
index 7226ef7d..9978eb40 100644
--- a/src/items/image/KReportScriptImage.h
+++ b/src/items/image/KReportScriptImage.h
@@ -1,103 +1,103 @@
/* 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 .
*/
#ifndef SCRIPTINGKRSCRIPTIMAGE_H
#define SCRIPTINGKRSCRIPTIMAGE_H
#include
#include
#include
class KReportItemImage;
namespace Scripting
{
/**
@brief Image item script interface
The user facing interface for scripting report image items
*/
class Image : public QObject
{
Q_OBJECT
public:
explicit Image(KReportItemImage *);
~Image() override;
public Q_SLOTS:
/**
* Get the position of the barcode
* @return position in points
*/
QPointF position() const;
/**
* Sets the position of the barcode in points
* @param Position
*/
void setPosition(const QPointF&);
/**
* Get the size of the barcode
* @return size in points
*/
QSizeF size() const;
/**
* Set the size of the barcode in points
* @param Size
*/
void setSize(const QSizeF&);
/**
* Get the resize mode for the image
* @return resizeMode Clip or Stretch
*/
QString resizeMode() const;
/**
* Sets the resize mode for the image
* @param ResizeMode "Stretch" or "Clip" default is to clip
*/
void setResizeMode(const QString &);
/**
* Sets the data for the static image
* the data should be base64 encoded
* @param RawImageData
*/
void setInlineImage(const QByteArray&);
/**
* Get the data from a file (expected to be an image)
* the returned data will be base64 encoded
- * @param Path location of file
- * @return File data enoded in base64
+ * @param path location of file
*/
- void loadFromFile(const QVariant &);
+ void loadFromFile(const QVariant &path);
+
private:
KReportItemImage *m_image;
};
}
#endif
diff --git a/src/items/text/KReportDesignerItemText.cpp b/src/items/text/KReportDesignerItemText.cpp
index f4993316..469c71ee 100644
--- a/src/items/text/KReportDesignerItemText.cpp
+++ b/src/items/text/KReportDesignerItemText.cpp
@@ -1,177 +1,170 @@
/* This file is part of the KDE project
* Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#include "KReportDesignerItemText.h"
#include "KReportDesignerItemBase.h"
#include "KReportDesigner.h"
#include "KReportLineStyle.h"
#include
#include
#include
#include
#include
#include "kreportplugin_debug.h"
//
// class ReportEntityText
//
// methods (constructors)
void KReportDesignerItemText::init(QGraphicsScene *scene)
{
//setFlags(ItemIsSelectable | ItemIsMovable);
if (scene)
scene->addItem(this);
connect(propertySet(), SIGNAL(propertyChanged(KPropertySet&,KProperty&)),
this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&)));
- m_controlSource->setListData(designer()->fieldKeys(), designer()->fieldNames());
+ dataSourceProperty()->setListData(designer()->fieldKeys(), designer()->fieldNames());
setZValue(z());
- updateRenderText(m_controlSource->value().toString(), m_itemValue->value().toString(),
+ updateRenderText(itemDataSource(), m_itemValue->value().toString(),
QLatin1String("textarea"));
}
KReportDesignerItemText::KReportDesignerItemText(KReportDesigner * rw, QGraphicsScene * scene, const QPointF &pos)
: KReportDesignerItemRectBase(rw, this)
{
Q_UNUSED(pos);
init(scene);
setSceneRect(properRect(*rw, getTextRect().width(), getTextRect().height()));
nameProperty()->setValue(designer()->suggestEntityName(typeName()));
}
KReportDesignerItemText::KReportDesignerItemText(const QDomNode & element, KReportDesigner *d, QGraphicsScene *scene)
: KReportItemText(element), KReportDesignerItemRectBase(d, this)
{
init(scene);
setSceneRect(KReportItemBase::scenePosition(item()->position()), KReportItemBase::sceneSize(item()->size()));
}
KReportDesignerItemText* KReportDesignerItemText::clone()
{
QDomDocument d;
QDomElement e = d.createElement(QLatin1String("clone"));
QDomNode n;
buildXML(&d, &e);
n = e.firstChild();
return new KReportDesignerItemText(n, designer(), nullptr);
}
KReportDesignerItemText::~KReportDesignerItemText
()
{}
QRectF KReportDesignerItemText::getTextRect() const
{
return QFontMetricsF(font()).boundingRect(QRectF(x(), y(), 0, 0), textFlags(), renderText());
}
void KReportDesignerItemText::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget)
{
Q_UNUSED(option);
Q_UNUSED(widget)
// store any values we plan on changing so we can restore them
QFont f = painter->font();
QPen p = painter->pen();
painter->setFont(font());
painter->setBackgroundMode(Qt::TransparentMode);
QColor bg = m_backgroundColor->value().value();
bg.setAlphaF(m_backgroundOpacity->value().toReal()*0.01);
painter->setPen(m_foregroundColor->value().value());
painter->fillRect(rect(), bg);
painter->drawText(rect(), textFlags(), renderText());
if ((Qt::PenStyle)m_lineStyle->value().toInt() == Qt::NoPen || m_lineWeight->value().toInt() <= 0) {
painter->setPen(QPen(Qt::lightGray));
} else {
painter->setPen(QPen(m_lineColor->value().value(), m_lineWeight->value().toInt(), (Qt::PenStyle)m_lineStyle->value().toInt()));
}
painter->drawRect(rect());
painter->setPen(m_foregroundColor->value().value());
drawHandles(painter);
// restore an values before we started just in case
painter->setFont(f);
painter->setPen(p);
}
void KReportDesignerItemText::buildXML(QDomDocument *doc, QDomElement *parent)
{
//kreportpluginDebug();
QDomElement entity = doc->createElement(QLatin1String("report:") + typeName());
// properties
addPropertyAsAttribute(&entity, nameProperty());
- addPropertyAsAttribute(&entity, m_controlSource);
+ addPropertyAsAttribute(&entity, dataSourceProperty());
addPropertyAsAttribute(&entity, m_verticalAlignment);
addPropertyAsAttribute(&entity, m_horizontalAlignment);
entity.setAttribute(QLatin1String("report:bottom-padding"), m_bottomPadding);
entity.setAttribute(QLatin1String("report:z-index"), z());
addPropertyAsAttribute(&entity, m_itemValue);
// bounding rect
buildXMLRect(doc, &entity, this);
//text style info
buildXMLTextStyle(doc, &entity, textStyle());
//Line Style
buildXMLLineStyle(doc, &entity, lineStyle());
parent->appendChild(entity);
}
-void KReportDesignerItemText::mousePressEvent(QGraphicsSceneMouseEvent * event)
-{
- m_controlSource->setListData(designer()->fieldKeys(), designer()->fieldNames());
- KReportDesignerItemRectBase::mousePressEvent(event);
-}
-
-
void KReportDesignerItemText::slotPropertyChanged(KPropertySet &s, KProperty &p)
{
Q_UNUSED(s);
if (p.name() == "name") {
//For some reason p.oldValue returns an empty string
if (!designer()->isEntityNameUnique(p.value().toString(), this)) {
p.setValue(oldName());
} else {
setOldName(p.value().toString());
}
}
KReportDesignerItemRectBase::propertyChanged(s, p);
if (designer()) {
designer()->setModified(true);
}
- updateRenderText(m_controlSource->value().toString(), m_itemValue->value().toString(),
+ updateRenderText(itemDataSource(), m_itemValue->value().toString(),
QLatin1String("textarea"));
}
diff --git a/src/items/text/KReportDesignerItemText.h b/src/items/text/KReportDesignerItemText.h
index 708c0e41..db3aebca 100644
--- a/src/items/text/KReportDesignerItemText.h
+++ b/src/items/text/KReportDesignerItemText.h
@@ -1,55 +1,52 @@
/* 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 KREPORTDESIGNERITEMTEXT_H
#define KREPORTDESIGNERITEMTEXT_H
#include "KReportDesignerItemRectBase.h"
#include "KReportItemText.h"
#include
//
// ReportEntityText
//
class KReportDesignerItemText : public KReportItemText, public KReportDesignerItemRectBase
{
Q_OBJECT
public:
KReportDesignerItemText(KReportDesigner *designer, QGraphicsScene *scene, const QPointF &pos);
KReportDesignerItemText(const QDomNode &element, KReportDesigner *designer,
QGraphicsScene *scene);
~KReportDesignerItemText() override;
void buildXML(QDomDocument *doc, QDomElement *parent) override;
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr) override;
KReportDesignerItemText* clone() override;
-protected:
- void mousePressEvent(QGraphicsSceneMouseEvent * event) override;
-
private:
QRectF getTextRect() const;
void init(QGraphicsScene *scene);
private Q_SLOTS:
void slotPropertyChanged(KPropertySet &, KProperty &);
};
#endif
diff --git a/src/items/text/KReportItemText.cpp b/src/items/text/KReportItemText.cpp
index a6f8c759..3aaaaad4 100644
--- a/src/items/text/KReportItemText.cpp
+++ b/src/items/text/KReportItemText.cpp
@@ -1,322 +1,309 @@
/* 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 "KReportUtils.h"
#include
#include
#include
#include
#include
#include
#include
#include
KReportItemText::KReportItemText()
: m_bottomPadding(0.0)
{
createProperties();
}
KReportItemText::KReportItemText(const QDomNode & element)
: KReportItemText()
{
nameProperty()->setValue(KReportUtils::readNameAttribute(element.toElement()));
- m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source")));
+ setItemDataSource(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());
QDomNodeList nl = element.childNodes();
QString n;
QDomNode node;
for (int i = 0; i < nl.count(); i++) {
node = nl.item(i);
n = node.nodeName();
if (n == QLatin1String("report:text-style")) {
KReportTextStyleData 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 & ) ) );
-
- //_query = new KProperty ( "Query", QStringList(), QStringList(), "Data Source", "Query" );
- m_controlSource = new KProperty("item-data-source", new KPropertyListData, QVariant(), tr("Data Source"));
+ createDataSourceProperty();
m_itemValue = new KProperty("value", QString(), tr("Value"), tr("Value used if not bound to a field"));
KPropertyListData *listData = new KPropertyListData(
{ QLatin1String("left"), QLatin1String("center"), QLatin1String("right") },
QVariantList{ tr("Left"), tr("Center"), tr("Right") });
m_horizontalAlignment = new KProperty("horizontal-align", listData, QLatin1String("left"),
tr("Horizontal Alignment"));
listData = new KPropertyListData(
{ QLatin1String("top"), QLatin1String("center"), QLatin1String("bottom") },
QVariantList{ tr("Top"), tr("Center"), tr("Bottom") });
m_verticalAlignment = new KProperty("vertical-align", listData, 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"), 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("suffix", 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;
}
}
KReportTextStyleData KReportItemText::textStyle() const
{
KReportTextStyleData 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();
- }
+ 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);
QFontMetricsF 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/items/text/KReportItemText.h b/src/items/text/KReportItemText.h
index c92e53cd..94b2ccfd 100644
--- a/src/items/text/KReportItemText.h
+++ b/src/items/text/KReportItemText.h
@@ -1,82 +1,78 @@
/* 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 .
*/
#ifndef KREPORTITEMTEXT_H
#define KREPORTITEMTEXT_H
#include "KReportItemBase.h"
#include
class QDomNode;
namespace Scripting
{
class Text;
}
/**
*/
class KReportItemText : public KReportItemBase
{
Q_OBJECT
public:
KReportItemText();
explicit KReportItemText(const QDomNode & element);
~KReportItemText() override;
QString typeName() const override;
int renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) override;
- QString itemDataSource() const override;
-
protected:
-
- KProperty* m_controlSource;
KProperty* m_horizontalAlignment;
KProperty* m_verticalAlignment;
KProperty* m_font;
KProperty* m_foregroundColor;
KProperty* m_backgroundColor;
KProperty* m_backgroundOpacity;
KProperty* m_lineColor;
KProperty* m_lineWeight;
KProperty* m_lineStyle;
KProperty* m_itemValue;
qreal m_bottomPadding;
Qt::Alignment textFlags() const;
QFont font() const {
return m_font->value().value();
}
void setBottomPadding(qreal bp);
qreal bottomPadding() const;
KReportTextStyleData textStyle() const;
KReportLineStyle lineStyle() const;
private:
void createProperties() override;
friend class Scripting::Text;
};
#endif
diff --git a/src/items/text/KReportScriptText.cpp b/src/items/text/KReportScriptText.cpp
index c174fefc..09303d38 100644
--- a/src/items/text/KReportScriptText.cpp
+++ b/src/items/text/KReportScriptText.cpp
@@ -1,208 +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 "KReportScriptText.h"
#include
#include
#include
#include
#include "kreportplugin_debug.h"
namespace Scripting
{
Text::Text(KReportItemText* t)
{
m_text = t;
}
Text::~Text()
{
}
QString Text::source() const
{
return m_text->itemDataSource();
}
void Text::setSource(const QString& s)
{
- m_text->m_controlSource->setValue(s);
+ m_text->setItemDataSource(s);
}
int Text::horizontalAlignment() const
{
const QString a = m_text->m_horizontalAlignment->value().toString().toLower();
if (a == QLatin1String("left")) {
return -1;
}
if (a == QLatin1String("center")) {
return 0;
}
if (a == QLatin1String("right")) {
return 1;
}
return -1;
}
void Text::setHorizonalAlignment(int a)
{
switch (a) {
case -1:
m_text->m_horizontalAlignment->setValue(QLatin1String("left"));
break;
case 0:
m_text->m_horizontalAlignment->setValue(QLatin1String("center"));
break;
case 1:
m_text->m_horizontalAlignment->setValue(QLatin1String("right"));
break;
default:
m_text->m_horizontalAlignment->setValue(QLatin1String("left"));
break;
}
}
int Text::verticalAlignment() const
{
const QString a = m_text->m_horizontalAlignment->value().toString().toLower();
if (a == QLatin1String("top")) {
return -1;
}
if (a == QLatin1String("middle")) {
return 0;
}
if (a == QLatin1String("bottom")) {
return 1;
}
return -1;
}
void Text::setVerticalAlignment(int a)
{
switch (a) {
case -1:
m_text->m_verticalAlignment->setValue(QLatin1String("top"));
break;
case 0:
m_text->m_verticalAlignment->setValue(QLatin1String("middle"));
break;
case 1:
m_text->m_verticalAlignment->setValue(QLatin1String("bottom"));
break;
default:
m_text->m_verticalAlignment->setValue(QLatin1String("middle"));
break;
}
}
QColor Text::backgroundColor() const
{
return m_text->m_backgroundColor->value().value();
}
void Text::setBackgroundColor(const QColor& c)
{
m_text->m_backgroundColor->setValue(QColor(c));
}
QColor Text::foregroundColor() const
{
return m_text->m_foregroundColor->value().value();
}
void Text::setForegroundColor(const QColor& c)
{
m_text->m_foregroundColor->setValue(QColor(c));
}
int Text::backgroundOpacity() const
{
return m_text->m_backgroundOpacity->value().toInt();
}
void Text::setBackgroundOpacity(int o)
{
m_text->m_backgroundOpacity->setValue(o);
}
QColor Text::lineColor() const
{
return m_text->m_lineColor->value().value();
}
void Text::setLineColor(const QColor& c)
{
m_text->m_lineColor->setValue(QColor(c));
}
int Text::lineWeight() const
{
return m_text->m_lineWeight->value().toInt();
}
void Text::setLineWeight(int w)
{
m_text->m_lineWeight->setValue(w);
}
int Text::lineStyle() const
{
return m_text->m_lineStyle->value().toInt();
}
void Text::setLineStyle(int s)
{
if (s < 0 || s > 5) {
s = 1;
}
m_text->m_lineStyle->setValue(s);
}
QPointF Text::position() const
{
return m_text->position();
}
void Text::setPosition(const QPointF& p)
{
m_text->setPosition(p);
}
QSizeF Text::size() const
{
return m_text->size();
}
void Text::setSize(const QSizeF& s)
{
m_text->setSize(s);
}
-void Text::loadFromFile(const QString &fn)
+bool Text::loadFromFile(const QString &fileName)
{
- QFile file(fn);
+ QFile file(fileName);
//kreportpluginDebug() << "Loading from" << fn;
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
- m_text->m_controlSource->setValue(tr("$Unable to read %1").arg(fn));
- return;
+ kreportpluginWarning() << "Failed to load value for text element from file" << fileName;
+ return false;
}
QTextStream in(&file);
QString data = in.readAll();
/*
while (!in.atEnd()) {
QString line = in.readLine();
process_line(line);
}*/
- m_text->m_controlSource->setValue(QVariant(QLatin1String("$") + data));
+ m_text->m_itemValue->setValue(data);
+ return true;
}
}
diff --git a/src/items/text/KReportScriptText.h b/src/items/text/KReportScriptText.h
index 224e64f3..c2567264 100644
--- a/src/items/text/KReportScriptText.h
+++ b/src/items/text/KReportScriptText.h
@@ -1,122 +1,122 @@
/* 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 .
*/
#ifndef SCRIPTINGKRSCRIPTTEXT_H
#define SCRIPTINGKRSCRIPTTEXT_H
#include
#include "KReportItemText.h"
namespace Scripting
{
/**
@brief Text item script interface
The user facing interface for scripting report text items
*/
class Text : public QObject
{
Q_OBJECT
public:
explicit Text(KReportItemText*);
~Text() override;
public Q_SLOTS:
- //! @return the source (column) that the text-item gets its data from*
+ //! @return the data source for the text element
+ //! The source can be a column name or a valid script expression if prefixed with a '='.
QString source() const;
- //! Sets the source (column) for the text-item.
- //! Valid values include a column name, fixed string if prefixed with '$'
- //! or a valid script expression if prefixed with a '='
- void setSource(const QString&);
+ //! Sets the data source for the text element.
+ //! @see source()
+ void setSource(const QString &s);
//! @return the horizontal alignment as an integer
//! Valid values are left: -1, center: 0, right; 1
int horizontalAlignment() const;
//! Sets the horizontal alignment
//! Valid values for alignment are left: -1, center: 0, right; 1
void setHorizonalAlignment(int);
//! @return the vertical alignment
//! Valid values are top: -1, middle: 0, bottom: 1
int verticalAlignment() const;
//! Sets the vertical alignment
//! Valid values for aligmnt are top: -1, middle: 0, bottom: 1
void setVerticalAlignment(int);
//! @return the background color of the lable
QColor backgroundColor() const;
//! Set the background color of the text-item to the given color
void setBackgroundColor(const QColor&);
//! @return the foreground (text) color of the text-item
QColor foregroundColor() const;
//! Sets the foreground (text) color of the text-item to the given color
void setForegroundColor(const QColor&);
//! @return the opacity of the text-item
int backgroundOpacity() const;
//! Sets the background opacity of the text-item
//! Valid values are in the range 0-100
void setBackgroundOpacity(int);
//! @return the border line color of the text-item
QColor lineColor() const;
//! Sets the border line color of the text-item to the given color
void setLineColor(const QColor&);
//! @return the border line weight (thickness) of the text-item
int lineWeight() const;
//! Sets the border line weight (thickness) of the text-item
void setLineWeight(int);
//! @return the border line style of the text-item. Values are from Qt::Penstyle range 0-5
int lineStyle() const;
//! Sets the border line style of the text-item to the given style in the range 0-5
void setLineStyle(int);
//! @returns the position of the text-item in points
QPointF position() const;
//! Sets the position of the text-item to the given point coordinates
void setPosition(const QPointF&);
//! @returns the size of the text-item in points
QSizeF size() const;
//! Sets the size of the text-item to the given size in points
void setSize(const QSizeF&);
- //!Load the contets for the text item from the given file
- void loadFromFile(const QString& fileName);
+ //!Load the contents for the text item from the given file
+ bool loadFromFile(const QString& fileName);
private:
KReportItemText *m_text;
};
}
#endif
diff --git a/src/plugins/barcode/KReportDesignerItemBarcode.cpp b/src/plugins/barcode/KReportDesignerItemBarcode.cpp
index 5f604c2b..3313dd31 100644
--- a/src/plugins/barcode/KReportDesignerItemBarcode.cpp
+++ b/src/plugins/barcode/KReportDesignerItemBarcode.cpp
@@ -1,173 +1,167 @@
/* This file is part of the KDE project
* Copyright (C) 2001-2007 by OpenMFG, LLC (info@openmfg.com)
* Copyright (C) 2007-2008 by Adam Pigg (adam@piggz.co.uk)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see .
*/
#include "KReportDesignerItemBarcode.h"
#include "KReportDesignerItemBase.h"
#include "KReportDesigner.h"
#include "barcodepaint.h"
#include
#include
#include
#include
#include
#include
#include "kreportplugin_debug.h"
void KReportDesignerItemBarcode::init(QGraphicsScene *scene)
{
if (scene)
scene->addItem(this);
connect(propertySet(), SIGNAL(propertyChanged(KPropertySet&,KProperty&)),
this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&)));
setMaxLength(5);
setZ(z());
updateRenderText(m_itemValue->value().toString().isEmpty() ? m_format->value().toString() : QString(), m_itemValue->value().toString(), QString());
}
// methods (constructors)
KReportDesignerItemBarcode::KReportDesignerItemBarcode(KReportDesigner * rw, QGraphicsScene* scene, const QPointF &pos)
: KReportDesignerItemRectBase(rw, this)
{
Q_UNUSED(pos);
init(scene);
setSceneRect(properRect(*rw, m_minWidthTotal*dpiX(), m_minHeight*dpiY()));
nameProperty()->setValue(designer()->suggestEntityName(typeName()));
}
KReportDesignerItemBarcode::KReportDesignerItemBarcode(const QDomNode & element, KReportDesigner * rw, QGraphicsScene* scene)
: KReportItemBarcode(element), KReportDesignerItemRectBase(rw, this)
{
init(scene);
setSceneRect(KReportItemBase::scenePosition(item()->position()), KReportItemBase::sceneSize(item()->size()));
}
KReportDesignerItemBarcode* KReportDesignerItemBarcode::clone()
{
QDomDocument d;
QDomElement e = d.createElement(QLatin1String("clone"));
QDomNode n;
buildXML(&d, &e);
n = e.firstChild();
return new KReportDesignerItemBarcode(n, designer(), nullptr);
}
// methods (deconstructor)
KReportDesignerItemBarcode::~KReportDesignerItemBarcode()
{}
QRectF KReportDesignerItemBarcode::getTextRect() const
{
QFont fnt = QFont();
return QFontMetricsF(fnt)
.boundingRect(QRectF(x(), y(), 0, 0), 0,
dataSourceAndObjectTypeName(itemDataSource(), QLatin1String("barcode")));
}
void KReportDesignerItemBarcode::paint(QPainter* painter,
const QStyleOptionGraphicsItem* option,
QWidget* widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
// store any values we plan on changing so we can restore them
QPen p = painter->pen();
painter->setBackground(Qt::white);
//Draw a border so user knows the object edge
painter->setPen(QPen(QColor(224, 224, 224)));
painter->drawRect(rect());
drawHandles(painter);
QByteArray fmt = m_format->value().toByteArray();
if (fmt == "i2of5") {
renderI2of5(rect().toRect(), renderText(), horizontalAlignment(), painter);
} else if (fmt == "3of9") {
render3of9(rect().toRect(), renderText(), horizontalAlignment(), painter);
} else if (fmt == "3of9+") {
renderExtended3of9(rect().toRect(), renderText(), horizontalAlignment(), painter);
} else if (fmt == "128") {
renderCode128(rect().toRect(), renderText(), horizontalAlignment(), painter);
} else if (fmt == "upc-a") {
renderCodeUPCA(rect().toRect(), renderText(), horizontalAlignment(), painter);
} else if (fmt == "upc-e") {
renderCodeUPCE(rect().toRect(), renderText(), horizontalAlignment(), painter);
} else if (fmt == "ean13") {
renderCodeEAN13(rect().toRect(), renderText(), horizontalAlignment(), painter);
} else if (fmt == "ean8") {
renderCodeEAN8(rect().toRect(), renderText(), horizontalAlignment(), painter);
}
painter->setPen(Qt::black);
painter->drawText(rect(), 0, dataSourceAndObjectTypeName(itemDataSource(),
QLatin1String("barcode")));
// restore an values before we started just in case
painter->setPen(p);
}
void KReportDesignerItemBarcode::buildXML(QDomDocument *doc, QDomElement *parent)
{
//kreportpluginDebug();
QDomElement entity = doc->createElement(QLatin1String("report:") + typeName());
// properties
addPropertyAsAttribute(&entity, nameProperty());
- addPropertyAsAttribute(&entity, m_controlSource);
+ addPropertyAsAttribute(&entity, dataSourceProperty());
addPropertyAsAttribute(&entity, m_horizontalAlignment);
addPropertyAsAttribute(&entity, m_format);
addPropertyAsAttribute(&entity, m_maxLength);
entity.setAttribute(QLatin1String("report:z-index"), zValue());
addPropertyAsAttribute(&entity, m_itemValue);
// bounding rect
buildXMLRect(doc, &entity, this);
parent->appendChild(entity);
}
void KReportDesignerItemBarcode::slotPropertyChanged(KPropertySet &s, KProperty &p)
{
if (p.name() == "name") {
//For some reason p.oldValue returns an empty string
if (!designer()->isEntityNameUnique(p.value().toString(), this)) {
p.setValue(oldName());
} else {
setOldName(p.value().toString());
}
}
updateRenderText(m_itemValue->value().toString().isEmpty() ? m_format->value().toString() : QString(), m_itemValue->value().toString(), QString());
KReportDesignerItemRectBase::propertyChanged(s, p);
if (designer()) designer()->setModified(true);
}
-
-void KReportDesignerItemBarcode::mousePressEvent(QGraphicsSceneMouseEvent * event)
-{
- m_controlSource->setListData(designer()->fieldKeys(), designer()->fieldNames());
- KReportDesignerItemRectBase::mousePressEvent(event);
-}
diff --git a/src/plugins/barcode/KReportDesignerItemBarcode.h b/src/plugins/barcode/KReportDesignerItemBarcode.h
index ab4b9850..f430ce5a 100644
--- a/src/plugins/barcode/KReportDesignerItemBarcode.h
+++ b/src/plugins/barcode/KReportDesignerItemBarcode.h
@@ -1,59 +1,56 @@
/* 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 KREPORTDESIGNERITEMBARCODE_H
#define KREPORTDESIGNERITEMBARCODE_H
#include "KReportDesignerItemRectBase.h"
#include "KReportItemBarcode.h"
#include
//
// ReportEntityBarcode
//
class KReportDesignerItemBarcode : public KReportItemBarcode, public KReportDesignerItemRectBase
{
Q_OBJECT
public:
KReportDesignerItemBarcode(KReportDesigner *designer, QGraphicsScene *scene,
const QPointF &pos);
KReportDesignerItemBarcode(const QDomNode &element, KReportDesigner *designer,
QGraphicsScene *scene);
~KReportDesignerItemBarcode() override;
void buildXML(QDomDocument *doc, QDomElement *parent) override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
QWidget *widget = nullptr) override;
KReportDesignerItemBarcode *clone() override;
-protected:
- void mousePressEvent(QGraphicsSceneMouseEvent * event) override;
-
private:
void init(QGraphicsScene *scene);
QRectF getTextRect() const;
private Q_SLOTS:
void slotPropertyChanged(KPropertySet &, KProperty &);
};
#endif
diff --git a/src/plugins/barcode/KReportItemBarcode.cpp b/src/plugins/barcode/KReportItemBarcode.cpp
index af87a0c7..1f86bda6 100644
--- a/src/plugins/barcode/KReportItemBarcode.cpp
+++ b/src/plugins/barcode/KReportItemBarcode.cpp
@@ -1,243 +1,236 @@
/* 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 "KReportItemBarcode.h"
#include "KReportUtils.h"
#include
#include
#include
#include
#include "kreportplugin_debug.h"
#include "barcodes.h"
KReportItemBarcode::KReportItemBarcode()
: m_minWidthData(0), m_minWidthTotal(0), m_minHeight(0)
{
createProperties();
}
KReportItemBarcode::KReportItemBarcode(const QDomNode & element)
: KReportItemBarcode()
{
nameProperty()->setValue(KReportUtils::readNameAttribute(element.toElement()));
- m_controlSource->setValue(element.toElement().attribute(QLatin1String("report:item-data-source")));
+ setItemDataSource(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_maxLength->setValue(element.toElement().attribute(QLatin1String("report:barcode-max-length")).toInt());
m_format->setValue(element.toElement().attribute(QLatin1String("report:barcode-format")));
parseReportRect(element.toElement());
}
void KReportItemBarcode::setMaxLength(int i)
{
if (i > 0) {
if (m_maxLength->value().toInt() != i) {
m_maxLength->setValue(i);
}
if (m_format->value().toString() == QLatin1String("3of9")) {
int C = i; // number of characters
int N = 2; // narrow mult for wide line
int X = 1; // narrow line width
int I = 1; // interchange line width
m_minWidthData = (((C + 2) * ((3 * N) + 6) * X) + ((C + 1) * I)) / 100.0;
//m_minHeight = m_minWidthData * 0.15;
/*if(min_height < 0.25)*/
m_minHeight = 0.25;
m_minWidthTotal = m_minWidthData + 0.22; // added a little buffer to make sure we don't loose any
// of our required quiet zone in conversions
} else if (m_format->value().toString() == QLatin1String("3of9+")) {
int C = i * 2; // number of characters
int N = 2; // narrow mult for wide line
int X = 1; // 1px narrow line
int I = 1; // 1px narrow line interchange
m_minWidthData = (((C + 2) * ((3 * N) + 6) * X) + ((C + 1) * I)) / 100.0;
//m_minHeight = m_minWidthData * 0.15;
/*if(min_height < 0.25)*/
m_minHeight = 0.25;
m_minWidthTotal = m_minWidthData + 0.22; // added a little buffer to make sure we don't loose any
// of our required quiet zone in conversions
} else if (m_format->value().toString() == QLatin1String("i2of5")) {
int C = i * 2; // number of characters
int N = 2; // narrow mult for wide line
int X = 1; // 1px narrow line
m_minWidthTotal = ((C * (2.0*N + 3.0) + 6.0 + N) * X);
m_minHeight = 0.25;
m_minWidthTotal = m_minWidthData + 0.22;
} else if (m_format->value().toString() == QLatin1String("128")) {
int C = i; // assuming 1:1 ratio of data passed in to data actually used in encoding
int X = 1; // 1px wide
m_minWidthData = (((11 * C) + 35) * X) / 100.0; // assuming CODE A or CODE B
//m_minHeight = m_minWidthData * 0.15;
/*if(min_height < 0.25)*/
m_minHeight = 0.25;
m_minWidthTotal = m_minWidthData + 0.22; // added a little bugger to make sure we don't loose any
// of our required quiet zone in conversions
} else if (m_format->value().toString() == QLatin1String("upc-a")) {
m_minWidthData = 0.95;
m_minWidthTotal = 1.15;
m_minHeight = 0.25;
} else if (m_format->value().toString() == QLatin1String("upc-e")) {
m_minWidthData = 0.52;
m_minWidthTotal = 0.70;
m_minHeight = 0.25;
} else if (m_format->value().toString() == QLatin1String("ean13")) {
m_minWidthData = 0.95;
m_minWidthTotal = 1.15;
m_minHeight = 0.25;
} else if (m_format->value().toString() == QLatin1String("ean8")) {
m_minWidthData = 0.67;
m_minWidthTotal = 0.90;
m_minHeight = 0.25;
} else {
kreportpluginWarning() << "Unknown format encountered: " << m_format->value().toString();
}
}
}
void KReportItemBarcode::createProperties()
{
- m_controlSource
- = new KProperty("item-data-source", new KPropertyListData, QVariant(), tr("Data Source"));
+ createDataSourceProperty();
m_itemValue = new KProperty("value", QString(), tr("Value"),
tr("Value used if not bound to a field"));
KPropertyListData *listData = new KPropertyListData(
{ QLatin1String("left"), QLatin1String("center"), QLatin1String("right") },
QVariantList{ tr("Left"), tr("Center"), tr("Right") });
m_horizontalAlignment = new KProperty("horizontal-align", listData, QLatin1String("left"),
tr("Horizontal Alignment"));
listData = new KPropertyListData(
QStringList()
<< QLatin1String("3of9") << QLatin1String("3of9+") << QLatin1String("128")
<< QLatin1String("ean8") << QLatin1String("ean13") << QLatin1String("i2of5")
<< QLatin1String("upc-a") << QLatin1String("upc-e"),
QStringList()
<< tr("Code 3 of 9", "Barcode symbology, keep short")
<< tr("Code 3 of 9 Ext.", "3 of 3 Extended: Barcode symbology, keep short")
<< tr("Code 128", "Barcode symbology, keep short")
<< tr("EAN-8", "Barcode symbology, keep short")
<< tr("EAN-13", "Barcode symbology, keep short")
<< tr("Interleaved 2 of 5", "Interleaved barcode 2 of 5: barcode symbology, keep short")
<< tr("UPC-A", "Barcode symbology, keep short")
<< tr("UPC-E", "Barcode symbology, keep short")
);
m_format = new KProperty("barcode-format", listData, QLatin1String("3of9"),
tr("Barcode Format"));
m_maxLength = new KProperty("barcode-max-length", 5, tr("Max Length"),
tr("Maximum Barcode Length"));
- propertySet()->addProperty(m_controlSource);
propertySet()->addProperty(m_itemValue);
propertySet()->addProperty(m_format);
propertySet()->addProperty(m_horizontalAlignment);
propertySet()->addProperty(m_maxLength);
}
KReportItemBarcode::~KReportItemBarcode()
{
}
Qt::Alignment KReportItemBarcode::horizontalAlignment() const
{
return KReportUtils::horizontalAlignment(m_horizontalAlignment->value().toString(),
Qt::AlignLeft);
}
-QString KReportItemBarcode::itemDataSource() const
-{
- return m_controlSource->value().toString();
-}
-
QString KReportItemBarcode::format() const
{
return m_format->value().toString();
}
int KReportItemBarcode::maxLength() const
{
return m_maxLength->value().toInt();
}
void KReportItemBarcode::setFormat(const QString& f)
{
m_format->setValue(f);
}
void KReportItemBarcode::setHorizontalAlignment(Qt::Alignment value)
{
m_horizontalAlignment->setValue(KReportUtils::horizontalToString(value));
}
//RTTI
QString KReportItemBarcode::typeName() const
{
return QLatin1String("barcode");
}
int KReportItemBarcode::renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset,
const QVariant &data, KReportScriptHandler *script)
{
Q_UNUSED(section);
Q_UNUSED(script);
QPointF pos = scenePosition(position());
QSizeF siz = sceneSize(size());
pos += offset;
QRectF rect = QRectF(pos, siz);
QString val;
- if (m_controlSource->value().toString().isEmpty()) {
+ if (itemDataSource().isEmpty()) {
val = m_itemValue->value().toString();
} else {
val = data.toString();
}
if (page) {
QByteArray fmt = m_format->value().toByteArray();
Qt::Alignment align = horizontalAlignment();
if (fmt == "3of9")
render3of9(page, rect, val, align);
else if (fmt == "3of9+")
renderExtended3of9(page, rect, val, align);
else if (fmt == "i2of5")
renderI2of5(page, rect, val, align);
else if (fmt == "128")
renderCode128(page, rect, val, align);
else if (fmt == "ean13")
renderCodeEAN13(page, rect, val, align);
else if (fmt == "ean8")
renderCodeEAN8(page, rect, val, align);
else if (fmt == "upc-a")
renderCodeUPCA(page, rect, val, align);
else if (fmt == "upc-e")
renderCodeUPCE(page, rect, val, align);
else {
kreportpluginWarning() << "Unknown barcode format:" << fmt;
}
}
return 0;
}
diff --git a/src/plugins/barcode/KReportItemBarcode.h b/src/plugins/barcode/KReportItemBarcode.h
index f04185e8..2afca0a2 100644
--- a/src/plugins/barcode/KReportItemBarcode.h
+++ b/src/plugins/barcode/KReportItemBarcode.h
@@ -1,72 +1,69 @@
/* 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 .
*/
#ifndef KREPORTITEMBRCODE_H
#define KREPORTITEMBRCODE_H
#include "KReportItemBase.h"
class QDomNode;
namespace Scripting
{
class Barcode;
}
/**
*/
class KReportItemBarcode : public KReportItemBase
{
Q_OBJECT
public:
KReportItemBarcode();
explicit KReportItemBarcode(const QDomNode &element);
~KReportItemBarcode() override;
QString typeName() const override;
int renderSimpleData(OROPage *page, OROSection *section, const QPointF &offset, const QVariant &data, KReportScriptHandler *script) override;
- QString itemDataSource() const override;
protected:
-
- KProperty * m_controlSource;
KProperty * m_horizontalAlignment;
KProperty * m_format;
KProperty * m_maxLength;
KProperty* m_itemValue;
Qt::Alignment horizontalAlignment() const;
void setHorizontalAlignment(Qt::Alignment value);
int maxLength() const;
void setMaxLength(int i);
QString format() const;
void setFormat(const QString&);
// all these values are in inches and
// are for internal use only
qreal m_minWidthData;
qreal m_minWidthTotal;
qreal m_minHeight;
private:
void createProperties() override;
friend class Scripting::Barcode;
};
#endif
diff --git a/src/plugins/barcode/KReportScriptBarcode.cpp b/src/plugins/barcode/KReportScriptBarcode.cpp
index 5c9c0789..4b188a71 100644
--- a/src/plugins/barcode/KReportScriptBarcode.cpp
+++ b/src/plugins/barcode/KReportScriptBarcode.cpp
@@ -1,85 +1,85 @@
/* 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 "KReportScriptBarcode.h"
#include
#include
#include
namespace Scripting
{
Barcode::Barcode(KReportItemBarcode *b)
{
m_barcode = b;
}
Barcode::~Barcode()
{
}
QPointF Barcode::position() const
{
return m_barcode->position();
}
void Barcode::setPosition(const QPointF& p)
{
m_barcode->setPosition(p);
}
QSizeF Barcode::size() const
{
return m_barcode->size();
}
void Barcode::setSize(const QSizeF& s)
{
m_barcode->setSize(s);
}
Qt::Alignment Barcode::horizontalAlignment() const
{
return m_barcode->horizontalAlignment();
}
void Barcode::setHorizonalAlignment(Qt::Alignment value)
{
m_barcode->setHorizontalAlignment(value);
}
-QString Barcode::source()
+QString Barcode::source() const
{
- return m_barcode->m_controlSource->value().toString();
+ return m_barcode->itemDataSource();
}
void Barcode::setSource(const QString& s)
{
- m_barcode->m_controlSource->setValue(s);
+ m_barcode->setItemDataSource(s);
}
-QString Barcode::format()
+QString Barcode::format() const
{
return m_barcode->m_format->value().toString();
}
void Barcode::setFormat(const QString& s)
{
m_barcode->m_format->setValue(s);
}
}
diff --git a/src/plugins/barcode/KReportScriptBarcode.h b/src/plugins/barcode/KReportScriptBarcode.h
index 19b35e32..0acaf5c7 100644
--- a/src/plugins/barcode/KReportScriptBarcode.h
+++ b/src/plugins/barcode/KReportScriptBarcode.h
@@ -1,114 +1,114 @@
/* 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 .
*/
#ifndef SCRIPTINGKRSCRIPTBARCODE_H
#define SCRIPTINGKRSCRIPTBARCODE_H
#include
#include "KReportItemBarcode.h"
namespace Scripting
{
/**
*/
class Barcode : public QObject
{
Q_OBJECT
public:
explicit Barcode(KReportItemBarcode *f);
~Barcode() override;
public Q_SLOTS:
/**
* Get the position of the barcode
* @return position in points
*/
QPointF position() const;
/**
* Sets the position of the barcode in points
* @param Position
*/
void setPosition(const QPointF&);
/**
* Get the size of the barcode
* @return size in points
*/
QSizeF size() const;
/**
* Set the size of the barcode in points
* @param Size
*/
void setSize(const QSizeF&);
/**
* Get the horizontal alignment
* Qt::AlignLeft Left
* Qt::AlignHCenter Center
* Qt::AlignRight Right
* @return alignment
*/
Qt::Alignment horizontalAlignment() const;
/**
* Sets the horizontal alignment
* @param Alignemnt
*/
void setHorizonalAlignment(Qt::Alignment value);
/**
- * Get the control source (field name) of the barcode
- * @return control source
+ * @return the data source for the element
+ * The source can be a column name or a valid script expression if prefixed with a '='.
*/
- QString source();
+ QString source() const;
/**
- * Set the control source (field name) of the barcode
- * @param controlsource
+ * Sets the data source for the element.
+ * @see source()
*/
- void setSource(const QString&);
+ void setSource(const QString &s);
/**
* Get the barcode format
* @return format as string
*/
- QString format();
+ QString format() const;
/**
* Set the barcode format
* @param format
*/
void setFormat(const QString&);
private:
KReportItemBarcode *m_barcode;
};
}
#endif
diff --git a/src/plugins/chart/KReportDesignerItemChart.cpp b/src/plugins/chart/KReportDesignerItemChart.cpp
index 6b1579bb..2e389ef6 100644
--- a/src/plugins/chart/KReportDesignerItemChart.cpp
+++ b/src/plugins/chart/KReportDesignerItemChart.cpp
@@ -1,201 +1,201 @@
/* 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 "KReportDesignerItemChart.h"
#include
#include "KReportDesigner.h"
#include
#include
#include
#include
#include
#include
void KReportDesignerItemChart::init(QGraphicsScene* scene, KoReportDesigner *d)
{
setPos(0, 0);
if (scene)
scene->addItem(this);
connect(m_set, SIGNAL(propertyChanged(KPropertySet&,KProperty&)),
this, SLOT(slotPropertyChanged(KPropertySet&,KProperty&)));
KoReportDesignerItemRectBase::init(&m_pos, &m_size, m_set, d);
setZValue(Z);
connect(m_reportDesigner, SIGNAL(reportDataChanged()), this, SLOT(slotReportDataChanged()));
}
KReportDesignerItemChart::KReportDesignerItemChart(KoReportDesigner * rd, QGraphicsScene* scene, const QPointF &pos)
: KoReportDesignerItemRectBase(rd)
{
Q_UNUSED(pos);
init(scene, rd);
setSceneRect(properRect(*rd, m_dpiX, m_dpiY));
m_name->setValue(m_reportDesigner->suggestEntityName(typeName()));
}
KReportDesignerItemChart::KReportDesignerItemChart(QDomNode *element, KoReportDesigner * rd, QGraphicsScene* scene) :
KReportItemChart(element), KoReportDesignerItemRectBase(rd)
{
init(scene, rd);
populateData();
setSceneRect(m_pos.toScene(), m_size.toScene());
}
KReportDesignerItemChart::~KReportDesignerItemChart()
{
}
void KReportDesignerItemChart::paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget *widget)
{
Q_UNUSED(option);
Q_UNUSED(widget);
// store any values we plan on changing so we can restore them
QFont f = painter->font();
QPen p = painter->pen();
QColor bg = Qt::white;
painter->fillRect(QGraphicsRectItem::rect(), bg);
if (m_chartWidget) {
m_chartWidget->setFixedSize(m_size.toScene().toSize());
painter->drawImage(rect().left(), rect().top(),
QPixmap::grabWidget(m_chartWidget).toImage(),
0, 0, rect().width(), rect().height());
}
bg.setAlpha(255);
painter->setBackground(bg);
painter->setPen(Qt::black);
- painter->drawText(rect(), 0, dataSourceAndObjectTypeName(m_dataSource->value().toString(), "chart"));
+ painter->drawText(rect(), 0, dataSourceAndObjectTypeName(itemDataSource(), "chart"));
painter->setPen(QPen(QColor(224, 224, 224)));
painter->drawRect(rect());
painter->setBackgroundMode(Qt::TransparentMode);
drawHandles(painter);
// restore an values before we started just in case
painter->setFont(f);
painter->setPen(p);
}
KReportDesignerItemChart* KReportDesignerItemChart::clone()
{
QDomDocument d;
QDomElement e = d.createElement("clone");
QDomNode n;
buildXML(&d, &e);
n = e.firstChild();
return new KReportDesignerItemChart(n, designer(), 0);
}
void KReportDesignerItemChart::buildXML(QDomDocument *doc, QDomElement *parent)
{
QDomElement entity = doc->createElement(QLatin1String("report:") + typeName());
// properties
- addPropertyAsAttribute(&entity, m_name);
- addPropertyAsAttribute(&entity, m_dataSource);
+ addPropertyAsAttribute(&entity, nameProperty());
+ addPropertyAsAttribute(&entity, dataSourceProperty());
addPropertyAsAttribute(&entity, m_chartType);
addPropertyAsAttribute(&entity, m_chartSubType);
addPropertyAsAttribute(&entity, m_threeD);
addPropertyAsAttribute(&entity, m_colorScheme);
addPropertyAsAttribute(&entity, m_aa);
addPropertyAsAttribute(&entity, m_xTitle);
addPropertyAsAttribute(&entity, m_yTitle);
addPropertyAsAttribute(&entity, m_backgroundColor);
addPropertyAsAttribute(&entity, m_displayLegend);
addPropertyAsAttribute(&entity, m_legendPosition);
addPropertyAsAttribute(&entity, m_legendOrientation);
addPropertyAsAttribute(&entity, m_linkChild);
addPropertyAsAttribute(&entity, m_linkMaster);
entity.setAttribute("report:z-index", zValue());
// bounding rect
buildXMLRect(doc, &entity, &m_pos, &m_size);
parent->appendChild(entity);
}
void KReportDesignerItemChart::slotPropertyChanged(KPropertySet &s, KProperty &p)
{
if (p.name() == "name") {
//For some reason p.oldValue returns an empty string
if (!m_reportDesigner->isEntityNameUnique(p.value().toString(), this)) {
p.setValue(m_oldName);
} else {
m_oldName = p.value().toString();
}
} else if (p.name() == "three-dimensions") {
set3D(p.value().toBool());
} else if (p.name() == "antialiased") {
setAA(p.value().toBool());
} else if (p.name() == "color-scheme") {
setColorScheme(p.value().toString());
} else if (p.name() == "data-source") {
populateData();
} else if (p.name() == "title-x-axis" || p.name() == "title-y-axis") {
setAxis(m_xTitle->value().toString(), m_yTitle->value().toString());
} else if (p.name() == "background-color") {
setBackgroundColor(p.value().value());
} else if (p.name() == "display-legend") {
if (m_chartWidget && p.value().toBool()) {
populateData();
}
} else if (p.name() == "legend-position") {
if (m_chartWidget) {
populateData();
}
} else if (p.name() == "legend-orientation") {
if (m_chartWidget) {
populateData();
}
} else if (p.name() == "chart-type") {
if (m_chartWidget) {
populateData();
//m_chartWidget->setType((KDChart::Widget::ChartType) m_chartType->value().toInt());
}
} else if (p.name() == "chart-sub-type") {
if (m_chartWidget) {
m_chartWidget->setSubType((KDChart::Widget::SubType) m_chartSubType->value().toInt());
}
}
KoReportDesignerItemRectBase::propertyChanged(s, p);
if (m_reportDesigner) m_reportDesigner->setModified(true);
}
void KReportDesignerItemChart::mousePressEvent(QGraphicsSceneMouseEvent * event)
{
if (m_reportDesigner->reportData()) {
QStringList ql = m_reportDesigner->reportData()->dataSources();
QStringList qn = m_reportDesigner->reportData()->dataSourceNames();
- m_dataSource->setListData(ql, qn);
+ dataSourceProperty()->setListData(ql, qn);
}
KoReportDesignerItemRectBase::mousePressEvent(event);
}
void KReportDesignerItemChart::slotReportDataChanged()
{
setConnection(m_reportDesigner->reportData());
}
diff --git a/src/plugins/chart/KReportItemChart.cpp b/src/plugins/chart/KReportItemChart.cpp
index e7446605..2c2880b5 100644
--- a/src/plugins/chart/KReportItemChart.cpp
+++ b/src/plugins/chart/KReportItemChart.cpp
@@ -1,429 +1,425 @@
/* 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 "KReportUtils.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(nullptr)
{
createProperties();
}
KReportItemChart::KReportItemChart(QDomNode *element)
: KReportItemChart()
{
QDomElement e = element->toElement();
m_name->setValue(KReportUtils::readNameAttribute(e));
- m_dataSource->setValue(e.attribute("report:data-source"));
+ setItemDataSource(e.attribute("report:item-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");
+ createDataSourceProperty();
m_font = new KProperty("font", QFontDatabase::systemFont(QFontDatabase::GeneralFont), tr("Font"), tr("Field Font"));
+ QList keys;
keys << 1 << 2 << 3 << 4 << 5;
+ QStringList strings;
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();
+ QStringList stringkeys;
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"));
m_yTitle = new KProperty("title-y-axis", QString(), tr("Y Axis Title"));
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"));
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