mirror of
https://github.com/python-LimeReport/LimeReport.git
synced 2024-12-23 20:22:58 +03:00
Nested scripts have been fixed
This commit is contained in:
parent
4553ed1053
commit
fde44e67c1
@ -127,7 +127,7 @@ RCC_DIR = $${ARCH_DIR}/$${BUILD_TYPE}/rcc
|
||||
|
||||
LIMEREPORT_VERSION_MAJOR = 1
|
||||
LIMEREPORT_VERSION_MINOR = 5
|
||||
LIMEREPORT_VERSION_RELEASE = 9
|
||||
LIMEREPORT_VERSION_RELEASE = 10
|
||||
|
||||
LIMEREPORT_VERSION = '$${LIMEREPORT_VERSION_MAJOR}.$${LIMEREPORT_VERSION_MINOR}.$${LIMEREPORT_VERSION_RELEASE}'
|
||||
DEFINES *= LIMEREPORT_VERSION_STR=\\\"$${LIMEREPORT_VERSION}\\\"
|
||||
|
@ -91,6 +91,10 @@ namespace Const{
|
||||
const QString EOW("~!@#$%^&*()+{}|:\"<>?,/;'[]\\-=");
|
||||
const int DEFAULT_TAB_INDENTION = 4;
|
||||
const int DOCKWIDGET_MARGINS = 4;
|
||||
|
||||
const char SCRIPT_SIGN = 'S';
|
||||
const char FIELD_SIGN = 'D';
|
||||
const char VARIABLE_SIGN = 'V';
|
||||
}
|
||||
QString extractClassName(QString className);
|
||||
QString escapeSimbols(const QString& value);
|
||||
|
@ -34,7 +34,7 @@ public:
|
||||
int childrenCount();
|
||||
int layoutSpacing() const;
|
||||
void setLayoutSpacing(int layoutSpacing);
|
||||
qreal layoutSpacingMM(){ return m_layoutSpacing * unitFactor();}
|
||||
qreal layoutSpacingMM(){ return m_layoutSpacing * Const::mmFACTOR;}
|
||||
protected:
|
||||
void beforeDelete();
|
||||
void childAddedEvent(BaseDesignIntf *child);
|
||||
|
@ -91,6 +91,10 @@ namespace Const{
|
||||
const QString EOW("~!@#$%^&*()+{}|:\"<>?,/;'[]\\-=");
|
||||
const int DEFAULT_TAB_INDENTION = 4;
|
||||
const int DOCKWIDGET_MARGINS = 4;
|
||||
|
||||
const char SCRIPT_SIGN = 'S';
|
||||
const char FIELD_SIGN = 'D';
|
||||
const char VARIABLE_SIGN = 'V';
|
||||
}
|
||||
QString extractClassName(QString className);
|
||||
QString escapeSimbols(const QString& value);
|
||||
|
@ -465,15 +465,13 @@ QString ScriptEngineManager::expandScripts(QString context, QVariant& varValue,
|
||||
|
||||
if (context.contains(rx)){
|
||||
|
||||
if (ScriptEngineManager::instance().dataManager()!=dataManager())
|
||||
if (ScriptEngineManager::instance().dataManager() != dataManager())
|
||||
ScriptEngineManager::instance().setDataManager(dataManager());
|
||||
|
||||
ScriptEngineType* se = ScriptEngineManager::instance().scriptEngine();
|
||||
|
||||
if (reportItem){
|
||||
|
||||
ScriptValueType svThis;
|
||||
|
||||
#ifdef USE_QJSENGINE
|
||||
svThis = getJSValue(*se, reportItem);
|
||||
se->globalObject().setProperty("THIS",svThis);
|
||||
@ -490,29 +488,37 @@ QString ScriptEngineManager::expandScripts(QString context, QVariant& varValue,
|
||||
|
||||
ScriptExtractor scriptExtractor(context);
|
||||
if (scriptExtractor.parse()){
|
||||
for(int i=0; i<scriptExtractor.count();++i){
|
||||
QString scriptBody = expandDataFields(scriptExtractor.bodyAt(i),EscapeSymbols, varValue, reportItem);
|
||||
scriptBody = expandUserVariables(scriptBody, FirstPass, EscapeSymbols, varValue);
|
||||
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()) {
|
||||
varValue = value.toVariant();
|
||||
context.replace(scriptExtractor.scriptAt(i),value.toString());
|
||||
} else {
|
||||
context.replace(scriptExtractor.scriptAt(i),se->uncaughtException().toString());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
context = replaceScripts(context, varValue, reportItem, se, scriptExtractor.scriptTree());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
QString ScriptEngineManager::replaceScripts(QString context, QVariant &varValue, QObject *reportItem, ScriptEngineType* se, ScriptNode *scriptTree)
|
||||
{
|
||||
foreach(ScriptNode* item, scriptTree->children()){
|
||||
QString scriptBody = expandDataFields(item->body(), EscapeSymbols, varValue, reportItem);
|
||||
if (item->children().size() > 0)
|
||||
scriptBody = replaceScripts(scriptBody, varValue, reportItem, se, item);
|
||||
scriptBody = expandUserVariables(scriptBody, FirstPass, EscapeSymbols, varValue);
|
||||
ScriptValueType value = se->evaluate(scriptBody);
|
||||
#ifdef USE_QJSENGINE
|
||||
if (!value.isError()){
|
||||
varValue = value.toVariant();
|
||||
context.replace(item->script(), value.toString());
|
||||
} else {
|
||||
context.replace(item->script(), value.toString());
|
||||
}
|
||||
#else
|
||||
if (!se->hasUncaughtException()) {
|
||||
varValue = value.toVariant();
|
||||
context.replace(scriptTree->children()[i]->script(), value.toString());
|
||||
} else {
|
||||
context.replace(scriptTree->children()[i]->script(), se->uncaughtException().toString());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return context;
|
||||
}
|
||||
|
||||
@ -530,7 +536,7 @@ QVariant ScriptEngineManager::evaluateScript(const QString& script){
|
||||
|
||||
ScriptExtractor scriptExtractor(script);
|
||||
if (scriptExtractor.parse()){
|
||||
QString scriptBody = expandDataFields(scriptExtractor.bodyAt(0),EscapeSymbols, varValue, 0);
|
||||
QString scriptBody = expandDataFields(scriptExtractor.scriptTree()[0].body(), EscapeSymbols, varValue, 0);
|
||||
scriptBody = expandUserVariables(scriptBody, FirstPass, EscapeSymbols, varValue);
|
||||
ScriptValueType value = se->evaluate(scriptBody);
|
||||
#ifdef USE_QJSENGINE
|
||||
@ -976,12 +982,11 @@ ScriptEngineManager::ScriptEngineManager()
|
||||
bool ScriptExtractor::parse()
|
||||
{
|
||||
int currentPos = 0;
|
||||
parse(currentPos,None);
|
||||
return m_scriptsBody.count()>0;
|
||||
|
||||
parse(currentPos, None, m_scriptTree);
|
||||
return m_scriptTree->children().count() > 0;
|
||||
}
|
||||
|
||||
bool ScriptExtractor::parse(int &curPos,const State& state)
|
||||
bool ScriptExtractor::parse(int &curPos, const State& state, ScriptNode* scriptNode)
|
||||
{
|
||||
while (curPos<m_context.length()){
|
||||
switch (state) {
|
||||
@ -990,13 +995,13 @@ bool ScriptExtractor::parse(int &curPos,const State& state)
|
||||
return true;
|
||||
} else {
|
||||
if (m_context[curPos]=='{')
|
||||
extractBracket(curPos);
|
||||
extractBracket(curPos, scriptNode);
|
||||
}
|
||||
case None:
|
||||
if (m_context[curPos]=='$'){
|
||||
int startPos = curPos;
|
||||
if (isStartScriptLexem(curPos))
|
||||
extractScript(curPos,substring(m_context,startPos,curPos));
|
||||
extractScript(curPos, substring(m_context,startPos,curPos), scriptNode->createChildNode());
|
||||
if (isStartFieldLexem(curPos) || isStartVariableLexem(curPos))
|
||||
skipField(curPos);
|
||||
}
|
||||
@ -1008,13 +1013,13 @@ bool ScriptExtractor::parse(int &curPos,const State& state)
|
||||
return false;
|
||||
}
|
||||
|
||||
void ScriptExtractor::extractScript(int &curPos, const QString& startStr)
|
||||
void ScriptExtractor::extractScript(int &curPos, const QString& startStr, ScriptNode* scriptNode)
|
||||
{
|
||||
int startPos = curPos;
|
||||
if (extractBracket(curPos)){
|
||||
if (extractBracket(curPos, scriptNode)){
|
||||
QString scriptBody = substring(m_context,startPos+1,curPos);
|
||||
m_scriptsBody.push_back(scriptBody);
|
||||
m_scriptsStartLex.push_back(startStr+'{');
|
||||
scriptNode->setBody(scriptBody);
|
||||
scriptNode->setStartLex(startStr+'{');
|
||||
}
|
||||
}
|
||||
|
||||
@ -1028,10 +1033,10 @@ void ScriptExtractor::skipField(int &curPos){
|
||||
}
|
||||
}
|
||||
|
||||
bool ScriptExtractor::extractBracket(int &curPos)
|
||||
bool ScriptExtractor::extractBracket(int &curPos, ScriptNode* scriptNode)
|
||||
{
|
||||
curPos++;
|
||||
return parse(curPos,OpenBracketFound);
|
||||
return parse(curPos,OpenBracketFound, scriptNode);
|
||||
}
|
||||
|
||||
bool ScriptExtractor::isStartLexem(int& curPos, QChar value){
|
||||
@ -1064,16 +1069,16 @@ bool ScriptExtractor::isStartLexem(int& curPos, QChar value){
|
||||
|
||||
bool ScriptExtractor::isStartScriptLexem(int& curPos)
|
||||
{
|
||||
return isStartLexem(curPos, SCRIPT_SIGN);
|
||||
return isStartLexem(curPos, Const::SCRIPT_SIGN);
|
||||
}
|
||||
|
||||
bool ScriptExtractor::isStartFieldLexem(int& curPos){
|
||||
return isStartLexem(curPos, FIELD_SIGN);
|
||||
return isStartLexem(curPos, Const::FIELD_SIGN);
|
||||
}
|
||||
|
||||
bool ScriptExtractor::isStartVariableLexem(int &curPos)
|
||||
{
|
||||
return isStartLexem(curPos, VARIABLE_SIGN);
|
||||
return isStartLexem(curPos, Const::VARIABLE_SIGN);
|
||||
}
|
||||
|
||||
|
||||
|
@ -396,6 +396,47 @@ private:
|
||||
QMap<QString, IWrapperCreator*> m_wrappersFactory;
|
||||
};
|
||||
|
||||
class ScriptNode{
|
||||
public:
|
||||
QString body(){return m_body;}
|
||||
void setBody(const QString& body){ m_body = body;}
|
||||
void setStartLex(const QString startLex){ m_startLex = startLex;}
|
||||
QString script(){return m_startLex + m_body + '}';}
|
||||
ScriptNode* createChildNode(){
|
||||
ScriptNode* result = new ScriptNode();
|
||||
m_children.append(result);
|
||||
return result;
|
||||
}
|
||||
QVector<ScriptNode*> children() const {return m_children;}
|
||||
private:
|
||||
QVector<ScriptNode*> m_children;
|
||||
QString m_body;
|
||||
QString m_startLex;
|
||||
};
|
||||
|
||||
class ScriptExtractor
|
||||
{
|
||||
public:
|
||||
enum State{None,BuksFound,SFound,StartScriptFound,OpenBracketFound,CloseBracketFound,DFound,VFound, SignFound};
|
||||
explicit ScriptExtractor(const QString& value):
|
||||
m_context(value), m_scriptTree(new ScriptNode()){}
|
||||
bool parse();
|
||||
ScriptNode* scriptTree(){return m_scriptTree;}
|
||||
private:
|
||||
bool isStartLexem(int &curPos, QChar value);
|
||||
bool parse(int& curPos, const State &state, ScriptNode *scriptNode);
|
||||
void skipField(int &curPos);
|
||||
void extractScript(int& curPos, const QString &startStr, ScriptNode *scriptNode);
|
||||
bool extractBracket(int& curPos, ScriptNode *scriptNode);
|
||||
bool isStartScriptLexem(int &curPos);
|
||||
bool isStartFieldLexem(int &curPos);
|
||||
bool isStartVariableLexem(int &curPos);
|
||||
QString substring(const QString& value, int start, int end);
|
||||
private:
|
||||
QString m_context;
|
||||
ScriptNode* m_scriptTree;
|
||||
};
|
||||
|
||||
class ScriptEngineManager : public QObject, public Singleton<ScriptEngineManager>, public IScriptEngineManager
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -423,6 +464,9 @@ public:
|
||||
QString expandUserVariables(QString context, RenderPass pass, ExpandType expandType, QVariant &varValue);
|
||||
QString expandDataFields(QString context, ExpandType expandType, QVariant &varValue, QObject* reportItem);
|
||||
QString expandScripts(QString context, QVariant &varValue, QObject* reportItem);
|
||||
|
||||
QString replaceScripts(QString context, QVariant& varValue, QObject *reportItem, ScriptEngineType *se, ScriptNode* scriptTree);
|
||||
|
||||
QVariant evaluateScript(const QString &script);
|
||||
void addBookMark(const QString &uniqKey, const QString &content);
|
||||
int findPageIndexByBookmark(const QString& uniqKey);
|
||||
@ -466,36 +510,6 @@ private:
|
||||
ScriptFunctionsManager* m_functionManager;
|
||||
};
|
||||
|
||||
class ScriptExtractor
|
||||
{
|
||||
public:
|
||||
enum State{None,BuksFound,SFound,StartScriptFound,OpenBracketFound,CloseBracketFound,DFound,VFound, SignFound};
|
||||
explicit ScriptExtractor(const QString& value):m_context(value){}
|
||||
bool parse();
|
||||
int count(){return m_scriptsBody.count();}
|
||||
QString bodyAt(int index){return m_scriptsBody[index];}
|
||||
QString scriptAt(int index){return m_scriptsStartLex[index]+m_scriptsBody[index]+'}';}
|
||||
|
||||
private:
|
||||
static const char SCRIPT_SIGN = 'S';
|
||||
static const char FIELD_SIGN = 'D';
|
||||
static const char VARIABLE_SIGN = 'V';
|
||||
|
||||
bool isStartLexem(int &curPos, QChar value);
|
||||
bool parse(int& curPos, const State &state);
|
||||
void skipField(int &curPos);
|
||||
void extractScript(int& curPos, const QString &startStr);
|
||||
bool extractBracket(int& curPos);
|
||||
bool isStartScriptLexem(int &curPos);
|
||||
bool isStartFieldLexem(int &curPos);
|
||||
bool isStartVariableLexem(int &curPos);
|
||||
QString substring(const QString& value, int start, int end);
|
||||
private:
|
||||
QString m_context;
|
||||
QVector<QString> m_scriptsBody;
|
||||
QVector<QString> m_scriptsStartLex;
|
||||
|
||||
};
|
||||
|
||||
#ifdef USE_QTSCRIPTENGINE
|
||||
class QFontPrototype : public QObject, public QScriptable {
|
||||
|
Loading…
Reference in New Issue
Block a user