forked from qt-creator/qt-creator
ModelEditor: Improve performance on finding a model delegate
Change-Id: Ide45583093d1d95c433858fc57c8c6ff772783a7 Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -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)
|
||||
|
@@ -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<DElement *> &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);
|
||||
}
|
||||
|
@@ -45,6 +45,7 @@ public:
|
||||
|
||||
const QList<DElement *> &diagramElements() const { return m_elements; }
|
||||
DElement *findDiagramElement(const Uid &key) const;
|
||||
DElement *findDelegate(const Uid &modelUid) const;
|
||||
void setDiagramElements(const QList<DElement *> &elements);
|
||||
|
||||
void addDiagramElement(DElement *element);
|
||||
@@ -65,6 +66,7 @@ public:
|
||||
private:
|
||||
QList<DElement *> m_elements;
|
||||
QHash<Uid, DElement *> m_elementMap;
|
||||
QHash<Uid, DElement *> m_modelUid2ElementMap;
|
||||
QDateTime m_lastModified;
|
||||
QString m_toolbarId;
|
||||
};
|
||||
|
Reference in New Issue
Block a user