diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2023-03-28 16:00:01 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2023-03-29 08:39:21 +0200 |
commit | f2c108518cd7161bbf38502975a5bb798a66d5dd (patch) | |
tree | fd953d09f1bca5474871d36db69cfa03ebb85544 /src/quick/items/qquickstateoperations.cpp | |
parent | 2b979a29795c8be957c44d38b8b3939605c6a0f2 (diff) |
AnchorChanges: Fix restore logic
The logic to decide whether a state change triggered a size change.
When AnchorChanges did not remove all old anchors, we might end up with
an anchor configuration that changes the size of an item (e.g.,
anchors.left and right being set), even if the new state only adds a
single anchor, e.g. anchors.left.
Moreover, we need to pass the correct dirty flags to setDirty, otherwise
the UI will not actually reflect the state of the Item.
As a driveby, fix an accidental double negation of qt_is_nan for
height.
Fixes: QTBUG-112354
Fixes: QTBUG-106677
Pick-to: 6.5 6.2
Change-Id: I6c456fbdc314672f4fcbe740d941b44183fd5500
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/quick/items/qquickstateoperations.cpp')
-rw-r--r-- | src/quick/items/qquickstateoperations.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/quick/items/qquickstateoperations.cpp b/src/quick/items/qquickstateoperations.cpp index a6e5eed56c..1c8bee7253 100644 --- a/src/quick/items/qquickstateoperations.cpp +++ b/src/quick/items/qquickstateoperations.cpp @@ -1063,6 +1063,9 @@ void QQuickAnchorChanges::reverse() stateHAnchors != QQuickAnchors::LeftAnchor && stateHAnchors != QQuickAnchors::RightAnchor && stateHAnchors != QQuickAnchors::HCenterAnchor); + // in case of an additive AnchorChange, we _did_ end up modifying the width + stateSetWidth |= ((stateHAnchors & QQuickAnchors::LeftAnchor) && (origHAnchors & QQuickAnchors::RightAnchor)) || + ((stateHAnchors & QQuickAnchors::RightAnchor) && (origHAnchors & QQuickAnchors::LeftAnchor)); bool origSetWidth = (origHAnchors && origHAnchors != QQuickAnchors::LeftAnchor && origHAnchors != QQuickAnchors::RightAnchor && @@ -1078,12 +1081,15 @@ void QQuickAnchorChanges::reverse() stateVAnchors != QQuickAnchors::BottomAnchor && stateVAnchors != QQuickAnchors::VCenterAnchor && stateVAnchors != QQuickAnchors::BaselineAnchor); + // in case of an additive AnchorChange, we _did_ end up modifying the height + stateSetHeight |= ((stateVAnchors & QQuickAnchors::TopAnchor) && (origVAnchors & QQuickAnchors::BottomAnchor)) || + ((stateVAnchors & QQuickAnchors::BottomAnchor) && (origVAnchors & QQuickAnchors::TopAnchor)); bool origSetHeight = (origVAnchors && origVAnchors != QQuickAnchors::TopAnchor && origVAnchors != QQuickAnchors::BottomAnchor && origVAnchors != QQuickAnchors::VCenterAnchor && origVAnchors != QQuickAnchors::BaselineAnchor); - if (d->origHeight.isValid() && stateSetHeight && !origSetHeight && !!qt_is_nan(d->origHeight)) { + if (d->origHeight.isValid() && stateSetHeight && !origSetHeight && !qt_is_nan(d->origHeight)) { targetPrivate->heightValidFlag = true; if (targetPrivate->height != d->origHeight) targetPrivate->height.setValueBypassingBindings(d->origHeight); @@ -1097,7 +1103,12 @@ void QQuickAnchorChanges::reverse() const QRectF newGeometry(d->target->position(), d->target->size()); if (newGeometry != oldGeometry) { - targetPrivate->dirty(QQuickItemPrivate::Position); + QQuickItemPrivate::DirtyType dirtyFlags {}; + if (newGeometry.topLeft() != oldGeometry.topLeft()) + dirtyFlags = QQuickItemPrivate::DirtyType(dirtyFlags | QQuickItemPrivate::Position); + if (newGeometry.size() != oldGeometry.size()) + dirtyFlags = QQuickItemPrivate::DirtyType(dirtyFlags | QQuickItemPrivate::Size); + targetPrivate->dirty(dirtyFlags); d->target->geometryChange(newGeometry, oldGeometry); } } |