0
0
mirror of https://github.com/fralx/LimeReport.git synced 2024-12-24 16:44:39 +03:00

Memory leak has been fixed

This commit is contained in:
Arin Alexander 2021-05-24 22:14:24 +03:00
parent 6420f913e6
commit 0a32845f82
3 changed files with 19 additions and 18 deletions

View File

@ -126,7 +126,7 @@ RCC_DIR = $${ARCH_DIR}/$${BUILD_TYPE}/rcc
LIMEREPORT_VERSION_MAJOR = 1 LIMEREPORT_VERSION_MAJOR = 1
LIMEREPORT_VERSION_MINOR = 5 LIMEREPORT_VERSION_MINOR = 5
LIMEREPORT_VERSION_RELEASE = 85 LIMEREPORT_VERSION_RELEASE = 86
LIMEREPORT_VERSION = '$${LIMEREPORT_VERSION_MAJOR}.$${LIMEREPORT_VERSION_MINOR}.$${LIMEREPORT_VERSION_RELEASE}' LIMEREPORT_VERSION = '$${LIMEREPORT_VERSION_MAJOR}.$${LIMEREPORT_VERSION_MINOR}.$${LIMEREPORT_VERSION_RELEASE}'
DEFINES *= LIMEREPORT_VERSION_STR=\\\"$${LIMEREPORT_VERSION}\\\" DEFINES *= LIMEREPORT_VERSION_STR=\\\"$${LIMEREPORT_VERSION}\\\"

View File

@ -488,9 +488,9 @@ QString ScriptEngineManager::expandScripts(QString context, QVariant& varValue,
return context; return context;
} }
QString ScriptEngineManager::replaceScripts(QString context, QVariant &varValue, QObject *reportItem, ScriptEngineType* se, ScriptNode *scriptTree) QString ScriptEngineManager::replaceScripts(QString context, QVariant &varValue, QObject *reportItem, ScriptEngineType* se, ScriptNode::Ptr scriptTree)
{ {
foreach(ScriptNode* item, scriptTree->children()){ foreach(ScriptNode::Ptr item, scriptTree->children()){
QString scriptBody = expandDataFields(item->body(), EscapeSymbols, varValue, reportItem); QString scriptBody = expandDataFields(item->body(), EscapeSymbols, varValue, reportItem);
if (item->children().size() > 0) if (item->children().size() > 0)
scriptBody = replaceScripts(scriptBody, varValue, reportItem, se, item); scriptBody = replaceScripts(scriptBody, varValue, reportItem, se, item);
@ -529,7 +529,7 @@ QVariant ScriptEngineManager::evaluateScript(const QString& script){
ScriptExtractor scriptExtractor(script); ScriptExtractor scriptExtractor(script);
if (scriptExtractor.parse()){ if (scriptExtractor.parse()){
QString scriptBody = expandDataFields(scriptExtractor.scriptTree()[0].body(), EscapeSymbols, varValue, 0); QString scriptBody = expandDataFields(scriptExtractor.scriptTree()->body(), EscapeSymbols, varValue, 0);
scriptBody = expandUserVariables(scriptBody, FirstPass, EscapeSymbols, varValue); scriptBody = expandUserVariables(scriptBody, FirstPass, EscapeSymbols, varValue);
ScriptValueType value = se->evaluate(scriptBody); ScriptValueType value = se->evaluate(scriptBody);
#ifdef USE_QJSENGINE #ifdef USE_QJSENGINE
@ -987,7 +987,7 @@ bool ScriptExtractor::parse()
return m_scriptTree->children().count() > 0; return m_scriptTree->children().count() > 0;
} }
bool ScriptExtractor::parse(int &curPos, const State& state, ScriptNode* scriptNode) bool ScriptExtractor::parse(int &curPos, const State& state, ScriptNode::Ptr scriptNode)
{ {
while (curPos<m_context.length()){ while (curPos<m_context.length()){
switch (state) { switch (state) {
@ -1014,7 +1014,7 @@ bool ScriptExtractor::parse(int &curPos, const State& state, ScriptNode* scriptN
return false; return false;
} }
void ScriptExtractor::extractScript(int &curPos, const QString& startStr, ScriptNode* scriptNode) void ScriptExtractor::extractScript(int &curPos, const QString& startStr, ScriptNode::Ptr scriptNode)
{ {
int startPos = curPos; int startPos = curPos;
if (extractBracket(curPos, scriptNode)){ if (extractBracket(curPos, scriptNode)){
@ -1034,7 +1034,7 @@ void ScriptExtractor::skipField(int &curPos){
} }
} }
bool ScriptExtractor::extractBracket(int &curPos, ScriptNode* scriptNode) bool ScriptExtractor::extractBracket(int &curPos, ScriptNode::Ptr scriptNode)
{ {
curPos++; curPos++;
return parse(curPos,OpenBracketFound, scriptNode); return parse(curPos,OpenBracketFound, scriptNode);

View File

@ -400,18 +400,19 @@ private:
class ScriptNode{ class ScriptNode{
public: public:
typedef QSharedPointer<ScriptNode> Ptr;
QString body(){return m_body;} QString body(){return m_body;}
void setBody(const QString& body){ m_body = body;} void setBody(const QString& body){ m_body = body;}
void setStartLex(const QString startLex){ m_startLex = startLex;} void setStartLex(const QString startLex){ m_startLex = startLex;}
QString script(){return m_startLex + m_body + '}';} QString script(){return m_startLex + m_body + '}';}
ScriptNode* createChildNode(){ Ptr createChildNode(){
ScriptNode* result = new ScriptNode(); Ptr result = Ptr(new ScriptNode());
m_children.append(result); m_children.append(result);
return result; return result;
} }
QVector<ScriptNode*> children() const {return m_children;} QVector<Ptr> children() const {return m_children;}
private: private:
QVector<ScriptNode*> m_children; QVector<Ptr> m_children;
QString m_body; QString m_body;
QString m_startLex; QString m_startLex;
}; };
@ -421,22 +422,22 @@ class ScriptExtractor
public: public:
enum State{None,BuksFound,SFound,StartScriptFound,OpenBracketFound,CloseBracketFound,DFound,VFound, SignFound}; enum State{None,BuksFound,SFound,StartScriptFound,OpenBracketFound,CloseBracketFound,DFound,VFound, SignFound};
explicit ScriptExtractor(const QString& value): explicit ScriptExtractor(const QString& value):
m_context(value), m_scriptTree(new ScriptNode()){} m_context(value), m_scriptTree(ScriptNode::Ptr(new ScriptNode())){}
bool parse(); bool parse();
ScriptNode* scriptTree(){return m_scriptTree;} ScriptNode::Ptr scriptTree(){return m_scriptTree;}
private: private:
bool isStartLexem(int &curPos, QChar value); bool isStartLexem(int &curPos, QChar value);
bool parse(int& curPos, const State &state, ScriptNode *scriptNode); bool parse(int& curPos, const State &state, ScriptNode::Ptr scriptNode);
void skipField(int &curPos); void skipField(int &curPos);
void extractScript(int& curPos, const QString &startStr, ScriptNode *scriptNode); void extractScript(int& curPos, const QString &startStr, ScriptNode::Ptr scriptNode);
bool extractBracket(int& curPos, ScriptNode *scriptNode); bool extractBracket(int& curPos, ScriptNode::Ptr scriptNode);
bool isStartScriptLexem(int &curPos); bool isStartScriptLexem(int &curPos);
bool isStartFieldLexem(int &curPos); bool isStartFieldLexem(int &curPos);
bool isStartVariableLexem(int &curPos); bool isStartVariableLexem(int &curPos);
QString substring(const QString& value, int start, int end); QString substring(const QString& value, int start, int end);
private: private:
QString m_context; QString m_context;
ScriptNode* m_scriptTree; ScriptNode::Ptr m_scriptTree;
}; };
class ScriptEngineManager : public QObject, public Singleton<ScriptEngineManager>, public IScriptEngineManager class ScriptEngineManager : public QObject, public Singleton<ScriptEngineManager>, public IScriptEngineManager
@ -467,7 +468,7 @@ public:
QString expandDataFields(QString context, ExpandType expandType, QVariant &varValue, QObject* reportItem); QString expandDataFields(QString context, ExpandType expandType, QVariant &varValue, QObject* reportItem);
QString expandScripts(QString context, QVariant &varValue, QObject* reportItem); QString expandScripts(QString context, QVariant &varValue, QObject* reportItem);
QString replaceScripts(QString context, QVariant& varValue, QObject *reportItem, ScriptEngineType *se, ScriptNode* scriptTree); QString replaceScripts(QString context, QVariant& varValue, QObject *reportItem, ScriptEngineType *se, ScriptNode::Ptr scriptTree);
QVariant evaluateScript(const QString &script); QVariant evaluateScript(const QString &script);
void addBookMark(const QString &uniqKey, const QString &content); void addBookMark(const QString &uniqKey, const QString &content);