summaryrefslogtreecommitdiffstats
path: root/tests/auto/gui/kernel/qmouseevent
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2022-10-14 10:15:01 +0200
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2022-12-10 06:38:58 +0100
commit12b7eab4d24e867675a27ab1785ff03318f9add1 (patch)
treea5223e98fce0890c6cb304a9d0724b87c6c641d4 /tests/auto/gui/kernel/qmouseevent
parent585f2a31c61c3981065015494f9d487d8ece4ad5 (diff)
Detach event points when cloning pointer events
Input events that originate from actual device interaction should reflect the device's state, and device and events need to be kept in sync so that event sequences (such as multi-touch events, where we have begin/update/end cycles spanning multiple events) are working correctly. For that reason, the event point data in pointer events is explicitly shared, and we only detach in exceptional situations. This saves us memory allocations, and makes sure that the event point data carried by events, and the event point data stored persistently in the device, are kept in sync. Cloned pointer events do not originate from device interactions, and should therefore not sync back to the device. E.g. accepting a clone should not modify the original event data stored in the device. There are exceptions here as well, e.g. when cloning an event in Qt in order to deliver a translated version of it to a different scene. Different points might even get delivered to different scenes or windows, or at least different items in the same scene. For that reason, we explicitly detach, and then explicitly write back the relevant states after the cloned event has been delivered. But in general, we should assume that cloned events do not write back to the device. Since QEventPoint is an explicitly shared data type that never detaches itself, we have to explicitly detach it when making copies that should not be shared. The ideal implementation of this would be to do the detach in the copy constructor of QPointerEvent, which is called when cloning. However, Qt itself makes copies of QPointerEvent without using clone, e.g. when assembling lists of touch events for the different subscenes or windows in QGuiApplicationPrivate::processTouchEvent, where event objects are added to a QVarLengthArray<QMutableTouchEvent>. This makes copies, and those copies must not detach. So we have to implement the special cloning behavior in each override of QPointerEvent::clone(). For this, introduce a dedicated macro for the common member functions. This macro must be used for QPointerEvent subclasses. Fixes: QTBUG-107560 Change-Id: I4b56f9e71c7d067ba9054a2a631e8ba5bc7b1ab9 Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'tests/auto/gui/kernel/qmouseevent')
-rw-r--r--tests/auto/gui/kernel/qmouseevent/tst_qmouseevent.cpp20
1 files changed, 20 insertions, 0 deletions
diff --git a/tests/auto/gui/kernel/qmouseevent/tst_qmouseevent.cpp b/tests/auto/gui/kernel/qmouseevent/tst_qmouseevent.cpp
index d7cc8a572c..dda91225e5 100644
--- a/tests/auto/gui/kernel/qmouseevent/tst_qmouseevent.cpp
+++ b/tests/auto/gui/kernel/qmouseevent/tst_qmouseevent.cpp
@@ -97,6 +97,7 @@ private slots:
void grabbers_data();
void grabbers();
void velocity();
+ void clone();
private:
MouseEventWidget* testMouseWidget;
@@ -309,5 +310,24 @@ void tst_QMouseEvent::velocity()
QVERIFY(testMouseWidget->velocity.y() > 0);
}
+void tst_QMouseEvent::clone()
+{
+ const QPointF pos(10.0f, 10.0f);
+
+ QMouseEvent originalMe(QEvent::MouseButtonPress, pos, pos, pos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
+ QVERIFY(!originalMe.allPointsAccepted());
+ QVERIFY(!originalMe.points().first().isAccepted());
+
+ // create a clone of the original
+ std::unique_ptr<QMouseEvent> clonedMe(originalMe.clone());
+ QVERIFY(!clonedMe->allPointsAccepted());
+ QVERIFY(!clonedMe->points().first().isAccepted());
+
+ // now we alter originalMe, which should *not* change clonedMe
+ originalMe.setAccepted(true);
+ QVERIFY(!clonedMe->allPointsAccepted());
+ QVERIFY(!clonedMe->points().first().isAccepted());
+}
+
QTEST_MAIN(tst_QMouseEvent)
#include "tst_qmouseevent.moc"