forked from qt-creator/qt-creator
ModelEditor: Improve performance
Use an additional hash map finding elements on diagram faster. Change-Id: I91adf9e3d0f79662895ffa61ca616438100529d6 Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -152,12 +152,11 @@ void DUpdateVisitor::visitMRelation(const MRelation *relation)
|
||||
drelation->setStereotypes(relation->stereotypes());
|
||||
if (isUpdating(relation->name() != drelation->name()))
|
||||
drelation->setName(relation->name());
|
||||
// TODO improve performance of MDiagram::findDiagramElement
|
||||
DObject *endAObject = dynamic_cast<DObject *>(m_diagram->findDiagramElement(drelation->endAUid()));
|
||||
if (!endAObject || relation->endAUid() != endAObject->modelUid()) {
|
||||
(void) isUpdating(true);
|
||||
endAObject = nullptr;
|
||||
// TODO use DiagramController::findDelegate (and improve performance of that method)
|
||||
// TODO use DiagramController::findDelegate
|
||||
foreach (DElement *diagramElement, m_diagram->diagramElements()) {
|
||||
if (diagramElement->modelUid().isValid() && diagramElement->modelUid() == relation->endAUid()) {
|
||||
endAObject = dynamic_cast<DObject *>(diagramElement);
|
||||
|
@@ -40,7 +40,7 @@ MDiagram::MDiagram()
|
||||
|
||||
MDiagram::MDiagram(const MDiagram &rhs)
|
||||
: MObject(rhs),
|
||||
m_elements(),
|
||||
// no deep copy
|
||||
// modification date is copied (instead of set to current time) to allow exact copies of the diagram
|
||||
m_lastModified(rhs.m_lastModified),
|
||||
m_toolbarId(rhs.toolbarId())
|
||||
@@ -66,17 +66,15 @@ MDiagram &MDiagram::operator=(const MDiagram &rhs)
|
||||
|
||||
DElement *MDiagram::findDiagramElement(const Uid &key) const
|
||||
{
|
||||
// PERFORM introduce map for better performance
|
||||
foreach (DElement *element, m_elements) {
|
||||
if (element->uid() == key)
|
||||
return element;
|
||||
}
|
||||
return nullptr;
|
||||
return m_elementMap.value(key);
|
||||
}
|
||||
|
||||
void MDiagram::setDiagramElements(const QList<DElement *> &elements)
|
||||
{
|
||||
m_elements = elements;
|
||||
m_elementMap.clear();
|
||||
for (DElement *element : elements)
|
||||
m_elementMap.insert(element->uid(), element);
|
||||
}
|
||||
|
||||
void MDiagram::addDiagramElement(DElement *element)
|
||||
@@ -84,6 +82,7 @@ void MDiagram::addDiagramElement(DElement *element)
|
||||
QMT_ASSERT(element, return);
|
||||
|
||||
m_elements.append(element);
|
||||
m_elementMap.insert(element->uid(), element);
|
||||
}
|
||||
|
||||
void MDiagram::insertDiagramElement(int beforeElement, DElement *element)
|
||||
@@ -91,13 +90,16 @@ void MDiagram::insertDiagramElement(int beforeElement, DElement *element)
|
||||
QMT_ASSERT(beforeElement >= 0 && beforeElement <= m_elements.size(), return);
|
||||
|
||||
m_elements.insert(beforeElement, element);
|
||||
m_elementMap.insert(element->uid(), element);
|
||||
}
|
||||
|
||||
void MDiagram::removeDiagramElement(int index)
|
||||
{
|
||||
QMT_ASSERT(index >= 0 && index < m_elements.size(), return);
|
||||
|
||||
delete m_elements.at(index);
|
||||
DElement *element = m_elements.at(index);
|
||||
m_elementMap.remove(element->uid());
|
||||
delete element;
|
||||
m_elements.removeAt(index);
|
||||
}
|
||||
|
||||
|
@@ -27,6 +27,7 @@
|
||||
|
||||
#include "mobject.h"
|
||||
|
||||
#include <QHash>
|
||||
#include <QDateTime>
|
||||
|
||||
namespace qmt {
|
||||
@@ -63,6 +64,7 @@ public:
|
||||
|
||||
private:
|
||||
QList<DElement *> m_elements;
|
||||
QHash<Uid, DElement *> m_elementMap;
|
||||
QDateTime m_lastModified;
|
||||
QString m_toolbarId;
|
||||
};
|
||||
|
Reference in New Issue
Block a user