From 89b8e81d5c3b11572a0288720d0b4145d2ec2a7e Mon Sep 17 00:00:00 2001 From: grggnzlz Date: Sat, 13 Mar 2021 06:12:08 +0100 Subject: [PATCH] Sketcher: Constraint svg caching ================================ Calls to: Gui::BitmapFactory().pixmapFromSvg(type.toLatin1().data(),QSizeF(edit->constraintIconSize,edit->constraintIconSize)); are expensive and the scaled pixmap is heavily reused. Solution is to cache the icon. --- src/Mod/Sketcher/Gui/ViewProviderSketch.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp index 0012d4639c08..a8d6e12fbaa6 100644 --- a/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp +++ b/src/Mod/Sketcher/Gui/ViewProviderSketch.cpp @@ -3692,7 +3692,14 @@ QImage ViewProviderSketch::renderConstrIcon(const QString &type, // Constants to help create constraint icons QString joinStr = QString::fromLatin1(", "); - QImage icon = Gui::BitmapFactory().pixmapFromSvg(type.toLatin1().data(),QSizeF(edit->constraintIconSize,edit->constraintIconSize)).toImage(); + QPixmap pxMap; + std::stringstream constraintName; + constraintName << type.toLatin1().data() << edit->constraintIconSize; // allow resizing by embedding size + if (! Gui::BitmapFactory().findPixmapInCache(constraintName.str().c_str(), pxMap)) { + pxMap = Gui::BitmapFactory().pixmapFromSvg(type.toLatin1().data(),QSizeF(edit->constraintIconSize,edit->constraintIconSize)); + Gui::BitmapFactory().addPixmapToCache(constraintName.str().c_str(), pxMap); // Cache for speed, avoiding pixmapFromSvg + } + QImage icon = pxMap.toImage(); QFont font = QApplication::font(); font.setPixelSize(static_cast(1.0 * edit->constraintIconSize)); @@ -3812,14 +3819,14 @@ void ViewProviderSketch::OnChange(Base::Subject &rCaller, const cha void ViewProviderSketch::subscribeToParameters() { - ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View"); - hGrp->Attach(this); + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View"); + hGrp->Attach(this); } void ViewProviderSketch::unsubscribeToParameters() { - ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View"); - hGrp->Detach(this); + ParameterGrp::handle hGrp = App::GetApplication().GetParameterGroupByPath("User parameter:BaseApp/Preferences/View"); + hGrp->Detach(this); } void ViewProviderSketch::updateInventorNodeSizes()