mirror of
https://github.com/python-LimeReport/LimeReport.git
synced 2024-12-24 20:44:39 +03:00
External drawing feature added to ImageItem
This commit is contained in:
parent
c00b8aa50c
commit
ce1656d2ef
@ -119,7 +119,7 @@ namespace Const{
|
|||||||
|
|
||||||
class ReportError : public std::runtime_error{
|
class ReportError : public std::runtime_error{
|
||||||
public:
|
public:
|
||||||
ReportError(const QString& message):std::runtime_error(message.toStdString()){}
|
ReportError(const QString& message);
|
||||||
};
|
};
|
||||||
|
|
||||||
class ReportSettings{
|
class ReportSettings{
|
||||||
@ -132,6 +132,18 @@ namespace Const{
|
|||||||
bool m_suppressAbsentFieldsAndVarsWarnings;
|
bool m_suppressAbsentFieldsAndVarsWarnings;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class IExternalPainter{
|
||||||
|
public:
|
||||||
|
virtual void paintByExternalPainter(const QString& objectName, QPainter* painter, const QStyleOptionGraphicsItem* options) = 0;
|
||||||
|
virtual ~IExternalPainter();
|
||||||
|
};
|
||||||
|
|
||||||
|
class IPainterProxy{
|
||||||
|
public:
|
||||||
|
virtual void setExternalPainter(IExternalPainter* externalPainter) = 0;
|
||||||
|
virtual ~IPainterProxy();
|
||||||
|
};
|
||||||
|
|
||||||
#ifdef HAVE_QT4
|
#ifdef HAVE_QT4
|
||||||
typedef QStyleOptionViewItemV4 StyleOptionViewItem;
|
typedef QStyleOptionViewItemV4 StyleOptionViewItem;
|
||||||
#else
|
#else
|
||||||
|
@ -135,6 +135,8 @@ signals:
|
|||||||
void currentDefaulLanguageChanged(QLocale::Language);
|
void currentDefaulLanguageChanged(QLocale::Language);
|
||||||
QLocale::Language getCurrentDefaultLanguage();
|
QLocale::Language getCurrentDefaultLanguage();
|
||||||
|
|
||||||
|
void externalPaint(const QString& objectName, QPainter* painter, const QStyleOptionGraphicsItem*);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void cancelRender();
|
void cancelRender();
|
||||||
protected:
|
protected:
|
||||||
|
@ -661,6 +661,8 @@ void DataBrowser::applyChanges(SQLEditResult result)
|
|||||||
break;
|
break;
|
||||||
case SQLEditResult::SubProxy:
|
case SQLEditResult::SubProxy:
|
||||||
changeProxy(result);
|
changeProxy(result);
|
||||||
|
break;
|
||||||
|
default: break;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
removeDatasource(result.datasourceName);
|
removeDatasource(result.datasourceName);
|
||||||
@ -679,6 +681,7 @@ void DataBrowser::addDatasource(SQLEditResult result)
|
|||||||
break;
|
break;
|
||||||
case SQLEditResult::SubProxy:
|
case SQLEditResult::SubProxy:
|
||||||
addProxy(result);
|
addProxy(result);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -48,11 +48,15 @@ bool VARIABLE_IS_NOT_USED registred = LimeReport::DesignElementsFactory::instanc
|
|||||||
namespace LimeReport{
|
namespace LimeReport{
|
||||||
|
|
||||||
ImageItem::ImageItem(QObject* owner,QGraphicsItem* parent)
|
ImageItem::ImageItem(QObject* owner,QGraphicsItem* parent)
|
||||||
:ItemDesignIntf(xmlTag,owner,parent),m_autoSize(false), m_scale(true), m_keepAspectRatio(true), m_center(true), m_format(Binary){}
|
:ItemDesignIntf(xmlTag,owner,parent), m_useExternalPainter(false), m_externalPainter(0),
|
||||||
|
m_autoSize(false), m_scale(true),
|
||||||
|
m_keepAspectRatio(true), m_center(true), m_format(Binary){}
|
||||||
|
|
||||||
BaseDesignIntf *ImageItem::createSameTypeItem(QObject *owner, QGraphicsItem *parent)
|
BaseDesignIntf *ImageItem::createSameTypeItem(QObject *owner, QGraphicsItem *parent)
|
||||||
{
|
{
|
||||||
return new ImageItem(owner,parent);
|
ImageItem* result = new ImageItem(owner,parent);
|
||||||
|
result->setExternalPainter(m_externalPainter);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageItem::loadPictureFromVariant(QVariant& data){
|
void ImageItem::loadPictureFromVariant(QVariant& data){
|
||||||
@ -91,6 +95,20 @@ void ImageItem::processPopUpAction(QAction *action)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ImageItem::useExternalPainter() const
|
||||||
|
{
|
||||||
|
return m_useExternalPainter;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImageItem::setUseExternalPainter(bool value)
|
||||||
|
{
|
||||||
|
if (m_useExternalPainter != value){
|
||||||
|
m_useExternalPainter = value;
|
||||||
|
notify("useExternalPainter",!value, value);
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ImageItem::updateItemSize(DataSourceManager* dataManager, RenderPass pass, int maxHeight)
|
void ImageItem::updateItemSize(DataSourceManager* dataManager, RenderPass pass, int maxHeight)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -293,9 +311,12 @@ void ImageItem::paint(QPainter *ppainter, const QStyleOptionGraphicsItem *option
|
|||||||
ppainter->setPen(Qt::black);
|
ppainter->setPen(Qt::black);
|
||||||
if (!datasource().isEmpty() && !field().isEmpty())
|
if (!datasource().isEmpty() && !field().isEmpty())
|
||||||
text = datasource()+"."+field();
|
text = datasource()+"."+field();
|
||||||
else text = tr("Image");
|
else if (m_useExternalPainter) text = tr("Ext."); else text = tr("Image");
|
||||||
ppainter->drawText(rect().adjusted(4,4,-4,-4), Qt::AlignCenter, text );
|
ppainter->drawText(rect().adjusted(4,4,-4,-4), Qt::AlignCenter, text );
|
||||||
} else {
|
} else {
|
||||||
|
if (m_externalPainter && m_useExternalPainter)
|
||||||
|
m_externalPainter->paintByExternalPainter(this->patternName(), ppainter, option);
|
||||||
|
else
|
||||||
ppainter->drawImage(point,img);
|
ppainter->drawImage(point,img);
|
||||||
}
|
}
|
||||||
ItemDesignIntf::paint(ppainter,option,widget);
|
ItemDesignIntf::paint(ppainter,option,widget);
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
namespace LimeReport{
|
namespace LimeReport{
|
||||||
|
|
||||||
class ImageItem : public LimeReport::ItemDesignIntf
|
class ImageItem : public LimeReport::ItemDesignIntf, public IPainterProxy
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_ENUMS(Format)
|
Q_ENUMS(Format)
|
||||||
@ -49,6 +49,8 @@ class ImageItem : public LimeReport::ItemDesignIntf
|
|||||||
Q_PROPERTY(QString resourcePath READ resourcePath WRITE setResourcePath)
|
Q_PROPERTY(QString resourcePath READ resourcePath WRITE setResourcePath)
|
||||||
Q_PROPERTY(QString variable READ variable WRITE setVariable)
|
Q_PROPERTY(QString variable READ variable WRITE setVariable)
|
||||||
Q_PROPERTY(bool watermark READ isWatermark WRITE setWatermark)
|
Q_PROPERTY(bool watermark READ isWatermark WRITE setWatermark)
|
||||||
|
Q_PROPERTY(bool useExternalPainter READ useExternalPainter WRITE setUseExternalPainter)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
enum Format {
|
enum Format {
|
||||||
Binary = 0,
|
Binary = 0,
|
||||||
@ -81,6 +83,12 @@ public:
|
|||||||
|
|
||||||
QString variable(){ return m_variable;}
|
QString variable(){ return m_variable;}
|
||||||
void setVariable(const QString& variable);
|
void setVariable(const QString& variable);
|
||||||
|
|
||||||
|
void setExternalPainter(IExternalPainter* externalPainter){ m_externalPainter = externalPainter;}
|
||||||
|
|
||||||
|
bool useExternalPainter() const;
|
||||||
|
void setUseExternalPainter(bool value);
|
||||||
|
|
||||||
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);
|
||||||
@ -91,6 +99,8 @@ protected:
|
|||||||
void processPopUpAction(QAction *action);
|
void processPopUpAction(QAction *action);
|
||||||
private:
|
private:
|
||||||
QImage m_picture;
|
QImage m_picture;
|
||||||
|
bool m_useExternalPainter;
|
||||||
|
IExternalPainter* m_externalPainter;
|
||||||
QString m_resourcePath;
|
QString m_resourcePath;
|
||||||
QString m_datasource;
|
QString m_datasource;
|
||||||
QString m_field;
|
QString m_field;
|
||||||
|
@ -77,6 +77,7 @@ void LimeReport::ItemLocationPropItem::setPropertyEditorData(QWidget *propertyEd
|
|||||||
}
|
}
|
||||||
|
|
||||||
void LimeReport::ItemLocationPropItem::setModelData(QWidget *propertyEditor, QAbstractItemModel *model, const QModelIndex &index){
|
void LimeReport::ItemLocationPropItem::setModelData(QWidget *propertyEditor, QAbstractItemModel *model, const QModelIndex &index){
|
||||||
|
Q_UNUSED(propertyEditor)
|
||||||
model->setData(index,object()->property(propertyName().toLatin1()));
|
model->setData(index,object()->property(propertyName().toLatin1()));
|
||||||
setValueToObject(propertyName(), propertyValue());
|
setValueToObject(propertyName(), propertyValue());
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
CONFIG(release, debug|release){
|
CONFIG(debug, debug|release){
|
||||||
TARGET = limereport
|
|
||||||
} else {
|
|
||||||
TARGET = limereportd
|
TARGET = limereportd
|
||||||
|
} else {
|
||||||
|
TARGET = limereport
|
||||||
}
|
}
|
||||||
|
|
||||||
TEMPLATE = lib
|
TEMPLATE = lib
|
||||||
|
@ -85,4 +85,8 @@ bool isColorDark(QColor color){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ReportError::ReportError(const QString& message):std::runtime_error(message.toStdString()){}
|
||||||
|
IExternalPainter::~IExternalPainter(){}
|
||||||
|
IPainterProxy::~IPainterProxy(){}
|
||||||
|
|
||||||
} //namespace LimeReport
|
} //namespace LimeReport
|
||||||
|
@ -119,7 +119,7 @@ namespace Const{
|
|||||||
|
|
||||||
class ReportError : public std::runtime_error{
|
class ReportError : public std::runtime_error{
|
||||||
public:
|
public:
|
||||||
ReportError(const QString& message):std::runtime_error(message.toStdString()){}
|
ReportError(const QString& message);
|
||||||
};
|
};
|
||||||
|
|
||||||
class ReportSettings{
|
class ReportSettings{
|
||||||
@ -132,6 +132,18 @@ namespace Const{
|
|||||||
bool m_suppressAbsentFieldsAndVarsWarnings;
|
bool m_suppressAbsentFieldsAndVarsWarnings;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class IExternalPainter{
|
||||||
|
public:
|
||||||
|
virtual void paintByExternalPainter(const QString& objectName, QPainter* painter, const QStyleOptionGraphicsItem* options) = 0;
|
||||||
|
virtual ~IExternalPainter();
|
||||||
|
};
|
||||||
|
|
||||||
|
class IPainterProxy{
|
||||||
|
public:
|
||||||
|
virtual void setExternalPainter(IExternalPainter* externalPainter) = 0;
|
||||||
|
virtual ~IPainterProxy();
|
||||||
|
};
|
||||||
|
|
||||||
#ifdef HAVE_QT4
|
#ifdef HAVE_QT4
|
||||||
typedef QStyleOptionViewItemV4 StyleOptionViewItem;
|
typedef QStyleOptionViewItemV4 StyleOptionViewItem;
|
||||||
#else
|
#else
|
||||||
|
@ -1118,12 +1118,32 @@ PageItemDesignIntf* ReportEnginePrivate::createRenderingPage(PageItemDesignIntf*
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ReportEnginePrivate::initReport()
|
||||||
|
{
|
||||||
|
for(int index = 0; index < pageCount(); ++index){
|
||||||
|
PageDesignIntf* page = pageAt(index);
|
||||||
|
if (page != 0){
|
||||||
|
foreach (BaseDesignIntf* item, page->pageItem()->childBaseItems()) {
|
||||||
|
IPainterProxy *proxyItem = dynamic_cast<IPainterProxy *>(item);
|
||||||
|
if (proxyItem){
|
||||||
|
proxyItem->setExternalPainter(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ReportEnginePrivate::paintByExternalPainter(const QString& objectName, QPainter* painter, const QStyleOptionGraphicsItem* options)
|
||||||
|
{
|
||||||
|
emit externalPaint(objectName, painter, options);
|
||||||
|
}
|
||||||
|
|
||||||
ReportPages ReportEnginePrivate::renderToPages()
|
ReportPages ReportEnginePrivate::renderToPages()
|
||||||
{
|
{
|
||||||
if (m_reportRendering) return ReportPages();
|
if (m_reportRendering) return ReportPages();
|
||||||
|
initReport();
|
||||||
m_reportRender = ReportRender::Ptr(new ReportRender);
|
m_reportRender = ReportRender::Ptr(new ReportRender);
|
||||||
updateTranslations();
|
updateTranslations();
|
||||||
|
|
||||||
connect(m_reportRender.data(),SIGNAL(pageRendered(int)),
|
connect(m_reportRender.data(),SIGNAL(pageRendered(int)),
|
||||||
this, SIGNAL(renderPageFinished(int)));
|
this, SIGNAL(renderPageFinished(int)));
|
||||||
|
|
||||||
@ -1232,6 +1252,9 @@ ReportEngine::ReportEngine(QObject *parent)
|
|||||||
connect(d, SIGNAL(getCurrentDefaultLanguage()),
|
connect(d, SIGNAL(getCurrentDefaultLanguage()),
|
||||||
this, SIGNAL(getCurrentDefaultLanguage()));
|
this, SIGNAL(getCurrentDefaultLanguage()));
|
||||||
|
|
||||||
|
connect(d, SIGNAL(externalPaint(const QString&, QPainter*, const QStyleOptionGraphicsItem*)),
|
||||||
|
this, SIGNAL(externalPaint(const QString&, QPainter*, const QStyleOptionGraphicsItem*)));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ReportEngine::~ReportEngine()
|
ReportEngine::~ReportEngine()
|
||||||
|
@ -135,6 +135,8 @@ signals:
|
|||||||
void currentDefaulLanguageChanged(QLocale::Language);
|
void currentDefaulLanguageChanged(QLocale::Language);
|
||||||
QLocale::Language getCurrentDefaultLanguage();
|
QLocale::Language getCurrentDefaultLanguage();
|
||||||
|
|
||||||
|
void externalPaint(const QString& objectName, QPainter* painter, const QStyleOptionGraphicsItem*);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void cancelRender();
|
void cancelRender();
|
||||||
protected:
|
protected:
|
||||||
|
@ -93,7 +93,10 @@ public:
|
|||||||
virtual void setCurrentDesignerLanguage(QLocale::Language language) = 0;
|
virtual void setCurrentDesignerLanguage(QLocale::Language language) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
class ReportEnginePrivate : public QObject, public ICollectionContainer, public ITranslationContainer,
|
class ReportEnginePrivate : public QObject,
|
||||||
|
public ICollectionContainer,
|
||||||
|
public ITranslationContainer,
|
||||||
|
public IExternalPainter,
|
||||||
public ReportEnginePrivateInterface
|
public ReportEnginePrivateInterface
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -214,6 +217,8 @@ signals:
|
|||||||
void currentDefaulLanguageChanged(QLocale::Language);
|
void currentDefaulLanguageChanged(QLocale::Language);
|
||||||
QLocale::Language getCurrentDefaultLanguage();
|
QLocale::Language getCurrentDefaultLanguage();
|
||||||
|
|
||||||
|
void externalPaint(const QString& objectName, QPainter* painter, const QStyleOptionGraphicsItem*);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
bool slotLoadFromFile(const QString& fileName);
|
bool slotLoadFromFile(const QString& fileName);
|
||||||
void cancelRender();
|
void cancelRender();
|
||||||
@ -242,6 +247,8 @@ private:
|
|||||||
PageItemDesignIntf *getPageByName(const QString& pageName);
|
PageItemDesignIntf *getPageByName(const QString& pageName);
|
||||||
ATranslationProperty fakeTranslationReader(){ return ATranslationProperty();}
|
ATranslationProperty fakeTranslationReader(){ return ATranslationProperty();}
|
||||||
PageItemDesignIntf *createRenderingPage(PageItemDesignIntf *page);
|
PageItemDesignIntf *createRenderingPage(PageItemDesignIntf *page);
|
||||||
|
void initReport();
|
||||||
|
void paintByExternalPainter(const QString& objectName, QPainter* painter, const QStyleOptionGraphicsItem* options);
|
||||||
private:
|
private:
|
||||||
QList<PageDesignIntf*> m_pages;
|
QList<PageDesignIntf*> m_pages;
|
||||||
QList<PageItemDesignIntf*> m_renderingPages;
|
QList<PageItemDesignIntf*> m_renderingPages;
|
||||||
|
Loading…
Reference in New Issue
Block a user