summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qevent.h
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2020-08-06 17:28:06 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2020-08-24 13:50:55 +0200
commit38806273e567a39bd7ca4ced5e6e38dfd7426f27 (patch)
treef2336bf4de830b806903b347238d1c7c6054f3b5 /src/gui/kernel/qevent.h
parent0c52e600b3b5c83d128e6b4068d523829357fef0 (diff)
Remove QEventPoint::event() in favor of device()
event()->device() was the most common use case anyway. The idea that the "parent" of a QEventPoint is the QPointerEvent interferes with the ability to copy and move event objects: the parent pointers are dangling unless we use the QPointerEvent subclass destructors to set the points' parents to null. Since there is no move constructor, even returning a QEventPoint from a function by value results in destroying the temporary instance and copying it to the caller's space. So the parent pointer is often useless, unless we do even more work to maintain it when the event moves. If we optimize to avoid copying QEventPoints too much (and perhaps enable exposing _mutable_ points to QML) by storing reusable instances in QPointingDevice (which is the current plan), then the actual parent will no longer be the event. Events are usually stack-allocated, thus temporary and intended to be movable. Change-Id: I24b648dcc046fc79d2401c781f1fda6cb00f47b0 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/gui/kernel/qevent.h')
-rw-r--r--src/gui/kernel/qevent.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h
index 8ba138a1bb..86878bfb67 100644
--- a/src/gui/kernel/qevent.h
+++ b/src/gui/kernel/qevent.h
@@ -106,10 +106,9 @@ public:
Q_DECLARE_FLAGS(States, State)
Q_FLAG(States)
- QEventPoint(int id = -1, const QPointerEvent *parent = nullptr);
+ QEventPoint(int id = -1, const QPointingDevice *device = nullptr);
QEventPoint(int pointId, State state, const QPointF &scenePosition, const QPointF &globalPosition);
- const QPointerEvent *event() const { return m_parent; }
QPointF position() const { return m_pos; }
QPointF pressPosition() const { return m_globalPressPos - m_globalPos + m_pos; }
QPointF grabPosition() const { return m_globalGrabPos - m_globalPos + m_pos; }
@@ -152,6 +151,7 @@ public:
#endif // QT_DEPRECATED_SINCE(6, 0)
QVector2D velocity() const { return m_velocity; }
State state() const { return m_state; }
+ const QPointingDevice *device() const { return m_device; }
int id() const { return m_pointId; }
QPointingDeviceUniqueId uniqueId() const { return m_uniqueId; }
ulong pressTimestamp() const { return m_pressTimestamp; }
@@ -169,7 +169,7 @@ public:
void clearPassiveGrabbers();
protected:
- const QPointerEvent *m_parent = nullptr;
+ const QPointingDevice *m_device = nullptr;
QPointF m_pos, m_scenePos, m_globalPos,
m_globalPressPos, m_globalGrabPos, m_globalLastPos;
qreal m_pressure = 1;
@@ -178,7 +178,7 @@ protected:
QVector2D m_velocity;
QPointer<QObject> m_exclusiveGrabber;
QList<QPointer <QObject> > m_passiveGrabbers;
- ulong m_timestamp = 0; // redundant with m_parent->timestamp(), but keeps timeHeld() working in a saved copy
+ ulong m_timestamp = 0;
ulong m_pressTimestamp = 0;
QPointingDeviceUniqueId m_uniqueId;
int m_pointId = -1;