diff --git a/limereport/lrscriptenginemanager.cpp b/limereport/lrscriptenginemanager.cpp index 91bc9bc..19d6a83 100644 --- a/limereport/lrscriptenginemanager.cpp +++ b/limereport/lrscriptenginemanager.cpp @@ -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 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<groupFunctionNames()){ JSFunctionDesc describer( diff --git a/limereport/lrscriptenginemanager.h b/limereport/lrscriptenginemanager.h index 784253d..d3b47ba 100644 --- a/limereport/lrscriptenginemanager.h +++ b/limereport/lrscriptenginemanager.h @@ -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& functionsDescribers(){return m_functions;} + const QHash& 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 m_functions; + QHash m_functions; ScriptEngineModel* m_model; ScriptEngineContext* m_context; DataSourceManager* m_dataManager;