QSinglePointEvent: port away from QMutableEventPoint::from()

Use the new static QMutableEventPoint setters, which do not depend on
undefined behavior.

Made it a separate commit, because, while straight-forward, it's a lot
of changes compared to other users.

Task-number: QTBUG-99615
Pick-to: 6.3
Change-Id: I580b6b225421a1e908f04c8e30adcdef6540ea52
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
Marc Mutz 2022-01-06 22:52:43 +01:00
parent b17c4d0e2e
commit 716c916c40

View File

@ -550,30 +550,30 @@ QSinglePointEvent::QSinglePointEvent(QEvent::Type type, const QPointingDevice *d
bool isWheel = (type == QEvent::Type::Wheel); bool isWheel = (type == QEvent::Type::Wheel);
auto devPriv = QPointingDevicePrivate::get(const_cast<QPointingDevice *>(pointingDevice())); auto devPriv = QPointingDevicePrivate::get(const_cast<QPointingDevice *>(pointingDevice()));
auto epd = devPriv->pointById(0); auto epd = devPriv->pointById(0);
QMutableEventPoint &mut = QMutableEventPoint::from(epd->eventPoint); QEventPoint &p = epd->eventPoint;
Q_ASSERT(mut.device() == dev); Q_ASSERT(p.device() == dev);
// mut is now a reference to a non-detached instance that lives in QPointingDevicePrivate::activePoints. // p is a reference to a non-detached instance that lives in QPointingDevicePrivate::activePoints.
// Update persistent info in that instance. // Update persistent info in that instance.
if (isPress || isWheel) if (isPress || isWheel)
mut.setGlobalLastPosition(globalPos); QMutableEventPoint::setGlobalLastPosition(p, globalPos);
else else
mut.setGlobalLastPosition(mut.globalPosition()); QMutableEventPoint::setGlobalLastPosition(p, p.globalPosition());
mut.setGlobalPosition(globalPos); QMutableEventPoint::setGlobalPosition(p, globalPos);
if (isWheel && mut.state() != QEventPoint::State::Updated) if (isWheel && p.state() != QEventPoint::State::Updated)
mut.setGlobalPressPosition(globalPos); QMutableEventPoint::setGlobalPressPosition(p, globalPos);
if (type == MouseButtonDblClick) if (type == MouseButtonDblClick)
mut.setState(QEventPoint::State::Stationary); QMutableEventPoint::setState(p, QEventPoint::State::Stationary);
else if (button == Qt::NoButton || isWheel) else if (button == Qt::NoButton || isWheel)
mut.setState(QEventPoint::State::Updated); QMutableEventPoint::setState(p, QEventPoint::State::Updated);
else if (isPress) else if (isPress)
mut.setState(QEventPoint::State::Pressed); QMutableEventPoint::setState(p, QEventPoint::State::Pressed);
else else
mut.setState(QEventPoint::State::Released); QMutableEventPoint::setState(p, QEventPoint::State::Released);
mut.setScenePosition(scenePos); QMutableEventPoint::setScenePosition(p, scenePos);
// Now detach, and update the detached instance with ephemeral state. // Now detach, and update the detached instance with ephemeral state.
mut.detach(); QMutableEventPoint::detach(p);
mut.setPosition(localPos); QMutableEventPoint::setPosition(p, localPos);
m_points.append(mut); m_points.append(p);
} }
/*! \internal /*! \internal