diff --git a/limereport/items/lrimageitem.cpp b/limereport/items/lrimageitem.cpp index 1233ac0..72f5a62 100644 --- a/limereport/items/lrimageitem.cpp +++ b/limereport/items/lrimageitem.cpp @@ -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(); + } 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(); - } 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; diff --git a/limereport/items/lrimageitem.h b/limereport/items/lrimageitem.h index 18b236f..0c8c807 100644 --- a/limereport/items/lrimageitem.h +++ b/limereport/items/lrimageitem.h @@ -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; + }; }