Cache TitleBar icons
Minor performance improvement. Detected by Milian when profiling.
This commit is contained in:
@@ -21,6 +21,8 @@
|
||||
#include "private/Utils_p.h"
|
||||
#include "private/TabWidget_p.h"
|
||||
|
||||
#include <QScopeGuard>
|
||||
|
||||
#ifdef KDDOCKWIDGETS_QTWIDGETS
|
||||
#include "private/widgets/FrameWidget_p.h"
|
||||
#include "private/widgets/TitleBarWidget_p.h"
|
||||
@@ -239,6 +241,11 @@ QUrl DefaultWidgetFactory::floatingWindowFilename() const
|
||||
// iconForButtonType impl is the same for QtQuick and QtWidgets
|
||||
QIcon DefaultWidgetFactory::iconForButtonType(TitleBarButtonType type, qreal dpr) const
|
||||
{
|
||||
auto key = std::make_pair(type, dpr);
|
||||
auto it = m_cachedIcons.find(key);
|
||||
if (it != m_cachedIcons.end())
|
||||
return *it;
|
||||
|
||||
QString iconName;
|
||||
switch (type) {
|
||||
case TitleBarButtonType::AutoHide:
|
||||
@@ -269,6 +276,11 @@ QIcon DefaultWidgetFactory::iconForButtonType(TitleBarButtonType type, qreal dpr
|
||||
return {};
|
||||
|
||||
QIcon icon(QStringLiteral(":/img/%1.png").arg(iconName));
|
||||
|
||||
auto atScopeEnd = qScopeGuard([&icon, this, key] {
|
||||
m_cachedIcons.insert(key, icon);
|
||||
});
|
||||
|
||||
if (!scalingFactorIsSupported(dpr))
|
||||
return icon;
|
||||
|
||||
@@ -282,3 +294,8 @@ QIcon DefaultWidgetFactory::iconForButtonType(TitleBarButtonType type, qreal dpr
|
||||
|
||||
return icon;
|
||||
}
|
||||
|
||||
void DefaultWidgetFactory::clearIconCache()
|
||||
{
|
||||
m_cachedIcons.clear();
|
||||
}
|
||||
|
||||
@@ -16,6 +16,10 @@
|
||||
#include "KDDockWidgets.h"
|
||||
#include "QWidgetAdapter.h"
|
||||
|
||||
#include <QMap>
|
||||
|
||||
#include <utility>
|
||||
|
||||
// clazy:excludeall=ctor-missing-parent-argument
|
||||
|
||||
/**
|
||||
@@ -187,11 +191,13 @@ public:
|
||||
#endif
|
||||
|
||||
QIcon iconForButtonType(TitleBarButtonType type, qreal dpr) const override;
|
||||
void clearIconCache();
|
||||
|
||||
static DropIndicatorType s_dropIndicatorType;
|
||||
|
||||
private:
|
||||
Q_DISABLE_COPY(DefaultWidgetFactory)
|
||||
mutable QMap<std::pair<TitleBarButtonType, qreal>, QIcon> m_cachedIcons;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user