diff options
author | Marc Mutz <marc.mutz@qt.io> | 2022-01-04 10:35:04 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2022-04-14 19:07:16 +0200 |
commit | da0f72ebb817bb9c92c7a183b281d8a4bf31a135 (patch) | |
tree | 072e6051b2464dba616634b94e1657d695a81715 | |
parent | ec59ae6189c2a0405cc50f548c95c7007603934f (diff) |
QEvent: start to de-inline copy ctor and clone() of all subclasses
There's no advantage to them being inline: Absent de-virtualisation,
clone() is only supposed to be called through the vtable, and the copy
ctor is only supposed to be used in the implementation of clone().
And when the compiler de-virtualises, we don't want the code
duplication associated with inlining.
Enforce this by introducing new macros to hide the boilerplate.
This fixes missing out-of-line dtors in:
- QSinglePointEvent
- QApplicationStateChangeEvent
- QFutureCallOutEvent
Wrong covariant return in:
- QFutureCallOutEvent
And missing clone() reimplementations in:
- QCloseEvent
- QIconDragEvent
- QShowEvent
- QHideEvent
- QDragEnterEvent
- QDragLeaveEvent
While these don't carry extra data or members, a dynamic_cast of the
result of clone() as well as using the expected covariant return value
would fail:
QShowEvent *e = ~~~;
QShowEvent *e2 = e->clone(); // ERROR: converting QEvent* to QShowEvent*
Check that reimplementing clone() is binary compatible (covariant
returns may change the numerical pointer value returned, cf.
https://community.kde.org/Policies/Binary_Compatibility_Issues_With_C%2B%2B).
The copy-assignment operator stays inline for the time being, as the
goal is to = delete it in the future.
This patch covers, roughly, QtCore and QtGui.
[ChangeLog][QtGui][QEvent subclasses] Fixed missing clone()
reimplementations on QCloseEvent, QIconDragEvent, QShowEvent,
QHideEvent, QDragEnterEvent, and QDragLeaveEvent.
Task-number: QTBUG-45582
Task-number: QTBUG-97601
Change-Id: Ib8a0519dbe85a7a8da61050d48be338004dfa69a
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r-- | src/corelib/kernel/qcoreevent.cpp | 27 | ||||
-rw-r--r-- | src/corelib/kernel/qcoreevent.h | 44 | ||||
-rw-r--r-- | src/corelib/thread/qfutureinterface.cpp | 2 | ||||
-rw-r--r-- | src/corelib/thread/qfutureinterface_p.h | 9 | ||||
-rw-r--r-- | src/gui/kernel/qevent.cpp | 243 | ||||
-rw-r--r-- | src/gui/kernel/qevent.h | 188 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qevent/CMakeLists.txt | 3 | ||||
-rw-r--r-- | tests/auto/gui/kernel/qevent/tst_qevent.cpp | 82 |
8 files changed, 205 insertions, 393 deletions
diff --git a/src/corelib/kernel/qcoreevent.cpp b/src/corelib/kernel/qcoreevent.cpp index 34b57bb4f8..2289938d4b 100644 --- a/src/corelib/kernel/qcoreevent.cpp +++ b/src/corelib/kernel/qcoreevent.cpp @@ -559,12 +559,7 @@ QTimerEvent::QTimerEvent(int timerId) : QEvent(Timer), id(timerId) {} -/*! - \internal -*/ -QTimerEvent::~QTimerEvent() -{ -} +Q_IMPL_EVENT_COMMON(QTimerEvent) /*! \fn int QTimerEvent::timerId() const @@ -606,12 +601,7 @@ QChildEvent::QChildEvent(Type type, QObject *child) : QEvent(type), c(child) {} -/*! - \internal -*/ -QChildEvent::~QChildEvent() -{ -} +Q_IMPL_EVENT_COMMON(QChildEvent) /*! \fn QObject *QChildEvent::child() const @@ -663,12 +653,7 @@ QDynamicPropertyChangeEvent::QDynamicPropertyChangeEvent(const QByteArray &name) { } -/*! - \internal -*/ -QDynamicPropertyChangeEvent::~QDynamicPropertyChangeEvent() -{ -} +Q_IMPL_EVENT_COMMON(QDynamicPropertyChangeEvent) /*! \fn QByteArray QDynamicPropertyChangeEvent::propertyName() const @@ -687,11 +672,7 @@ QDeferredDeleteEvent::QDeferredDeleteEvent() , level(0) { } -/*! - \internal -*/ -QDeferredDeleteEvent::~QDeferredDeleteEvent() -{ } +Q_IMPL_EVENT_COMMON(QDeferredDeleteEvent) /*! \fn int QDeferredDeleteEvent::loopLevel() const diff --git a/src/corelib/kernel/qcoreevent.h b/src/corelib/kernel/qcoreevent.h index 4a4910e893..f737a55514 100644 --- a/src/corelib/kernel/qcoreevent.h +++ b/src/corelib/kernel/qcoreevent.h @@ -53,6 +53,29 @@ protected: \ Class &operator=(const Class &other) = default; \ Class &operator=(Class &&) = delete +#define Q_DECL_EVENT_COMMON(Class) \ + protected: \ + Class(const Class &); \ + Class(Class &&) = delete; \ + Class &operator=(const Class &other) = default; \ + Class &operator=(Class &&) = delete; \ + public: \ + Class* clone() const override; \ + ~Class() override; \ + private: + +#define Q_IMPL_EVENT_COMMON(Class) \ + Class::Class(const Class &) = default; \ + Class::~Class() = default; \ + Class* Class::clone() const \ + { \ + auto c = new Class(*this); \ + QEvent *e = c; \ + /* check that covariant return is safe to add */ \ + Q_ASSERT(reinterpret_cast<quintptr>(c) == reinterpret_cast<quintptr>(e)); \ + return c; \ + } + class QEventPrivate; class Q_CORE_EXPORT QEvent // event base class { @@ -367,14 +390,11 @@ private: class Q_CORE_EXPORT QTimerEvent : public QEvent { - Q_EVENT_DISABLE_COPY(QTimerEvent); + Q_DECL_EVENT_COMMON(QTimerEvent) public: explicit QTimerEvent(int timerId); - ~QTimerEvent(); int timerId() const { return id; } - QTimerEvent *clone() const override { return new QTimerEvent(*this); } - protected: int id; }; @@ -383,46 +403,38 @@ class QObject; class Q_CORE_EXPORT QChildEvent : public QEvent { - Q_EVENT_DISABLE_COPY(QChildEvent); + Q_DECL_EVENT_COMMON(QChildEvent) public: QChildEvent(Type type, QObject *child); - ~QChildEvent(); + QObject *child() const { return c; } bool added() const { return type() == ChildAdded; } bool polished() const { return type() == ChildPolished; } bool removed() const { return type() == ChildRemoved; } - QChildEvent *clone() const override { return new QChildEvent(*this); } - protected: QObject *c; }; class Q_CORE_EXPORT QDynamicPropertyChangeEvent : public QEvent { - Q_EVENT_DISABLE_COPY(QDynamicPropertyChangeEvent); + Q_DECL_EVENT_COMMON(QDynamicPropertyChangeEvent) public: explicit QDynamicPropertyChangeEvent(const QByteArray &name); - ~QDynamicPropertyChangeEvent(); inline QByteArray propertyName() const { return n; } - QDynamicPropertyChangeEvent *clone() const override { return new QDynamicPropertyChangeEvent(*this); } - private: QByteArray n; }; class Q_CORE_EXPORT QDeferredDeleteEvent : public QEvent { - Q_EVENT_DISABLE_COPY(QDeferredDeleteEvent); + Q_DECL_EVENT_COMMON(QDeferredDeleteEvent) public: explicit QDeferredDeleteEvent(); - ~QDeferredDeleteEvent(); int loopLevel() const { return level; } - QDeferredDeleteEvent *clone() const override { return new QDeferredDeleteEvent(*this); } - private: int level; friend class QCoreApplication; diff --git a/src/corelib/thread/qfutureinterface.cpp b/src/corelib/thread/qfutureinterface.cpp index 0fde190bc0..71d6670538 100644 --- a/src/corelib/thread/qfutureinterface.cpp +++ b/src/corelib/thread/qfutureinterface.cpp @@ -74,6 +74,8 @@ const auto suspendingOrSuspended = QFutureCallOutInterface::~QFutureCallOutInterface() = default; +Q_IMPL_EVENT_COMMON(QFutureCallOutEvent) + QFutureInterfaceBase::QFutureInterfaceBase(State initialState) : d(new QFutureInterfaceBasePrivate(initialState)) { } diff --git a/src/corelib/thread/qfutureinterface_p.h b/src/corelib/thread/qfutureinterface_p.h index 24902cbc9a..c6ea30b07f 100644 --- a/src/corelib/thread/qfutureinterface_p.h +++ b/src/corelib/thread/qfutureinterface_p.h @@ -65,9 +65,9 @@ QT_REQUIRE_CONFIG(future); QT_BEGIN_NAMESPACE -class QFutureCallOutEvent : public QEvent +class Q_CORE_EXPORT QFutureCallOutEvent : public QEvent { - Q_EVENT_DISABLE_COPY(QFutureCallOutEvent); + Q_DECL_EVENT_COMMON(QFutureCallOutEvent) public: enum CallOutType { Started, @@ -104,11 +104,6 @@ public: int index2; QString text; - QEvent *clone() const override - { - return new QFutureCallOutEvent(callOutType, index1, index2, text); - } - private: QFutureCallOutEvent(CallOutType callOutType, int index1, diff --git a/src/gui/kernel/qevent.cpp b/src/gui/kernel/qevent.cpp index c613b7abc4..cadad0166f 100644 --- a/src/gui/kernel/qevent.cpp +++ b/src/gui/kernel/qevent.cpp @@ -91,12 +91,7 @@ QEnterEvent::QEnterEvent(const QPointF &localPos, const QPointF &scenePos, const { } -/*! - \internal -*/ -QEnterEvent::~QEnterEvent() -{ -} +Q_IMPL_EVENT_COMMON(QEnterEvent) /*! \fn QPoint QEnterEvent::globalPos() const @@ -183,12 +178,7 @@ QInputEvent::QInputEvent(QEvent::Type type, QEvent::SinglePointEventTag, const Q : QEvent(type, QEvent::SinglePointEventTag{}), m_dev(dev), m_modState(modifiers), m_reserved(0) {} -/*! - \internal -*/ -QInputEvent::~QInputEvent() -{ -} +Q_IMPL_EVENT_COMMON(QInputEvent) /*! \fn QInputDevice *QInputEvent::device() const @@ -294,9 +284,7 @@ QPointerEvent::QPointerEvent(QEvent::Type type, QEvent::SinglePointEventTag, con { } -QPointerEvent::~QPointerEvent() -{ -} +Q_IMPL_EVENT_COMMON(QPointerEvent) /*! Returns the point whose \l {QEventPoint::id()}{id} matches the given \a id, @@ -598,6 +586,8 @@ QSinglePointEvent::QSinglePointEvent(QEvent::Type type, const QPointingDevice *d m_points << point; } +Q_IMPL_EVENT_COMMON(QSinglePointEvent) + /*! Returns \c true if this event represents a \l {button()}{button} being pressed. */ @@ -785,12 +775,7 @@ QMouseEvent::QMouseEvent(QEvent::Type type, const QPointF &localPos, const QPoin { } -/*! - \internal -*/ -QMouseEvent::~QMouseEvent() -{ -} +Q_IMPL_EVENT_COMMON(QMouseEvent) /*! \since 5.3 @@ -1105,12 +1090,7 @@ QHoverEvent::QHoverEvent(Type type, const QPointF &pos, const QPointF &oldPos, } #endif -/*! - \internal -*/ -QHoverEvent::~QHoverEvent() -{ -} +Q_IMPL_EVENT_COMMON(QHoverEvent) #if QT_CONFIG(wheelevent) /*! @@ -1235,12 +1215,7 @@ QWheelEvent::QWheelEvent(const QPointF &pos, const QPointF &globalPos, QPoint pi m_invertedScrolling = inverted; } -/*! - \internal -*/ -QWheelEvent::~QWheelEvent() -{ -} +Q_IMPL_EVENT_COMMON(QWheelEvent) /*! Returns \c true if this event's phase() is Qt::ScrollBegin. @@ -1420,12 +1395,7 @@ QKeyEvent::QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, } -/*! - \internal -*/ -QKeyEvent::~QKeyEvent() -{ -} +Q_IMPL_EVENT_COMMON(QKeyEvent) /*! \fn quint32 QKeyEvent::nativeScanCode() const @@ -1599,12 +1569,7 @@ QFocusEvent::QFocusEvent(Type type, Qt::FocusReason reason) : QEvent(type), m_reason(reason) {} -/*! - \internal -*/ -QFocusEvent::~QFocusEvent() -{ -} +Q_IMPL_EVENT_COMMON(QFocusEvent) /*! Returns the reason for this focus event. @@ -1677,12 +1642,7 @@ QPaintEvent::QPaintEvent(const QRect &paintRect) {} -/*! - \internal -*/ -QPaintEvent::~QPaintEvent() -{ -} +Q_IMPL_EVENT_COMMON(QPaintEvent) /*! \fn const QRect &QPaintEvent::rect() const @@ -1724,12 +1684,7 @@ QMoveEvent::QMoveEvent(const QPoint &pos, const QPoint &oldPos) : QEvent(Move), m_pos(pos), m_oldPos(oldPos) {} -/*! - \internal -*/ -QMoveEvent::~QMoveEvent() -{ -} +Q_IMPL_EVENT_COMMON(QMoveEvent) /*! \fn const QPoint &QMoveEvent::pos() const @@ -1776,12 +1731,7 @@ QExposeEvent::QExposeEvent(const QRegion &exposeRegion) { } -/*! - \internal -*/ -QExposeEvent::~QExposeEvent() -{ -} +Q_IMPL_EVENT_COMMON(QExposeEvent) /*! \class QPlatformSurfaceEvent @@ -1825,12 +1775,7 @@ QPlatformSurfaceEvent::QPlatformSurfaceEvent(SurfaceEventType surfaceEventType) { } -/*! - \internal -*/ -QPlatformSurfaceEvent::~QPlatformSurfaceEvent() -{ -} +Q_IMPL_EVENT_COMMON(QPlatformSurfaceEvent) /*! \fn const QRegion &QExposeEvent::region() const @@ -1861,12 +1806,7 @@ QResizeEvent::QResizeEvent(const QSize &size, const QSize &oldSize) : QEvent(Resize), m_size(size), m_oldSize(oldSize) {} -/*! - \internal -*/ -QResizeEvent::~QResizeEvent() -{ -} +Q_IMPL_EVENT_COMMON(QResizeEvent) /*! \fn const QSize &QResizeEvent::size() const @@ -1941,11 +1881,7 @@ QCloseEvent::QCloseEvent() : QEvent(Close) {} -/*! \internal -*/ -QCloseEvent::~QCloseEvent() -{ -} +Q_IMPL_EVENT_COMMON(QCloseEvent) /*! \class QIconDragEvent @@ -1974,10 +1910,7 @@ QIconDragEvent::QIconDragEvent() : QEvent(IconDrag) { ignore(); } -/*! \internal */ -QIconDragEvent::~QIconDragEvent() -{ -} +Q_IMPL_EVENT_COMMON(QIconDragEvent) /*! \class QContextMenuEvent @@ -2013,11 +1946,7 @@ QContextMenuEvent::QContextMenuEvent(Reason reason, const QPoint &pos, const QPo : QInputEvent(ContextMenu, QPointingDevice::primaryPointingDevice(), modifiers), m_pos(pos), m_globalPos(globalPos), m_reason(reason) {} - -/*! \internal */ -QContextMenuEvent::~QContextMenuEvent() -{ -} +Q_IMPL_EVENT_COMMON(QContextMenuEvent) #if QT_DEPRECATED_SINCE(6, 4) /*! @@ -2334,9 +2263,7 @@ QInputMethodEvent::QInputMethodEvent(const QString &preeditText, const QList<Att { } -QInputMethodEvent::~QInputMethodEvent() -{ -} +Q_IMPL_EVENT_COMMON(QInputMethodEvent) /*! Sets the commit string to \a commitString. @@ -2443,12 +2370,7 @@ QInputMethodQueryEvent::QInputMethodQueryEvent(Qt::InputMethodQueries queries) { } -/*! - \internal - */ -QInputMethodQueryEvent::~QInputMethodQueryEvent() -{ -} +Q_IMPL_EVENT_COMMON(QInputMethodQueryEvent) /*! Sets property \a query to \a value. @@ -2600,12 +2522,7 @@ QTabletEvent::QTabletEvent(Type type, const QPointingDevice *dev, const QPointF QMutableEventPoint::setRotation(p, rotation); } -/*! - \internal -*/ -QTabletEvent::~QTabletEvent() -{ -} +Q_IMPL_EVENT_COMMON(QTabletEvent) /*! \fn qreal QTabletEvent::tangentialPressure() const @@ -2929,7 +2846,7 @@ QNativeGestureEvent::QNativeGestureEvent(Qt::NativeGestureType type, const QPoin Q_ASSERT(fingerCount < 16); // we store it in 4 bits unsigned } -QNativeGestureEvent::~QNativeGestureEvent() = default; +Q_IMPL_EVENT_COMMON(QNativeGestureEvent) /*! \fn QNativeGestureEvent::gestureType() const @@ -3032,12 +2949,7 @@ QDragMoveEvent::QDragMoveEvent(const QPoint& pos, Qt::DropActions actions, const , m_rect(pos, QSize(1, 1)) {} -/*! - Destroys the event. -*/ -QDragMoveEvent::~QDragMoveEvent() -{ -} +Q_IMPL_EVENT_COMMON(QDragMoveEvent) /*! \fn void QDragMoveEvent::accept(const QRect &rectangle) @@ -3150,10 +3062,7 @@ QDropEvent::QDropEvent(const QPointF& pos, Qt::DropActions actions, const QMimeD ignore(); } -/*! \internal */ -QDropEvent::~QDropEvent() -{ -} +Q_IMPL_EVENT_COMMON(QDropEvent) /*! @@ -3298,11 +3207,7 @@ QDragEnterEvent::QDragEnterEvent(const QPoint& point, Qt::DropActions actions, c : QDragMoveEvent(point, actions, data, buttons, modifiers, DragEnter) {} -/*! \internal -*/ -QDragEnterEvent::~QDragEnterEvent() -{ -} +Q_IMPL_EVENT_COMMON(QDragEnterEvent) /*! \class QDragMoveEvent @@ -3356,11 +3261,8 @@ QDragLeaveEvent::QDragLeaveEvent() : QEvent(DragLeave) {} -/*! \internal -*/ -QDragLeaveEvent::~QDragLeaveEvent() -{ -} +Q_IMPL_EVENT_COMMON(QDragLeaveEvent) + #endif // QT_CONFIG(draganddrop) /*! @@ -3442,11 +3344,7 @@ QHelpEvent::QHelpEvent(Type type, const QPoint &pos, const QPoint &globalPos) \sa pos(), globalX(), globalY() */ -/*! \internal -*/ -QHelpEvent::~QHelpEvent() -{ -} +Q_IMPL_EVENT_COMMON(QHelpEvent) #ifndef QT_NO_STATUSTIP @@ -3501,11 +3399,7 @@ QStatusTipEvent::QStatusTipEvent(const QString &tip) : QEvent(StatusTip), m_tip(tip) {} -/*! \internal -*/ -QStatusTipEvent::~QStatusTipEvent() -{ -} +Q_IMPL_EVENT_COMMON(QStatusTipEvent) /*! \fn QString QStatusTipEvent::tip() const @@ -3541,11 +3435,7 @@ QWhatsThisClickedEvent::QWhatsThisClickedEvent(const QString &href) : QEvent(WhatsThisClicked), m_href(href) {} -/*! \internal -*/ -QWhatsThisClickedEvent::~QWhatsThisClickedEvent() -{ -} +Q_IMPL_EVENT_COMMON(QWhatsThisClickedEvent) /*! \fn QString QWhatsThisClickedEvent::href() const @@ -3587,11 +3477,7 @@ QActionEvent::QActionEvent(int type, QAction *action, QAction *before) : QEvent(static_cast<QEvent::Type>(type)), m_action(action), m_before(before) {} -/*! \internal -*/ -QActionEvent::~QActionEvent() -{ -} +Q_IMPL_EVENT_COMMON(QActionEvent) /*! \fn QAction *QActionEvent::action() const @@ -3641,11 +3527,7 @@ QHideEvent::QHideEvent() : QEvent(Hide) {} -/*! \internal -*/ -QHideEvent::~QHideEvent() -{ -} +Q_IMPL_EVENT_COMMON(QHideEvent) /*! \class QShowEvent @@ -3671,11 +3553,7 @@ QShowEvent::QShowEvent() : QEvent(Show) {} -/*! \internal -*/ -QShowEvent::~QShowEvent() -{ -} +Q_IMPL_EVENT_COMMON(QShowEvent) /*! \class QFileOpenEvent @@ -3732,12 +3610,7 @@ QFileOpenEvent::QFileOpenEvent(const QUrl &url) { } - -/*! \internal -*/ -QFileOpenEvent::~QFileOpenEvent() -{ -} +Q_IMPL_EVENT_COMMON(QFileOpenEvent) /*! \fn QString QFileOpenEvent::file() const @@ -3795,11 +3668,7 @@ QToolBarChangeEvent::QToolBarChangeEvent(bool t) : QEvent(ToolBarChange), m_toggle(t) {} -/*! \internal -*/ -QToolBarChangeEvent::~QToolBarChangeEvent() -{ -} +Q_IMPL_EVENT_COMMON(QToolBarChangeEvent) /*! \fn bool QToolBarChangeEvent::toggle() const @@ -3832,12 +3701,7 @@ QShortcutEvent::QShortcutEvent(const QKeySequence &key, int id, bool ambiguous) { } -/*! - Destroys the event object. -*/ -QShortcutEvent::~QShortcutEvent() -{ -} +Q_IMPL_EVENT_COMMON(QShortcutEvent) #endif // QT_CONFIG(shortcut) @@ -4426,11 +4290,7 @@ bool QWindowStateChangeEvent::isOverride() const return m_override; } -/*! \internal -*/ -QWindowStateChangeEvent::~QWindowStateChangeEvent() -{ -} +Q_IMPL_EVENT_COMMON(QWindowStateChangeEvent) /*! @@ -4604,11 +4464,7 @@ QTouchEvent::QTouchEvent(QEvent::Type eventType, QMutableEventPoint::setDevice(point, device); } -/*! - Destroys the QTouchEvent. -*/ -QTouchEvent::~QTouchEvent() -{ } +Q_IMPL_EVENT_COMMON(QTouchEvent) /*! Returns true if this event includes at least one newly-pressed touchpoint. @@ -4682,12 +4538,7 @@ QScrollPrepareEvent::QScrollPrepareEvent(const QPointF &startPos) { } -/*! - Destroys QScrollEvent. -*/ -QScrollPrepareEvent::~QScrollPrepareEvent() -{ -} +Q_IMPL_EVENT_COMMON(QScrollPrepareEvent) /*! \fn QPointF QScrollPrepareEvent::startPos() const @@ -4785,12 +4636,7 @@ QScrollEvent::QScrollEvent(const QPointF &contentPos, const QPointF &overshootDi { } -/*! - Destroys QScrollEvent. -*/ -QScrollEvent::~QScrollEvent() -{ -} +Q_IMPL_EVENT_COMMON(QScrollEvent) /*! \fn QPointF QScrollEvent::contentPos() const @@ -4827,12 +4673,7 @@ QScreenOrientationChangeEvent::QScreenOrientationChangeEvent(QScreen *screen, Qt { } -/*! - Destroys QScreenOrientationChangeEvent. -*/ -QScreenOrientationChangeEvent::~QScreenOrientationChangeEvent() -{ -} +Q_IMPL_EVENT_COMMON(QScreenOrientationChangeEvent) /*! \fn QScreen *QScreenOrientationChangeEvent::screen() const @@ -4855,6 +4696,8 @@ QApplicationStateChangeEvent::QApplicationStateChangeEvent(Qt::ApplicationState { } +Q_IMPL_EVENT_COMMON(QApplicationStateChangeEvent) + /*! \fn Qt::ApplicationState QApplicationStateChangeEvent::applicationState() const diff --git a/src/gui/kernel/qevent.h b/src/gui/kernel/qevent.h index 34d8f6a223..a0391db2b7 100644 --- a/src/gui/kernel/qevent.h +++ b/src/gui/kernel/qevent.h @@ -59,6 +59,8 @@ # include <QtGui/qkeysequence.h> #endif +class tst_QEvent; + QT_BEGIN_NAMESPACE class QFile; @@ -74,11 +76,9 @@ class QGesture; class Q_GUI_EXPORT QInputEvent : public QEvent { - Q_EVENT_DISABLE_COPY(QInputEvent); + Q_DECL_EVENT_COMMON(QInputEvent) public: explicit QInputEvent(Type type, const QInputDevice *m_dev, Qt::KeyboardModifiers modifiers = Qt::NoModifier); - ~QInputEvent(); - QInputEvent *clone() const override { return new QInputEvent(*this); } const QInputDevice *device() const { return m_dev; } QInputDevice::DeviceType deviceType() const { return m_dev ? m_dev->type() : QInputDevice::DeviceType::Unknown; } @@ -100,13 +100,10 @@ protected: class Q_GUI_EXPORT QPointerEvent : public QInputEvent { - Q_EVENT_DISABLE_COPY(QPointerEvent); + Q_DECL_EVENT_COMMON(QPointerEvent) public: explicit QPointerEvent(Type type, const QPointingDevice *dev, Qt::KeyboardModifiers modifiers = Qt::NoModifier, const QList<QEventPoint> &points = {}); - ~QPointerEvent(); - - QPointerEvent *clone() const override { return new QPointerEvent(*this); } const QPointingDevice *pointingDevice() const; QPointingDevice::PointerType pointerType() const { @@ -142,7 +139,7 @@ class Q_GUI_EXPORT QSinglePointEvent : public QPointerEvent Q_PROPERTY(QObject *exclusivePointGrabber READ exclusivePointGrabber WRITE setExclusivePointGrabber) - Q_EVENT_DISABLE_COPY(QSinglePointEvent); + Q_DECL_EVENT_COMMON(QSinglePointEvent) public: inline Qt::MouseButton button() const { return m_button; } inline Qt::MouseButtons buttons() const { return m_mouseState; } @@ -163,9 +160,8 @@ public: void setExclusivePointGrabber(QObject *exclusiveGrabber) { QPointerEvent::setExclusiveGrabber(points().first(), exclusiveGrabber); } - QSinglePointEvent *clone() const override { return new QSinglePointEvent(*this); } - protected: + friend class ::tst_QEvent; QSinglePointEvent(Type type, const QPointingDevice *dev, const QEventPoint &point, Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::MouseEventSource source); @@ -195,13 +191,10 @@ protected: class Q_GUI_EXPORT QEnterEvent : public QSinglePointEvent { - Q_EVENT_DISABLE_COPY(QEnterEvent); + Q_DECL_EVENT_COMMON(QEnterEvent) public: QEnterEvent(const QPointF &localPos, const QPointF &scenePos, const QPointF &globalPos, const QPointingDevice *device = QPointingDevice::primaryPointingDevice()); - ~QEnterEvent(); - - QEnterEvent *clone() const override { return new QEnterEvent(*this); } #if QT_DEPRECATED_SINCE(6, 0) #ifndef QT_NO_INTEGER_EVENT_COORDINATES @@ -229,7 +222,7 @@ public: class Q_GUI_EXPORT QMouseEvent : public QSinglePointEvent { - Q_EVENT_DISABLE_COPY(QMouseEvent); + Q_DECL_EVENT_COMMON(QMouseEvent) public: #if QT_DEPRECATED_SINCE(6, 4) QT_DEPRECATED_VERSION_X_6_4("Use another constructor") @@ -249,9 +242,6 @@ public: Qt::MouseButton button, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::MouseEventSource source, const QPointingDevice *device = QPointingDevice::primaryPointingDevice()); - ~QMouseEvent(); - - QMouseEvent *clone() const override { return new QMouseEvent(*this); } #ifndef QT_NO_INTEGER_EVENT_COORDINATES inline QPoint pos() const { return position().toPoint(); } @@ -282,7 +272,7 @@ public: class Q_GUI_EXPORT QHoverEvent : public QSinglePointEvent { - Q_EVENT_DISABLE_COPY(QHoverEvent); + Q_DECL_EVENT_COMMON(QHoverEvent) public: QHoverEvent(Type type, const QPointF &pos, const QPointF &globalPos, const QPointF &oldPos, Qt::KeyboardModifiers modifiers = Qt::NoModifier, @@ -293,9 +283,6 @@ public: Qt::KeyboardModifiers modifiers = Qt::NoModifier, const QPointingDevice *device = QPointingDevice::primaryPointingDevice()); #endif - ~QHoverEvent(); - - QHoverEvent *clone() const override { return new QHoverEvent(*this); } #if QT_DEPRECATED_SINCE(6, 0) #ifndef QT_NO_INTEGER_EVENT_COORDINATES @@ -327,7 +314,7 @@ class Q_GUI_EXPORT QWheelEvent : public QSinglePointEvent Q_PROPERTY(Qt::ScrollPhase phase READ phase) Q_PROPERTY(bool inverted READ inverted) - Q_EVENT_DISABLE_COPY(QWheelEvent); + Q_DECL_EVENT_COMMON(QWheelEvent) public: enum { DefaultDeltasPerStep = 120 }; @@ -335,9 +322,6 @@ public: Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Qt::ScrollPhase phase, bool inverted, Qt::MouseEventSource source = Qt::MouseEventNotSynthesized, const QPointingDevice *device = QPointingDevice::primaryPointingDevice()); - ~QWheelEvent(); - - QWheelEvent *clone() const override { return new QWheelEvent(*this); } inline QPoint pixelDelta() const { return m_pixelDelta; } inline QPoint angleDelta() const { return m_angleDelta; } @@ -361,7 +345,7 @@ protected: #if QT_CONFIG(tabletevent) class Q_GUI_EXPORT QTabletEvent : public QSinglePointEvent { - Q_EVENT_DISABLE_COPY(QTabletEvent); + Q_DECL_EVENT_COMMON(QTabletEvent) public: QTabletEvent(Type t, const QPointingDevice *device, const QPointF &pos, const QPointF &globalPos, @@ -369,9 +353,6 @@ public: float tangentialPressure, qreal rotation, float z, Qt::KeyboardModifiers keyState, Qt::MouseButton button, Qt::MouseButtons buttons); - ~QTabletEvent(); - - QTabletEvent *clone() const override { return new QTabletEvent(*this); } #if QT_DEPRECATED_SINCE(6, 0) QT_DEPRECATED_VERSION_X_6_0("Use position()") @@ -416,7 +397,7 @@ protected: #if QT_CONFIG(gestures) class Q_GUI_EXPORT QNativeGestureEvent : public QSinglePointEvent { - Q_EVENT_DISABLE_COPY(QNativeGestureEvent); + Q_DECL_EVENT_COMMON(QNativeGestureEvent) public: #if QT_DEPRECATED_SINCE(6, 2) QT_DEPRECATED_VERSION_X_6_2("Use the other constructor") @@ -426,9 +407,6 @@ public: QNativeGestureEvent(Qt::NativeGestureType type, const QPointingDevice *dev, int fingerCount, const QPointF &localPos, const QPointF &scenePos, const QPointF &globalPos, qreal value, const QPointF &delta, quint64 sequenceId = UINT64_MAX); - ~QNativeGestureEvent(); - - QNativeGestureEvent *clone() const override { return new QNativeGestureEvent(*this); } Qt::NativeGestureType gestureType() const { return m_gestureType; } int fingerCount() const { return m_fingerCount; } @@ -472,7 +450,7 @@ protected: class Q_GUI_EXPORT QKeyEvent : public QInputEvent { - Q_EVENT_DISABLE_COPY(QKeyEvent); + Q_DECL_EVENT_COMMON(QKeyEvent) public: QKeyEvent(Type type, int key, Qt::KeyboardModifiers modifiers, const QString& text = QString(), bool autorep = false, quint16 count = 1); @@ -480,9 +458,6 @@ public: quint32 nativeScanCode, quint32 nativeVirtualKey, quint32 nativeModifiers, const QString &text = QString(), bool autorep = false, quint16 count = 1, const QInputDevice *device = QInputDevice::primaryKeyboard()); - ~QKeyEvent(); - - QKeyEvent *clone() const override { return new QKeyEvent(*this); } int key() const { return m_key; } #if QT_CONFIG(shortcut) @@ -521,12 +496,9 @@ protected: class Q_GUI_EXPORT QFocusEvent : public QEvent { - Q_EVENT_DISABLE_COPY(QFocusEvent); + Q_DECL_EVENT_COMMON(QFocusEvent) public: explicit QFocusEvent(Type type, Qt::FocusReason reason=Qt::OtherFocusReason); - ~QFocusEvent(); - - QFocusEvent *clone() const override { return new QFocusEvent(*this); } inline bool gotFocus() const { return type() == FocusIn; } inline bool lostFocus() const { return type() == FocusOut; } @@ -540,13 +512,10 @@ private: class Q_GUI_EXPORT QPaintEvent : public QEvent { - Q_EVENT_DISABLE_COPY(QPaintEvent); + Q_DECL_EVENT_COMMON(QPaintEvent) public: explicit QPaintEvent(const QRegion& paintRegion); explicit QPaintEvent(const QRect &paintRect); - ~QPaintEvent(); - - QPaintEvent *clone() const override { return new QPaintEvent(*this); } inline const QRect &rect() const { return m_rect; } inline const QRegion ®ion() const { return m_region; } @@ -559,12 +528,9 @@ protected: class Q_GUI_EXPORT QMoveEvent : public QEvent { - Q_EVENT_DISABLE_COPY(QMoveEvent); + Q_DECL_EVENT_COMMON(QMoveEvent) public: QMoveEvent(const QPoint &pos, const QPoint &oldPos); - ~QMoveEvent(); - - QMoveEvent *clone() const override { return new QMoveEvent(*this); } inline const QPoint &pos() const { return m_pos; } inline const QPoint &oldPos() const { return m_oldPos;} @@ -575,12 +541,9 @@ protected: class Q_GUI_EXPORT QExposeEvent : public QEvent { - Q_EVENT_DISABLE_COPY(QExposeEvent); + Q_DECL_EVENT_COMMON(QExposeEvent) public: explicit QExposeEvent(const QRegion &m_region); - ~QExposeEvent(); - - QExposeEvent *clone() const override { return new QExposeEvent(*this); } #if QT_DEPRECATED_SINCE(6, 0) QT_DEPRECATED_VERSION_X_6_0("Handle QPaintEvent instead") @@ -593,7 +556,7 @@ protected: class Q_GUI_EXPORT QPlatformSurfaceEvent : public QEvent { - Q_EVENT_DISABLE_COPY(QPlatformSurfaceEvent); + Q_DECL_EVENT_COMMON(QPlatformSurfaceEvent) public: enum SurfaceEventType { SurfaceCreated, @@ -601,9 +564,6 @@ public: }; explicit QPlatformSurfaceEvent(SurfaceEventType surfaceEventType); - ~QPlatformSurfaceEvent(); - - QPlatformSurfaceEvent *clone() const override { return new QPlatformSurfaceEvent(*this); } inline SurfaceEventType surfaceEventType() const { return m_surfaceEventType; } @@ -613,12 +573,9 @@ protected: class Q_GUI_EXPORT QResizeEvent : public QEvent { - Q_EVENT_DISABLE_COPY(QResizeEvent); + Q_DECL_EVENT_COMMON(QResizeEvent) public: QResizeEvent(const QSize &size, const QSize &oldSize); - ~QResizeEvent(); - - QResizeEvent *clone() const override { return new QResizeEvent(*this); } inline const QSize &size() const { return m_size; } inline const QSize &oldSize()const { return m_oldSize;} @@ -630,43 +587,39 @@ protected: class Q_GUI_EXPORT QCloseEvent : public QEvent { - Q_EVENT_DISABLE_COPY(QCloseEvent); + Q_DECL_EVENT_COMMON(QCloseEvent) public: QCloseEvent(); - ~QCloseEvent(); }; class Q_GUI_EXPORT QIconDragEvent : public QEvent { - Q_EVENT_DISABLE_COPY(QIconDragEvent); + Q_DECL_EVENT_COMMON(QIconDragEvent) public: QIconDragEvent(); - ~QIconDragEvent(); }; class Q_GUI_EXPORT QShowEvent : public QEvent { - Q_EVENT_DISABLE_COPY(QShowEvent); + Q_DECL_EVENT_COMMON(QShowEvent) public: QShowEvent(); - ~QShowEvent(); }; class Q_GUI_EXPORT QHideEvent : public QEvent { - Q_EVENT_DISABLE_COPY(QHideEvent); + Q_DECL_EVENT_COMMON(QHideEvent) public: QHideEvent(); - ~QHideEvent(); }; #ifndef QT_NO_CONTEXTMENU class Q_GUI_EXPORT QContextMenuEvent : public QInputEvent { - Q_EVENT_DISABLE_COPY(QContextMenuEvent); + Q_DECL_EVENT_COMMON(QContextMenuEvent) public: enum Reason { Mouse, Keyboard, Other }; @@ -676,9 +629,6 @@ public: QT_DEPRECATED_VERSION_X_6_4("Use the other constructor") QContextMenuEvent(Reason reason, const QPoint &pos); #endif - ~QContextMenuEvent(); - - QContextMenuEvent *clone() const override { return new QContextMenuEvent(*this); } inline int x() const { return m_pos.x(); } inline int y() const { return m_pos.y(); } @@ -700,7 +650,7 @@ protected: #ifndef QT_NO_INPUTMETHOD class Q_GUI_EXPORT QInputMethodEvent : public QEvent { - Q_EVENT_DISABLE_COPY(QInputMethodEvent); + Q_DECL_EVENT_COMMON(QInputMethodEvent) public: enum AttributeType { TextFormat, @@ -721,9 +671,6 @@ public: }; QInputMethodEvent(); QInputMethodEvent(const QString &preeditText, const QList<Attribute> &attributes); - ~QInputMethodEvent(); - - QInputMethodEvent *clone() const override { return new QInputMethodEvent(*this); } void setCommitString(const QString &commitString, int replaceFrom = 0, int replaceLength = 0); inline const QList<Attribute> &attributes() const { return m_attributes; } @@ -757,12 +704,9 @@ Q_DECLARE_TYPEINFO(QInputMethodEvent::Attribute, Q_RELOCATABLE_TYPE); class Q_GUI_EXPORT QInputMethodQueryEvent : public QEvent { - Q_EVENT_DISABLE_COPY(QInputMethodQueryEvent); + Q_DECL_EVENT_COMMON(QInputMethodQueryEvent) public: explicit QInputMethodQueryEvent(Qt::InputMethodQueries queries); - ~QInputMethodQueryEvent(); - - QInputMethodQueryEvent *clone() const override { return new QInputMethodQueryEvent(*this); } Qt::InputMethodQueries queries() const { return m_queries; } @@ -787,13 +731,10 @@ class QMimeData; class Q_GUI_EXPORT QDropEvent : public QEvent { - Q_EVENT_DISABLE_COPY(QDropEvent); + Q_DECL_EVENT_COMMON(QDropEvent) public: QDropEvent(const QPointF& pos, Qt::DropActions actions, const QMimeData *data, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Type type = Drop); - ~QDropEvent(); - - QDropEvent *clone() const override { return new QDropEvent(*this); } #if QT_DEPRECATED_SINCE(6, 0) QT_DEPRECATED_VERSION_X_6_0("Use position().toPoint()") @@ -834,13 +775,10 @@ protected: class Q_GUI_EXPORT QDragMoveEvent : public QDropEvent { - Q_EVENT_DISABLE_COPY(QDragMoveEvent); + Q_DECL_EVENT_COMMON(QDragMoveEvent) public: QDragMoveEvent(const QPoint &pos, Qt::DropActions actions, const QMimeData *data, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers, Type type = DragMove); - ~QDragMoveEvent(); - - QDragMoveEvent *clone() const override { return new QDragMoveEvent(*this); } inline QRect answerRect() const { return m_rect; } @@ -857,32 +795,27 @@ protected: class Q_GUI_EXPORT QDragEnterEvent : public QDragMoveEvent { - Q_EVENT_DISABLE_COPY(QDragEnterEvent); + Q_DECL_EVENT_COMMON(QDragEnterEvent) public: QDragEnterEvent(const QPoint &pos, Qt::DropActions actions, const QMimeData *data, Qt::MouseButtons buttons, Qt::KeyboardModifiers modifiers); - ~QDragEnterEvent(); }; class Q_GUI_EXPORT QDragLeaveEvent : public QEvent { - Q_EVENT_DISABLE_COPY(QDragLeaveEvent); + Q_DECL_EVENT_COMMON(QDragLeaveEvent) public: QDragLeaveEvent(); - ~QDragLeaveEvent(); }; #endif // QT_CONFIG(draganddrop) class Q_GUI_EXPORT QHelpEvent : public QEvent { - Q_EVENT_DISABLE_COPY(QHelpEvent); + Q_DECL_EVENT_COMMON(QHelpEvent) public: QHelpEvent(Type type, const QPoint &pos, const QPoint &globalPos); - ~QHelpEvent(); - - QHelpEvent *clone() const override { return new QHelpEvent(*this); } inline int x() const { return m_pos.x(); } inline int y() const { return m_pos.y(); } @@ -900,12 +833,9 @@ private: #ifndef QT_NO_STATUSTIP class Q_GUI_EXPORT QStatusTipEvent : public QEvent { - Q_EVENT_DISABLE_COPY(QStatusTipEvent); + Q_DECL_EVENT_COMMON(QStatusTipEvent) public: explicit QStatusTipEvent(const QString &tip); - ~QStatusTipEvent(); - - QStatusTipEvent *clone() const override { return new QStatusTipEvent(*this); } inline QString tip() const { return m_tip; } private: @@ -916,12 +846,9 @@ private: #if QT_CONFIG(whatsthis) class Q_GUI_EXPORT QWhatsThisClickedEvent : public QEvent { - Q_EVENT_DISABLE_COPY(QWhatsThisClickedEvent); + Q_DECL_EVENT_COMMON(QWhatsThisClickedEvent) public: explicit QWhatsThisClickedEvent(const QString &href); - ~QWhatsThisClickedEvent(); - - QWhatsThisClickedEvent *clone() const override { return new QWhatsThisClickedEvent(*this); } inline QString href() const { return m_href; } private: @@ -932,12 +859,9 @@ private: #if QT_CONFIG(action) class Q_GUI_EXPORT QActionEvent : public QEvent { - Q_EVENT_DISABLE_COPY(QActionEvent); + Q_DECL_EVENT_COMMON(QActionEvent) public: QActionEvent(int type, QAction *action, QAction *before = nullptr); - ~QActionEvent(); - - QActionEvent *clone() const override { return new QActionEvent(*this); } inline QAction *action() const { return m_action; } inline QAction *before() const { return m_before; } @@ -949,13 +873,10 @@ private: class Q_GUI_EXPORT QFileOpenEvent : public QEvent { - Q_EVENT_DISABLE_COPY(QFileOpenEvent); + Q_DECL_EVENT_COMMON(QFileOpenEvent) public: explicit QFileOpenEvent(const QString &file); explicit QFileOpenEvent(const QUrl &url); - ~QFileOpenEvent(); - - QFileOpenEvent *clone() const override { return new QFileOpenEvent(*this); } inline QString file() const { return m_file; } QUrl url() const { return m_url; } @@ -968,12 +889,9 @@ private: #ifndef QT_NO_TOOLBAR class Q_GUI_EXPORT QToolBarChangeEvent : public QEvent { - Q_EVENT_DISABLE_COPY(QToolBarChangeEvent); + Q_DECL_EVENT_COMMON(QToolBarChangeEvent) public: explicit QToolBarChangeEvent(bool t); - ~QToolBarChangeEvent(); - - QToolBarChangeEvent *clone() const override { return new QToolBarChangeEvent(*this); } inline bool toggle() const { return m_toggle; } private: @@ -984,12 +902,9 @@ private: #if QT_CONFIG(shortcut) class Q_GUI_EXPORT QShortcutEvent : public QEvent { - Q_EVENT_DISABLE_COPY(QShortcutEvent); + Q_DECL_EVENT_COMMON(QShortcutEvent) public: QShortcutEvent(const QKeySequence &key, int id, bool ambiguous = false); - ~QShortcutEvent(); - - QShortcutEvent *clone() const override { return new QShortcutEvent(*this); } inline const QKeySequence &key() const { return m_sequence; } inline int shortcutId() const { return m_shortcutId; } @@ -1003,12 +918,9 @@ protected: class Q_GUI_EXPORT QWindowStateChangeEvent: public QEvent { - Q_EVENT_DISABLE_COPY(QWindowStateChangeEvent); + Q_DECL_EVENT_COMMON(QWindowStateChangeEvent) public: explicit QWindowStateChangeEvent(Qt::WindowStates oldState, bool isOverride = false); - ~QWindowStateChangeEvent(); - - QWindowStateChangeEvent *clone() const override { return new QWindowStateChangeEvent(*this); } inline Qt::WindowStates oldState() const { return m_oldStates; } bool isOverride() const; @@ -1024,7 +936,7 @@ Q_GUI_EXPORT QDebug operator<<(QDebug, const QEvent *); class Q_GUI_EXPORT QTouchEvent : public QPointerEvent { - Q_EVENT_DISABLE_COPY(QTouchEvent); + Q_DECL_EVENT_COMMON(QTouchEvent) public: using TouchPoint = QEventPoint; // source compat @@ -1040,9 +952,6 @@ public: QEventPoint::States touchPointStates, const QList<QEventPoint> &touchPoints = {}); #endif - ~QTouchEvent(); - - QTouchEvent *clone() const override { return new QTouchEvent(*this); } inline QObject *target() const { return m_target; } inline QEventPoint::States touchPointStates() const { return m_touchPointStates; } @@ -1062,12 +971,9 @@ protected: class Q_GUI_EXPORT QScrollPrepareEvent : public QEvent { - Q_EVENT_DISABLE_COPY(QScrollPrepareEvent); + Q_DECL_EVENT_COMMON(QScrollPrepareEvent) public: explicit QScrollPrepareEvent(const QPointF &startPos); - ~QScrollPrepareEvent(); - - QScrollPrepareEvent *clone() const override { return new QScrollPrepareEvent(*this); } QPointF startPos() const { return m_startPos; } @@ -1089,7 +995,7 @@ private: class Q_GUI_EXPORT QScrollEvent : public QEvent { - Q_EVENT_DISABLE_COPY(QScrollEvent); + Q_DECL_EVENT_COMMON(QScrollEvent) public: enum ScrollState { @@ -1099,9 +1005,6 @@ public: }; QScrollEvent(const QPointF &contentPos, const QPointF &overshoot, ScrollState scrollState); - ~QScrollEvent(); - - QScrollEvent *clone() const override { return new QScrollEvent(*this); } QPointF contentPos() const { return m_contentPos; } QPointF overshootDistance() const { return m_overshoot; } @@ -1115,12 +1018,9 @@ private: class Q_GUI_EXPORT QScreenOrientationChangeEvent : public QEvent { - Q_EVENT_DISABLE_COPY(QScreenOrientationChangeEvent); + Q_DECL_EVENT_COMMON(QScreenOrientationChangeEvent) public: QScreenOrientationChangeEvent(QScreen *screen, Qt::ScreenOrientation orientation); - ~QScreenOrientationChangeEvent(); - - QScreenOrientationChangeEvent *clone() const override { return new QScreenOrientationChangeEvent(*this); } QScreen *screen() const { return m_screen; } Qt::ScreenOrientation orientation() const { return m_orientation; } @@ -1132,12 +1032,10 @@ private: class Q_GUI_EXPORT QApplicationStateChangeEvent : public QEvent { - Q_EVENT_DISABLE_COPY(QApplicationStateChangeEvent); + Q_DECL_EVENT_COMMON(QApplicationStateChangeEvent) public: explicit QApplicationStateChangeEvent(Qt::ApplicationState state); - QApplicationStateChangeEvent *clone() const override { return new QApplicationStateChangeEvent(*this); } - Qt::ApplicationState applicationState() const { return m_applicationState; } private: diff --git a/tests/auto/gui/kernel/qevent/CMakeLists.txt b/tests/auto/gui/kernel/qevent/CMakeLists.txt index 2bb22eb469..7b37b0c51a 100644 --- a/tests/auto/gui/kernel/qevent/CMakeLists.txt +++ b/tests/auto/gui/kernel/qevent/CMakeLists.txt @@ -7,4 +7,7 @@ qt_internal_add_test(tst_qevent SOURCES tst_qevent.cpp + PUBLIC_LIBRARIES + Qt::Gui + Qt::CorePrivate ) diff --git a/tests/auto/gui/kernel/qevent/tst_qevent.cpp b/tests/auto/gui/kernel/qevent/tst_qevent.cpp index 6542ed5ad3..cc8ac6ea6c 100644 --- a/tests/auto/gui/kernel/qevent/tst_qevent.cpp +++ b/tests/auto/gui/kernel/qevent/tst_qevent.cpp @@ -29,8 +29,73 @@ #include <QTest> -#include <QtCore/qcoreapplication.h> -#include <QtCore/qcoreevent.h> +#include <QtGui/qguiapplication.h> +#include <QtGui/qevent.h> +#include <QtCore/private/qfutureinterface_p.h> + +#define FOR_EACH_CORE_EVENT(X) \ + /* qcoreevent.h */ \ + X(QEvent, (QEvent::None)) \ + X(QTimerEvent, (42)) \ + X(QChildEvent, (QEvent::ChildAdded, nullptr)) \ + X(QDynamicPropertyChangeEvent, ("size")) \ + X(QDeferredDeleteEvent, ()) \ + /* qfutureinterface_p.h */ \ + X(QFutureCallOutEvent, ()) \ + /* end */ + +#define FOR_EACH_GUI_EVENT(X) \ + /* qevent.h */ \ + X(QInputEvent, (QEvent::None, nullptr)) \ + X(QPointerEvent, (QEvent::None, nullptr)) \ + /* doesn't work with nullptr: */ \ + X(QSinglePointEvent, (QEvent::None, QPointingDevice::primaryPointingDevice(), {}, {}, {}, {}, {}, {})) \ + X(QEnterEvent, ({}, {}, {})) \ + X(QMouseEvent, (QEvent::None, {}, {}, {}, {}, {}, {}, {}, QPointingDevice::primaryPointingDevice())) \ + X(QHoverEvent, (QEvent::None, {}, {}, QPointF{})) \ + X(QWheelEvent, ({}, {}, {}, {}, {}, {}, {}, {})) \ + X(QTabletEvent, (QEvent::None, QPointingDevice::primaryPointingDevice(), {}, {}, {}, {}, {}, {}, {}, {}, {}, {}, {})) \ + X(QNativeGestureEvent, ({}, QPointingDevice::primaryPointingDevice(), 0, {}, {}, {}, {}, {})) \ + X(QKeyEvent, (QEvent::None, 0, {})) \ + X(QFocusEvent, (QEvent::None)) \ + X(QPaintEvent, (QRect{0, 0, 100, 100})) \ + X(QMoveEvent, ({}, {})) \ + X(QExposeEvent, ({})) \ + X(QPlatformSurfaceEvent, ({})) \ + X(QResizeEvent, ({}, {})) \ + X(QCloseEvent, ()) \ + X(QIconDragEvent, ()) \ + X(QShowEvent, ()) \ + X(QHideEvent, ()) \ + QT_WARNING_PUSH \ + QT_WARNING_DISABLE_DEPRECATED \ + X(QContextMenuEvent, (QContextMenuEvent::Reason::Keyboard, {})) \ + QT_WARNING_POP \ + X(QInputMethodEvent, ()) \ + X(QInputMethodQueryEvent, ({})) \ + X(QDropEvent, ({}, {}, {}, {}, {})) \ + X(QDragMoveEvent, ({}, {}, {}, {}, {})) \ + X(QDragEnterEvent, ({}, {}, {}, {}, {})) \ + X(QDragLeaveEvent, ()) \ + X(QHelpEvent, ({}, {}, {})) \ + X(QStatusTipEvent, ({})) \ + X(QWhatsThisClickedEvent, ({})) \ + X(QActionEvent, (0, nullptr)) \ + X(QFileOpenEvent, (QString{})) \ + X(QToolBarChangeEvent, (false)) \ + X(QShortcutEvent, ({}, 0)) \ + X(QWindowStateChangeEvent, ({})) \ + X(QTouchEvent, (QEvent::None)) \ + X(QScrollPrepareEvent, ({})) \ + X(QScrollEvent, ({}, {}, {})) \ + X(QScreenOrientationChangeEvent, (nullptr, {})) \ + X(QApplicationStateChangeEvent, ({})) \ + /* end */ + +#define FOR_EACH_EVENT(X) \ + FOR_EACH_CORE_EVENT(X) \ + FOR_EACH_GUI_EVENT(X) \ + /* end */ class tst_QEvent : public QObject { @@ -40,6 +105,7 @@ public: ~tst_QEvent(); private slots: + void clone() const; void registerEventType_data(); void registerEventType(); void exhaustEventTypeRegistration(); // keep behind registerEventType() test @@ -55,6 +121,18 @@ tst_QEvent::tst_QEvent() tst_QEvent::~tst_QEvent() { } +void tst_QEvent::clone() const +{ +#define ACTION(Type, Init) do { \ + const std::unique_ptr<const Type> e(new Type Init); \ + auto c = e->clone(); \ + static_assert(std::is_same_v<decltype(c), Type *>); \ + delete c; \ + } while (0); + + FOR_EACH_EVENT(ACTION) +} + void tst_QEvent::registerEventType_data() { QTest::addColumn<int>("hint"); |