Tidy up in QGraphicsWidget::resize()

Simplify various conditions.
Eliminate duplication from an overly-complex if/else cascade.
Move the set-up of a QGraphicsSceneResizeEvent to only happen if it's
going to be used.

Change-Id: Ie51aa5de5f2bd1603478ae0cda0fd4279334f45a
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
Edward Welbourne 2021-10-13 13:34:21 +02:00
parent ed9665597d
commit c179549a74

View File

@ -387,50 +387,41 @@ void QGraphicsWidget::setGeometry(const QRectF &rect)
if (newGeom == d->geom)
return;
// Update and prepare to change the geometry (remove from index) if the size has changed.
if (wd->scene) {
if (rect.topLeft() == d->geom.topLeft()) {
prepareGeometryChange();
}
}
// Update and prepare to change the geometry (remove from index) if
// the size has changed.
if (wd->scene && rect.topLeft() == d->geom.topLeft())
prepareGeometryChange();
}
// Update the layout item geometry
{
bool moved = oldPos != pos();
if (moved) {
// Send move event.
QGraphicsSceneMoveEvent event;
event.setOldPos(oldPos);
event.setNewPos(pos());
QCoreApplication::sendEvent(this, &event);
if (wd->inSetPos) {
//set the new pos
d->geom.moveTopLeft(pos());
emit geometryChanged();
return;
}
if (oldPos != pos()) {
// Send move event.
QGraphicsSceneMoveEvent event;
event.setOldPos(oldPos);
event.setNewPos(pos());
QCoreApplication::sendEvent(this, &event);
if (wd->inSetPos) {
// Set the new position:
d->geom.moveTopLeft(pos());
emit geometryChanged();
return;
}
QSizeF oldSize = size();
QGraphicsLayoutItem::setGeometry(newGeom);
// Send resize event
bool resized = newGeom.size() != oldSize;
if (resized) {
}
QSizeF oldSize = size();
QGraphicsLayoutItem::setGeometry(newGeom);
// Send resize event, if appropriate:
if (newGeom.size() != oldSize) {
if (oldSize.width() != newGeom.size().width())
emit widthChanged();
if (oldSize.height() != newGeom.size().height())
emit heightChanged();
QGraphicsLayout *lay = wd->layout;
if (!QGraphicsLayout::instantInvalidatePropagation() || !lay || lay->isActivated()) {
QGraphicsSceneResizeEvent re;
re.setOldSize(oldSize);
re.setNewSize(newGeom.size());
if (oldSize.width() != newGeom.size().width())
emit widthChanged();
if (oldSize.height() != newGeom.size().height())
emit heightChanged();
QGraphicsLayout *lay = wd->layout;
if (QGraphicsLayout::instantInvalidatePropagation()) {
if (!lay || lay->isActivated()) {
QCoreApplication::sendEvent(this, &re);
}
} else {
QCoreApplication::sendEvent(this, &re);
}
QCoreApplication::sendEvent(this, &re);
}
}