mirror of
https://github.com/fralx/LimeReport.git
synced 2024-12-24 08:34:38 +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{
|
||||
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
|
||||
|
@ -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:
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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,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)
|
||||
{
|
||||
|
||||
@ -293,9 +311,12 @@ 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 {
|
||||
if (m_externalPainter && m_useExternalPainter)
|
||||
m_externalPainter->paintByExternalPainter(this->patternName(), ppainter, option);
|
||||
else
|
||||
ppainter->drawImage(point,img);
|
||||
}
|
||||
ItemDesignIntf::paint(ppainter,option,widget);
|
||||
|
@ -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;
|
||||
|
@ -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());
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
CONFIG(release, debug|release){
|
||||
TARGET = limereport
|
||||
} else {
|
||||
CONFIG(debug, debug|release){
|
||||
TARGET = limereportd
|
||||
} else {
|
||||
TARGET = limereport
|
||||
}
|
||||
|
||||
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
|
||||
|
@ -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
|
||||
|
@ -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()
|
||||
|
@ -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:
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user