0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 00:33:02 +03:00

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,7 +1,7 @@
CONFIG(release, debug|release){
TARGET = limereport
} else {
CONFIG(debug, debug|release){
TARGET = limereportd
} else {
TARGET = limereport
}
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

View File

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

View File

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

View File

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

View File

@ -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<PageDesignIntf*> m_pages;
QList<PageItemDesignIntf*> m_renderingPages;

View File

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