0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-25 00:54:39 +03:00

Merge pull request #87 from beardeddragon5/master

Datasources like Postgres Databases return binary data not in is real…
This commit is contained in:
fralx 2017-09-29 22:26:30 +03:00 committed by GitHub
commit 21356952c0
2 changed files with 40 additions and 3 deletions

View File

@ -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<QImage>();
} else
} 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);
}
}
}

View File

@ -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;
};
}