diff --git a/include/lrglobal.h b/include/lrglobal.h index 3ecebb1..d1cb8b9 100644 --- a/include/lrglobal.h +++ b/include/lrglobal.h @@ -119,7 +119,7 @@ namespace Const{ class ReportError : public std::runtime_error{ public: - ReportError(const QString& message):std::runtime_error(message.toStdString()){} + ReportError(const QString& message); }; class ReportSettings{ @@ -132,6 +132,18 @@ namespace Const{ 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 typedef QStyleOptionViewItemV4 StyleOptionViewItem; #else diff --git a/include/lrreportengine.h b/include/lrreportengine.h index 38f8c1b..2abf45b 100644 --- a/include/lrreportengine.h +++ b/include/lrreportengine.h @@ -135,6 +135,8 @@ signals: void currentDefaulLanguageChanged(QLocale::Language); QLocale::Language getCurrentDefaultLanguage(); + void externalPaint(const QString& objectName, QPainter* painter, const QStyleOptionGraphicsItem*); + public slots: void cancelRender(); protected: diff --git a/limereport/databrowser/lrdatabrowser.cpp b/limereport/databrowser/lrdatabrowser.cpp index 50eaa6a..10de89e 100644 --- a/limereport/databrowser/lrdatabrowser.cpp +++ b/limereport/databrowser/lrdatabrowser.cpp @@ -661,6 +661,8 @@ void DataBrowser::applyChanges(SQLEditResult result) break; case SQLEditResult::SubProxy: changeProxy(result); + break; + default: break; } } else { removeDatasource(result.datasourceName); @@ -679,6 +681,7 @@ void DataBrowser::addDatasource(SQLEditResult result) break; case SQLEditResult::SubProxy: addProxy(result); + break; default: break; } diff --git a/limereport/items/lrimageitem.cpp b/limereport/items/lrimageitem.cpp index 0c61d00..ca92e71 100644 --- a/limereport/items/lrimageitem.cpp +++ b/limereport/items/lrimageitem.cpp @@ -48,11 +48,15 @@ bool VARIABLE_IS_NOT_USED registred = LimeReport::DesignElementsFactory::instanc namespace LimeReport{ 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) { - return new ImageItem(owner,parent); + ImageItem* result = new ImageItem(owner,parent); + result->setExternalPainter(m_externalPainter); + return result; } void ImageItem::loadPictureFromVariant(QVariant& data){ @@ -91,12 +95,26 @@ 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) { - if (m_picture.isNull()){ - if (!m_datasource.isEmpty() && !m_field.isEmpty()){ - IDataSource* ds = dataManager->dataSource(m_datasource); + 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); @@ -293,10 +311,13 @@ void ImageItem::paint(QPainter *ppainter, const QStyleOptionGraphicsItem *option ppainter->setPen(Qt::black); if (!datasource().isEmpty() && !field().isEmpty()) 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 ); } else { - ppainter->drawImage(point,img); + if (m_externalPainter && m_useExternalPainter) + m_externalPainter->paintByExternalPainter(this->patternName(), ppainter, option); + else + ppainter->drawImage(point,img); } ItemDesignIntf::paint(ppainter,option,widget); ppainter->restore(); diff --git a/limereport/items/lrimageitem.h b/limereport/items/lrimageitem.h index f6713df..91a3d92 100644 --- a/limereport/items/lrimageitem.h +++ b/limereport/items/lrimageitem.h @@ -33,7 +33,7 @@ namespace LimeReport{ -class ImageItem : public LimeReport::ItemDesignIntf +class ImageItem : public LimeReport::ItemDesignIntf, public IPainterProxy { Q_OBJECT Q_ENUMS(Format) @@ -49,6 +49,8 @@ class ImageItem : public LimeReport::ItemDesignIntf Q_PROPERTY(QString resourcePath READ resourcePath WRITE setResourcePath) Q_PROPERTY(QString variable READ variable WRITE setVariable) Q_PROPERTY(bool watermark READ isWatermark WRITE setWatermark) + Q_PROPERTY(bool useExternalPainter READ useExternalPainter WRITE setUseExternalPainter) + public: enum Format { Binary = 0, @@ -81,6 +83,12 @@ public: QString variable(){ return m_variable;} void setVariable(const QString& variable); + + void setExternalPainter(IExternalPainter* externalPainter){ m_externalPainter = externalPainter;} + + bool useExternalPainter() const; + void setUseExternalPainter(bool value); + protected: BaseDesignIntf* createSameTypeItem(QObject *owner, QGraphicsItem *parent); void updateItemSize(DataSourceManager *dataManager, RenderPass pass, int maxHeight); @@ -91,6 +99,8 @@ protected: void processPopUpAction(QAction *action); private: QImage m_picture; + bool m_useExternalPainter; + IExternalPainter* m_externalPainter; QString m_resourcePath; QString m_datasource; QString m_field; diff --git a/limereport/items/lrsubitemparentpropitem.cpp b/limereport/items/lrsubitemparentpropitem.cpp index b02cfa7..61ff802 100644 --- a/limereport/items/lrsubitemparentpropitem.cpp +++ b/limereport/items/lrsubitemparentpropitem.cpp @@ -77,6 +77,7 @@ void LimeReport::ItemLocationPropItem::setPropertyEditorData(QWidget *propertyEd } void LimeReport::ItemLocationPropItem::setModelData(QWidget *propertyEditor, QAbstractItemModel *model, const QModelIndex &index){ + Q_UNUSED(propertyEditor) model->setData(index,object()->property(propertyName().toLatin1())); setValueToObject(propertyName(), propertyValue()); } diff --git a/limereport/limereport.pro b/limereport/limereport.pro index 533bd97..3c324b0 100644 --- a/limereport/limereport.pro +++ b/limereport/limereport.pro @@ -1,7 +1,7 @@ -CONFIG(release, debug|release){ - TARGET = limereport -} else { +CONFIG(debug, debug|release){ TARGET = limereportd +} else { + TARGET = limereport } TEMPLATE = lib diff --git a/limereport/lrglobal.cpp b/limereport/lrglobal.cpp index 55ab31b..4d8da61 100644 --- a/limereport/lrglobal.cpp +++ b/limereport/lrglobal.cpp @@ -85,4 +85,8 @@ bool isColorDark(QColor color){ } } +ReportError::ReportError(const QString& message):std::runtime_error(message.toStdString()){} +IExternalPainter::~IExternalPainter(){} +IPainterProxy::~IPainterProxy(){} + } //namespace LimeReport diff --git a/limereport/lrglobal.h b/limereport/lrglobal.h index 3ecebb1..d1cb8b9 100644 --- a/limereport/lrglobal.h +++ b/limereport/lrglobal.h @@ -119,7 +119,7 @@ namespace Const{ class ReportError : public std::runtime_error{ public: - ReportError(const QString& message):std::runtime_error(message.toStdString()){} + ReportError(const QString& message); }; class ReportSettings{ @@ -132,6 +132,18 @@ namespace Const{ 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 typedef QStyleOptionViewItemV4 StyleOptionViewItem; #else diff --git a/limereport/lrreportengine.cpp b/limereport/lrreportengine.cpp index 06fc9bc..ab09828 100644 --- a/limereport/lrreportengine.cpp +++ b/limereport/lrreportengine.cpp @@ -1118,12 +1118,32 @@ PageItemDesignIntf* ReportEnginePrivate::createRenderingPage(PageItemDesignIntf* 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(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() { if (m_reportRendering) return ReportPages(); + initReport(); m_reportRender = ReportRender::Ptr(new ReportRender); updateTranslations(); - connect(m_reportRender.data(),SIGNAL(pageRendered(int)), this, SIGNAL(renderPageFinished(int))); @@ -1232,6 +1252,9 @@ ReportEngine::ReportEngine(QObject *parent) connect(d, SIGNAL(getCurrentDefaultLanguage()), this, SIGNAL(getCurrentDefaultLanguage())); + connect(d, SIGNAL(externalPaint(const QString&, QPainter*, const QStyleOptionGraphicsItem*)), + this, SIGNAL(externalPaint(const QString&, QPainter*, const QStyleOptionGraphicsItem*))); + } ReportEngine::~ReportEngine() diff --git a/limereport/lrreportengine.h b/limereport/lrreportengine.h index 38f8c1b..2abf45b 100644 --- a/limereport/lrreportengine.h +++ b/limereport/lrreportengine.h @@ -135,6 +135,8 @@ signals: void currentDefaulLanguageChanged(QLocale::Language); QLocale::Language getCurrentDefaultLanguage(); + void externalPaint(const QString& objectName, QPainter* painter, const QStyleOptionGraphicsItem*); + public slots: void cancelRender(); protected: diff --git a/limereport/lrreportengine_p.h b/limereport/lrreportengine_p.h index ef2d85e..9afe41e 100644 --- a/limereport/lrreportengine_p.h +++ b/limereport/lrreportengine_p.h @@ -93,7 +93,10 @@ public: 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 { Q_OBJECT @@ -214,6 +217,8 @@ signals: void currentDefaulLanguageChanged(QLocale::Language); QLocale::Language getCurrentDefaultLanguage(); + void externalPaint(const QString& objectName, QPainter* painter, const QStyleOptionGraphicsItem*); + public slots: bool slotLoadFromFile(const QString& fileName); void cancelRender(); @@ -242,6 +247,8 @@ private: PageItemDesignIntf *getPageByName(const QString& pageName); ATranslationProperty fakeTranslationReader(){ return ATranslationProperty();} PageItemDesignIntf *createRenderingPage(PageItemDesignIntf *page); + void initReport(); + void paintByExternalPainter(const QString& objectName, QPainter* painter, const QStyleOptionGraphicsItem* options); private: QList m_pages; QList m_renderingPages; diff --git a/limereport/lrreportrender.h b/limereport/lrreportrender.h index 80c4538..6c14bda 100644 --- a/limereport/lrreportrender.h +++ b/limereport/lrreportrender.h @@ -193,7 +193,7 @@ private: QList m_ranges; QVector m_columnedBandItems; unsigned long long m_currentNameIndex; - bool m_newPageStarted; + bool m_newPageStarted; bool m_renderingFirstTOC; };