0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 08:34:38 +03:00

Merge branch 'master' into 1.4

# Conflicts:
#	limereport/lrscriptenginemanager.h
This commit is contained in:
Arin Alexander 2016-08-12 22:15:50 +04:00
commit 0a2d906a89
4 changed files with 43 additions and 27 deletions

View File

@ -37,9 +37,9 @@ namespace LimeReport{
class IScriptEngineManager{
public:
virtual QScriptEngine* scriptEngine() = 0;
virtual QScriptValue addFunction(const QString& name, QScriptEngine::FunctionSignature function,
virtual bool addFunction(const QString& name, QScriptEngine::FunctionSignature function,
const QString& category="", const QString& description="") = 0;
virtual QScriptValue addFunction(const QString &name, const QString& script,
virtual bool addFunction(const QString &name, const QString& script,
const QString &category="", const QString &description="") = 0;
virtual const QString& lastError() const = 0;
virtual ~IScriptEngineManager(){}

View File

@ -328,26 +328,40 @@ void ScriptEngineManager::deleteFunction(const QString &functionsName)
}
}
QScriptValue ScriptEngineManager::addFunction(const QString& name,
bool ScriptEngineManager::containsFunction(const QString& functionName){
foreach (ScriptFunctionDesc funct, m_functions) {
if (funct.name.compare(functionName)== 0){
return true;
}
}
return false;
}
bool ScriptEngineManager::addFunction(const QString& name,
QScriptEngine::FunctionSignature function,
const QString& category,
const QString& description)
{
ScriptFunctionDesc funct;
funct.name = name;
funct.description = description;
funct.category = category;
funct.scriptValue = scriptEngine()->newFunction(function);
funct.scriptValue.setProperty("functionName",name);
funct.scriptValue.setData(m_scriptEngine->toScriptValue(this));
funct.type = ScriptFunctionDesc::Native;
m_functions.append(funct);
if (m_model)
m_model->updateModel();
return funct.scriptValue;
if (!containsFunction(name)){
ScriptFunctionDesc funct;
funct.name = name;
funct.description = description;
funct.category = category;
funct.scriptValue = scriptEngine()->newFunction(function);
funct.scriptValue.setProperty("functionName",name);
funct.scriptValue.setData(m_scriptEngine->toScriptValue(this));
funct.type = ScriptFunctionDesc::Native;
m_functions.append(funct);
if (m_model)
m_model->updateModel();
m_scriptEngine->globalObject().setProperty(funct.name,funct.scriptValue);
return true;
} else {
return false;
}
}
QScriptValue ScriptEngineManager::addFunction(const QString& name, const QString& script, const QString& category, const QString& description)
bool ScriptEngineManager::addFunction(const QString& name, const QString& script, const QString& category, const QString& description)
{
QScriptSyntaxCheckResult cr = m_scriptEngine->checkSyntax(script);
if (cr.state() == QScriptSyntaxCheckResult::Valid){
@ -359,11 +373,11 @@ QScriptValue ScriptEngineManager::addFunction(const QString& name, const QString
funct.type = ScriptFunctionDesc::Script;
funct.scriptValue.setData(m_scriptEngine->toScriptValue(this));
m_functions.append(funct);
m_model->updateModel();
return funct.scriptValue;
m_model->updateModel();
return true;
} else {
m_lastError = cr.errorMessage();
return QScriptValue();
return false;
}
}
@ -428,10 +442,10 @@ ScriptEngineManager::ScriptEngineManager()
// 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);
}
// foreach(ScriptFunctionDesc func, m_functions){
// if (func.type==ScriptFunctionDesc::Native)
// m_scriptEngine->globalObject().setProperty(func.name,func.scriptValue);
// }
m_model = new ScriptEngineModel(this);

View File

@ -178,9 +178,9 @@ public:
friend class Singleton<ScriptEngineManager>;
bool isFunctionExists(const QString& functionName) const;
void deleteFunction(const QString& functionsName);
QScriptValue addFunction(const QString& name, QScriptEngine::FunctionSignature function,
bool addFunction(const QString& name, QScriptEngine::FunctionSignature function,
const QString& category="", const QString& description="");
QScriptValue addFunction(const QString &name, const QString& script,
bool addFunction(const QString &name, const QString& script,
const QString &category="", const QString &description="");
const QString& lastError() const {return m_lastError;}
QStringList functionsNames();
@ -189,8 +189,10 @@ public:
void setContext(ScriptEngineContext* context){m_context=context;}
DataSourceManager* dataManager() const {return m_dataManager;}
void setDataManager(DataSourceManager* dataManager);
protected:
void updateModel();
bool containsFunction(const QString &functionName);
private:
Q_DISABLE_COPY(ScriptEngineManager)
private:

View File

@ -37,9 +37,9 @@ namespace LimeReport{
class IScriptEngineManager{
public:
virtual QScriptEngine* scriptEngine() = 0;
virtual QScriptValue addFunction(const QString& name, QScriptEngine::FunctionSignature function,
virtual bool addFunction(const QString& name, QScriptEngine::FunctionSignature function,
const QString& category="", const QString& description="") = 0;
virtual QScriptValue addFunction(const QString &name, const QString& script,
virtual bool addFunction(const QString &name, const QString& script,
const QString &category="", const QString &description="") = 0;
virtual const QString& lastError() const = 0;
virtual ~IScriptEngineManager(){}