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:
parent
d79aec5faf
commit
3bbc02507a
@ -54,6 +54,28 @@ BaseDesignIntf *ImageItem::createSameTypeItem(QObject *owner, QGraphicsItem *par
|
|||||||
return new ImageItem(owner,parent);
|
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)
|
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);
|
IDataSource* ds = dataManager->dataSource(m_datasource);
|
||||||
if (ds) {
|
if (ds) {
|
||||||
QVariant data = ds->data(m_field);
|
QVariant data = ds->data(m_field);
|
||||||
if (data.isValid()){
|
loadPictureFromVariant(data);
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else if (!m_resourcePath.isEmpty()){
|
} else if (!m_resourcePath.isEmpty()){
|
||||||
m_picture = QImage(m_resourcePath);
|
m_picture = QImage(m_resourcePath);
|
||||||
|
} else if (!m_variable.isEmpty()){
|
||||||
|
QVariant data = dataManager->variable(m_variable);
|
||||||
|
loadPictureFromVariant(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (m_autoSize){
|
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
|
bool ImageItem::center() const
|
||||||
{
|
{
|
||||||
return m_center;
|
return m_center;
|
||||||
|
@ -47,6 +47,7 @@ class ImageItem : public LimeReport::ItemDesignIntf
|
|||||||
Q_PROPERTY(bool keepAspectRatio READ keepAspectRatio WRITE setKeepAspectRatio)
|
Q_PROPERTY(bool keepAspectRatio READ keepAspectRatio WRITE setKeepAspectRatio)
|
||||||
Q_PROPERTY(bool center READ center WRITE setCenter)
|
Q_PROPERTY(bool center READ center WRITE setCenter)
|
||||||
Q_PROPERTY(QString resourcePath READ resourcePath WRITE setResourcePath)
|
Q_PROPERTY(QString resourcePath READ resourcePath WRITE setResourcePath)
|
||||||
|
Q_PROPERTY(QString variable READ variable WRITE setVariable)
|
||||||
public:
|
public:
|
||||||
enum Format {
|
enum Format {
|
||||||
Binary = 0,
|
Binary = 0,
|
||||||
@ -75,14 +76,16 @@ public:
|
|||||||
void setCenter(bool center);
|
void setCenter(bool center);
|
||||||
Format format() const;
|
Format format() const;
|
||||||
void setFormat(Format format);
|
void setFormat(Format format);
|
||||||
|
|
||||||
qreal minHeight() const;
|
qreal minHeight() const;
|
||||||
|
|
||||||
|
QString variable(){ return m_variable;}
|
||||||
|
void setVariable(const QString& variable);
|
||||||
protected:
|
protected:
|
||||||
BaseDesignIntf* createSameTypeItem(QObject *owner, QGraphicsItem *parent);
|
BaseDesignIntf* createSameTypeItem(QObject *owner, QGraphicsItem *parent);
|
||||||
void updateItemSize(DataSourceManager *dataManager, RenderPass pass, int maxHeight);
|
void updateItemSize(DataSourceManager *dataManager, RenderPass pass, int maxHeight);
|
||||||
bool isNeedUpdateSize(RenderPass) const;
|
bool isNeedUpdateSize(RenderPass) const;
|
||||||
bool drawDesignBorders() const {return m_picture.isNull();}
|
bool drawDesignBorders() const {return m_picture.isNull();}
|
||||||
|
void loadPictureFromVariant(QVariant& data);
|
||||||
private:
|
private:
|
||||||
QImage m_picture;
|
QImage m_picture;
|
||||||
QString m_resourcePath;
|
QString m_resourcePath;
|
||||||
@ -93,6 +96,8 @@ private:
|
|||||||
bool m_keepAspectRatio;
|
bool m_keepAspectRatio;
|
||||||
bool m_center;
|
bool m_center;
|
||||||
Format m_format;
|
Format m_format;
|
||||||
|
QString m_variable;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user