Update parent item's bounding rect explicitly

If the parent's bounding rect may change, call its update method
explicitly. This way the code is more readable as there is less
signal-slot magic.
This commit is contained in:
Vlad Zahorodnii 2021-07-05 20:32:03 +03:00
parent fb276dbdd2
commit db6b4c9c2e

View file

@ -51,6 +51,7 @@ void Item::setX(int x)
}
scheduleRepaint(boundingRect());
m_x = x;
updateBoundingRect();
scheduleRepaint(boundingRect());
Q_EMIT xChanged();
}
@ -67,6 +68,7 @@ void Item::setY(int y)
}
scheduleRepaint(boundingRect());
m_y = y;
updateBoundingRect();
scheduleRepaint(boundingRect());
Q_EMIT yChanged();
}
@ -131,10 +133,6 @@ void Item::addChild(Item *item)
{
Q_ASSERT(!m_childItems.contains(item));
connect(item, &Item::xChanged, this, &Item::updateBoundingRect);
connect(item, &Item::yChanged, this, &Item::updateBoundingRect);
connect(item, &Item::boundingRectChanged, this, &Item::updateBoundingRect);
m_childItems.append(item);
updateBoundingRect();
scheduleRepaint(item->boundingRect().translated(item->position()));
@ -147,10 +145,6 @@ void Item::removeChild(Item *item)
m_childItems.removeOne(item);
disconnect(item, &Item::xChanged, this, &Item::updateBoundingRect);
disconnect(item, &Item::yChanged, this, &Item::updateBoundingRect);
disconnect(item, &Item::boundingRectChanged, this, &Item::updateBoundingRect);
updateBoundingRect();
}
@ -178,6 +172,7 @@ void Item::setPosition(const QPoint &point)
scheduleRepaint(boundingRect());
m_x = point.x();
m_y = point.y();
updateBoundingRect();
scheduleRepaint(boundingRect());
if (xDirty) {
@ -236,6 +231,9 @@ void Item::updateBoundingRect()
if (m_boundingRect != boundingRect) {
m_boundingRect = boundingRect;
Q_EMIT boundingRectChanged();
if (m_parentItem) {
m_parentItem->updateBoundingRect();
}
}
}