0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 08:34:38 +03:00

Load image from variable has been added

This commit is contained in:
Arin Alexander 2018-03-16 19:12:14 +03:00
parent d79aec5faf
commit 3bbc02507a
2 changed files with 42 additions and 20 deletions

View File

@ -54,6 +54,28 @@ BaseDesignIntf *ImageItem::createSameTypeItem(QObject *owner, QGraphicsItem *par
return new ImageItem(owner,parent);
}
void ImageItem::loadPictureFromVariant(QVariant& data){
if (data.isValid()){
if (data.type()==QVariant::Image){
m_picture = data.value<QImage>();
} 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;
}
}
}
}
void ImageItem::updateItemSize(DataSourceManager* dataManager, RenderPass pass, int maxHeight)
{
@ -62,28 +84,13 @@ void ImageItem::updateItemSize(DataSourceManager* dataManager, RenderPass pass,
IDataSource* ds = dataManager->dataSource(m_datasource);
if (ds) {
QVariant data = ds->data(m_field);
if (data.isValid()){
if (data.type()==QVariant::Image){
m_picture = data.value<QImage>();
} 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;
}
}
}
loadPictureFromVariant(data);
}
} else if (!m_resourcePath.isEmpty()){
m_picture = QImage(m_resourcePath);
} else if (!m_variable.isEmpty()){
QVariant data = dataManager->variable(m_variable);
loadPictureFromVariant(data);
}
}
if (m_autoSize){
@ -112,6 +119,16 @@ qreal ImageItem::minHeight() const{
}
}
void ImageItem::setVariable(const QString& content)
{
if (m_variable!=content){
QString oldValue = m_variable;
m_variable=content;
update();
notify("content", oldValue, m_variable);
}
}
bool ImageItem::center() const
{
return m_center;

View File

@ -47,6 +47,7 @@ class ImageItem : public LimeReport::ItemDesignIntf
Q_PROPERTY(bool keepAspectRatio READ keepAspectRatio WRITE setKeepAspectRatio)
Q_PROPERTY(bool center READ center WRITE setCenter)
Q_PROPERTY(QString resourcePath READ resourcePath WRITE setResourcePath)
Q_PROPERTY(QString variable READ variable WRITE setVariable)
public:
enum Format {
Binary = 0,
@ -75,14 +76,16 @@ public:
void setCenter(bool center);
Format format() const;
void setFormat(Format format);
qreal minHeight() const;
QString variable(){ return m_variable;}
void setVariable(const QString& variable);
protected:
BaseDesignIntf* createSameTypeItem(QObject *owner, QGraphicsItem *parent);
void updateItemSize(DataSourceManager *dataManager, RenderPass pass, int maxHeight);
bool isNeedUpdateSize(RenderPass) const;
bool drawDesignBorders() const {return m_picture.isNull();}
void loadPictureFromVariant(QVariant& data);
private:
QImage m_picture;
QString m_resourcePath;
@ -93,6 +96,8 @@ private:
bool m_keepAspectRatio;
bool m_center;
Format m_format;
QString m_variable;
};
}