0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-25 00:54:39 +03:00

Prevent multi run initscript

Prevent multi run initscript

Prevent multi run initscript &
Build without HAVE_UI_LOADER has been fixed
This commit is contained in:
Arin Alexander 2017-04-20 23:34:32 +03:00
parent cbf205b728
commit d89fcc53a8
11 changed files with 166 additions and 333 deletions

View File

@ -77,8 +77,9 @@ ReportDesignWidget::ReportDesignWidget(ReportEngine *report, QMainWindow *mainWi
connect(m_report,SIGNAL(pagesLoadFinished()),this,SLOT(slotPagesLoadFinished())); connect(m_report,SIGNAL(pagesLoadFinished()),this,SLOT(slotPagesLoadFinished()));
connect(m_report,SIGNAL(cleared()),this,SIGNAL(cleared())); connect(m_report,SIGNAL(cleared()),this,SIGNAL(cleared()));
connect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(slotCurrentTabChanged(int))); connect(m_tabWidget, SIGNAL(currentChanged(int)), this, SLOT(slotCurrentTabChanged(int)));
#ifdef HAVE_UI_LOADER
connect(m_report->scriptContext(), SIGNAL(dialogDeleted(QString)), this, SLOT(slotDialogDeleted(QString))); connect(m_report->scriptContext(), SIGNAL(dialogDeleted(QString)), this, SLOT(slotDialogDeleted(QString)));
#endif
//m_instance=this; //m_instance=this;
m_scriptEditor->setPlainText(m_report->scriptContext()->initScript()); m_scriptEditor->setPlainText(m_report->scriptContext()->initScript());
m_zoomer = new GraphicsViewZoomer(activeView()); m_zoomer = new GraphicsViewZoomer(activeView());

View File

@ -1277,7 +1277,9 @@ void ReportDesignWindow::slotActivePageChanged()
switch (m_editorTabType) { switch (m_editorTabType) {
case ReportDesignWidget::Dialog: case ReportDesignWidget::Dialog:
m_dialogEditorsState = saveState(); m_dialogEditorsState = saveState();
#ifdef HAVE_UI_LOADER
m_scriptBrowser->updateDialogsTree(); m_scriptBrowser->updateDialogsTree();
#endif
break; break;
default: default:
m_pageEditorsState = saveState(); m_pageEditorsState = saveState();

View File

@ -795,15 +795,26 @@ ReportPages ReportEnginePrivate::renderToPages()
connect(m_reportRender.data(),SIGNAL(pageRendered(int)), connect(m_reportRender.data(),SIGNAL(pageRendered(int)),
this, SIGNAL(renderPageFinished(int))); this, SIGNAL(renderPageFinished(int)));
if (m_pages.count()){ if (m_pages.count()){
#ifdef HAVE_UI_LOADER
m_scriptEngineContext->initDialogs();
#endif
ReportPages result; ReportPages result;
m_reportRendering = true; m_reportRendering = true;
emit renderStarted();
m_reportRender->setDatasources(dataManager()); m_reportRender->setDatasources(dataManager());
m_reportRender->setScriptContext(scriptContext()); m_reportRender->setScriptContext(scriptContext());
foreach (PageDesignIntf* page, m_pages) { foreach (PageDesignIntf* page, m_pages) {
m_pages.at(0)->setReportSettings(&m_reportSettings); scriptContext()->baseDesignIntfToScript(page->pageItem());
}
if (m_scriptEngineContext->runInitScript()){
emit renderStarted();
foreach(PageDesignIntf* page , m_pages){
page->setReportSettings(&m_reportSettings);
result.append(m_reportRender->renderPageToPages(page)); result.append(m_reportRender->renderPageToPages(page));
} }
@ -811,6 +822,7 @@ ReportPages ReportEnginePrivate::renderToPages()
emit renderFinished(); emit renderFinished();
m_reportRender.clear(); m_reportRender.clear();
m_reportRendering = false; m_reportRendering = false;
}
return result; return result;
} else { } else {
return ReportPages(); return ReportPages();

View File

@ -181,7 +181,6 @@ private:
bool m_reportRendering; bool m_reportRendering;
bool m_resultIsEditable; bool m_resultIsEditable;
QString m_passPhrase; QString m_passPhrase;
QFileSystemWatcher *m_fileWatcher; QFileSystemWatcher *m_fileWatcher;
}; };

View File

@ -165,35 +165,6 @@ void ReportRender::setScriptContext(ScriptEngineContext* scriptContext)
m_scriptEngineContext=scriptContext; m_scriptEngineContext=scriptContext;
} }
bool ReportRender::runInitScript(){
if (m_scriptEngineContext){
ScriptEngineType* engine = ScriptEngineManager::instance().scriptEngine();
#ifndef USE_QJSENGINE
engine->pushContext();
#endif
ScriptValueType res = engine->evaluate(m_scriptEngineContext->initScript());
if (res.isBool()) return res.toBool();
#ifdef USE_QJSENGINE
if (res.isError()){
QMessageBox::critical(0,tr("Error"),
QString("Line %1: %2 ").arg(res.property("lineNumber").toString())
.arg(res.toString())
);
return false;
}
#else
if (engine->hasUncaughtException()) {
QMessageBox::critical(0,tr("Error"),
QString("Line %1: %2 ").arg(engine->uncaughtExceptionLineNumber())
.arg(engine->uncaughtException().toString())
);
return false;
}
#endif
}
return true;
}
void ReportRender::initDatasources(){ void ReportRender::initDatasources(){
try{ try{
datasources()->setAllDatasourcesToFirst(); datasources()->setAllDatasourcesToFirst();
@ -222,29 +193,17 @@ void ReportRender::renderPage(PageDesignIntf* patternPage)
m_curentNameIndex = 0; m_curentNameIndex = 0;
m_patternPageItem = patternPage->pageItem(); m_patternPageItem = patternPage->pageItem();
if (m_patternPageItem->resetPageNumber() && m_pageCount>0) { if (m_patternPageItem->resetPageNumber() && m_pageCount>0) {
resetPageNumber(PageReset); resetPageNumber(PageReset);
} }
m_renderCanceled = false; m_renderCanceled = false;
BandDesignIntf* reportFooter = m_patternPageItem->bandByType(BandDesignIntf::ReportFooter); BandDesignIntf* reportFooter = m_patternPageItem->bandByType(BandDesignIntf::ReportFooter);
m_reportFooterHeight = 0; m_reportFooterHeight = 0;
if (reportFooter) if (reportFooter)
m_reportFooterHeight = reportFooter->height(); m_reportFooterHeight = reportFooter->height();
initGroups(); initGroups();
#ifdef HAVE_UI_LOADER
initDialogs();
#endif
if (m_scriptEngineContext){
baseDesignIntfToScript(patternPage->pageItem());
foreach (BaseDesignIntf* item, patternPage->pageItem()->childBaseItems()){
baseDesignIntfToScript(item);
}
}
if (runInitScript()){
clearPageMap(); clearPageMap();
try{ try{
@ -282,7 +241,7 @@ void ReportRender::renderPage(PageDesignIntf* patternPage)
#ifndef USE_QJSENGINE #ifndef USE_QJSENGINE
ScriptEngineManager::instance().scriptEngine()->popContext(); ScriptEngineManager::instance().scriptEngine()->popContext();
#endif #endif
}
} }
int ReportRender::pageCount() int ReportRender::pageCount()
@ -325,31 +284,6 @@ void ReportRender::initVariables()
m_datasources->setReportVariable("#PAGE_COUNT",0); m_datasources->setReportVariable("#PAGE_COUNT",0);
} }
#ifdef HAVE_UI_LOADER
#ifdef USE_QJSENGINE
void registerChildObjects(ScriptEngineType* se, ScriptValueType* sv){
foreach(QObject* obj, sv->toQObject()->children()){
ScriptValueType child = se->newQObject(obj);
sv->setProperty(obj->objectName(),child);
registerChildObjects(se, &child);
}
}
#endif
void ReportRender::initDialogs(){
if (m_scriptEngineContext){
ScriptEngineType* se = ScriptEngineManager::instance().scriptEngine();
foreach(DialogDescriber::Ptr dialog, m_scriptEngineContext->dialogDescribers()){
ScriptValueType sv = se->newQObject(m_scriptEngineContext->getDialog(dialog->name()));
#ifdef USE_QJSENGINE
registerChildObjects(se,&sv);
#endif
se->globalObject().setProperty(dialog->name(),sv);
}
}
}
#endif
void ReportRender::clearPageMap() void ReportRender::clearPageMap()
{ {
m_renderedPages.clear(); m_renderedPages.clear();
@ -548,7 +482,6 @@ void ReportRender::renderDataBand(BandDesignIntf *dataBand)
if (header && !header->printAlways()) if (header && !header->printAlways())
renderDataHeader(header); renderDataHeader(header);
//renderChildHeader(dataBand,PrintNotAlwaysPrintable);
renderGroupHeader(dataBand, bandDatasource, true); renderGroupHeader(dataBand, bandDatasource, true);
bool firstTime = true; bool firstTime = true;
@ -662,14 +595,10 @@ void ReportRender::renderPageItems(PageItemDesignIntf* patternPage)
m_renderPageItem, m_renderPageItem,
m_renderPageItem); m_renderPageItem);
pageItems.append(cloneItem); pageItems.append(cloneItem);
//cloneItem->updateItemSize(m_datasources);
} }
} }
m_renderPageItem->restoreLinks(); m_renderPageItem->restoreLinks();
m_renderPageItem->updateSubItemsSize(FirstPass,m_datasources); m_renderPageItem->updateSubItemsSize(FirstPass,m_datasources);
// foreach(BaseDesignIntf* item, pageItems){
// item->updateItemSize(m_datasources);
// }
} }
qreal ReportRender::calcPageFooterHeight(PageItemDesignIntf *patternPage) qreal ReportRender::calcPageFooterHeight(PageItemDesignIntf *patternPage)
@ -1068,9 +997,6 @@ void ReportRender::secondRenderPass(ReportPages renderedPages)
foreach(BaseDesignIntf* item, page->childBaseItems()){ foreach(BaseDesignIntf* item, page->childBaseItems()){
item->updateItemSize(m_datasources, SecondPass); item->updateItemSize(m_datasources, SecondPass);
} }
// foreach(BandDesignIntf* band, page->childBands()){
// band->updateItemSize(m_datasources, SecondPass);
// }
} }
} }
@ -1080,7 +1006,6 @@ BandDesignIntf *ReportRender::saveUppperPartReturnBottom(BandDesignIntf *band, i
BandDesignIntf* upperBandPart = dynamic_cast<BandDesignIntf*>(band->cloneUpperPart(sliceHeight)); BandDesignIntf* upperBandPart = dynamic_cast<BandDesignIntf*>(band->cloneUpperPart(sliceHeight));
BandDesignIntf* bottomBandPart = dynamic_cast<BandDesignIntf*>(band->cloneBottomPart(sliceHeight)); BandDesignIntf* bottomBandPart = dynamic_cast<BandDesignIntf*>(band->cloneBottomPart(sliceHeight));
if (!bottomBandPart->isEmpty()){ if (!bottomBandPart->isEmpty()){
//bottomBandPart->updateItemSize(FirstPass,height);
if (patternBand->keepFooterTogether()) if (patternBand->keepFooterTogether())
closeFooterGroup(patternBand); closeFooterGroup(patternBand);
} }
@ -1097,8 +1022,7 @@ BandDesignIntf *ReportRender::saveUppperPartReturnBottom(BandDesignIntf *band, i
savePage(); savePage();
startNewPage(); startNewPage();
} }
// if (!bottomBandPart->isEmpty() && patternBand->keepFooterTogether())
// openFooterGroup(patternBand);
delete band; delete band;
return bottomBandPart; return bottomBandPart;
} }
@ -1107,7 +1031,7 @@ BandDesignIntf *ReportRender::renderData(BandDesignIntf *patternBand)
{ {
BandDesignIntf* bandClone = dynamic_cast<BandDesignIntf*>(patternBand->cloneItem(PreviewMode)); BandDesignIntf* bandClone = dynamic_cast<BandDesignIntf*>(patternBand->cloneItem(PreviewMode));
baseDesignIntfToScript(bandClone); m_scriptEngineContext->baseDesignIntfToScript(bandClone);
emit(patternBand->beforeRender()); emit(patternBand->beforeRender());
if (patternBand->isFooter()){ if (patternBand->isFooter()){
@ -1120,7 +1044,7 @@ BandDesignIntf *ReportRender::renderData(BandDesignIntf *patternBand)
bandClone->updateItemSize(m_datasources); bandClone->updateItemSize(m_datasources);
baseDesignIntfToScript(bandClone); m_scriptEngineContext->baseDesignIntfToScript(bandClone);
emit(patternBand->afterData()); emit(patternBand->afterData());
return bandClone; return bandClone;
@ -1143,7 +1067,7 @@ void ReportRender::startNewPage(bool isFirst)
initColumns(); initColumns();
initRenderPage(); initRenderPage();
baseDesignIntfToScript(m_renderPageItem); m_scriptEngineContext->baseDesignIntfToScript(m_renderPageItem);
m_renderPageItem->setObjectName(QLatin1String("ReportPage")+QString::number(m_pageCount)); m_renderPageItem->setObjectName(QLatin1String("ReportPage")+QString::number(m_pageCount));
m_maxHeightByColumn[m_currentColumn]=m_renderPageItem->pageRect().height(); m_maxHeightByColumn[m_currentColumn]=m_renderPageItem->pageRect().height();
@ -1360,37 +1284,4 @@ void ReportRender::cancelRender(){
m_renderCanceled = true; m_renderCanceled = true;
} }
void ReportRender::baseDesignIntfToScript(BaseDesignIntf *item) } // namespace LimeReport
{
if ( item ) {
if (item->metaObject()->indexOfSignal("beforeRender()")!=-1)
item->disconnect(SIGNAL(beforeRender()));
if (item->metaObject()->indexOfSignal("afterData()")!=-1)
item->disconnect(SIGNAL(afterData()));
if (item->metaObject()->indexOfSignal("afterRender()")!=-1)
item->disconnect(SIGNAL(afterRender()));
ScriptEngineType* engine = ScriptEngineManager::instance().scriptEngine();
#ifdef USE_QJSENGINE
//sItem = engine->newQObject(item);
ScriptValueType sItem = getCppOwnedJSValue(*engine, item);
engine->globalObject().setProperty(item->patternName(), sItem);
#else
ScriptValueType sItem = engine->globalObject().property(item->patternName());
if (sItem.isValid()){
engine->newQObject(sItem, item);
} else {
sItem = engine->newQObject(item);
engine->globalObject().setProperty(item->patternName(),sItem);
}
#endif
foreach(BaseDesignIntf* child, item->childBaseItems()){
baseDesignIntfToScript(child);
}
}
}
}

View File

@ -87,29 +87,20 @@ signals:
public slots: public slots:
void cancelRender(); void cancelRender();
private: private:
void baseDesignIntfToScript(BaseDesignIntf* item);
void renderPage(PageDesignIntf *patternPage);
void initDatasources(); void initDatasources();
void initDatasource(const QString &name); void initDatasource(const QString &name);
void initRenderPage(); void initRenderPage();
#ifdef HAVE_UI_LOADER
void initDialogs();
#endif
void initVariables(); void initVariables();
bool runInitScript(); void initGroups();
void clearPageMap(); void clearPageMap();
void renderPage(PageDesignIntf *patternPage);
BandDesignIntf* renderBand(BandDesignIntf *patternBand, BandDesignIntf *bandData, DataRenderMode mode = NotStartNewPage, bool isLast = false); BandDesignIntf* renderBand(BandDesignIntf *patternBand, BandDesignIntf *bandData, DataRenderMode mode = NotStartNewPage, bool isLast = false);
void renderDataBand(BandDesignIntf* dataBand); void renderDataBand(BandDesignIntf* dataBand);
void renderPageHeader(PageItemDesignIntf* patternPage); void renderPageHeader(PageItemDesignIntf* patternPage);
void renderReportHeader(PageItemDesignIntf* patternPage, PageRenderStage stage); void renderReportHeader(PageItemDesignIntf* patternPage, PageRenderStage stage);
void renderPageFooter(PageItemDesignIntf* patternPage); void renderPageFooter(PageItemDesignIntf* patternPage);
void moveTearOffBand();
void renderPageItems(PageItemDesignIntf* patternPage); void renderPageItems(PageItemDesignIntf* patternPage);
qreal calcPageFooterHeight(PageItemDesignIntf* patternPage);
qreal calcSlicePercent(qreal height);
void renderChildHeader(BandDesignIntf* parent, BandPrintMode printMode); void renderChildHeader(BandDesignIntf* parent, BandPrintMode printMode);
void renderChildFooter(BandDesignIntf* parent, BandPrintMode printMode); void renderChildFooter(BandDesignIntf* parent, BandPrintMode printMode);
void renderChildBands(BandDesignIntf* parentBand); void renderChildBands(BandDesignIntf* parentBand);
@ -117,8 +108,10 @@ private:
void renderDataHeader(BandDesignIntf* header); void renderDataHeader(BandDesignIntf* header);
void renderGroupHeader(BandDesignIntf* parentBand, IDataSource* dataSource, bool firstTime); void renderGroupHeader(BandDesignIntf* parentBand, IDataSource* dataSource, bool firstTime);
void renderGroupFooter(BandDesignIntf* parentBand); void renderGroupFooter(BandDesignIntf* parentBand);
void moveTearOffBand();
qreal calcPageFooterHeight(PageItemDesignIntf* patternPage);
qreal calcSlicePercent(qreal height);
void initGroups();
bool containsGroupsFunction(BandDesignIntf* band); bool containsGroupsFunction(BandDesignIntf* band);
void extractGroupsFunction(BandDesignIntf* band); void extractGroupsFunction(BandDesignIntf* band);
void replaceGroupsFunction(BandDesignIntf* band); void replaceGroupsFunction(BandDesignIntf* band);
@ -169,10 +162,7 @@ private:
QMultiMap< BandDesignIntf*, GroupBandsHolder* > m_childBands; QMultiMap< BandDesignIntf*, GroupBandsHolder* > m_childBands;
QList<BandDesignIntf*> m_reprintableBands; QList<BandDesignIntf*> m_reprintableBands;
QList<BandDesignIntf*> m_recalcBands; QList<BandDesignIntf*> m_recalcBands;
// QList<BandDesignIntf*> m_lastRenderedHeaders;
//int m_maxHeightByColumn[0];
//int m_currentStartDataPos;
int m_currentIndex; int m_currentIndex;
int m_pageCount; int m_pageCount;

View File

@ -32,12 +32,14 @@
#include <QDate> #include <QDate>
#include <QStringList> #include <QStringList>
#include <QScriptValueIterator> #include <QScriptValueIterator>
#include <QMessageBox>
#ifdef HAVE_UI_LOADER #ifdef HAVE_UI_LOADER
#include <QUiLoader> #include <QUiLoader>
#include <QBuffer> #include <QBuffer>
#include <QWidget> #include <QWidget>
#endif #endif
#include "lrdatasourcemanager.h" #include "lrdatasourcemanager.h"
#include "lrbasedesignintf.h"
Q_DECLARE_METATYPE(QColor) Q_DECLARE_METATYPE(QColor)
Q_DECLARE_METATYPE(QFont) Q_DECLARE_METATYPE(QFont)
@ -192,146 +194,9 @@ void ScriptEngineModel::updateModel()
} }
categ->addChild(funcDesc.name,funcDesc.description,ScriptEngineNode::Function,QIcon(":/report/images/function")); categ->addChild(funcDesc.name,funcDesc.description,ScriptEngineNode::Function,QIcon(":/report/images/function"));
} }
//reset();
endResetModel(); endResetModel();
} }
//QScriptValue line(QScriptContext* pcontext, QScriptEngine* pengine){
// ScriptEngineManager* sm = qscriptvalue_cast<ScriptEngineManager*>(pcontext->callee().data());
// DataSourceManager* dm = sm->dataManager();
// QString band = pcontext->argument(0).toString();
// QScriptValue res;
// QString varName = QLatin1String("line_")+band.toLower();
// if (dm->variable(varName).isValid()){
// res=pengine->newVariant(dm->variable(varName));
// } else res=pengine->newVariant(QString("Variable line for band %1 not found").arg(band));
// return res;
//}
//QScriptValue setVariable(QScriptContext* pcontext, QScriptEngine* /*pengine*/){
// QString name = pcontext->argument(0).toString();
// QVariant value = pcontext->argument(1).toVariant();
// ScriptEngineManager* sm = qscriptvalue_cast<ScriptEngineManager*>(pcontext->callee().data());
// DataSourceManager* dm = sm->dataManager();
// dm->changeVariable(name,value);
// return QScriptValue();
//}
//QScriptValue getVariable(QScriptContext* pcontext, QScriptEngine* pengine){
// QString name = pcontext->argument(0).toString();
// ScriptEngineManager* sm = qscriptvalue_cast<ScriptEngineManager*>(pcontext->callee().data());
// DataSourceManager* dm = sm->dataManager();
// QScriptValue res = pengine->newVariant(dm->variable(name));
// return res;
//}
//QScriptValue getField(QScriptContext* pcontext, QScriptEngine* pengine){
// QString name = pcontext->argument(0).toString();
// ScriptEngineManager* sm = qscriptvalue_cast<ScriptEngineManager*>(pcontext->callee().data());
// DataSourceManager* dm = sm->dataManager();
// QScriptValue res = pengine->newVariant(dm->fieldData(name));
// return res;
//}
//QScriptValue numberFormat(QScriptContext* pcontext, QScriptEngine* pengine){
// QVariant value = pcontext->argument(0).toVariant();
// char format = (pcontext->argumentCount()>1)?pcontext->argument(1).toString()[0].toLatin1():'f';
// int precision = (pcontext->argumentCount()>2)?pcontext->argument(2).toInt32():2;
// QString locale = (pcontext->argumentCount()>3)?pcontext->argument(3).toString():"";
// QScriptValue res = (locale.isEmpty())?pengine->newVariant(QString::number(value.toDouble(),format,precision)):
// pengine->newVariant(QLocale(locale).toString(value.toDouble(),format,precision));
// return res;
//}
//#if QT_VERSION>0x040800
//QScriptValue currencyFormat(QScriptContext* pcontext, QScriptEngine* pengine){
// QVariant value = pcontext->argument(0).toVariant();
// QString locale = (pcontext->argumentCount()>1)?pcontext->argument(1).toString():QLocale::system().name();
// return pengine->newVariant(QLocale(locale).toCurrencyString(value.toDouble()));
//}
//QScriptValue currencyUSBasedFormat(QScriptContext* pcontext, QScriptEngine* pengine){
// QVariant value = pcontext->argument(0).toVariant();
// QString CurrencySymbol = (pcontext->argumentCount()>1)?pcontext->argument(1).toString():QLocale::system().currencySymbol();
// // Format it using USA locale
// QString vTempStr=QLocale(QLocale::English, QLocale::UnitedStates).toCurrencyString(value.toDouble());
// // Replace currency symbol if necesarry
// if (CurrencySymbol!="") vTempStr.replace("$", CurrencySymbol);
// return pengine->newVariant(vTempStr);
//}
//#endif
//QScriptValue dateFormat(QScriptContext* pcontext, QScriptEngine* pengine){
// QVariant value = pcontext->argument(0).toVariant();
// QString format = (pcontext->argumentCount()>1)?pcontext->argument(1).toString().toLatin1():"dd.MM.yyyy";
// QScriptValue res = pengine->newVariant(QLocale().toString(value.toDate(),format));
// return res;
//}
//QScriptValue timeFormat(QScriptContext* pcontext, QScriptEngine* pengine){
// QVariant value = pcontext->argument(0).toVariant();
// QString format = (pcontext->argumentCount()>1)?pcontext->argument(1).toString().toLatin1():"hh:mm";
// QScriptValue res = pengine->newVariant(QLocale().toString(value.toTime(),format));
// return res;
//}
//QScriptValue dateTimeFormat(QScriptContext* pcontext, QScriptEngine* pengine){
// QVariant value = pcontext->argument(0).toVariant();
// QString format = (pcontext->argumentCount()>1)?pcontext->argument(1).toString().toLatin1():"dd.MM.yyyy hh:mm";
// QScriptValue res = pengine->newVariant(QLocale().toString(value.toDateTime(),format));
// return res;
//}
//QScriptValue now(QScriptContext* /*pcontext*/, QScriptEngine* pengine){
// return pengine->newVariant(QDateTime::currentDateTime());
//}
//QScriptValue date(QScriptContext* /*pcontext*/, QScriptEngine* pengine){
// return pengine->newVariant(QDate::currentDate());
//}
//QScriptValue callGroupFunction(const QString& functionName, QScriptContext* pcontext, QScriptEngine* pengine){
// ScriptEngineManager* sm = qscriptvalue_cast<ScriptEngineManager*>(pcontext->callee().data());
// DataSourceManager* dm = sm->dataManager();
// QString expression;
// QString band;
// if (functionName.compare("COUNT",Qt::CaseInsensitive) == 0 && pcontext->argumentCount()==1){
// expression = " ";
// band = pcontext->argument(0).toString();
// } else {
// expression = dm->getExpression(pcontext->argument(0).toString());
// band = pcontext->argument(1).toString();
// }
// QScriptValue res;
// GroupFunction* gf = dm->groupFunction(functionName,expression,band);
// if (gf){
// if (gf->isValid()){
// res=pengine->newVariant(gf->calculate());
// }else{
// res=pengine->newVariant(gf->error());
// }
// }
// else {
// res=pengine->newVariant(QString(QObject::tr("Function %1 not found or have wrong arguments").arg(functionName)));
// }
// return res;
//}
//QScriptValue groupFunction(QScriptContext* pcontext, QScriptEngine* pengine){
// return callGroupFunction(pcontext->callee().property("functionName").toString(),pcontext,pengine);
//}
ScriptEngineManager::~ScriptEngineManager() ScriptEngineManager::~ScriptEngineManager()
{ {
delete m_model; delete m_model;
@ -896,20 +761,6 @@ ScriptEngineManager::ScriptEngineManager()
createSetVariableFunction(); createSetVariableFunction();
createGetFieldFunction(); createGetFieldFunction();
createGetVariableFunction(); createGetVariableFunction();
// addFunction("line",line,"SYSTEM", "line(\""+tr("BandName")+"\")");
// addFunction("numberFormat",numberFormat,"NUMBER", "numberFormat(\""+tr("Value")+"\",\""+tr("Format")+"\",\""+
// tr("Precision")+"\",\""+
// tr("Locale")+"\")");
// addFunction("dateFormat",dateFormat,"DATE&TIME", "dateFormat(\""+tr("Value")+"\",\""+tr("Format")+"\")");
// addFunction("timeFormat",timeFormat,"DATE&TIME", "dateFormat(\""+tr("Value")+"\",\""+tr("Format")+"\")");
// addFunction("dateTimeFormat", dateTimeFormat, "DATE&TIME", "dateTimeFormat(\""+tr("Value")+"\",\""+tr("Format")+"\")");
// addFunction("date",date,"DATE&TIME","date()");
// addFunction("now",now,"DATE&TIME","now()");
// addFunction("currencyFormat",currencyFormat,"NUMBER","currencyFormat(\""+tr("Value")+"\",\""+tr("Locale")+"\")");
// addFunction("currencyUSBasedFormat",currencyUSBasedFormat,"NUMBER","currencyUSBasedFormat(\""+tr("Value")+",\""+tr("CurrencySymbol")+"\")");
// addFunction("setVariable", setVariable, "GENERAL", "setVariable(\""+tr("Name")+"\",\""+tr("Value")+"\")");
#ifndef USE_QJSENGINE #ifndef USE_QJSENGINE
QScriptValue colorCtor = m_scriptEngine->newFunction(constructColor); QScriptValue colorCtor = m_scriptEngine->newFunction(constructColor);
m_scriptEngine->globalObject().setProperty("QColor", colorCtor); m_scriptEngine->globalObject().setProperty("QColor", colorCtor);
@ -919,15 +770,6 @@ ScriptEngineManager::ScriptEngineManager()
QScriptValue fontConstructor = m_scriptEngine->newFunction(QFontPrototype::constructorQFont, fontProto); QScriptValue fontConstructor = m_scriptEngine->newFunction(QFontPrototype::constructorQFont, fontProto);
m_scriptEngine->globalObject().setProperty("QFont", fontConstructor); m_scriptEngine->globalObject().setProperty("QFont", fontConstructor);
#endif #endif
// foreach(QString func, dataManager()->groupFunctionNames()){
// addFunction(func, groupFunction,"GROUP FUNCTIONS", func+"(\""+tr("FieldName")+"\",\""+tr("BandName")+"\")");
// }
// foreach(ScriptFunctionDesc func, m_functions){
// if (func.type==ScriptFunctionDesc::Native)
// m_scriptEngine->globalObject().setProperty(func.name,func.scriptValue);
// }
m_model = new ScriptEngineModel(this); m_model = new ScriptEngineModel(this);
} }
@ -1275,6 +1117,93 @@ QString ScriptEngineContext::getNewDialogName()
} }
#endif #endif
void ScriptEngineContext::baseDesignIntfToScript(BaseDesignIntf* item)
{
if ( item ) {
if (item->metaObject()->indexOfSignal("beforeRender()")!=-1)
item->disconnect(SIGNAL(beforeRender()));
if (item->metaObject()->indexOfSignal("afterData()")!=-1)
item->disconnect(SIGNAL(afterData()));
if (item->metaObject()->indexOfSignal("afterRender()")!=-1)
item->disconnect(SIGNAL(afterRender()));
ScriptEngineType* engine = ScriptEngineManager::instance().scriptEngine();
#ifdef USE_QJSENGINE
//sItem = engine->newQObject(item);
ScriptValueType sItem = getCppOwnedJSValue(*engine, item);
engine->globalObject().setProperty(item->patternName(), sItem);
#else
ScriptValueType sItem = engine->globalObject().property(item->patternName());
if (sItem.isValid()){
engine->newQObject(sItem, item);
} else {
sItem = engine->newQObject(item);
engine->globalObject().setProperty(item->patternName(),sItem);
}
#endif
foreach(BaseDesignIntf* child, item->childBaseItems()){
baseDesignIntfToScript(child);
}
}
}
#ifdef HAVE_UI_LOADER
#ifdef USE_QJSENGINE
void registerChildObjects(ScriptEngineType* se, ScriptValueType* sv){
foreach(QObject* obj, sv->toQObject()->children()){
ScriptValueType child = se->newQObject(obj);
sv->setProperty(obj->objectName(),child);
registerChildObjects(se, &child);
}
}
#endif
void ScriptEngineContext::initDialogs(){
ScriptEngineType* se = ScriptEngineManager::instance().scriptEngine();
foreach(DialogDescriber::Ptr dialog, dialogDescribers()){
ScriptValueType sv = se->newQObject(getDialog(dialog->name()));
#ifdef USE_QJSENGINE
registerChildObjects(se,&sv);
#endif
se->globalObject().setProperty(dialog->name(),sv);
}
}
#endif
bool ScriptEngineContext::runInitScript(){
ScriptEngineType* engine = ScriptEngineManager::instance().scriptEngine();
#ifndef USE_QJSENGINE
engine->pushContext();
#endif
ScriptValueType res = engine->evaluate(initScript());
if (res.isBool()) return res.toBool();
#ifdef USE_QJSENGINE
if (res.isError()){
QMessageBox::critical(0,tr("Error"),
QString("Line %1: %2 ").arg(res.property("lineNumber").toString())
.arg(res.toString())
);
return false;
}
#else
if (engine->hasUncaughtException()) {
QMessageBox::critical(0,tr("Error"),
QString("Line %1: %2 ").arg(engine->uncaughtExceptionLineNumber())
.arg(engine->uncaughtException().toString())
);
return false;
}
#endif
return true;
}
QString ScriptEngineContext::initScript() const QString ScriptEngineContext::initScript() const
{ {
return m_initScript; return m_initScript;

View File

@ -54,6 +54,7 @@
namespace LimeReport{ namespace LimeReport{
class DataSourceManager; class DataSourceManager;
class BaseDesignIntf;
struct ScriptFunctionDesc{ struct ScriptFunctionDesc{
enum FuncType {Native,Script}; enum FuncType {Native,Script};
@ -153,14 +154,19 @@ public:
void deleteDialog(const QString& dialogName); void deleteDialog(const QString& dialogName);
QDialog *getDialog(const QString &dialogName); QDialog *getDialog(const QString &dialogName);
QString getNewDialogName(); QString getNewDialogName();
void initDialogs();
#endif #endif
void baseDesignIntfToScript(BaseDesignIntf *item);
void clear(); void clear();
QString initScript() const; QString initScript() const;
void setInitScript(const QString& initScript); void setInitScript(const QString& initScript);
bool runInitScript();
#ifdef HAVE_UI_LOADER
signals: signals:
void dialogNameChanged(QString dialogName); void dialogNameChanged(QString dialogName);
void dialogDeleted(QString dialogName); void dialogDeleted(QString dialogName);
void dialogAdded(QString dialogName); void dialogAdded(QString dialogName);
#endif
protected: protected:
QObject* createElement(const QString& collectionName,const QString& elementType); QObject* createElement(const QString& collectionName,const QString& elementType);
int elementsCount(const QString& collectionName); int elementsCount(const QString& collectionName);

View File

@ -59,7 +59,9 @@ void ScriptBrowser::setReportEditor(ReportDesignWidget* report)
m_report=report; m_report=report;
connect(m_report,SIGNAL(cleared()),this,SLOT(slotClear())); connect(m_report,SIGNAL(cleared()),this,SLOT(slotClear()));
connect(m_report,SIGNAL(loaded()),this,SLOT(slotUpdate())); connect(m_report,SIGNAL(loaded()),this,SLOT(slotUpdate()));
#ifdef HAVE_UI_LOADER
connect(m_report->scriptContext(), SIGNAL(dialogAdded(QString)), this, SLOT(slotDialogAdded(QString))); connect(m_report->scriptContext(), SIGNAL(dialogAdded(QString)), this, SLOT(slotDialogAdded(QString)));
#endif
updateFunctionTree(); updateFunctionTree();
} }
@ -139,12 +141,13 @@ void ScriptBrowser::slotUpdate()
updateFunctionTree(); updateFunctionTree();
} }
#ifdef HAVE_UI_LOADER
void ScriptBrowser::slotDialogAdded(QString) void ScriptBrowser::slotDialogAdded(QString)
{ {
updateDialogsTree(); updateDialogsTree();
} }
#ifdef HAVE_UI_LOADER
void ScriptBrowser::on_tbAddDialog_clicked() void ScriptBrowser::on_tbAddDialog_clicked()
{ {
QFileDialog fileDialog(this); QFileDialog fileDialog(this);

View File

@ -62,8 +62,8 @@ protected:
private slots: private slots:
void slotClear(); void slotClear();
void slotUpdate(); void slotUpdate();
void slotDialogAdded(QString);
#ifdef HAVE_UI_LOADER #ifdef HAVE_UI_LOADER
void slotDialogAdded(QString);
void on_tbAddDialog_clicked(); void on_tbAddDialog_clicked();
void on_tbRunDialog_clicked(); void on_tbRunDialog_clicked();
void on_tbDeleteDialog_clicked(); void on_tbDeleteDialog_clicked();