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 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{
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()
{
for (int i = 0; i<m_childs.count(); ++i){
delete m_childs[i];
}
qDeleteAll(m_childs.begin(), m_childs.end());
}
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);
m_childs.push_back(res);
@ -213,26 +217,23 @@ ScriptEngineManager::~ScriptEngineManager()
bool ScriptEngineManager::isFunctionExists(const QString &functionName) const
{
foreach (ScriptFunctionDesc desc, m_functions) {
if (desc.name.compare(functionName,Qt::CaseInsensitive)==0){
return true;
}
}
return false;
return m_functions.contains(functionName);
// foreach (ScriptFunctionDesc desc, m_functions.values()) {
// if (desc.name.compare(functionName,Qt::CaseInsensitive)==0){
// return true;
// }
// }
// return false;
}
void ScriptEngineManager::deleteFunction(const QString &functionsName)
{
QMutableListIterator<ScriptFunctionDesc> it(m_functions);
while(it.hasNext()){
if (it.next().name.compare(functionsName, Qt::CaseInsensitive)==0){
it.remove();
}
}
m_functions.remove(functionsName);
}
bool ScriptEngineManager::addFunction(const JSFunctionDesc &functionDescriber)
{
if (m_functions.contains(functionDescriber.name())) return false;
ScriptValueType functionManager = scriptEngine()->globalObject().property(functionDescriber.managerName());
#ifdef USE_QJSENGINE
if (functionManager.isUndefined()){
@ -254,7 +255,7 @@ bool ScriptEngineManager::addFunction(const JSFunctionDesc &functionDescriber)
funct.description = functionDescriber.description();
funct.category = functionDescriber.category();
funct.type = ScriptFunctionDesc::Native;
m_functions.append(funct);
m_functions.insert(funct.name, funct);
if (m_model)
m_model->updateModel();
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
#if QT_VERSION > 0x050600
Q_DECL_DEPRECATED
@ -317,7 +309,7 @@ bool ScriptEngineManager::addFunction(const QString& name, const QString& script
funct.category = category;
funct.description = description;
funct.type = ScriptFunctionDesc::Script;
m_functions.append(funct);
m_functions.insert(name, funct);
m_model->updateModel();
return true;
} else {
@ -328,16 +320,17 @@ bool ScriptEngineManager::addFunction(const QString& name, const QString& script
QStringList ScriptEngineManager::functionsNames()
{
QStringList res;
foreach(ScriptFunctionDesc func, m_functions){
res<<func.name;
}
return res;
return m_functions.keys();
// QStringList res;
// foreach(ScriptFunctionDesc func, m_functions){
// res<<func.name;
// }
// return res;
}
void ScriptEngineManager::setDataManager(DataSourceManager *dataManager){
if (dataManager && m_dataManager != dataManager){
m_dataManager = dataManager;
m_dataManager = dataManager;
if (m_dataManager){
foreach(QString func, m_dataManager->groupFunctionNames()){
JSFunctionDesc describer(

View File

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