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>
This commit is contained in:
parent
496c977b43
commit
76dc75c5ff
@ -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) :
|
||||
|
@ -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)
|
||||
|
@ -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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user