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

View File

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