From 36707b549f0e146fd1f670e5f16b8ce1259f1a0b Mon Sep 17 00:00:00 2001 From: Mike Krus Date: Mon, 23 Nov 2020 11:20:41 +0000 Subject: Handle fallout from QEvent loosing it's copy constructor Task-number: QTBUG-88757 Change-Id: I5097faecd2e895d4685a4cc57a4e2a5c079f2255 Reviewed-by: Paul Lemire (cherry picked from commit d826238b65b0ebd8034900224b382bd85e6add27) Reviewed-by: Qt Cherry-pick Bot --- src/input/frontend/qkeyevent.cpp | 8 ++++---- src/input/frontend/qkeyevent.h | 22 +++++++++++----------- src/input/frontend/qmouseevent.cpp | 26 +++++++++++++++++--------- src/input/frontend/qmouseevent.h | 33 +++++++++++++++++---------------- 4 files changed, 49 insertions(+), 40 deletions(-) (limited to 'src/input') diff --git a/src/input/frontend/qkeyevent.cpp b/src/input/frontend/qkeyevent.cpp index efbddc771..07319ea53 100644 --- a/src/input/frontend/qkeyevent.cpp +++ b/src/input/frontend/qkeyevent.cpp @@ -74,16 +74,16 @@ namespace Qt3DInput { QKeyEvent::QKeyEvent(QEvent::Type type, int key, Qt::KeyboardModifiers modifiers, const QString &text, bool autorep, ushort count) : QObject() - , m_event(type, key, modifiers, text, autorep, count) + , m_event(new QT_PREPEND_NAMESPACE(QKeyEvent){type, key, modifiers, text, autorep, count}) { - m_event.setAccepted(false); + m_event->setAccepted(false); } QKeyEvent::QKeyEvent(const QT_PREPEND_NAMESPACE(QKeyEvent) &ke) : QObject() - , m_event(ke) + , m_event(static_cast(ke.clone())) { - m_event.setAccepted(false); + m_event->setAccepted(false); } /*! \internal */ diff --git a/src/input/frontend/qkeyevent.h b/src/input/frontend/qkeyevent.h index c1e221aae..52be3b213 100644 --- a/src/input/frontend/qkeyevent.h +++ b/src/input/frontend/qkeyevent.h @@ -69,21 +69,21 @@ public: explicit QKeyEvent(const QT_PREPEND_NAMESPACE(QKeyEvent) &ke); ~QKeyEvent(); - inline int key() const { return m_event.key(); } - inline QString text() const { return m_event.text(); } - inline int modifiers() const { return m_event.modifiers(); } - inline bool isAutoRepeat() const { return m_event.isAutoRepeat(); } - inline int count() const { return m_event.count(); } - inline quint32 nativeScanCode() const { return m_event.nativeScanCode(); } - inline bool isAccepted() const { return m_event.isAccepted(); } - inline void setAccepted(bool accepted) { m_event.setAccepted(accepted); } - inline QEvent::Type type() const { return m_event.type(); } + inline int key() const { return m_event->key(); } + inline QString text() const { return m_event->text(); } + inline int modifiers() const { return m_event->modifiers(); } + inline bool isAutoRepeat() const { return m_event->isAutoRepeat(); } + inline int count() const { return m_event->count(); } + inline quint32 nativeScanCode() const { return m_event->nativeScanCode(); } + inline bool isAccepted() const { return m_event->isAccepted(); } + inline void setAccepted(bool accepted) { m_event->setAccepted(accepted); } + inline QEvent::Type type() const { return m_event->type(); } #if QT_CONFIG(shortcut) - Q_INVOKABLE bool matches(QKeySequence::StandardKey key_) const { return m_event.matches(key_); } + Q_INVOKABLE bool matches(QKeySequence::StandardKey key_) const { return m_event->matches(key_); } #endif private: - QT_PREPEND_NAMESPACE(QKeyEvent) m_event; + std::unique_ptr m_event; }; } // namespace Qt3DInput diff --git a/src/input/frontend/qmouseevent.cpp b/src/input/frontend/qmouseevent.cpp index 2b06c824d..d73724360 100644 --- a/src/input/frontend/qmouseevent.cpp +++ b/src/input/frontend/qmouseevent.cpp @@ -46,9 +46,9 @@ namespace Qt3DInput { namespace { template -typename EventClass::Modifiers modifiersForEvent(const QtEventClass &event) +typename EventClass::Modifiers modifiersForEvent(const QtEventClass *event) { - const Qt::KeyboardModifiers eventModifiers = event.modifiers(); + const Qt::KeyboardModifiers eventModifiers = event->modifiers(); int modifiers = EventClass::NoModifier; if (eventModifiers & Qt::ShiftModifier) @@ -259,7 +259,11 @@ typename EventClass::Modifiers modifiersForEvent(const QtEventClass &event) */ QMouseEvent::QMouseEvent(const QT_PREPEND_NAMESPACE(QMouseEvent) &e) : QObject() - , m_event(e) +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + , m_event(static_cast(e.clone())) +#else + , m_even(new QT_PREPEND_NAMESPACE(QMouseEvent)(e)) +#endif { } @@ -272,7 +276,7 @@ QMouseEvent::~QMouseEvent() */ QMouseEvent::Buttons QMouseEvent::button() const { - switch (m_event.button()) { + switch (m_event->button()) { case Qt::LeftButton: return QMouseEvent::LeftButton; case Qt::RightButton: @@ -292,7 +296,7 @@ QMouseEvent::Buttons QMouseEvent::button() const */ int QMouseEvent::buttons() const { - return m_event.buttons(); + return m_event->buttons(); } /*! @@ -300,7 +304,7 @@ int QMouseEvent::buttons() const */ QMouseEvent::Modifiers QMouseEvent::modifiers() const { - return modifiersForEvent(m_event); + return modifiersForEvent(m_event.get()); } /*! @@ -478,7 +482,11 @@ QMouseEvent::Modifiers QMouseEvent::modifiers() const */ QWheelEvent::QWheelEvent(const QT_PREPEND_NAMESPACE(QWheelEvent) &e) : QObject() - , m_event(e) +#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) + , m_event(static_cast(e.clone())) +#else + , m_even(new QT_PREPEND_NAMESPACE(QMouseEvent)(e)) +#endif { } @@ -492,7 +500,7 @@ QWheelEvent::~QWheelEvent() */ int QWheelEvent::buttons() const { - return m_event.buttons(); + return m_event->buttons(); } /*! @@ -500,7 +508,7 @@ int QWheelEvent::buttons() const */ QWheelEvent::Modifiers QWheelEvent::modifiers() const { - return modifiersForEvent(m_event); + return modifiersForEvent(m_event.get()); } #endif // QT_CONFIG(wheelevent) diff --git a/src/input/frontend/qmouseevent.h b/src/input/frontend/qmouseevent.h index a663c2e44..809c71ec5 100644 --- a/src/input/frontend/qmouseevent.h +++ b/src/input/frontend/qmouseevent.h @@ -45,6 +45,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE namespace Qt3DInput { @@ -59,7 +61,6 @@ class Q_3DINPUTSHARED_EXPORT QMouseEvent : public QObject Q_PROPERTY(int buttons READ buttons CONSTANT) Q_PROPERTY(Qt3DInput::QMouseEvent::Modifiers modifiers READ modifiers CONSTANT) Q_PROPERTY(bool accepted READ isAccepted WRITE setAccepted) - public: enum Buttons { LeftButton = Qt::LeftButton, @@ -84,25 +85,25 @@ public: explicit QMouseEvent(const QT_PREPEND_NAMESPACE(QMouseEvent) &e); ~QMouseEvent(); - inline int x() const { return int(m_event.position().x()); } - inline int y() const { return int(m_event.position().y()); } + inline int x() const { return int(m_event->position().x()); } + inline int y() const { return int(m_event->position().y()); } inline bool wasHeld() const { #if QT_CONFIG(gestures) - return static_cast(m_event.type()) == Qt::TapAndHoldGesture; + return static_cast(m_event->type()) == Qt::TapAndHoldGesture; #else - return false; + return false; #endif } Buttons button() const; int buttons() const; Modifiers modifiers() const; - inline bool isAccepted() const { return m_event.isAccepted(); } - inline void setAccepted(bool accepted) { m_event.setAccepted(accepted); } - inline QEvent::Type type() const { return m_event.type(); } + inline bool isAccepted() const { return m_event->isAccepted(); } + inline void setAccepted(bool accepted) { m_event->setAccepted(accepted); } + inline QEvent::Type type() const { return m_event->type(); } private: - QT_PREPEND_NAMESPACE(QMouseEvent) m_event; + std::unique_ptr m_event; }; typedef QSharedPointer QMouseEventPtr; @@ -142,18 +143,18 @@ public: explicit QWheelEvent(const QT_PREPEND_NAMESPACE(QWheelEvent) &e); ~QWheelEvent(); - inline int x() const { return int(m_event.position().x()); } - inline int y() const { return int(m_event.position().y()); } - inline QPoint angleDelta() const { return m_event.angleDelta(); } + inline int x() const { return int(m_event->position().x()); } + inline int y() const { return int(m_event->position().y()); } + inline QPoint angleDelta() const { return m_event->angleDelta(); } int buttons() const; Modifiers modifiers() const; - inline bool isAccepted() const { return m_event.isAccepted(); } - inline void setAccepted(bool accepted) { m_event.setAccepted(accepted); } - inline QEvent::Type type() const { return m_event.type(); } + inline bool isAccepted() const { return m_event->isAccepted(); } + inline void setAccepted(bool accepted) { m_event->setAccepted(accepted); } + inline QEvent::Type type() const { return m_event->type(); } private: - QT_PREPEND_NAMESPACE(QWheelEvent) m_event; + std::unique_ptr m_event; }; typedef QSharedPointer QWheelEventPtr; -- cgit v1.2.3