External drawing feature added to ImageItem

This commit is contained in:
Arin Alexander 2018-12-12 22:55:03 +03:00
parent c00b8aa50c
commit ce1656d2ef
13 changed files with 113 additions and 16 deletions

View File

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

View File

@ -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:

View File

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

View File

@ -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,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) void ImageItem::updateItemSize(DataSourceManager* dataManager, RenderPass pass, int maxHeight)
{ {
if (m_picture.isNull()){ if (m_picture.isNull()){
if (!m_datasource.isEmpty() && !m_field.isEmpty()){ if (!m_datasource.isEmpty() && !m_field.isEmpty()){
IDataSource* ds = dataManager->dataSource(m_datasource); IDataSource* ds = dataManager->dataSource(m_datasource);
if (ds) { if (ds) {
QVariant data = ds->data(m_field); QVariant data = ds->data(m_field);
loadPictureFromVariant(data); loadPictureFromVariant(data);
@ -293,10 +311,13 @@ 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 {
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); ItemDesignIntf::paint(ppainter,option,widget);
ppainter->restore(); ppainter->restore();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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()

View File

@ -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:

View File

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

View File

@ -193,7 +193,7 @@ private:
QList<PagesRange> m_ranges; QList<PagesRange> m_ranges;
QVector<BandDesignIntf*> m_columnedBandItems; QVector<BandDesignIntf*> m_columnedBandItems;
unsigned long long m_currentNameIndex; unsigned long long m_currentNameIndex;
bool m_newPageStarted; bool m_newPageStarted;
bool m_renderingFirstTOC; bool m_renderingFirstTOC;
}; };