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

Memory leak has been fixed

This commit is contained in:
Arin Alexander 2020-02-04 17:16:48 +03:00
parent fa386a1b6e
commit 0b422bee3b
2 changed files with 33 additions and 41 deletions

View File

@ -60,14 +60,18 @@ QScriptValue constructColor(QScriptContext *context, QScriptEngine *engine)
namespace LimeReport{ namespace LimeReport{
ScriptEngineNode::ScriptEngineNode(const QString &name, const QString &description,
ScriptEngineNode::NodeType type, ScriptEngineNode *parent, const QIcon &icon)
:m_name(name), m_description(description), m_icon(icon), m_type(type), m_parent(parent)
{}
ScriptEngineNode::~ScriptEngineNode() ScriptEngineNode::~ScriptEngineNode()
{ {
for (int i = 0; i<m_childs.count(); ++i){ qDeleteAll(m_childs.begin(), m_childs.end());
delete m_childs[i];
}
} }
ScriptEngineNode*ScriptEngineNode::addChild(const QString& name, const QString& description, ScriptEngineNode::NodeType type, const QIcon& icon) ScriptEngineNode*ScriptEngineNode::addChild(const QString& name, const QString& description,
ScriptEngineNode::NodeType type, const QIcon& icon)
{ {
ScriptEngineNode* res = new ScriptEngineNode(name, description, type,this,icon); ScriptEngineNode* res = new ScriptEngineNode(name, description, type,this,icon);
m_childs.push_back(res); m_childs.push_back(res);
@ -213,26 +217,23 @@ ScriptEngineManager::~ScriptEngineManager()
bool ScriptEngineManager::isFunctionExists(const QString &functionName) const bool ScriptEngineManager::isFunctionExists(const QString &functionName) const
{ {
foreach (ScriptFunctionDesc desc, m_functions) { return m_functions.contains(functionName);
if (desc.name.compare(functionName,Qt::CaseInsensitive)==0){ // foreach (ScriptFunctionDesc desc, m_functions.values()) {
return true; // if (desc.name.compare(functionName,Qt::CaseInsensitive)==0){
} // return true;
} // }
return false; // }
// return false;
} }
void ScriptEngineManager::deleteFunction(const QString &functionsName) void ScriptEngineManager::deleteFunction(const QString &functionsName)
{ {
QMutableListIterator<ScriptFunctionDesc> it(m_functions); m_functions.remove(functionsName);
while(it.hasNext()){
if (it.next().name.compare(functionsName, Qt::CaseInsensitive)==0){
it.remove();
}
}
} }
bool ScriptEngineManager::addFunction(const JSFunctionDesc &functionDescriber) bool ScriptEngineManager::addFunction(const JSFunctionDesc &functionDescriber)
{ {
if (m_functions.contains(functionDescriber.name())) return false;
ScriptValueType functionManager = scriptEngine()->globalObject().property(functionDescriber.managerName()); ScriptValueType functionManager = scriptEngine()->globalObject().property(functionDescriber.managerName());
#ifdef USE_QJSENGINE #ifdef USE_QJSENGINE
if (functionManager.isUndefined()){ if (functionManager.isUndefined()){
@ -254,7 +255,7 @@ bool ScriptEngineManager::addFunction(const JSFunctionDesc &functionDescriber)
funct.description = functionDescriber.description(); funct.description = functionDescriber.description();
funct.category = functionDescriber.category(); funct.category = functionDescriber.category();
funct.type = ScriptFunctionDesc::Native; funct.type = ScriptFunctionDesc::Native;
m_functions.append(funct); m_functions.insert(funct.name, funct);
if (m_model) if (m_model)
m_model->updateModel(); m_model->updateModel();
return true; return true;
@ -269,15 +270,6 @@ bool ScriptEngineManager::addFunction(const JSFunctionDesc &functionDescriber)
} }
bool ScriptEngineManager::containsFunction(const QString& functionName){
foreach (ScriptFunctionDesc funct, m_functions) {
if (funct.name.compare(functionName)== 0){
return true;
}
}
return false;
}
#ifdef USE_QTSCRIPTENGINE #ifdef USE_QTSCRIPTENGINE
#if QT_VERSION > 0x050600 #if QT_VERSION > 0x050600
Q_DECL_DEPRECATED Q_DECL_DEPRECATED
@ -317,7 +309,7 @@ bool ScriptEngineManager::addFunction(const QString& name, const QString& script
funct.category = category; funct.category = category;
funct.description = description; funct.description = description;
funct.type = ScriptFunctionDesc::Script; funct.type = ScriptFunctionDesc::Script;
m_functions.append(funct); m_functions.insert(name, funct);
m_model->updateModel(); m_model->updateModel();
return true; return true;
} else { } else {
@ -328,16 +320,17 @@ bool ScriptEngineManager::addFunction(const QString& name, const QString& script
QStringList ScriptEngineManager::functionsNames() QStringList ScriptEngineManager::functionsNames()
{ {
QStringList res; return m_functions.keys();
foreach(ScriptFunctionDesc func, m_functions){ // QStringList res;
res<<func.name; // foreach(ScriptFunctionDesc func, m_functions){
} // res<<func.name;
return res; // }
// return res;
} }
void ScriptEngineManager::setDataManager(DataSourceManager *dataManager){ void ScriptEngineManager::setDataManager(DataSourceManager *dataManager){
if (dataManager && m_dataManager != dataManager){ if (dataManager && m_dataManager != dataManager){
m_dataManager = dataManager; m_dataManager = dataManager;
if (m_dataManager){ if (m_dataManager){
foreach(QString func, m_dataManager->groupFunctionNames()){ foreach(QString func, m_dataManager->groupFunctionNames()){
JSFunctionDesc describer( JSFunctionDesc describer(

View File

@ -98,14 +98,15 @@ struct ScriptFunctionDesc{
class ScriptEngineNode { class ScriptEngineNode {
public: public:
enum NodeType{Root,Category,Function,Dialog,DialogElement}; enum NodeType{Root, Category, Function, Dialog, DialogElement};
ScriptEngineNode(const QString& name="", const QString& description ="", NodeType type=Root, ScriptEngineNode* parent=0, const QIcon& icon=QIcon()) ScriptEngineNode(const QString& name = "", const QString& description = "", NodeType type = Root,
:m_name(name), m_description(description), m_icon(icon), m_type(type), m_parent(parent){} ScriptEngineNode* parent = 0, const QIcon& icon = QIcon());
virtual ~ScriptEngineNode(); virtual ~ScriptEngineNode();
int childCount(){return m_childs.count();} int childCount(){return m_childs.count();}
ScriptEngineNode* child(int index){return m_childs[index];} ScriptEngineNode* child(int index){return m_childs[index];}
ScriptEngineNode* parent(){return m_parent;} ScriptEngineNode* parent(){return m_parent;}
ScriptEngineNode* addChild(const QString& name="", const QString &description="", NodeType type=Root, const QIcon& icon=QIcon()); ScriptEngineNode* addChild(const QString& name = "", const QString &description = "",
NodeType type = Root, const QIcon& icon = QIcon());
int row(); int row();
QString name(){return m_name;} QString name(){return m_name;}
QString description(){return m_description;} QString description(){return m_description;}
@ -455,7 +456,7 @@ public:
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();
const QList<ScriptFunctionDesc>& functionsDescribers(){return m_functions;} const QHash<QString,ScriptFunctionDesc>& functionsDescribers(){return m_functions;}
ScriptEngineModel* model(){return m_model;} ScriptEngineModel* model(){return m_model;}
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;}
@ -473,10 +474,8 @@ public:
void addTableOfContentsItem(const QString& uniqKey, const QString& content, int indent); void addTableOfContentsItem(const QString& uniqKey, const QString& content, int indent);
void clearTableOfContents(); void clearTableOfContents();
ScriptValueType moveQObjectToScript(QObject* object, const QString objectName); ScriptValueType moveQObjectToScript(QObject* object, const QString objectName);
protected: protected:
void updateModel(); void updateModel();
bool containsFunction(const QString &functionName);
private: private:
Q_DISABLE_COPY(ScriptEngineManager) Q_DISABLE_COPY(ScriptEngineManager)
bool createLineFunction(); bool createLineFunction();
@ -503,7 +502,7 @@ private:
ScriptEngineManager(); ScriptEngineManager();
ScriptEngineType* m_scriptEngine; ScriptEngineType* m_scriptEngine;
QString m_lastError; QString m_lastError;
QList<ScriptFunctionDesc> m_functions; QHash<QString,ScriptFunctionDesc> m_functions;
ScriptEngineModel* m_model; ScriptEngineModel* m_model;
ScriptEngineContext* m_context; ScriptEngineContext* m_context;
DataSourceManager* m_dataManager; DataSourceManager* m_dataManager;