diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2021-10-13 13:34:21 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2021-10-14 18:40:22 +0200 |
commit | c179549a7402d70ed4be5ab3af5939667f4238a1 (patch) | |
tree | 322bab81e3370fb459433554a034b628726dccad | |
parent | ed9665597d1f8c67012e14877faa78e536449ed4 (diff) |
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>
-rw-r--r-- | src/widgets/graphicsview/qgraphicswidget.cpp | 65 |
1 files changed, 28 insertions, 37 deletions
diff --git a/src/widgets/graphicsview/qgraphicswidget.cpp b/src/widgets/graphicsview/qgraphicswidget.cpp index 2745dff351..c857d5dc5a 100644 --- a/src/widgets/graphicsview/qgraphicswidget.cpp +++ b/src/widgets/graphicsview/qgraphicswidget.cpp @@ -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); } } |