mirror of
https://github.com/fralx/LimeReport.git
synced 2024-12-24 08:34:38 +03:00
init commit
This commit is contained in:
parent
836a03d68b
commit
2c50a9a791
@ -736,13 +736,17 @@ void TextItem::expandContent(DataSourceManager* dataManager, RenderPass pass)
|
||||
ExpandType expandType = (allowHTML() && !allowHTMLInFields())?ReplaceHTMLSymbols:NoEscapeSymbols;
|
||||
switch(pass){
|
||||
case FirstPass:
|
||||
context=expandUserVariables(context, pass, expandType, dataManager);
|
||||
context=expandScripts(context, dataManager);
|
||||
context=expandDataFields(context, expandType, dataManager);
|
||||
if (!fillInSecondPass()){
|
||||
context=expandUserVariables(context, pass, expandType, dataManager);
|
||||
context=expandScripts(context, dataManager);
|
||||
context=expandDataFields(context, expandType, dataManager);
|
||||
}
|
||||
break;
|
||||
case SecondPass:;
|
||||
context=expandUserVariables(context, pass, expandType, dataManager);
|
||||
context=expandScripts(context, dataManager);
|
||||
if (fillInSecondPass())
|
||||
context=expandDataFields(context, expandType, dataManager);
|
||||
}
|
||||
|
||||
if (expandType == NoEscapeSymbols && !m_varValue.isNull() &&m_valueType!=Default) {
|
||||
|
@ -178,6 +178,13 @@ QString BandDesignIntf::translateBandName(const BaseDesignIntf* item) const{
|
||||
}
|
||||
}
|
||||
|
||||
void BandDesignIntf::copyBookmarks(BandDesignIntf* sourceBand)
|
||||
{
|
||||
foreach(QString key, sourceBand->bookmarks()){
|
||||
addBookmark(key,sourceBand->getBookMark(key));
|
||||
}
|
||||
}
|
||||
|
||||
void BandDesignIntf::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
|
||||
{
|
||||
|
||||
@ -801,6 +808,12 @@ qreal BandDesignIntf::bottomSpace() const
|
||||
return m_bottomSpace.isValid() ? m_bottomSpace.value() : height()-findMaxBottom();
|
||||
}
|
||||
|
||||
QVariant BandDesignIntf::getBookMark(const QString& key){
|
||||
if (m_bookmarks.contains(key))
|
||||
return m_bookmarks.value(key);
|
||||
else return QVariant();
|
||||
}
|
||||
|
||||
void BandDesignIntf::slotPropertyObjectNameChanged(const QString &, const QString& newName)
|
||||
{
|
||||
update();
|
||||
|
@ -238,6 +238,12 @@ public:
|
||||
void setUseAlternateBackgroundColor(bool useAlternateBackgroundColor);
|
||||
void replaceGroupsFunction(BandDesignIntf *band);
|
||||
qreal bottomSpace() const;
|
||||
|
||||
void addBookmark(const QString& key, const QVariant& value){ m_bookmarks.insert(key, value);}
|
||||
QList<QString> bookmarks(){ return m_bookmarks.keys();}
|
||||
QVariant getBookMark(const QString& key);
|
||||
void copyBookmarks(BandDesignIntf* sourceBand);
|
||||
|
||||
signals:
|
||||
void bandRendered(BandDesignIntf* band);
|
||||
void bandRegistred();
|
||||
@ -262,6 +268,7 @@ protected:
|
||||
void preparePopUpMenu(QMenu &menu);
|
||||
void processPopUpAction(QAction *action);
|
||||
QString translateBandName(const BaseDesignIntf *item) const;
|
||||
|
||||
private slots:
|
||||
void childBandDeleted(QObject* band);
|
||||
void slotPropertyObjectNameChanged(const QString&,const QString&);
|
||||
@ -296,6 +303,7 @@ private:
|
||||
QColor m_alternateBackgroundColor;
|
||||
bool m_useAlternateBackgroundColor;
|
||||
InitializedValue m_bottomSpace;
|
||||
QMap<QString,QVariant> m_bookmarks;
|
||||
};
|
||||
|
||||
class DataBandDesignIntf : public BandDesignIntf{
|
||||
|
@ -79,7 +79,8 @@ BaseDesignIntf::BaseDesignIntf(const QString &storageTypeName, QObject *owner, Q
|
||||
m_borderColor(Qt::black),
|
||||
m_reportSettings(0),
|
||||
m_patternName(""),
|
||||
m_patternItem(0)
|
||||
m_patternItem(0),
|
||||
m_fillInSecondPass(false)
|
||||
{
|
||||
setGeometry(QRectF(0, 0, m_width, m_height));
|
||||
if (BaseDesignIntf *item = dynamic_cast<BaseDesignIntf *>(parent)) {
|
||||
@ -702,6 +703,21 @@ void BaseDesignIntf::turnOnSelectionMarker(bool value)
|
||||
}
|
||||
}
|
||||
|
||||
bool BaseDesignIntf::fillInSecondPass() const
|
||||
{
|
||||
return m_fillInSecondPass;
|
||||
}
|
||||
|
||||
void BaseDesignIntf::setFillInSecondPass(bool fillInSecondPass)
|
||||
{
|
||||
|
||||
if (m_fillInSecondPass != fillInSecondPass){
|
||||
m_fillInSecondPass = fillInSecondPass;
|
||||
notify("fillInSecondPass",!fillInSecondPass,fillInSecondPass);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
QString BaseDesignIntf::patternName() const
|
||||
{
|
||||
return (m_patternName.isEmpty()) ? objectName() : m_patternName;
|
||||
|
@ -96,6 +96,7 @@ class BaseDesignIntf :
|
||||
Q_PROPERTY(int borderLineSize READ borderLineSize WRITE setBorderLineSize)
|
||||
Q_PROPERTY(bool isVisible READ isVisible WRITE setItemVisible DESIGNABLE false)
|
||||
Q_PROPERTY(QColor borderColor READ borderColor WRITE setBorderColor)
|
||||
Q_PROPERTY(bool fillInSecondPass READ fillInSecondPass WRITE setFillInSecondPass)
|
||||
friend class ReportRender;
|
||||
public:
|
||||
enum BGMode { TransparentMode, OpaqueMode};
|
||||
@ -276,6 +277,8 @@ public:
|
||||
BaseDesignIntf* patternItem() const;
|
||||
void setPatternItem(BaseDesignIntf* patternItem);
|
||||
virtual QMap<QString, QString> getStringForTranslation();
|
||||
bool fillInSecondPass() const;
|
||||
void setFillInSecondPass(bool fillInSecondPass);
|
||||
|
||||
Q_INVOKABLE QString setItemWidth(qreal width);
|
||||
Q_INVOKABLE QString setItemHeight(qreal height);
|
||||
@ -286,7 +289,6 @@ public:
|
||||
Q_INVOKABLE QString setItemPosX(qreal xValue);
|
||||
Q_INVOKABLE QString setItemPosY(qreal yValue);
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
//ICollectionContainer
|
||||
@ -405,6 +407,7 @@ private:
|
||||
ReportSettings* m_reportSettings;
|
||||
QString m_patternName;
|
||||
BaseDesignIntf* m_patternItem;
|
||||
bool m_fillInSecondPass;
|
||||
|
||||
signals:
|
||||
void geometryChanged(QObject* object, QRectF newGeometry, QRectF oldGeometry);
|
||||
|
@ -75,6 +75,11 @@ ReportEnginePrivate::ReportEnginePrivate(QObject *parent) :
|
||||
m_datasources = new DataSourceManager(this);
|
||||
m_datasources->setReportSettings(&m_reportSettings);
|
||||
m_scriptEngineContext = new ScriptEngineContext(this);
|
||||
|
||||
ICallbackDatasource* tableOfContens = m_datasources->createCallbackDatasource("tableofcontens");
|
||||
connect(tableOfContens, SIGNAL(getCallbackData(LimeReport::CallbackInfo,QVariant&)),
|
||||
m_scriptEngineContext->tableOfContens(), SLOT(slotOneSlotDS(LimeReport::CallbackInfo,QVariant&)));
|
||||
|
||||
m_datasources->setObjectName("datasources");
|
||||
connect(m_datasources,SIGNAL(loadCollectionFinished(QString)),this,SLOT(slotDataSourceCollectionLoaded(QString)));
|
||||
connect(m_fileWatcher,SIGNAL(fileChanged(const QString &)),this,SLOT(slotLoadFromFile(const QString &)));
|
||||
@ -917,6 +922,8 @@ ReportPages ReportEnginePrivate::renderToPages()
|
||||
|
||||
bool isFirst = true;
|
||||
|
||||
// m_reportRender->secondRenderPass(result);
|
||||
|
||||
foreach(PageDesignIntf* page , m_pages){
|
||||
if (page->pageItem()->getIsTOC()){
|
||||
page->setReportSettings(&m_reportSettings);
|
||||
@ -933,6 +940,7 @@ ReportPages ReportEnginePrivate::renderToPages()
|
||||
}
|
||||
|
||||
m_reportRender->secondRenderPass(result);
|
||||
|
||||
emit renderFinished();
|
||||
m_reportRender.clear();
|
||||
}
|
||||
@ -1174,6 +1182,7 @@ ReportEngine::ReportEngine(ReportEnginePrivate &dd, QObject *parent)
|
||||
}
|
||||
|
||||
ScriptEngineManager*LimeReport::ReportEnginePrivate::scriptManager(){
|
||||
ScriptEngineManager::instance().setContext(scriptContext());
|
||||
ScriptEngineManager::instance().setDataManager(dataManager());
|
||||
return &ScriptEngineManager::instance();
|
||||
}
|
||||
|
@ -420,6 +420,7 @@ BandDesignIntf* ReportRender::renderBand(BandDesignIntf *patternBand, BandDesign
|
||||
}
|
||||
|
||||
patternBand->emitBandRendered(bandClone);
|
||||
m_scriptEngineContext->setCurrentBand(bandClone);
|
||||
emit(patternBand->afterRender());
|
||||
|
||||
if ( isLast && bandClone->keepFooterTogether() && bandClone->sliceLastRow() ){
|
||||
@ -1025,12 +1026,23 @@ BandDesignIntf* ReportRender::sliceBand(BandDesignIntf *band, BandDesignIntf* pa
|
||||
|
||||
}
|
||||
|
||||
void ReportRender::updateTOC(BaseDesignIntf* item, int pageNumber){
|
||||
BandDesignIntf* band = dynamic_cast<BandDesignIntf*>(item);
|
||||
if (band){
|
||||
TableOfContens* toc = m_scriptEngineContext->tableOfContens();
|
||||
foreach (QString key, band->bookmarks()){
|
||||
toc->setItem(key, band->getBookMark(key).toString(), pageNumber);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ReportRender::secondRenderPass(ReportPages renderedPages)
|
||||
{
|
||||
for(int i=0; i<renderedPages.count(); ++i){
|
||||
PageItemDesignIntf::Ptr page = renderedPages.at(i);
|
||||
m_datasources->setReportVariable("#PAGE_COUNT",findLastPageNumber(i));
|
||||
foreach(BaseDesignIntf* item, page->childBaseItems()){
|
||||
if (!m_scriptEngineContext->tableOfContens()->isEmpty()) updateTOC(item, i+1);
|
||||
item->updateItemSize(m_datasources, SecondPass);
|
||||
}
|
||||
}
|
||||
@ -1044,10 +1056,13 @@ BandDesignIntf *ReportRender::saveUppperPartReturnBottom(BandDesignIntf *band, i
|
||||
if (!bottomBandPart->isEmpty()){
|
||||
if (patternBand->keepFooterTogether())
|
||||
closeFooterGroup(patternBand);
|
||||
if (upperBandPart->isEmpty())
|
||||
bottomBandPart->copyBookmarks(band);
|
||||
}
|
||||
if (!upperBandPart->isEmpty()){
|
||||
upperBandPart->updateItemSize(m_datasources, FirstPass, height);
|
||||
registerBand(upperBandPart);
|
||||
upperBandPart->copyBookmarks(band);
|
||||
} else delete upperBandPart;
|
||||
|
||||
if (band->columnsCount()>1 &&
|
||||
@ -1068,6 +1083,7 @@ BandDesignIntf *ReportRender::renderData(BandDesignIntf *patternBand)
|
||||
BandDesignIntf* bandClone = dynamic_cast<BandDesignIntf*>(patternBand->cloneItem(PreviewMode));
|
||||
|
||||
m_scriptEngineContext->baseDesignIntfToScript(patternBand->page()->pageItem()->objectName(), bandClone);
|
||||
m_scriptEngineContext->setCurrentBand(bandClone);
|
||||
emit(patternBand->beforeRender());
|
||||
|
||||
if (patternBand->isFooter()){
|
||||
@ -1308,6 +1324,7 @@ void ReportRender::savePage(bool isLast)
|
||||
}
|
||||
|
||||
moveTearOffBand();
|
||||
m_scriptEngineContext->setCurrentPage(m_renderPageItem);
|
||||
emit m_patternPageItem->afterRender();
|
||||
if (isLast) emit m_patternPageItem->afterLastPageRendered();
|
||||
|
||||
|
@ -158,6 +158,7 @@ private:
|
||||
qreal maxColumnHeight();
|
||||
void renameChildItems(BaseDesignIntf *item);
|
||||
void renderGroupFooterByHeader(BandDesignIntf *groupHeader);
|
||||
void updateTOC(BaseDesignIntf* item, int pageNumber);
|
||||
private:
|
||||
DataSourceManager* m_datasources;
|
||||
ScriptEngineContext* m_scriptEngineContext;
|
||||
@ -189,6 +190,7 @@ private:
|
||||
unsigned long long m_curentNameIndex;
|
||||
|
||||
|
||||
|
||||
};
|
||||
} // namespace LimeReport
|
||||
#endif // LRREPORTRENDER_H
|
||||
|
@ -40,6 +40,7 @@
|
||||
#endif
|
||||
#include "lrdatasourcemanager.h"
|
||||
#include "lrbasedesignintf.h"
|
||||
#include "lrbanddesignintf.h"
|
||||
|
||||
Q_DECLARE_METATYPE(QColor)
|
||||
Q_DECLARE_METATYPE(QFont)
|
||||
@ -201,8 +202,6 @@ ScriptEngineManager::~ScriptEngineManager()
|
||||
{
|
||||
delete m_model;
|
||||
m_model = 0;
|
||||
delete m_tableOfContens;
|
||||
m_tableOfContens = 0;
|
||||
delete m_scriptEngine;
|
||||
}
|
||||
|
||||
@ -345,9 +344,12 @@ void ScriptEngineManager::setDataManager(DataSourceManager *dataManager){
|
||||
);
|
||||
addFunction(describer);
|
||||
}
|
||||
ICallbackDatasource* tableOfContens = m_dataManager->createCallbackDatasource("tableofcontens");
|
||||
connect(tableOfContens, SIGNAL(getCallbackData(LimeReport::CallbackInfo,QVariant&)),
|
||||
m_tableOfContens, SLOT(slotOneSlotDS(LimeReport::CallbackInfo,QVariant&)));
|
||||
|
||||
// qDebug()<<"is script context exists before set datamanager is called"<< (m_context == 0);
|
||||
|
||||
// ICallbackDatasource* tableOfContens = m_dataManager->createCallbackDatasource("tableofcontens");
|
||||
// connect(tableOfContens, SIGNAL(getCallbackData(LimeReport::CallbackInfo,QVariant&)),
|
||||
// m_tableOfContens, SLOT(slotOneSlotDS(LimeReport::CallbackInfo,QVariant&)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -431,8 +433,8 @@ QString ScriptEngineManager::expandDataFields(QString context, ExpandType expand
|
||||
fieldValue = replaceHTMLSymbols(varValue.toString());
|
||||
else fieldValue = varValue.toString();
|
||||
}
|
||||
|
||||
context.replace(rx.cap(0),fieldValue);
|
||||
if (varValue.isValid())
|
||||
context.replace(rx.cap(0),fieldValue);
|
||||
|
||||
} else {
|
||||
QString error;
|
||||
@ -540,7 +542,20 @@ QVariant ScriptEngineManager::evaluateScript(const QString& script){
|
||||
|
||||
void ScriptEngineManager::addTableOfContensItem(const QString& uniqKey, const QString& content, int pageNumber, int indent)
|
||||
{
|
||||
m_tableOfContens->setItem(uniqKey, content, pageNumber, indent);
|
||||
Q_ASSERT(m_context != 0);
|
||||
if (m_context){
|
||||
BandDesignIntf* currentBand = m_context->getCurrentBand();
|
||||
m_context->tableOfContens()->setItem(uniqKey, content, pageNumber, indent);
|
||||
if (currentBand)
|
||||
currentBand->addBookmark(uniqKey, content);
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptEngineManager::clearTableOfContens(){
|
||||
if (m_context) {
|
||||
if (m_context->tableOfContens())
|
||||
m_context->tableOfContens()->clear();
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptEngineManager::updateModel()
|
||||
@ -813,7 +828,6 @@ ScriptEngineManager::ScriptEngineManager()
|
||||
createClearTableOfContensFunction();
|
||||
|
||||
m_model = new ScriptEngineModel(this);
|
||||
m_tableOfContens = new TableOfContens();
|
||||
}
|
||||
|
||||
bool ScriptExtractor::parse()
|
||||
@ -1049,6 +1063,7 @@ void ScriptEngineContext::clear()
|
||||
m_createdDialogs.clear();
|
||||
#endif
|
||||
m_initScript.clear();
|
||||
m_tableOfContens->clear();
|
||||
m_lastError="";
|
||||
}
|
||||
|
||||
@ -1131,6 +1146,36 @@ DialogDescriber* ScriptEngineContext::findDialogContainer(const QString& dialogN
|
||||
return 0;
|
||||
}
|
||||
|
||||
TableOfContens* ScriptEngineContext::tableOfContens() const
|
||||
{
|
||||
return m_tableOfContens;
|
||||
}
|
||||
|
||||
void ScriptEngineContext::setTableOfContens(TableOfContens* tableOfContens)
|
||||
{
|
||||
m_tableOfContens = tableOfContens;
|
||||
}
|
||||
|
||||
PageItemDesignIntf* ScriptEngineContext::getCurrentPage() const
|
||||
{
|
||||
return m_currentPage;
|
||||
}
|
||||
|
||||
void ScriptEngineContext::setCurrentPage(PageItemDesignIntf* currentPage)
|
||||
{
|
||||
m_currentPage = currentPage;
|
||||
}
|
||||
|
||||
BandDesignIntf* ScriptEngineContext::getCurrentBand() const
|
||||
{
|
||||
return m_currentBand;
|
||||
}
|
||||
|
||||
void ScriptEngineContext::setCurrentBand(BandDesignIntf* currentBand)
|
||||
{
|
||||
m_currentBand = currentBand;
|
||||
}
|
||||
|
||||
QDialog* ScriptEngineContext::getDialog(const QString& dialogName)
|
||||
{
|
||||
QDialog* dialog = findDialog(dialogName);
|
||||
@ -1221,6 +1266,9 @@ bool ScriptEngineContext::runInitScript(){
|
||||
|
||||
ScriptEngineType* engine = ScriptEngineManager::instance().scriptEngine();
|
||||
ScriptEngineManager::instance().clearTableOfContens();
|
||||
ScriptEngineManager::instance().setContext(this);
|
||||
m_tableOfContens->clear();
|
||||
|
||||
#ifndef USE_QJSENGINE
|
||||
engine->pushContext();
|
||||
#endif
|
||||
@ -1477,7 +1525,8 @@ void TableOfContens::setItem(const QString& uniqKey, const QString& content, int
|
||||
item = m_hash.value(uniqKey);
|
||||
item->content = content;
|
||||
item->pageNumber = pageNumber;
|
||||
item->indent = indent;
|
||||
if (indent>0)
|
||||
item->indent = indent;
|
||||
} else {
|
||||
item = new ContentItem;
|
||||
item->content = content;
|
||||
|
@ -56,6 +56,8 @@ namespace LimeReport{
|
||||
|
||||
class DataSourceManager;
|
||||
class BaseDesignIntf;
|
||||
class PageItemDesignIntf;
|
||||
class BandDesignIntf;
|
||||
|
||||
struct ContentItem {
|
||||
QString content;
|
||||
@ -66,9 +68,11 @@ struct ContentItem {
|
||||
class TableOfContens : public QObject{
|
||||
Q_OBJECT
|
||||
public:
|
||||
TableOfContens(QObject* parent = 0):QObject(parent){}
|
||||
~TableOfContens();
|
||||
void setItem(const QString& uniqKey, const QString& content, int pageNumber, int indent = 0);
|
||||
void clear();
|
||||
bool isEmpty(){ return m_tableOfContens.isEmpty();}
|
||||
private slots:
|
||||
void slotOneSlotDS(LimeReport::CallbackInfo info, QVariant &data);
|
||||
private:
|
||||
@ -164,7 +168,7 @@ public:
|
||||
#ifdef HAVE_UI_LOADER
|
||||
typedef QSharedPointer<QDialog> DialogPtr;
|
||||
#endif
|
||||
explicit ScriptEngineContext(QObject* parent=0):QObject(parent){}
|
||||
explicit ScriptEngineContext(QObject* parent=0):QObject(parent), m_tableOfContens(new TableOfContens(this)){}
|
||||
#ifdef HAVE_UI_LOADER
|
||||
void addDialog(const QString& name, const QByteArray& description);
|
||||
bool changeDialog(const QString& name, const QByteArray &description);
|
||||
@ -182,7 +186,15 @@ public:
|
||||
QString initScript() const;
|
||||
void setInitScript(const QString& initScript);
|
||||
bool runInitScript();
|
||||
#ifdef HAVE_UI_LOADER
|
||||
|
||||
BandDesignIntf* getCurrentBand() const;
|
||||
void setCurrentBand(BandDesignIntf* currentBand);
|
||||
PageItemDesignIntf* getCurrentPage() const;
|
||||
void setCurrentPage(PageItemDesignIntf* currentPage);
|
||||
TableOfContens* tableOfContens() const;
|
||||
void setTableOfContens(TableOfContens* tableOfContens);
|
||||
|
||||
#ifdef HAVE_UI_LOADER
|
||||
signals:
|
||||
void dialogNameChanged(QString dialogName);
|
||||
void dialogDeleted(QString dialogName);
|
||||
@ -205,6 +217,9 @@ private:
|
||||
#endif
|
||||
QString m_lastError;
|
||||
QString m_initScript;
|
||||
BandDesignIntf* m_currentBand;
|
||||
PageItemDesignIntf* m_currentPage;
|
||||
TableOfContens* m_tableOfContens;
|
||||
};
|
||||
|
||||
class JSFunctionDesc{
|
||||
@ -306,7 +321,7 @@ public:
|
||||
QString expandScripts(QString context, QVariant &varValue, QObject* reportItem);
|
||||
QVariant evaluateScript(const QString &script);
|
||||
void addTableOfContensItem(const QString& uniqKey, const QString& content, int pageNumber, int indent);
|
||||
void clearTableOfContens(){ m_tableOfContens->clear(); }
|
||||
void clearTableOfContens();
|
||||
|
||||
protected:
|
||||
void updateModel();
|
||||
@ -336,7 +351,6 @@ private:
|
||||
ScriptEngineContext* m_context;
|
||||
DataSourceManager* m_dataManager;
|
||||
ScriptFunctionsManager* m_functionManager;
|
||||
TableOfContens* m_tableOfContens;
|
||||
};
|
||||
|
||||
class ScriptExtractor
|
||||
|
Loading…
Reference in New Issue
Block a user