diff options
author | Jochen Becher <[email protected]> | 2018-01-13 12:49:02 +0100 |
---|---|---|
committer | Jochen Becher <[email protected]> | 2018-01-15 19:14:26 +0000 |
commit | 9660c595506cb842333b2d595888a8257ceb0094 (patch) | |
tree | 54448cb67e767ea21908bc3050c369e07e3a635a /src/libs/modelinglib | |
parent | 753bf8a73607fb5b5ee27584b6277ce359b27b8b (diff) |
ModelEditor: Improve performance of loading large models
Change-Id: Ic162d4805827cae9d34d7af9b6d56f3580b0f41d
Reviewed-by: Tobias Hunger <[email protected]>
Diffstat (limited to 'src/libs/modelinglib')
-rw-r--r-- | src/libs/modelinglib/qmt/stereotype/stereotypecontroller.cpp | 50 | ||||
-rw-r--r-- | src/libs/modelinglib/qmt/style/style.h | 3 |
2 files changed, 50 insertions, 3 deletions
diff --git a/src/libs/modelinglib/qmt/stereotype/stereotypecontroller.cpp b/src/libs/modelinglib/qmt/stereotype/stereotypecontroller.cpp index 0db6b692467..5f70cb77da0 100644 --- a/src/libs/modelinglib/qmt/stereotype/stereotypecontroller.cpp +++ b/src/libs/modelinglib/qmt/stereotype/stereotypecontroller.cpp @@ -43,6 +43,47 @@ namespace qmt { +namespace { + +struct IconKey { + IconKey(StereotypeIcon::Element element, const QList<QString> &stereotypes, const QString &defaultIconPath, + const Uid &styleUid, const QSize &size, const QMarginsF &margins, qreal lineWidth) + : m_element(element), + m_stereotypes(stereotypes), + m_defaultIconPath(defaultIconPath), + m_styleUid(styleUid), + m_size(size), + m_margins(margins), + m_lineWidth(lineWidth) + { + } + + const StereotypeIcon::Element m_element; + const QList<QString> m_stereotypes; + const QString m_defaultIconPath; + const Uid m_styleUid; + const QSize m_size; + const QMarginsF m_margins; + const qreal m_lineWidth; +}; + +bool operator==(const IconKey &lhs, const IconKey &rhs) { + return lhs.m_element == rhs.m_element + && lhs.m_stereotypes == rhs.m_stereotypes + && lhs.m_defaultIconPath == rhs.m_defaultIconPath + && lhs.m_styleUid == rhs.m_styleUid + && lhs.m_size == rhs.m_size + && lhs.m_margins == rhs.m_margins + && lhs.m_lineWidth == rhs.m_lineWidth; +} + +uint qHash(const IconKey &key) { + return ::qHash(key.m_element) + qHash(key.m_stereotypes) + qHash(key.m_defaultIconPath) + + qHash(key.m_styleUid) + ::qHash(key.m_size.width()) + ::qHash(key.m_size.height()); +} + +} + class StereotypeController::StereotypeControllerPrivate { public: @@ -51,6 +92,7 @@ public: QHash<QString, CustomRelation> m_relationIdToCustomRelationMap; QList<Toolbar> m_toolbars; QList<Toolbar> m_elementToolbars; + QHash<IconKey, QIcon> m_iconMap; }; StereotypeController::StereotypeController(QObject *parent) : @@ -131,9 +173,10 @@ QIcon StereotypeController::createIcon(StereotypeIcon::Element element, const QL const QString &defaultIconPath, const Style *style, const QSize &size, const QMarginsF &margins, qreal lineWidth) { - // TODO implement cache with key build from element, stereotypes, defaultIconPath, style, size and margins - // TODO implement unique id for style which can be used as key - QIcon icon; + IconKey key(element, stereotypes, defaultIconPath, style->uid(), size, margins, lineWidth); + QIcon icon = d->m_iconMap.value(key); + if (!icon.isNull()) + return icon; QString stereotypeIconId = findStereotypeIconId(element, stereotypes); if (!stereotypeIconId.isEmpty()) { StereotypeIcon stereotypeIcon = findStereotypeIcon(stereotypeIconId); @@ -202,6 +245,7 @@ QIcon StereotypeController::createIcon(StereotypeIcon::Element element, const QL } if (icon.isNull() && !defaultIconPath.isEmpty()) icon = QIcon(defaultIconPath); + d->m_iconMap.insert(key, icon); return icon; } diff --git a/src/libs/modelinglib/qmt/style/style.h b/src/libs/modelinglib/qmt/style/style.h index 9add43d26e8..b2012e4f042 100644 --- a/src/libs/modelinglib/qmt/style/style.h +++ b/src/libs/modelinglib/qmt/style/style.h @@ -26,6 +26,7 @@ #pragma once #include "qmt/infrastructure/qmt_global.h" +#include "qmt/infrastructure/uid.h" #include <QString> #include <QPen> @@ -45,6 +46,7 @@ public: explicit Style(Type type); virtual ~Style(); + Uid uid() const { return m_uid; } Type type() const { return m_type; } QPen linePen() const { return m_linePen; } void setLinePen(const QPen &pen); @@ -68,6 +70,7 @@ public: void setHeaderFont(const QFont &font); private: + Uid m_uid; Type m_type; QPen m_linePen; QPen m_outerLinePen; |