Reduce spurious signal emissions

Summary:
We were reporting that the margins were changing whenever anything changed
in a FrameSvg, this patch makes sure we are only reporting the changes
when it actually changes.
This also fixes a binding loop in Desktop.qml from plasma-desktop.

BUG: 382233

Reviewers: #plasma, davidedmundson

Reviewed By: #plasma, davidedmundson

Subscribers: broulik, davidedmundson, plasma-devel, #frameworks

Tags: #plasma, #frameworks

Differential Revision: https://phabricator.kde.org/D8809
This commit is contained in:
Aleix Pol 2017-11-14 03:13:07 +01:00
parent eab0378735
commit 11c9206bf6
3 changed files with 44 additions and 23 deletions

View File

@ -232,6 +232,13 @@ qreal FrameSvgItemMargins::vertical() const
return top() + bottom(); return top() + bottom();
} }
QVector<qreal> FrameSvgItemMargins::margins() const
{
qreal left, top, right, bottom;
m_frameSvg->getMargins(left, top, right, bottom);
return {left, top, right, bottom};
}
void FrameSvgItemMargins::update() void FrameSvgItemMargins::update()
{ {
emit marginsChanged(); emit marginsChanged();
@ -272,12 +279,32 @@ FrameSvgItem::~FrameSvgItem()
{ {
} }
class CheckMarginsChange
{
public:
CheckMarginsChange(FrameSvgItemMargins *margins)
: m_oldMargins(margins ? margins->margins() : QVector<qreal>()), m_margins(margins)
{}
~CheckMarginsChange() {
if (m_margins && m_margins->margins() != m_oldMargins) {
m_margins->update();
}
}
const QVector<qreal> m_oldMargins;
FrameSvgItemMargins *const m_margins;
};
void FrameSvgItem::setImagePath(const QString &path) void FrameSvgItem::setImagePath(const QString &path)
{ {
if (m_frameSvg->imagePath() == path) { if (m_frameSvg->imagePath() == path) {
return; return;
} }
CheckMarginsChange checkMargins(m_margins);
CheckMarginsChange checkFixedMargins(m_fixedMargins);
updateDevicePixelRatio(); updateDevicePixelRatio();
m_frameSvg->setImagePath(path); m_frameSvg->setImagePath(path);
@ -290,12 +317,6 @@ void FrameSvgItem::setImagePath(const QString &path)
} }
emit imagePathChanged(); emit imagePathChanged();
if (m_margins) {
m_margins->update();
}
if (m_fixedMargins) {
m_fixedMargins->update();
}
if (isComponentComplete()) { if (isComponentComplete()) {
applyPrefixes(); applyPrefixes();
@ -325,6 +346,9 @@ void FrameSvgItem::setPrefix(const QVariant &prefixes)
return; return;
} }
CheckMarginsChange checkMargins(m_margins);
CheckMarginsChange checkFixedMargins(m_fixedMargins);
m_prefixes = prefixList; m_prefixes = prefixList;
applyPrefixes(); applyPrefixes();
@ -337,12 +361,6 @@ void FrameSvgItem::setPrefix(const QVariant &prefixes)
} }
emit prefixChanged(); emit prefixChanged();
if (m_margins) {
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()));
@ -415,12 +433,11 @@ void FrameSvgItem::setEnabledBorders(const Plasma::FrameSvg::EnabledBorders bord
return; return;
} }
CheckMarginsChange checkMargins(m_margins);
m_frameSvg->setEnabledBorders(borders); m_frameSvg->setEnabledBorders(borders);
emit enabledBordersChanged(); emit enabledBordersChanged();
m_textureChanged = true; m_textureChanged = true;
if (m_margins) {
m_margins->update();
}
update(); update();
} }
@ -446,6 +463,9 @@ void FrameSvgItem::geometryChanged(const QRectF &newGeometry,
void FrameSvgItem::doUpdate() void FrameSvgItem::doUpdate()
{ {
CheckMarginsChange checkMargins(m_margins);
CheckMarginsChange checkFixedMargins(m_fixedMargins);
//if the theme changed, the available prefix may have changed as well //if the theme changed, the available prefix may have changed as well
applyPrefixes(); applyPrefixes();
@ -473,12 +493,7 @@ void FrameSvgItem::doUpdate()
m_textureChanged = true; m_textureChanged = true;
update(); update();
if (m_margins) {
m_margins->update();
}
if (m_fixedMargins) {
m_fixedMargins->update();
}
emit repaintNeeded(); emit repaintNeeded();
} }
@ -569,6 +584,9 @@ void FrameSvgItem::classBegin()
void FrameSvgItem::componentComplete() void FrameSvgItem::componentComplete()
{ {
CheckMarginsChange checkMargins(m_margins);
CheckMarginsChange checkFixedMargins(m_fixedMargins);
QQuickItem::componentComplete(); QQuickItem::componentComplete();
m_frameSvg->resizeFrame(QSize(width(), height())); m_frameSvg->resizeFrame(QSize(width(), height()));
m_frameSvg->setRepaintBlocked(false); m_frameSvg->setRepaintBlocked(false);

View File

@ -83,6 +83,9 @@ public:
qreal horizontal() const; qreal horizontal() const;
qreal vertical() const; qreal vertical() const;
/// returns a vector with left, top, right, bottom
QVector<qreal> margins() const;
void setFixed(bool fixed); void setFixed(bool fixed);
bool isFixed() const; bool isFixed() const;

View File

@ -275,7 +275,7 @@ qreal FrameSvg::fixedMarginSize(const Plasma::Types::MarginEdge edge) const
void FrameSvg::getMargins(qreal &left, qreal &top, qreal &right, qreal &bottom) const void FrameSvg::getMargins(qreal &left, qreal &top, qreal &right, qreal &bottom) const
{ {
if (d->frame->noBorderPadding) { if (!d->frame || d->frame->noBorderPadding) {
left = top = right = bottom = 0; left = top = right = bottom = 0;
return; return;
} }
@ -288,7 +288,7 @@ void FrameSvg::getMargins(qreal &left, qreal &top, qreal &right, qreal &bottom)
void FrameSvg::getFixedMargins(qreal &left, qreal &top, qreal &right, qreal &bottom) const void FrameSvg::getFixedMargins(qreal &left, qreal &top, qreal &right, qreal &bottom) const
{ {
if (d->frame->noBorderPadding) { if (!d->frame || d->frame->noBorderPadding) {
left = top = right = bottom = 0; left = top = right = bottom = 0;
return; return;
} }