From db60ee67f1483fe7035235dd27c7d85bf8c31fc9 Mon Sep 17 00:00:00 2001 From: Arin Alexander Date: Mon, 25 Jul 2016 16:05:40 +0300 Subject: [PATCH] setVariable function has been added (Thanks to Muthu Samy) --- limereport/lrscriptenginemanager.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/limereport/lrscriptenginemanager.cpp b/limereport/lrscriptenginemanager.cpp index 1e3f264..0cba11c 100644 --- a/limereport/lrscriptenginemanager.cpp +++ b/limereport/lrscriptenginemanager.cpp @@ -203,6 +203,18 @@ QScriptValue line(QScriptContext* pcontext, QScriptEngine* pengine){ return res; } +QScriptValue setVariable(QScriptContext* pcontext, QScriptEngine* /*pengine*/){ + + QString name = pcontext->argument(0).toString(); + QVariant value = pcontext->argument(1).toVariant(); + + ScriptEngineManager* sm = qscriptvalue_cast(pcontext->callee().data()); + DataSourceManager* dm = sm->dataManager(); + + dm->changeVariable(name,value); + return QScriptValue(); +} + QScriptValue numberFormat(QScriptContext* pcontext, QScriptEngine* pengine){ QVariant value = pcontext->argument(0).toVariant(); char format = (pcontext->argumentCount()>1)?pcontext->argument(1).toString()[0].toLatin1():'f'; @@ -390,8 +402,9 @@ ScriptEngineManager::ScriptEngineManager() 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("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")+"\")"); QScriptValue colorCtor = m_scriptEngine->newFunction(constructColor); m_scriptEngine->globalObject().setProperty("QColor", colorCtor);