QGuiApplication: port the last user of QMutableEventPoint::from()

... to the new static setter API, preventing the undefined behavior
that from() depended on.

Remove from() and constFrom().

Task-number: QTBUG-99615
Pick-to: 6.3
Change-Id: I69c52aa286eaf51303734e42184af36815cf828a
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
This commit is contained in:
Marc Mutz 2022-01-07 12:26:21 +01:00 committed by Shawn Rutledge
parent 3215416e3c
commit 31669722d9
3 changed files with 40 additions and 44 deletions

View File

@ -524,8 +524,8 @@ void QMutableEventPoint::detach(QEventPoint &p)
} }
/*! \internal /*! \internal
Update current state from the given \a other point, assuming that this Update \a target state from the \a other point, assuming that \a target
instance contains state from the previous event and \a other contains new contains state from the previous event and \a other contains new
values that came in from a device. values that came in from a device.
That is: global position and other valuators will be updated, but That is: global position and other valuators will be updated, but
@ -537,40 +537,40 @@ void QMutableEventPoint::detach(QEventPoint &p)
\li properties that should be persistent between events (such as grabbers) \li properties that should be persistent between events (such as grabbers)
\endlist \endlist
*/ */
void QMutableEventPoint::updateFrom(const QEventPoint &other) void QMutableEventPoint::update(const QEventPoint &other, QEventPoint &target)
{ {
detach(); detach(target);
setPressure(other.pressure()); setPressure(target, other.pressure());
switch (other.state()) { switch (other.state()) {
case QEventPoint::State::Pressed: case QEventPoint::State::Pressed:
setGlobalPressPosition(other.globalPosition()); setGlobalPressPosition(target, other.globalPosition());
setGlobalLastPosition(other.globalPosition()); setGlobalLastPosition(target, other.globalPosition());
if (pressure() < 0) if (target.pressure() < 0)
setPressure(1); setPressure(target, 1);
break; break;
case QEventPoint::State::Released: case QEventPoint::State::Released:
if (globalPosition() != other.globalPosition()) if (target.globalPosition() != other.globalPosition())
setGlobalLastPosition(globalPosition()); setGlobalLastPosition(target, target.globalPosition());
setPressure(0); setPressure(target, 0);
break; break;
default: // update or stationary default: // update or stationary
if (globalPosition() != other.globalPosition()) if (target.globalPosition() != other.globalPosition())
setGlobalLastPosition(globalPosition()); setGlobalLastPosition(target, target.globalPosition());
if (pressure() < 0) if (target.pressure() < 0)
setPressure(1); setPressure(target, 1);
break; break;
} }
setState(other.state()); setState(target, other.state());
setPosition(other.position()); setPosition(target, other.position());
setScenePosition(other.scenePosition()); setScenePosition(target, other.scenePosition());
setGlobalPosition(other.globalPosition()); setGlobalPosition(target, other.globalPosition());
setEllipseDiameters(other.ellipseDiameters()); setEllipseDiameters(target, other.ellipseDiameters());
setRotation(other.rotation()); setRotation(target, other.rotation());
setVelocity(other.velocity()); setVelocity(target, other.velocity());
} }
/*! \internal /*! \internal

View File

@ -133,13 +133,7 @@ public:
d->pos = position; d->pos = position;
} }
void updateFrom(const QEventPoint &other); static void update(const QEventPoint &from, QEventPoint &to);
static QMutableEventPoint *from(QEventPoint *me) { return static_cast<QMutableEventPoint *>(me); }
static QMutableEventPoint &from(QEventPoint &me) { return static_cast<QMutableEventPoint &>(me); }
static const QMutableEventPoint &constFrom(const QEventPoint &me) { return static_cast<const QMutableEventPoint &>(me); }
void detach() { detach(*this); } void detach() { detach(*this); }
static void detach(QEventPoint &p); static void detach(QEventPoint &p);

View File

@ -2849,7 +2849,7 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
for (auto &tempPt : e->points) { for (auto &tempPt : e->points) {
// update state // update state
auto epd = devPriv->pointById(tempPt.id()); auto epd = devPriv->pointById(tempPt.id());
auto &mut = QMutableEventPoint::from(epd->eventPoint); auto &ep = epd->eventPoint;
epd->eventPoint.setAccepted(false); epd->eventPoint.setAccepted(false);
switch (tempPt.state()) { switch (tempPt.state()) {
case QEventPoint::State::Pressed: case QEventPoint::State::Pressed:
@ -2859,19 +2859,21 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
// If the QPA event didn't tell us which window, find the one under the touchpoint position. // If the QPA event didn't tell us which window, find the one under the touchpoint position.
if (!window) if (!window)
window = QGuiApplication::topLevelAt(tempPt.globalPosition().toPoint()); window = QGuiApplication::topLevelAt(tempPt.globalPosition().toPoint());
mut.setWindow(window); QMutableEventPoint::setWindow(ep, window);
break; break;
case QEventPoint::State::Released: case QEventPoint::State::Released:
if (Q_UNLIKELY(!window.isNull() && window != mut.window())) if (Q_UNLIKELY(!window.isNull() && window != QMutableEventPoint::window(ep)))
qCWarning(lcPtrDispatch) << "delivering touch release to same window" << mut.window() << "not" << window.data(); qCWarning(lcPtrDispatch) << "delivering touch release to same window"
window = mut.window(); << QMutableEventPoint::window(ep) << "not" << window.data();
window = QMutableEventPoint::window(ep);
break; break;
default: // update or stationary default: // update or stationary
if (Q_UNLIKELY(!window.isNull() && window != mut.window())) if (Q_UNLIKELY(!window.isNull() && window != QMutableEventPoint::window(ep)))
qCWarning(lcPtrDispatch) << "delivering touch update to same window" << mut.window() << "not" << window.data(); qCWarning(lcPtrDispatch) << "delivering touch update to same window"
window = mut.window(); << QMutableEventPoint::window(ep) << "not" << window.data();
window = QMutableEventPoint::window(ep);
break; break;
} }
// If we somehow still don't have a window, we can't deliver this touchpoint. (should never happen) // If we somehow still don't have a window, we can't deliver this touchpoint. (should never happen)
@ -2879,30 +2881,30 @@ void QGuiApplicationPrivate::processTouchEvent(QWindowSystemInterfacePrivate::To
qCWarning(lcPtrDispatch) << "skipping" << &tempPt << ": no target window"; qCWarning(lcPtrDispatch) << "skipping" << &tempPt << ": no target window";
continue; continue;
} }
mut.updateFrom(tempPt); QMutableEventPoint::update(tempPt, ep);
Q_ASSERT(window.data() != nullptr); Q_ASSERT(window.data() != nullptr);
// make the *scene* position the same as the *global* position // make the *scene* position the same as the *global* position
mut.setScenePosition(tempPt.globalPosition()); QMutableEventPoint::setScenePosition(ep, tempPt.globalPosition());
// store the scene position as local position, for now // store the scene position as local position, for now
mut.setPosition(window->mapFromGlobal(tempPt.globalPosition())); QMutableEventPoint::setPosition(ep, window->mapFromGlobal(tempPt.globalPosition()));
// setTimeStamp has side effects, so we do it last // setTimeStamp has side effects, so we do it last
mut.setTimestamp(e->timestamp); QMutableEventPoint::setTimestamp(ep, e->timestamp);
// add the touchpoint to the event that will be delivered to the window // add the touchpoint to the event that will be delivered to the window
bool added = false; bool added = false;
for (QMutableTouchEvent &ev : touchEvents) { for (QMutableTouchEvent &ev : touchEvents) {
if (ev.target() == window.data()) { if (ev.target() == window.data()) {
ev.addPoint(mut); ev.addPoint(ep);
added = true; added = true;
break; break;
} }
} }
if (!added) { if (!added) {
QMutableTouchEvent mte(e->touchType, device, e->modifiers, {mut}); QMutableTouchEvent mte(e->touchType, device, e->modifiers, {ep});
mte.setTimestamp(e->timestamp); mte.setTimestamp(e->timestamp);
mte.setTarget(window.data()); mte.setTarget(window.data());
touchEvents.append(mte); touchEvents.append(mte);