diff --git a/src/libs/modelinglib/qmt/diagram_controller/diagramcontroller.cpp b/src/libs/modelinglib/qmt/diagram_controller/diagramcontroller.cpp index aa768e1106e..aa8ad153b17 100644 --- a/src/libs/modelinglib/qmt/diagram_controller/diagramcontroller.cpp +++ b/src/libs/modelinglib/qmt/diagram_controller/diagramcontroller.cpp @@ -429,18 +429,12 @@ DElement *DiagramController::findElement(const Uid &key, const MDiagram *diagram bool DiagramController::hasDelegate(const MElement *modelElement, const MDiagram *diagram) const { - // PERFORM smarter implementation after map is introduced return findDelegate(modelElement, diagram) != nullptr; } DElement *DiagramController::findDelegate(const MElement *modelElement, const MDiagram *diagram) const { - // PERFORM use map to increase performance - foreach (DElement *diagramElement, diagram->diagramElements()) { - if (diagramElement->modelUid().isValid() && diagramElement->modelUid() == modelElement->uid()) - return diagramElement; - } - return nullptr; + return diagram->findDelegate(modelElement->uid()); } void DiagramController::startUpdateElement(DElement *element, MDiagram *diagram, UpdateAction updateAction) diff --git a/src/libs/modelinglib/qmt/model/mdiagram.cpp b/src/libs/modelinglib/qmt/model/mdiagram.cpp index dbd8487ed9e..8c9dccc5f32 100644 --- a/src/libs/modelinglib/qmt/model/mdiagram.cpp +++ b/src/libs/modelinglib/qmt/model/mdiagram.cpp @@ -69,12 +69,20 @@ DElement *MDiagram::findDiagramElement(const Uid &key) const return m_elementMap.value(key); } +DElement *MDiagram::findDelegate(const Uid &modelUid) const +{ + return m_modelUid2ElementMap.value(modelUid); +} + void MDiagram::setDiagramElements(const QList &elements) { m_elements = elements; m_elementMap.clear(); - for (DElement *element : elements) + m_modelUid2ElementMap.clear(); + for (DElement *element : elements) { m_elementMap.insert(element->uid(), element); + m_modelUid2ElementMap.insert(element->modelUid(), element); + } } void MDiagram::addDiagramElement(DElement *element) @@ -83,6 +91,7 @@ void MDiagram::addDiagramElement(DElement *element) m_elements.append(element); m_elementMap.insert(element->uid(), element); + m_modelUid2ElementMap.insert(element->modelUid(), element); } void MDiagram::insertDiagramElement(int beforeElement, DElement *element) @@ -91,6 +100,7 @@ void MDiagram::insertDiagramElement(int beforeElement, DElement *element) m_elements.insert(beforeElement, element); m_elementMap.insert(element->uid(), element); + m_modelUid2ElementMap.insert(element->modelUid(), element); } void MDiagram::removeDiagramElement(int index) @@ -99,6 +109,7 @@ void MDiagram::removeDiagramElement(int index) DElement *element = m_elements.at(index); m_elementMap.remove(element->uid()); + m_modelUid2ElementMap.remove(element->modelUid()); delete element; m_elements.removeAt(index); } diff --git a/src/libs/modelinglib/qmt/model/mdiagram.h b/src/libs/modelinglib/qmt/model/mdiagram.h index 879b7c0021d..40520d577f6 100644 --- a/src/libs/modelinglib/qmt/model/mdiagram.h +++ b/src/libs/modelinglib/qmt/model/mdiagram.h @@ -45,6 +45,7 @@ public: const QList &diagramElements() const { return m_elements; } DElement *findDiagramElement(const Uid &key) const; + DElement *findDelegate(const Uid &modelUid) const; void setDiagramElements(const QList &elements); void addDiagramElement(DElement *element); @@ -65,6 +66,7 @@ public: private: QList m_elements; QHash m_elementMap; + QHash m_modelUid2ElementMap; QDateTime m_lastModified; QString m_toolbarId; };