mirror of
https://github.com/fralx/LimeReport.git
synced 2024-12-24 08:34:38 +03:00
ScriptEngineManager::addFunction has been fixed
This commit is contained in:
parent
1320c6f8ee
commit
71fe049ff4
@ -37,9 +37,9 @@ namespace LimeReport{
|
|||||||
class IScriptEngineManager{
|
class IScriptEngineManager{
|
||||||
public:
|
public:
|
||||||
virtual QScriptEngine* scriptEngine() = 0;
|
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;
|
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;
|
const QString &category="", const QString &description="") = 0;
|
||||||
virtual const QString& lastError() const = 0;
|
virtual const QString& lastError() const = 0;
|
||||||
virtual ~IScriptEngineManager(){}
|
virtual ~IScriptEngineManager(){}
|
||||||
|
@ -323,26 +323,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,
|
QScriptEngine::FunctionSignature function,
|
||||||
const QString& category,
|
const QString& category,
|
||||||
const QString& description)
|
const QString& description)
|
||||||
{
|
{
|
||||||
ScriptFunctionDesc funct;
|
if (!containsFunction(name)){
|
||||||
funct.name = name;
|
ScriptFunctionDesc funct;
|
||||||
funct.description = description;
|
funct.name = name;
|
||||||
funct.category = category;
|
funct.description = description;
|
||||||
funct.scriptValue = scriptEngine()->newFunction(function);
|
funct.category = category;
|
||||||
funct.scriptValue.setProperty("functionName",name);
|
funct.scriptValue = scriptEngine()->newFunction(function);
|
||||||
funct.scriptValue.setData(m_scriptEngine->toScriptValue(this));
|
funct.scriptValue.setProperty("functionName",name);
|
||||||
funct.type = ScriptFunctionDesc::Native;
|
funct.scriptValue.setData(m_scriptEngine->toScriptValue(this));
|
||||||
m_functions.append(funct);
|
funct.type = ScriptFunctionDesc::Native;
|
||||||
if (m_model)
|
m_functions.append(funct);
|
||||||
m_model->updateModel();
|
if (m_model)
|
||||||
return funct.scriptValue;
|
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);
|
QScriptSyntaxCheckResult cr = m_scriptEngine->checkSyntax(script);
|
||||||
if (cr.state() == QScriptSyntaxCheckResult::Valid){
|
if (cr.state() == QScriptSyntaxCheckResult::Valid){
|
||||||
@ -354,11 +368,11 @@ QScriptValue ScriptEngineManager::addFunction(const QString& name, const QString
|
|||||||
funct.type = ScriptFunctionDesc::Script;
|
funct.type = ScriptFunctionDesc::Script;
|
||||||
funct.scriptValue.setData(m_scriptEngine->toScriptValue(this));
|
funct.scriptValue.setData(m_scriptEngine->toScriptValue(this));
|
||||||
m_functions.append(funct);
|
m_functions.append(funct);
|
||||||
m_model->updateModel();
|
m_model->updateModel();
|
||||||
return funct.scriptValue;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
m_lastError = cr.errorMessage();
|
m_lastError = cr.errorMessage();
|
||||||
return QScriptValue();
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -418,10 +432,10 @@ ScriptEngineManager::ScriptEngineManager()
|
|||||||
// addFunction(func, groupFunction,"GROUP FUNCTIONS", func+"(\""+tr("FieldName")+"\",\""+tr("BandName")+"\")");
|
// addFunction(func, groupFunction,"GROUP FUNCTIONS", func+"(\""+tr("FieldName")+"\",\""+tr("BandName")+"\")");
|
||||||
// }
|
// }
|
||||||
|
|
||||||
foreach(ScriptFunctionDesc func, m_functions){
|
// foreach(ScriptFunctionDesc func, m_functions){
|
||||||
if (func.type==ScriptFunctionDesc::Native)
|
// if (func.type==ScriptFunctionDesc::Native)
|
||||||
m_scriptEngine->globalObject().setProperty(func.name,func.scriptValue);
|
// m_scriptEngine->globalObject().setProperty(func.name,func.scriptValue);
|
||||||
}
|
// }
|
||||||
|
|
||||||
m_model = new ScriptEngineModel(this);
|
m_model = new ScriptEngineModel(this);
|
||||||
|
|
||||||
|
@ -114,9 +114,9 @@ public:
|
|||||||
friend class Singleton<ScriptEngineManager>;
|
friend class Singleton<ScriptEngineManager>;
|
||||||
bool isFunctionExists(const QString& functionName) const;
|
bool isFunctionExists(const QString& functionName) const;
|
||||||
void deleteFunction(const QString& functionsName);
|
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="");
|
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 &category="", const QString &description="");
|
||||||
const QString& lastError() const {return m_lastError;}
|
const QString& lastError() const {return m_lastError;}
|
||||||
QStringList functionsNames();
|
QStringList functionsNames();
|
||||||
@ -124,6 +124,7 @@ public:
|
|||||||
ScriptEngineModel* model(){return m_model;}
|
ScriptEngineModel* model(){return m_model;}
|
||||||
DataSourceManager* dataManager() const {return m_dataManager;}
|
DataSourceManager* dataManager() const {return m_dataManager;}
|
||||||
void setDataManager(DataSourceManager* dataManager);
|
void setDataManager(DataSourceManager* dataManager);
|
||||||
|
bool containsFunction(const QString &functionName);
|
||||||
private:
|
private:
|
||||||
Q_DISABLE_COPY(ScriptEngineManager)
|
Q_DISABLE_COPY(ScriptEngineManager)
|
||||||
private:
|
private:
|
||||||
|
@ -37,9 +37,9 @@ namespace LimeReport{
|
|||||||
class IScriptEngineManager{
|
class IScriptEngineManager{
|
||||||
public:
|
public:
|
||||||
virtual QScriptEngine* scriptEngine() = 0;
|
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;
|
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;
|
const QString &category="", const QString &description="") = 0;
|
||||||
virtual const QString& lastError() const = 0;
|
virtual const QString& lastError() const = 0;
|
||||||
virtual ~IScriptEngineManager(){}
|
virtual ~IScriptEngineManager(){}
|
||||||
|
Loading…
Reference in New Issue
Block a user