[FrameSvgItem] Create margins/fixedMargins object on demand

On my machine I end up creating 490 margins and 490 fixed margin objects.
After this change I only create 171 margin objects and 20 fixed margin objects.

Differential Revision: https://phabricator.kde.org/D7582
This commit is contained in:
Kai Uwe Broulik 2017-08-29 11:10:19 +02:00
parent 3e284c2404
commit a8ce2e85ec
2 changed files with 34 additions and 14 deletions

View File

@ -254,14 +254,13 @@ bool FrameSvgItemMargins::isFixed() const
FrameSvgItem::FrameSvgItem(QQuickItem *parent)
: QQuickItem(parent),
m_margins(nullptr),
m_fixedMargins(nullptr),
m_textureChanged(false),
m_sizeChanged(false),
m_fastPath(true)
{
m_frameSvg = new Plasma::FrameSvg(this);
m_margins = new FrameSvgItemMargins(m_frameSvg, this);
m_fixedMargins = new FrameSvgItemMargins(m_frameSvg, this);
m_fixedMargins->setFixed(true);
setFlag(ItemHasContents, true);
connect(m_frameSvg, &FrameSvg::repaintNeeded, this, &FrameSvgItem::doUpdate);
connect(&Units::instance(), &Units::devicePixelRatioChanged, this, &FrameSvgItem::updateDevicePixelRatio);
@ -291,8 +290,12 @@ void FrameSvgItem::setImagePath(const QString &path)
}
emit imagePathChanged();
m_margins->update();
m_fixedMargins->update();
if (m_margins) {
m_margins->update();
}
if (m_fixedMargins) {
m_fixedMargins->update();
}
if (isComponentComplete()) {
applyPrefixes();
@ -334,8 +337,12 @@ void FrameSvgItem::setPrefix(const QVariant &prefixes)
}
emit prefixChanged();
m_margins->update();
m_fixedMargins->update();
if (m_margins) {
m_margins->update();
}
if (m_fixedMargins) {
m_fixedMargins->update();
}
if (isComponentComplete()) {
m_frameSvg->resizeFrame(QSizeF(width(), height()));
@ -354,13 +361,20 @@ QString FrameSvgItem::usedPrefix() const
return m_frameSvg->prefix();
}
FrameSvgItemMargins *FrameSvgItem::margins() const
FrameSvgItemMargins *FrameSvgItem::margins()
{
if (!m_margins) {
m_margins = new FrameSvgItemMargins(m_frameSvg, this);
}
return m_margins;
}
FrameSvgItemMargins *FrameSvgItem::fixedMargins() const
FrameSvgItemMargins *FrameSvgItem::fixedMargins()
{
if (!m_fixedMargins) {
m_fixedMargins = new FrameSvgItemMargins(m_frameSvg, this);
m_fixedMargins->setFixed(true);
}
return m_fixedMargins;
}
@ -404,7 +418,9 @@ void FrameSvgItem::setEnabledBorders(const Plasma::FrameSvg::EnabledBorders bord
m_frameSvg->setEnabledBorders(borders);
emit enabledBordersChanged();
m_textureChanged = true;
m_margins->update();
if (m_margins) {
m_margins->update();
}
update();
}
@ -449,8 +465,12 @@ void FrameSvgItem::doUpdate()
m_textureChanged = true;
update();
m_margins->update();
m_fixedMargins->update();
if (m_margins) {
m_margins->update();
}
if (m_fixedMargins) {
m_fixedMargins->update();
}
emit repaintNeeded();
}

View File

@ -203,8 +203,8 @@ public:
void setEnabledBorders(const Plasma::FrameSvg::EnabledBorders borders);
Plasma::FrameSvg::EnabledBorders enabledBorders() const;
FrameSvgItemMargins *margins() const;
FrameSvgItemMargins *fixedMargins() const;
FrameSvgItemMargins *margins();
FrameSvgItemMargins *fixedMargins();
void setColorGroup(Plasma::Theme::ColorGroup group);
Plasma::Theme::ColorGroup colorGroup() const;