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:
parent
fb276dbdd2
commit
db6b4c9c2e
1 changed files with 6 additions and 8 deletions
14
src/item.cpp
14
src/item.cpp
|
@ -51,6 +51,7 @@ void Item::setX(int x)
|
||||||
}
|
}
|
||||||
scheduleRepaint(boundingRect());
|
scheduleRepaint(boundingRect());
|
||||||
m_x = x;
|
m_x = x;
|
||||||
|
updateBoundingRect();
|
||||||
scheduleRepaint(boundingRect());
|
scheduleRepaint(boundingRect());
|
||||||
Q_EMIT xChanged();
|
Q_EMIT xChanged();
|
||||||
}
|
}
|
||||||
|
@ -67,6 +68,7 @@ void Item::setY(int y)
|
||||||
}
|
}
|
||||||
scheduleRepaint(boundingRect());
|
scheduleRepaint(boundingRect());
|
||||||
m_y = y;
|
m_y = y;
|
||||||
|
updateBoundingRect();
|
||||||
scheduleRepaint(boundingRect());
|
scheduleRepaint(boundingRect());
|
||||||
Q_EMIT yChanged();
|
Q_EMIT yChanged();
|
||||||
}
|
}
|
||||||
|
@ -131,10 +133,6 @@ void Item::addChild(Item *item)
|
||||||
{
|
{
|
||||||
Q_ASSERT(!m_childItems.contains(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);
|
m_childItems.append(item);
|
||||||
updateBoundingRect();
|
updateBoundingRect();
|
||||||
scheduleRepaint(item->boundingRect().translated(item->position()));
|
scheduleRepaint(item->boundingRect().translated(item->position()));
|
||||||
|
@ -147,10 +145,6 @@ void Item::removeChild(Item *item)
|
||||||
|
|
||||||
m_childItems.removeOne(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();
|
updateBoundingRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,6 +172,7 @@ void Item::setPosition(const QPoint &point)
|
||||||
scheduleRepaint(boundingRect());
|
scheduleRepaint(boundingRect());
|
||||||
m_x = point.x();
|
m_x = point.x();
|
||||||
m_y = point.y();
|
m_y = point.y();
|
||||||
|
updateBoundingRect();
|
||||||
scheduleRepaint(boundingRect());
|
scheduleRepaint(boundingRect());
|
||||||
|
|
||||||
if (xDirty) {
|
if (xDirty) {
|
||||||
|
@ -236,6 +231,9 @@ void Item::updateBoundingRect()
|
||||||
if (m_boundingRect != boundingRect) {
|
if (m_boundingRect != boundingRect) {
|
||||||
m_boundingRect = boundingRect;
|
m_boundingRect = boundingRect;
|
||||||
Q_EMIT boundingRectChanged();
|
Q_EMIT boundingRectChanged();
|
||||||
|
if (m_parentItem) {
|
||||||
|
m_parentItem->updateBoundingRect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue