mirror of
https://github.com/python-LimeReport/LimeReport.git
synced 2024-12-24 12:34:39 +03:00
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.
This commit is contained in:
parent
986c7cfb5d
commit
be1cc163cd
@ -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
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user