0
0
mirror of https://github.com/fralx/LimeReport.git synced 2025-01-11 17:18:10 +03:00

resourcePath property has been added to ImageItem

This commit is contained in:
Arin Alexander 2016-12-05 22:58:52 +03:00
parent eac1a029d9
commit 229e8f529d
2 changed files with 25 additions and 13 deletions

View File

@ -56,16 +56,21 @@ BaseDesignIntf *ImageItem::createSameTypeItem(QObject *owner, QGraphicsItem *par
void ImageItem::updateItemSize(DataSourceManager* dataManager, RenderPass pass, int maxHeight)
{
if (!m_datasource.isEmpty() && !m_field.isEmpty() && m_picture.isNull()){
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
m_picture.loadFromData(data.toByteArray());
}
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.type()==QVariant::Image){
m_picture = data.value<QImage>();
} else
m_picture.loadFromData(data.toByteArray());
}
}
} else if (!m_resourcePath.isEmpty()){
m_picture = QImage(m_resourcePath);
}
}
if (m_autoSize){
@ -80,6 +85,11 @@ bool ImageItem::isNeedUpdateSize(RenderPass) const
return m_picture.isNull() || m_autoSize;
}
QString ImageItem::resourcePath() const
{
return m_resourcePath;
}
qreal ImageItem::minHeight() const{
if (!m_picture.isNull() && autoSize())
{

View File

@ -44,12 +44,14 @@ class ImageItem : public LimeReport::ItemDesignIntf
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:
ImageItem(QObject *owner, QGraphicsItem *parent);
virtual void paint(QPainter *ppainter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void setImage(QImage value);
QImage image(){return m_picture;}
void setContent(const QString &value){m_content=value;}
void setResourcePath(const QString &value){m_resourcePath=value;}
QString resourcePath() const;
QString datasource() const;
void setDatasource(const QString &datasource);
QString field() const;
@ -72,8 +74,8 @@ protected:
bool isNeedUpdateSize(RenderPass) const;
bool drawDesignBorders() const {return m_picture.isNull();}
private:
QImage m_picture;
QString m_content;
QImage m_picture;
QString m_resourcePath;
QString m_datasource;
QString m_field;
bool m_autoSize;