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{ 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(){}

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, 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){
@ -359,11 +373,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;
} }
} }
@ -428,10 +442,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);

View File

@ -178,9 +178,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();
@ -189,8 +189,10 @@ public:
void setContext(ScriptEngineContext* context){m_context=context;} void setContext(ScriptEngineContext* context){m_context=context;}
DataSourceManager* dataManager() const {return m_dataManager;} DataSourceManager* dataManager() const {return m_dataManager;}
void setDataManager(DataSourceManager* dataManager); void setDataManager(DataSourceManager* dataManager);
protected: protected:
void updateModel(); void updateModel();
bool containsFunction(const QString &functionName);
private: private:
Q_DISABLE_COPY(ScriptEngineManager) Q_DISABLE_COPY(ScriptEngineManager)
private: private:

View File

@ -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(){}