0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-25 00:54:39 +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,14 +54,7 @@ BaseDesignIntf *ImageItem::createSameTypeItem(QObject *owner, QGraphicsItem *par
return new ImageItem(owner,parent); return new ImageItem(owner,parent);
} }
void ImageItem::updateItemSize(DataSourceManager* dataManager, RenderPass pass, int maxHeight) void ImageItem::loadPictureFromVariant(QVariant& data){
{
if (m_picture.isNull()){
if (!m_datasource.isEmpty() && !m_field.isEmpty()){
IDataSource* ds = dataManager->dataSource(m_datasource);
if (ds) {
QVariant data = ds->data(m_field);
if (data.isValid()){ if (data.isValid()){
if (data.type()==QVariant::Image){ if (data.type()==QVariant::Image){
m_picture = data.value<QImage>(); m_picture = data.value<QImage>();
@ -81,9 +74,23 @@ void ImageItem::updateItemSize(DataSourceManager* dataManager, RenderPass pass,
} }
} }
}
void ImageItem::updateItemSize(DataSourceManager* dataManager, RenderPass pass, int maxHeight)
{
if (m_picture.isNull()){
if (!m_datasource.isEmpty() && !m_field.isEmpty()){
IDataSource* ds = dataManager->dataSource(m_datasource);
if (ds) {
QVariant data = ds->data(m_field);
loadPictureFromVariant(data);
} }
} 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;

View File

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