diff options
author | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2020-11-16 14:57:20 +0100 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2020-11-17 06:21:05 +0100 |
commit | 76dc75c5ff32f61782a413df4915f4ebe9236d76 (patch) | |
tree | 2391cf4ed4f17aaf4116f5e771c4f74065112970 | |
parent | 496c977b43b131c6bf315cc030c21023b60e2661 (diff) | |
download | qtbase-76dc75c5ff32f61782a413df4915f4ebe9236d76.tar.gz |
Allow QMutableSinglePointEvent to be copy- and default-constructed
Since QMutableSinglePointEvent is just an access-helper to QSinglePointEvent,
we can safely create one from the other. This covers QMouseEvent as well
with the right casting in place.
And by making QMSPE default constructable, we can use it in code that
needs to frequently copy event data, for example in QtQuick.
This allows us to make the copy c'tor and assignment operators for QEvent
classes protected, which prevents potentially dangerous (ie. slicing)
implicit copies.
Change-Id: I815774847cca63896f46c43df683053b3d952b61
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
-rw-r--r-- | src/gui/kernel/qevent_p.h | 3 | ||||
-rw-r--r-- | src/widgets/graphicsview/qgraphicsview.cpp | 7 | ||||
-rw-r--r-- | src/widgets/graphicsview/qgraphicsview_p.h | 4 |
3 files changed, 7 insertions, 7 deletions
diff --git a/src/gui/kernel/qevent_p.h b/src/gui/kernel/qevent_p.h index 7c9974db7f..a776b957a5 100644 --- a/src/gui/kernel/qevent_p.h +++ b/src/gui/kernel/qevent_p.h @@ -84,7 +84,8 @@ static_assert(sizeof(QMutableTouchEvent) == sizeof(QTouchEvent)); class Q_GUI_EXPORT QMutableSinglePointEvent : public QSinglePointEvent { public: - QMutableSinglePointEvent(Type type, const QPointingDevice *device, const QEventPoint &point, + QMutableSinglePointEvent(const QSinglePointEvent &other) : QSinglePointEvent(other) {} + QMutableSinglePointEvent(Type type = QEvent::None, const QPointingDevice *device = nullptr, const QEventPoint &point = QEventPoint(), Qt::MouseButton button = Qt::NoButton, Qt::MouseButtons buttons = Qt::NoButton, Qt::KeyboardModifiers modifiers = Qt::NoModifier, Qt::MouseEventSource source = Qt::MouseEventSynthesizedByQt) : diff --git a/src/widgets/graphicsview/qgraphicsview.cpp b/src/widgets/graphicsview/qgraphicsview.cpp index 7c7c094962..847d5fd45c 100644 --- a/src/widgets/graphicsview/qgraphicsview.cpp +++ b/src/widgets/graphicsview/qgraphicsview.cpp @@ -340,7 +340,6 @@ QGraphicsViewPrivate::QGraphicsViewPrivate() hasUpdateClip(false), mousePressButton(Qt::NoButton), leftIndent(0), topIndent(0), - lastMouseEvent(QEvent::None, QPointF(), QPointF(), QPointF(), Qt::NoButton, { }, { }), alignment(Qt::AlignCenter), transformationAnchor(QGraphicsView::AnchorViewCenter), resizeAnchor(QGraphicsView::NoAnchor), viewportUpdateMode(QGraphicsView::MinimalViewportUpdate), @@ -628,7 +627,8 @@ void QGraphicsViewPrivate::replayLastMouseEvent() { if (!useLastMouseEvent || !scene) return; - mouseMoveEventHandler(&lastMouseEvent); + QSinglePointEvent *spe = static_cast<QSinglePointEvent *>(&lastMouseEvent); + mouseMoveEventHandler(static_cast<QMouseEvent *>(spe)); } /*! @@ -637,8 +637,7 @@ void QGraphicsViewPrivate::replayLastMouseEvent() void QGraphicsViewPrivate::storeMouseEvent(QMouseEvent *event) { useLastMouseEvent = true; - lastMouseEvent = QMouseEvent(QEvent::MouseMove, event->position(), event->scenePosition(), event->globalPosition(), - event->button(), event->buttons(), event->modifiers()); + lastMouseEvent = *event; } void QGraphicsViewPrivate::mouseMoveEventHandler(QMouseEvent *event) diff --git a/src/widgets/graphicsview/qgraphicsview_p.h b/src/widgets/graphicsview/qgraphicsview_p.h index 8a8f6bf880..0b137e91dc 100644 --- a/src/widgets/graphicsview/qgraphicsview_p.h +++ b/src/widgets/graphicsview/qgraphicsview_p.h @@ -54,7 +54,7 @@ #include <QtWidgets/private/qtwidgetsglobal_p.h> #include "qgraphicsview.h" -#include <QtGui/qevent.h> +#include <QtGui/private/qevent_p.h> #include <QtCore/qcoreapplication.h> #include "qgraphicssceneevent.h" #include <QtWidgets/qstyleoption.h> @@ -123,7 +123,7 @@ public: qreal topIndent; // Replaying mouse events - QMouseEvent lastMouseEvent; + QMutableSinglePointEvent lastMouseEvent; void replayLastMouseEvent(); void storeMouseEvent(QMouseEvent *event); void mouseMoveEventHandler(QMouseEvent *event); |