mirror of
https://github.com/python-LimeReport/LimeReport.git
synced 2024-12-24 12:34:39 +03:00
QJSEngine -> QQmlEngine
This commit is contained in:
parent
c37a310918
commit
7406789cbb
@ -43,7 +43,8 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_QJSENGINE
|
#ifdef USE_QJSENGINE
|
||||||
#include <QJSEngine>
|
//#include <QJSEngine>
|
||||||
|
#include <QQmlEngine>
|
||||||
#else
|
#else
|
||||||
#include <QScriptEngine>
|
#include <QScriptEngine>
|
||||||
#endif
|
#endif
|
||||||
@ -138,8 +139,15 @@ namespace Const{
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_QJSENGINE
|
#ifdef USE_QJSENGINE
|
||||||
typedef QJSEngine ScriptEngineType;
|
typedef QQmlEngine ScriptEngineType;
|
||||||
typedef QJSValue ScriptValueType;
|
typedef QJSValue ScriptValueType;
|
||||||
|
template <typename T>
|
||||||
|
static inline QJSValue getCppOwnedJSValue(QJSEngine &e, T *p)
|
||||||
|
{
|
||||||
|
QJSValue res = e.newQObject(p);
|
||||||
|
QQmlEngine::setObjectOwnership(p, QQmlEngine::CppOwnership);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
typedef QScriptEngine ScriptEngineType;
|
typedef QScriptEngine ScriptEngineType;
|
||||||
typedef QScriptValue ScriptValueType;
|
typedef QScriptValue ScriptValueType;
|
||||||
|
@ -43,7 +43,8 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_QJSENGINE
|
#ifdef USE_QJSENGINE
|
||||||
#include <QJSEngine>
|
//#include <QJSEngine>
|
||||||
|
#include <QQmlEngine>
|
||||||
#else
|
#else
|
||||||
#include <QScriptEngine>
|
#include <QScriptEngine>
|
||||||
#endif
|
#endif
|
||||||
@ -138,8 +139,15 @@ namespace Const{
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef USE_QJSENGINE
|
#ifdef USE_QJSENGINE
|
||||||
typedef QJSEngine ScriptEngineType;
|
typedef QQmlEngine ScriptEngineType;
|
||||||
typedef QJSValue ScriptValueType;
|
typedef QJSValue ScriptValueType;
|
||||||
|
template <typename T>
|
||||||
|
static inline QJSValue getCppOwnedJSValue(QJSEngine &e, T *p)
|
||||||
|
{
|
||||||
|
QJSValue res = e.newQObject(p);
|
||||||
|
QQmlEngine::setObjectOwnership(p, QQmlEngine::CppOwnership);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
typedef QScriptEngine ScriptEngineType;
|
typedef QScriptEngine ScriptEngineType;
|
||||||
typedef QScriptValue ScriptValueType;
|
typedef QScriptValue ScriptValueType;
|
||||||
|
@ -167,17 +167,29 @@ void ReportRender::setScriptContext(ScriptEngineContext* scriptContext)
|
|||||||
|
|
||||||
bool ReportRender::runInitScript(){
|
bool ReportRender::runInitScript(){
|
||||||
if (m_scriptEngineContext){
|
if (m_scriptEngineContext){
|
||||||
QScriptEngine* engine = ScriptEngineManager::instance().scriptEngine();
|
ScriptEngineType* engine = ScriptEngineManager::instance().scriptEngine();
|
||||||
|
#ifndef USE_QJSENGINE
|
||||||
engine->pushContext();
|
engine->pushContext();
|
||||||
QScriptValue res = engine->evaluate(m_scriptEngineContext->initScript());
|
#endif
|
||||||
|
ScriptValueType res = engine->evaluate(m_scriptEngineContext->initScript());
|
||||||
if (res.isBool()) return res.toBool();
|
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()) {
|
if (engine->hasUncaughtException()) {
|
||||||
QMessageBox::critical(0,tr("Error"),
|
QMessageBox::critical(0,tr("Error"),
|
||||||
QString("Line %1: %2 ").arg(engine->uncaughtExceptionLineNumber())
|
QString("Line %1: %2 ").arg(engine->uncaughtExceptionLineNumber())
|
||||||
.arg(engine->uncaughtException().toString())
|
.arg(engine->uncaughtException().toString())
|
||||||
);
|
);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -269,8 +281,9 @@ void ReportRender::renderPage(PageDesignIntf* patternPage)
|
|||||||
renderBand(tearOffBand, 0, StartNewPageAsNeeded);
|
renderBand(tearOffBand, 0, StartNewPageAsNeeded);
|
||||||
|
|
||||||
savePage(true);
|
savePage(true);
|
||||||
|
#ifndef USE_QJSENGINE
|
||||||
ScriptEngineManager::instance().scriptEngine()->popContext();
|
ScriptEngineManager::instance().scriptEngine()->popContext();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1262,18 +1275,26 @@ void ReportRender::baseDesignIntfToScript(BaseDesignIntf *item)
|
|||||||
if (item->metaObject()->indexOfSignal("afterRender()")!=-1)
|
if (item->metaObject()->indexOfSignal("afterRender()")!=-1)
|
||||||
item->disconnect(SIGNAL(afterRender()));
|
item->disconnect(SIGNAL(afterRender()));
|
||||||
|
|
||||||
QScriptEngine* engine = ScriptEngineManager::instance().scriptEngine();
|
ScriptEngineType* engine = ScriptEngineManager::instance().scriptEngine();
|
||||||
QScriptValue sItem = engine->globalObject().property(item->patternName());
|
|
||||||
|
#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()){
|
if (sItem.isValid()){
|
||||||
engine->newQObject(sItem, item);
|
engine->newQObject(sItem, item);
|
||||||
} else {
|
} else {
|
||||||
sItem = engine->newQObject(item);
|
sItem = engine->newQObject(item);
|
||||||
engine->globalObject().setProperty(item->patternName(),sItem);
|
engine->globalObject().setProperty(item->patternName(),sItem);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
foreach(BaseDesignIntf* child, item->childBaseItems()){
|
foreach(BaseDesignIntf* child, item->childBaseItems()){
|
||||||
baseDesignIntfToScript(child);
|
baseDesignIntfToScript(child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -196,141 +196,141 @@ void ScriptEngineModel::updateModel()
|
|||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
QScriptValue line(QScriptContext* pcontext, QScriptEngine* pengine){
|
//QScriptValue line(QScriptContext* pcontext, QScriptEngine* pengine){
|
||||||
ScriptEngineManager* sm = qscriptvalue_cast<ScriptEngineManager*>(pcontext->callee().data());
|
// ScriptEngineManager* sm = qscriptvalue_cast<ScriptEngineManager*>(pcontext->callee().data());
|
||||||
DataSourceManager* dm = sm->dataManager();
|
// DataSourceManager* dm = sm->dataManager();
|
||||||
QString band = pcontext->argument(0).toString();
|
// QString band = pcontext->argument(0).toString();
|
||||||
QScriptValue res;
|
// QScriptValue res;
|
||||||
QString varName = QLatin1String("line_")+band.toLower();
|
// QString varName = QLatin1String("line_")+band.toLower();
|
||||||
if (dm->variable(varName).isValid()){
|
// if (dm->variable(varName).isValid()){
|
||||||
res=pengine->newVariant(dm->variable(varName));
|
// res=pengine->newVariant(dm->variable(varName));
|
||||||
} else res=pengine->newVariant(QString("Variable line for band %1 not found").arg(band));
|
// } else res=pengine->newVariant(QString("Variable line for band %1 not found").arg(band));
|
||||||
return res;
|
// return res;
|
||||||
}
|
//}
|
||||||
|
|
||||||
QScriptValue setVariable(QScriptContext* pcontext, QScriptEngine* /*pengine*/){
|
//QScriptValue setVariable(QScriptContext* pcontext, QScriptEngine* /*pengine*/){
|
||||||
|
|
||||||
QString name = pcontext->argument(0).toString();
|
// QString name = pcontext->argument(0).toString();
|
||||||
QVariant value = pcontext->argument(1).toVariant();
|
// QVariant value = pcontext->argument(1).toVariant();
|
||||||
|
|
||||||
ScriptEngineManager* sm = qscriptvalue_cast<ScriptEngineManager*>(pcontext->callee().data());
|
// ScriptEngineManager* sm = qscriptvalue_cast<ScriptEngineManager*>(pcontext->callee().data());
|
||||||
DataSourceManager* dm = sm->dataManager();
|
// DataSourceManager* dm = sm->dataManager();
|
||||||
|
|
||||||
dm->changeVariable(name,value);
|
// dm->changeVariable(name,value);
|
||||||
return QScriptValue();
|
// return QScriptValue();
|
||||||
}
|
//}
|
||||||
|
|
||||||
QScriptValue getVariable(QScriptContext* pcontext, QScriptEngine* pengine){
|
//QScriptValue getVariable(QScriptContext* pcontext, QScriptEngine* pengine){
|
||||||
|
|
||||||
QString name = pcontext->argument(0).toString();
|
// QString name = pcontext->argument(0).toString();
|
||||||
|
|
||||||
ScriptEngineManager* sm = qscriptvalue_cast<ScriptEngineManager*>(pcontext->callee().data());
|
// ScriptEngineManager* sm = qscriptvalue_cast<ScriptEngineManager*>(pcontext->callee().data());
|
||||||
DataSourceManager* dm = sm->dataManager();
|
// DataSourceManager* dm = sm->dataManager();
|
||||||
QScriptValue res = pengine->newVariant(dm->variable(name));
|
// QScriptValue res = pengine->newVariant(dm->variable(name));
|
||||||
|
|
||||||
return res;
|
// return res;
|
||||||
}
|
//}
|
||||||
|
|
||||||
QScriptValue getField(QScriptContext* pcontext, QScriptEngine* pengine){
|
//QScriptValue getField(QScriptContext* pcontext, QScriptEngine* pengine){
|
||||||
|
|
||||||
QString name = pcontext->argument(0).toString();
|
// QString name = pcontext->argument(0).toString();
|
||||||
|
|
||||||
ScriptEngineManager* sm = qscriptvalue_cast<ScriptEngineManager*>(pcontext->callee().data());
|
// ScriptEngineManager* sm = qscriptvalue_cast<ScriptEngineManager*>(pcontext->callee().data());
|
||||||
DataSourceManager* dm = sm->dataManager();
|
// DataSourceManager* dm = sm->dataManager();
|
||||||
QScriptValue res = pengine->newVariant(dm->fieldData(name));
|
// QScriptValue res = pengine->newVariant(dm->fieldData(name));
|
||||||
|
|
||||||
return res;
|
// return res;
|
||||||
}
|
//}
|
||||||
|
|
||||||
QScriptValue numberFormat(QScriptContext* pcontext, QScriptEngine* pengine){
|
//QScriptValue numberFormat(QScriptContext* pcontext, QScriptEngine* pengine){
|
||||||
QVariant value = pcontext->argument(0).toVariant();
|
// QVariant value = pcontext->argument(0).toVariant();
|
||||||
char format = (pcontext->argumentCount()>1)?pcontext->argument(1).toString()[0].toLatin1():'f';
|
// char format = (pcontext->argumentCount()>1)?pcontext->argument(1).toString()[0].toLatin1():'f';
|
||||||
int precision = (pcontext->argumentCount()>2)?pcontext->argument(2).toInt32():2;
|
// int precision = (pcontext->argumentCount()>2)?pcontext->argument(2).toInt32():2;
|
||||||
QString locale = (pcontext->argumentCount()>3)?pcontext->argument(3).toString():"";
|
// QString locale = (pcontext->argumentCount()>3)?pcontext->argument(3).toString():"";
|
||||||
QScriptValue res = (locale.isEmpty())?pengine->newVariant(QString::number(value.toDouble(),format,precision)):
|
// QScriptValue res = (locale.isEmpty())?pengine->newVariant(QString::number(value.toDouble(),format,precision)):
|
||||||
pengine->newVariant(QLocale(locale).toString(value.toDouble(),format,precision));
|
// pengine->newVariant(QLocale(locale).toString(value.toDouble(),format,precision));
|
||||||
return res;
|
// return res;
|
||||||
}
|
//}
|
||||||
#if QT_VERSION>0x040800
|
//#if QT_VERSION>0x040800
|
||||||
QScriptValue currencyFormat(QScriptContext* pcontext, QScriptEngine* pengine){
|
//QScriptValue currencyFormat(QScriptContext* pcontext, QScriptEngine* pengine){
|
||||||
QVariant value = pcontext->argument(0).toVariant();
|
// QVariant value = pcontext->argument(0).toVariant();
|
||||||
QString locale = (pcontext->argumentCount()>1)?pcontext->argument(1).toString():QLocale::system().name();
|
// QString locale = (pcontext->argumentCount()>1)?pcontext->argument(1).toString():QLocale::system().name();
|
||||||
return pengine->newVariant(QLocale(locale).toCurrencyString(value.toDouble()));
|
// return pengine->newVariant(QLocale(locale).toCurrencyString(value.toDouble()));
|
||||||
}
|
//}
|
||||||
|
|
||||||
QScriptValue currencyUSBasedFormat(QScriptContext* pcontext, QScriptEngine* pengine){
|
//QScriptValue currencyUSBasedFormat(QScriptContext* pcontext, QScriptEngine* pengine){
|
||||||
QVariant value = pcontext->argument(0).toVariant();
|
// QVariant value = pcontext->argument(0).toVariant();
|
||||||
QString CurrencySymbol = (pcontext->argumentCount()>1)?pcontext->argument(1).toString():QLocale::system().currencySymbol();
|
// QString CurrencySymbol = (pcontext->argumentCount()>1)?pcontext->argument(1).toString():QLocale::system().currencySymbol();
|
||||||
// Format it using USA locale
|
// // Format it using USA locale
|
||||||
QString vTempStr=QLocale(QLocale::English, QLocale::UnitedStates).toCurrencyString(value.toDouble());
|
// QString vTempStr=QLocale(QLocale::English, QLocale::UnitedStates).toCurrencyString(value.toDouble());
|
||||||
// Replace currency symbol if necesarry
|
// // Replace currency symbol if necesarry
|
||||||
if (CurrencySymbol!="") vTempStr.replace("$", CurrencySymbol);
|
// if (CurrencySymbol!="") vTempStr.replace("$", CurrencySymbol);
|
||||||
return pengine->newVariant(vTempStr);
|
// return pengine->newVariant(vTempStr);
|
||||||
}
|
//}
|
||||||
#endif
|
//#endif
|
||||||
QScriptValue dateFormat(QScriptContext* pcontext, QScriptEngine* pengine){
|
//QScriptValue dateFormat(QScriptContext* pcontext, QScriptEngine* pengine){
|
||||||
QVariant value = pcontext->argument(0).toVariant();
|
// QVariant value = pcontext->argument(0).toVariant();
|
||||||
QString format = (pcontext->argumentCount()>1)?pcontext->argument(1).toString().toLatin1():"dd.MM.yyyy";
|
// QString format = (pcontext->argumentCount()>1)?pcontext->argument(1).toString().toLatin1():"dd.MM.yyyy";
|
||||||
QScriptValue res = pengine->newVariant(QLocale().toString(value.toDate(),format));
|
// QScriptValue res = pengine->newVariant(QLocale().toString(value.toDate(),format));
|
||||||
return res;
|
// return res;
|
||||||
}
|
//}
|
||||||
|
|
||||||
QScriptValue timeFormat(QScriptContext* pcontext, QScriptEngine* pengine){
|
//QScriptValue timeFormat(QScriptContext* pcontext, QScriptEngine* pengine){
|
||||||
QVariant value = pcontext->argument(0).toVariant();
|
// QVariant value = pcontext->argument(0).toVariant();
|
||||||
QString format = (pcontext->argumentCount()>1)?pcontext->argument(1).toString().toLatin1():"hh:mm";
|
// QString format = (pcontext->argumentCount()>1)?pcontext->argument(1).toString().toLatin1():"hh:mm";
|
||||||
QScriptValue res = pengine->newVariant(QLocale().toString(value.toTime(),format));
|
// QScriptValue res = pengine->newVariant(QLocale().toString(value.toTime(),format));
|
||||||
return res;
|
// return res;
|
||||||
}
|
//}
|
||||||
|
|
||||||
QScriptValue dateTimeFormat(QScriptContext* pcontext, QScriptEngine* pengine){
|
//QScriptValue dateTimeFormat(QScriptContext* pcontext, QScriptEngine* pengine){
|
||||||
QVariant value = pcontext->argument(0).toVariant();
|
// QVariant value = pcontext->argument(0).toVariant();
|
||||||
QString format = (pcontext->argumentCount()>1)?pcontext->argument(1).toString().toLatin1():"dd.MM.yyyy hh:mm";
|
// QString format = (pcontext->argumentCount()>1)?pcontext->argument(1).toString().toLatin1():"dd.MM.yyyy hh:mm";
|
||||||
QScriptValue res = pengine->newVariant(QLocale().toString(value.toDateTime(),format));
|
// QScriptValue res = pengine->newVariant(QLocale().toString(value.toDateTime(),format));
|
||||||
return res;
|
// return res;
|
||||||
}
|
//}
|
||||||
|
|
||||||
QScriptValue now(QScriptContext* /*pcontext*/, QScriptEngine* pengine){
|
//QScriptValue now(QScriptContext* /*pcontext*/, QScriptEngine* pengine){
|
||||||
return pengine->newVariant(QDateTime::currentDateTime());
|
// return pengine->newVariant(QDateTime::currentDateTime());
|
||||||
}
|
//}
|
||||||
|
|
||||||
QScriptValue date(QScriptContext* /*pcontext*/, QScriptEngine* pengine){
|
//QScriptValue date(QScriptContext* /*pcontext*/, QScriptEngine* pengine){
|
||||||
return pengine->newVariant(QDate::currentDate());
|
// return pengine->newVariant(QDate::currentDate());
|
||||||
}
|
//}
|
||||||
|
|
||||||
QScriptValue callGroupFunction(const QString& functionName, QScriptContext* pcontext, QScriptEngine* pengine){
|
//QScriptValue callGroupFunction(const QString& functionName, QScriptContext* pcontext, QScriptEngine* pengine){
|
||||||
|
|
||||||
ScriptEngineManager* sm = qscriptvalue_cast<ScriptEngineManager*>(pcontext->callee().data());
|
// ScriptEngineManager* sm = qscriptvalue_cast<ScriptEngineManager*>(pcontext->callee().data());
|
||||||
DataSourceManager* dm = sm->dataManager();
|
// DataSourceManager* dm = sm->dataManager();
|
||||||
|
|
||||||
QString expression;
|
// QString expression;
|
||||||
QString band;
|
// QString band;
|
||||||
|
|
||||||
if (functionName.compare("COUNT",Qt::CaseInsensitive) == 0 && pcontext->argumentCount()==1){
|
// if (functionName.compare("COUNT",Qt::CaseInsensitive) == 0 && pcontext->argumentCount()==1){
|
||||||
expression = " ";
|
// expression = " ";
|
||||||
band = pcontext->argument(0).toString();
|
// band = pcontext->argument(0).toString();
|
||||||
} else {
|
// } else {
|
||||||
expression = dm->getExpression(pcontext->argument(0).toString());
|
// expression = dm->getExpression(pcontext->argument(0).toString());
|
||||||
band = pcontext->argument(1).toString();
|
// band = pcontext->argument(1).toString();
|
||||||
}
|
// }
|
||||||
|
|
||||||
QScriptValue res;
|
// QScriptValue res;
|
||||||
GroupFunction* gf = dm->groupFunction(functionName,expression,band);
|
// GroupFunction* gf = dm->groupFunction(functionName,expression,band);
|
||||||
if (gf){
|
// if (gf){
|
||||||
if (gf->isValid()){
|
// if (gf->isValid()){
|
||||||
res=pengine->newVariant(gf->calculate());
|
// res=pengine->newVariant(gf->calculate());
|
||||||
}else{
|
// }else{
|
||||||
res=pengine->newVariant(gf->error());
|
// res=pengine->newVariant(gf->error());
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
else {
|
// else {
|
||||||
res=pengine->newVariant(QString(QObject::tr("Function %1 not found or have wrong arguments").arg(functionName)));
|
// res=pengine->newVariant(QString(QObject::tr("Function %1 not found or have wrong arguments").arg(functionName)));
|
||||||
}
|
// }
|
||||||
return res;
|
// return res;
|
||||||
}
|
//}
|
||||||
|
|
||||||
QScriptValue groupFunction(QScriptContext* pcontext, QScriptEngine* pengine){
|
//QScriptValue groupFunction(QScriptContext* pcontext, QScriptEngine* pengine){
|
||||||
return callGroupFunction(pcontext->callee().property("functionName").toString(),pcontext,pengine);
|
// return callGroupFunction(pcontext->callee().property("functionName").toString(),pcontext,pengine);
|
||||||
}
|
//}
|
||||||
|
|
||||||
ScriptEngineManager::~ScriptEngineManager()
|
ScriptEngineManager::~ScriptEngineManager()
|
||||||
{
|
{
|
||||||
@ -589,16 +589,24 @@ QString ScriptEngineManager::expandScripts(QString context, QVariant& varValue,
|
|||||||
if (ScriptEngineManager::instance().dataManager()!=dataManager())
|
if (ScriptEngineManager::instance().dataManager()!=dataManager())
|
||||||
ScriptEngineManager::instance().setDataManager(dataManager());
|
ScriptEngineManager::instance().setDataManager(dataManager());
|
||||||
|
|
||||||
QScriptEngine* se = ScriptEngineManager::instance().scriptEngine();
|
ScriptEngineType* se = ScriptEngineManager::instance().scriptEngine();
|
||||||
|
|
||||||
if (reportItem){
|
if (reportItem){
|
||||||
QScriptValue svThis = se->globalObject().property("THIS");
|
|
||||||
|
ScriptValueType svThis;
|
||||||
|
|
||||||
|
#ifdef USE_QJSENGINE
|
||||||
|
svThis = getCppOwnedJSValue(*se, reportItem);
|
||||||
|
se->globalObject().setProperty("THIS",svThis);
|
||||||
|
#else
|
||||||
|
svThis = se->globalObject().property("THIS");
|
||||||
if (svThis.isValid()){
|
if (svThis.isValid()){
|
||||||
se->newQObject(svThis, this);
|
se->newQObject(svThis, reportItem);
|
||||||
} else {
|
} else {
|
||||||
svThis = se->newQObject(this);
|
svThis = se->newQObject(reportItem);
|
||||||
se->globalObject().setProperty("THIS",svThis);
|
se->globalObject().setProperty("THIS",svThis);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptExtractor scriptExtractor(context);
|
ScriptExtractor scriptExtractor(context);
|
||||||
@ -606,16 +614,26 @@ QString ScriptEngineManager::expandScripts(QString context, QVariant& varValue,
|
|||||||
for(int i=0; i<scriptExtractor.count();++i){
|
for(int i=0; i<scriptExtractor.count();++i){
|
||||||
QString scriptBody = expandDataFields(scriptExtractor.bodyAt(i),EscapeSymbols, varValue, reportItem);
|
QString scriptBody = expandDataFields(scriptExtractor.bodyAt(i),EscapeSymbols, varValue, reportItem);
|
||||||
scriptBody = expandUserVariables(scriptBody, FirstPass, EscapeSymbols, varValue);
|
scriptBody = expandUserVariables(scriptBody, FirstPass, EscapeSymbols, varValue);
|
||||||
QScriptValue value = se->evaluate(scriptBody);
|
ScriptValueType value = se->evaluate(scriptBody);
|
||||||
|
#ifdef USE_QJSENGINE
|
||||||
|
if (!value.isError()){
|
||||||
|
varValue = value.toVariant();
|
||||||
|
context.replace(scriptExtractor.scriptAt(i),value.toString());
|
||||||
|
} else {
|
||||||
|
context.replace(scriptExtractor.scriptAt(i),value.toString());
|
||||||
|
}
|
||||||
|
#else
|
||||||
if (!se->hasUncaughtException()) {
|
if (!se->hasUncaughtException()) {
|
||||||
varValue = value.toVariant();
|
varValue = value.toVariant();
|
||||||
context.replace(scriptExtractor.scriptAt(i),value.toString());
|
context.replace(scriptExtractor.scriptAt(i),value.toString());
|
||||||
} else {
|
} else {
|
||||||
context.replace(scriptExtractor.scriptAt(i),se->uncaughtException().toString());
|
context.replace(scriptExtractor.scriptAt(i),se->uncaughtException().toString());
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -629,14 +647,18 @@ QVariant ScriptEngineManager::evaluateScript(const QString& script){
|
|||||||
if (ScriptEngineManager::instance().dataManager()!=dataManager())
|
if (ScriptEngineManager::instance().dataManager()!=dataManager())
|
||||||
ScriptEngineManager::instance().setDataManager(dataManager());
|
ScriptEngineManager::instance().setDataManager(dataManager());
|
||||||
|
|
||||||
QScriptEngine* se = ScriptEngineManager::instance().scriptEngine();
|
ScriptEngineType* se = ScriptEngineManager::instance().scriptEngine();
|
||||||
|
|
||||||
ScriptExtractor scriptExtractor(script);
|
ScriptExtractor scriptExtractor(script);
|
||||||
if (scriptExtractor.parse()){
|
if (scriptExtractor.parse()){
|
||||||
QString scriptBody = expandDataFields(scriptExtractor.bodyAt(0),EscapeSymbols, varValue, 0);
|
QString scriptBody = expandDataFields(scriptExtractor.bodyAt(0),EscapeSymbols, varValue, 0);
|
||||||
scriptBody = expandUserVariables(scriptBody, FirstPass, EscapeSymbols, varValue);
|
scriptBody = expandUserVariables(scriptBody, FirstPass, EscapeSymbols, varValue);
|
||||||
QScriptValue value = se->evaluate(scriptBody);
|
ScriptValueType value = se->evaluate(scriptBody);
|
||||||
|
#ifdef USE_QJSENGINE
|
||||||
|
if (!value.isError()){
|
||||||
|
#else
|
||||||
if (!se->hasUncaughtException()) {
|
if (!se->hasUncaughtException()) {
|
||||||
|
#endif
|
||||||
return value.toVariant();
|
return value.toVariant();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -820,6 +842,36 @@ bool ScriptEngineManager::createSetVariableFunction(){
|
|||||||
return addFunction(fd);
|
return addFunction(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ScriptEngineManager::createGetVariableFunction()
|
||||||
|
{
|
||||||
|
JSFunctionDesc fd;
|
||||||
|
fd.setManager(m_functionManager);
|
||||||
|
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
|
||||||
|
fd.setCategory("GENERAL");
|
||||||
|
fd.setName("getVariable");
|
||||||
|
fd.setDescription("getVariable(\""+tr("Name")+"\")");
|
||||||
|
fd.setScriptWrapper(QString("function getVariable(name){"
|
||||||
|
"return %1.getVariable(name);}"
|
||||||
|
).arg(LimeReport::Const::FUNCTION_MANAGER_NAME)
|
||||||
|
);
|
||||||
|
return addFunction(fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ScriptEngineManager::createGetFieldFunction()
|
||||||
|
{
|
||||||
|
JSFunctionDesc fd;
|
||||||
|
fd.setManager(m_functionManager);
|
||||||
|
fd.setManagerName(LimeReport::Const::FUNCTION_MANAGER_NAME);
|
||||||
|
fd.setCategory("GENERAL");
|
||||||
|
fd.setName("getField");
|
||||||
|
fd.setDescription("getField(\""+tr("Name")+"\")");
|
||||||
|
fd.setScriptWrapper(QString("function getField(name){"
|
||||||
|
"return %1.getField(name);}"
|
||||||
|
).arg(LimeReport::Const::FUNCTION_MANAGER_NAME)
|
||||||
|
);
|
||||||
|
return addFunction(fd);
|
||||||
|
}
|
||||||
|
|
||||||
ScriptEngineManager::ScriptEngineManager()
|
ScriptEngineManager::ScriptEngineManager()
|
||||||
:m_model(0), m_dataManager(0)
|
:m_model(0), m_dataManager(0)
|
||||||
{
|
{
|
||||||
@ -839,6 +891,8 @@ ScriptEngineManager::ScriptEngineManager()
|
|||||||
createCurrencyUSBasedFormatFunction();
|
createCurrencyUSBasedFormatFunction();
|
||||||
#endif
|
#endif
|
||||||
createSetVariableFunction();
|
createSetVariableFunction();
|
||||||
|
createGetFieldFunction();
|
||||||
|
createGetVariableFunction();
|
||||||
|
|
||||||
// addFunction("line",line,"SYSTEM", "line(\""+tr("BandName")+"\")");
|
// addFunction("line",line,"SYSTEM", "line(\""+tr("BandName")+"\")");
|
||||||
// addFunction("numberFormat",numberFormat,"NUMBER", "numberFormat(\""+tr("Value")+"\",\""+tr("Format")+"\",\""+
|
// addFunction("numberFormat",numberFormat,"NUMBER", "numberFormat(\""+tr("Value")+"\",\""+tr("Format")+"\",\""+
|
||||||
@ -1235,10 +1289,17 @@ void JSFunctionDesc::setScriptWrapper(const QString &scriptWrapper)
|
|||||||
m_scriptWrapper = scriptWrapper;
|
m_scriptWrapper = scriptWrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant ScriptFunctionsManager::calcGroupFunction(const QString &name, const QString &fieldName, const QString &bandName)
|
QVariant ScriptFunctionsManager::calcGroupFunction(const QString &name, const QString &expressionID, const QString &bandName)
|
||||||
{
|
{
|
||||||
if (m_scriptEngineManager->dataManager()){
|
if (m_scriptEngineManager->dataManager()){
|
||||||
GroupFunction* gf = m_scriptEngineManager->dataManager()->groupFunction(name,fieldName,bandName);
|
QString expression = "";
|
||||||
|
if (name.compare("COUNT",Qt::CaseInsensitive) == 0){
|
||||||
|
expression = " ";
|
||||||
|
} else {
|
||||||
|
expression = m_scriptEngineManager->dataManager()->getExpression(expressionID);
|
||||||
|
}
|
||||||
|
|
||||||
|
GroupFunction* gf = m_scriptEngineManager->dataManager()->groupFunction(name,expression,bandName);
|
||||||
if (gf){
|
if (gf){
|
||||||
if (gf->isValid()){
|
if (gf->isValid()){
|
||||||
return gf->calculate();
|
return gf->calculate();
|
||||||
@ -1316,6 +1377,19 @@ void ScriptFunctionsManager::setVariable(const QString &name, QVariant value)
|
|||||||
DataSourceManager* dm = scriptEngineManager()->dataManager();
|
DataSourceManager* dm = scriptEngineManager()->dataManager();
|
||||||
dm->changeVariable(name,value);
|
dm->changeVariable(name,value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVariant ScriptFunctionsManager::getVariable(const QString &name)
|
||||||
|
{
|
||||||
|
DataSourceManager* dm = scriptEngineManager()->dataManager();
|
||||||
|
return dm->variable(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
QVariant ScriptFunctionsManager::getField(const QString &field)
|
||||||
|
{
|
||||||
|
DataSourceManager* dm = scriptEngineManager()->dataManager();
|
||||||
|
return dm->fieldData(field);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef USE_QJSENGINE
|
#ifdef USE_QJSENGINE
|
||||||
QFont ScriptFunctionsManager::font(const QString &family, int pointSize, bool bold, bool italic, bool underLine)
|
QFont ScriptFunctionsManager::font(const QString &family, int pointSize, bool bold, bool italic, bool underLine)
|
||||||
{
|
{
|
||||||
|
@ -216,7 +216,7 @@ class ScriptFunctionsManager : public QObject{
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit ScriptFunctionsManager(QObject* parent = 0):QObject(parent){}
|
explicit ScriptFunctionsManager(QObject* parent = 0):QObject(parent){}
|
||||||
Q_INVOKABLE QVariant calcGroupFunction(const QString& name, const QString& fieldName, const QString& bandName);
|
Q_INVOKABLE QVariant calcGroupFunction(const QString& name, const QString& expressionID, const QString& bandName);
|
||||||
Q_INVOKABLE QVariant line(const QString& bandName);
|
Q_INVOKABLE QVariant line(const QString& bandName);
|
||||||
Q_INVOKABLE QVariant numberFormat(QVariant value, const char &format, int precision, const QString &locale);
|
Q_INVOKABLE QVariant numberFormat(QVariant value, const char &format, int precision, const QString &locale);
|
||||||
Q_INVOKABLE QVariant dateFormat(QVariant value, const QString& format);
|
Q_INVOKABLE QVariant dateFormat(QVariant value, const QString& format);
|
||||||
@ -226,7 +226,9 @@ public:
|
|||||||
Q_INVOKABLE QVariant now();
|
Q_INVOKABLE QVariant now();
|
||||||
Q_INVOKABLE QVariant currencyFormat(QVariant value, const QString& locale);
|
Q_INVOKABLE QVariant currencyFormat(QVariant value, const QString& locale);
|
||||||
Q_INVOKABLE QVariant currencyUSBasedFormat(QVariant value, const QString& currencySymbol);
|
Q_INVOKABLE QVariant currencyUSBasedFormat(QVariant value, const QString& currencySymbol);
|
||||||
Q_INVOKABLE void setVariable(const QString& name, QVariant value);
|
Q_INVOKABLE void setVariable(const QString& name, QVariant value);
|
||||||
|
Q_INVOKABLE QVariant getVariable(const QString& name);
|
||||||
|
Q_INVOKABLE QVariant getField(const QString& field);
|
||||||
Q_INVOKABLE QVariant color(const QString& color){ return QColor(color);}
|
Q_INVOKABLE QVariant color(const QString& color){ return QColor(color);}
|
||||||
#ifdef USE_QJSENGINE
|
#ifdef USE_QJSENGINE
|
||||||
Q_INVOKABLE QFont font(const QString& family, int pointSize = -1, bool bold = false, bool italic = false, bool underLine = false);
|
Q_INVOKABLE QFont font(const QString& family, int pointSize = -1, bool bold = false, bool italic = false, bool underLine = false);
|
||||||
@ -283,6 +285,8 @@ private:
|
|||||||
bool createCurrencyFormatFunction();
|
bool createCurrencyFormatFunction();
|
||||||
bool createCurrencyUSBasedFormatFunction();
|
bool createCurrencyUSBasedFormatFunction();
|
||||||
bool createSetVariableFunction();
|
bool createSetVariableFunction();
|
||||||
|
bool createGetVariableFunction();
|
||||||
|
bool createGetFieldFunction();
|
||||||
private:
|
private:
|
||||||
ScriptEngineManager();
|
ScriptEngineManager();
|
||||||
ScriptEngineType* m_scriptEngine;
|
ScriptEngineType* m_scriptEngine;
|
||||||
|
Loading…
Reference in New Issue
Block a user