From be1cc163cde4b539f098427511edac9efbac1955 Mon Sep 17 00:00:00 2001 From: Matthias Ramsauer Date: Fri, 29 Sep 2017 17:46:32 +0200 Subject: [PATCH] Datasources like Postgres Databases return binary data not in is real format. In Postgres for example you can select if you want to get the data as 'hex', 'base64' or some octal format encoded. --- limereport/items/lrimageitem.cpp | 32 +++++++++++++++++++++++++++++--- limereport/items/lrimageitem.h | 11 +++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/limereport/items/lrimageitem.cpp b/limereport/items/lrimageitem.cpp index ede6a1f..1233ac0 100644 --- a/limereport/items/lrimageitem.cpp +++ b/limereport/items/lrimageitem.cpp @@ -47,7 +47,7 @@ bool VARIABLE_IS_NOT_USED registred = LimeReport::DesignElementsFactory::instanc namespace LimeReport{ ImageItem::ImageItem(QObject* owner,QGraphicsItem* parent) - :ItemDesignIntf(xmlTag,owner,parent),m_autoSize(false), m_scale(true), m_keepAspectRatio(true), m_center(true){} + :ItemDesignIntf(xmlTag,owner,parent),m_autoSize(false), m_scale(true), m_keepAspectRatio(true), m_center(true), m_format(Binary){} BaseDesignIntf *ImageItem::createSameTypeItem(QObject *owner, QGraphicsItem *parent) { @@ -65,8 +65,21 @@ void ImageItem::updateItemSize(DataSourceManager* dataManager, RenderPass pass, if (data.isValid()){ if (data.type()==QVariant::Image){ m_picture = data.value(); - } else - m_picture.loadFromData(data.toByteArray()); + } else { + switch (m_format) { + default: + case Binary: + m_picture.loadFromData(data.toByteArray()); + break; + case Hex: + m_picture.loadFromData(QByteArray::fromHex(data.toByteArray())); + break; + case Base64: + m_picture.loadFromData(QByteArray::fromBase64(data.toByteArray())); + break; + } + } + } } } else if (!m_resourcePath.isEmpty()){ @@ -267,6 +280,19 @@ void ImageItem::setImage(QImage value) } } +ImageItem::Format ImageItem::format() const +{ + return m_format; +} +void ImageItem::setFormat(Format format) +{ + if (m_format!=format){ + Format oldValue = m_format; + m_format=format; + update(); + notify("format",oldValue,format); + } +} } diff --git a/limereport/items/lrimageitem.h b/limereport/items/lrimageitem.h index 631f292..18b236f 100644 --- a/limereport/items/lrimageitem.h +++ b/limereport/items/lrimageitem.h @@ -36,16 +36,24 @@ namespace LimeReport{ class ImageItem : public LimeReport::ItemDesignIntf { Q_OBJECT + Q_ENUMS(Format) Q_PROPERTY(QImage image READ image WRITE setImage) Q_PROPERTY(int opacity READ opacity WRITE setOpacity) Q_PROPERTY(QString datasource READ datasource WRITE setDatasource) Q_PROPERTY(QString field READ field WRITE setField) + Q_PROPERTY(Format format READ format WRITE setFormat) Q_PROPERTY(bool autoSize READ autoSize WRITE setAutoSize) Q_PROPERTY(bool scale READ scale WRITE setScale) Q_PROPERTY(bool keepAspectRatio READ keepAspectRatio WRITE setKeepAspectRatio) Q_PROPERTY(bool center READ center WRITE setCenter) Q_PROPERTY(QString resourcePath READ resourcePath WRITE setResourcePath) public: + enum Format { + Binary = 0, + Hex = 1, + Base64 = 2 + }; + ImageItem(QObject *owner, QGraphicsItem *parent); virtual void paint(QPainter *ppainter, const QStyleOptionGraphicsItem *option, QWidget *widget); void setImage(QImage value); @@ -65,6 +73,8 @@ public: void setKeepAspectRatio(bool keepAspectRatio); bool center() const; void setCenter(bool center); + Format format() const; + void setFormat(Format format); qreal minHeight() const; @@ -82,6 +92,7 @@ private: bool m_scale; bool m_keepAspectRatio; bool m_center; + Format m_format; }; }