summaryrefslogtreecommitdiffstats
path: root/src/corelib/kernel/qcoreevent.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/kernel/qcoreevent.cpp')
-rw-r--r--src/corelib/kernel/qcoreevent.cpp192
1 files changed, 74 insertions, 118 deletions
diff --git a/src/corelib/kernel/qcoreevent.cpp b/src/corelib/kernel/qcoreevent.cpp
index cc611ec038..9c99530268 100644
--- a/src/corelib/kernel/qcoreevent.cpp
+++ b/src/corelib/kernel/qcoreevent.cpp
@@ -1,44 +1,9 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Copyright (C) 2016 Intel Corporation.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the QtCore module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 3 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL3 included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 3 requirements
-** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 2.0 or (at your option) the GNU General
-** Public license version 3 or any later version approved by the KDE Free
-** Qt Foundation. The licenses are as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-2.0.html and
-** https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2022 The Qt Company Ltd.
+// Copyright (C) 2016 Intel Corporation.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#include "qcoreevent.h"
+#include "qcoreevent_p.h"
#include "qcoreapplication.h"
#include "qcoreapplication_p.h"
@@ -50,6 +15,9 @@
QT_BEGIN_NAMESPACE
+Q_TRACE_POINT(qtcore, QEvent_ctor, QEvent *event, QEvent::Type type);
+Q_TRACE_POINT(qtcore, QEvent_dtor, QEvent *event, QEvent::Type type);
+
/*!
\class QEvent
\inmodule QtCore
@@ -111,6 +79,8 @@ QT_BEGIN_NAMESPACE
\value ChildAdded An object gets a child (QChildEvent).
\value ChildPolished A widget child gets polished (QChildEvent).
\value ChildRemoved An object loses a child (QChildEvent).
+ \value [since 6.7] ChildWindowAdded A child window was added to the window.
+ \value [since 6.7] ChildWindowRemoved A child window was removed from the window.
\value Clipboard The clipboard contents have changed.
\value Close Widget was closed (QCloseEvent).
\value CloseSoftwareInputPanel A widget wants to close the software input panel (SIP).
@@ -118,6 +88,8 @@ QT_BEGIN_NAMESPACE
\value ContextMenu Context popup menu (QContextMenuEvent).
\value CursorChange The widget's cursor has changed.
\value DeferredDelete The object will be deleted after it has cleaned up (QDeferredDeleteEvent)
+ \value [since 6.6] DevicePixelRatioChange
+ The devicePixelRatio has changed for this widget's or window's underlying backing store.
\value DragEnter The cursor enters a widget during a drag and drop operation (QDragEnterEvent).
\value DragLeave The cursor leaves a widget during a drag and drop operation (QDragLeaveEvent).
\value DragMove A drag and drop operation is in progress (QDragMoveEvent).
@@ -153,6 +125,7 @@ QT_BEGIN_NAMESPACE
\value GraphicsSceneMove Widget was moved (QGraphicsSceneMoveEvent).
\value GraphicsSceneResize Widget was resized (QGraphicsSceneResizeEvent).
\value GraphicsSceneWheel Mouse wheel rolled in a graphics scene (QGraphicsSceneWheelEvent).
+ \value GraphicsSceneLeave The cursor leaves a graphics scene (QGraphicsSceneWheelEvent).
\value Hide Widget was hidden (QHideEvent).
\value HideToParent A child widget has been hidden.
\value HoverEnter The mouse cursor enters a hover widget (QHoverEvent).
@@ -189,15 +162,20 @@ QT_BEGIN_NAMESPACE
\value OrientationChange The screens orientation has changes (QScreenOrientationChangeEvent).
\value Paint Screen update necessary (QPaintEvent).
\value PaletteChange Palette of the widget changed.
- \value ParentAboutToChange The widget parent is about to change.
- \value ParentChange The widget parent has changed.
+ \value ParentAboutToChange The object parent is about to change.
+ Only sent to some object types, such as QWidget.
+ \value ParentChange The object parent has changed.
+ Only sent to some object types, such as QWidget.
+ \value [since 6.7] ParentWindowAboutToChange The parent window is about to change.
+ \value [since 6.7] ParentWindowChange The parent window has changed.
\value PlatformPanel A platform specific panel has been requested.
\value PlatformSurface A native platform surface has been created or is about to be destroyed (QPlatformSurfaceEvent).
\omitvalue Pointer
\value Polish The widget is polished.
\value PolishRequest The widget should be polished.
\value QueryWhatsThis The widget should accept the event if it has "What's This?" help (QHelpEvent).
- \value ReadOnlyChange Widget's read-only state has changed (since Qt 5.4).
+ \value Quit The application has exited.
+ \value [since 5.4] ReadOnlyChange Widget's read-only state has changed.
\value RequestSoftwareInputPanel A widget wants to open a software input panel (SIP).
\value Resize Widget's size changed (QResizeEvent).
\value ScrollPrepare The object needs to fill in its geometry information (QScrollPrepareEvent).
@@ -224,7 +202,7 @@ QT_BEGIN_NAMESPACE
\omitvalue OkRequest
\value TabletEnterProximity Wacom tablet enter proximity event (QTabletEvent), sent to QApplication.
\value TabletLeaveProximity Wacom tablet leave proximity event (QTabletEvent), sent to QApplication.
- \value TabletTrackingChange The Wacom tablet tracking state has changed (since Qt 5.9).
+ \value [since 5.9] TabletTrackingChange The Wacom tablet tracking state has changed.
\omitvalue ThemeChange
\value ThreadChange The object is moved to another thread. This is the last event sent to this object in the previous thread. See QObject::moveToThread().
\value Timer Regular timer events (QTimerEvent).
@@ -250,7 +228,7 @@ QT_BEGIN_NAMESPACE
\value WindowStateChange The \l{QWindow::windowState()}{window's state} (minimized, maximized or full-screen) has changed (QWindowStateChangeEvent).
\value WindowTitleChange The window title has changed.
\value WindowUnblocked The window is unblocked after a modal dialog exited.
- \value WinIdChange The window system identifer for this native widget has changed.
+ \value WinIdChange The window system identifier for this native widget has changed.
\value ZOrderChange The widget's z-order has changed. This event is never sent to top level windows.
User events should have values between \c User and \c{MaxUser}:
@@ -283,39 +261,29 @@ QT_BEGIN_NAMESPACE
\omitvalue ApplicationDeactivate
\omitvalue ApplicationDeactivated
\omitvalue MacGLWindowChange
- \omitvalue MacGLClearDrawable
\omitvalue NetworkReplyUpdated
\omitvalue FutureCallOut
\omitvalue NativeGesture
\omitvalue WindowChangeInternal
\omitvalue ScreenChangeInternal
+ \omitvalue WindowAboutToChangeInternal
*/
/*!
- Contructs an event object of type \a type.
+ Constructs an event object of type \a type.
*/
QEvent::QEvent(Type type)
- : d(nullptr), t(type), posted(false), spont(false), m_accept(true), m_inputEvent(false), m_pointerEvent(false)
+ : t(type), m_reserved(0),
+ m_inputEvent(false), m_pointerEvent(false), m_singlePointEvent(false)
{
- Q_TRACE(QEvent_ctor, this, t);
+ Q_TRACE(QEvent_ctor, this, type);
}
/*!
+ \fn QEvent::QEvent(const QEvent &other)
\internal
- Attempts to copy the \a other event.
-
- Copying events is a bad idea, yet some Qt 4 code does it (notably,
- QApplication and the state machine).
- */
-QEvent::QEvent(const QEvent &other)
- : d(other.d), t(other.t), posted(other.posted), spont(other.spont),
- m_accept(other.m_accept)
-{
- Q_TRACE(QEvent_ctor, this, t);
- // if QEventPrivate becomes available, make sure to implement a
- // virtual QEventPrivate *clone() const; function so we can copy here
- Q_ASSERT_X(!d, "QEvent", "Impossible, this can't happen: QEventPrivate isn't defined anywhere");
-}
+ Copies the \a other event.
+*/
/*!
\internal
@@ -336,23 +304,21 @@ QEvent::QEvent(const QEvent &other)
/*!
\internal
+ \since 6.0
+ \fn QEvent::QEvent(Type type, QEvent::SinglePointEventTag)
+
+ Constructs an event object of type \a type, setting the singlePointEvent,
+ pointerEvent and inputEvent flags to \c true.
+*/
+
+/*!
+ \fn QEvent &QEvent::operator=(const QEvent &other)
+ \internal
Attempts to copy the \a other event.
Copying events is a bad idea, yet some Qt 4 code does it (notably,
QApplication and the state machine).
*/
-QEvent &QEvent::operator=(const QEvent &other)
-{
- // if QEventPrivate becomes available, make sure to implement a
- // virtual QEventPrivate *clone() const; function so we can copy here
- Q_ASSERT_X(!other.d, "QEvent", "Impossible, this can't happen: QEventPrivate isn't defined anywhere");
-
- t = other.t;
- posted = other.posted;
- spont = other.spont;
- m_accept = other.m_accept;
- return *this;
-}
/*!
Destroys the event. If it was \l{QCoreApplication::postEvent()}{posted},
@@ -361,16 +327,20 @@ QEvent &QEvent::operator=(const QEvent &other)
QEvent::~QEvent()
{
- Q_TRACE(QEvent_dtor, this, t);
- if (posted && QCoreApplication::instance())
+ if (m_posted && QCoreApplication::instance())
QCoreApplicationPrivate::removePostedEvent(this);
- Q_ASSERT_X(!d, "QEvent", "Impossible, this can't happen: QEventPrivate isn't defined anywhere");
}
+/*!
+ Creates and returns an identical copy of this event.
+ \since 6.0
+*/
+QEvent *QEvent::clone() const
+{ return new QEvent(*this); }
/*!
\property QEvent::accepted
- the accept flag of the event object
+ \brief the accept flag of the event object.
Setting the accept parameter indicates that the event receiver
wants the event. Unwanted events might be propagated to the parent
@@ -379,6 +349,10 @@ QEvent::~QEvent()
For convenience, the accept flag can also be set with accept(),
and cleared with ignore().
+
+ \note Accepting a QPointerEvent implicitly
+ \l {QEventPoint::setAccepted()}{accepts} all the
+ \l {QPointerEvent::points()}{points} that the event carries.
*/
/*!
@@ -438,6 +412,13 @@ QEvent::~QEvent()
subclasses.
*/
+/*!
+ \fn bool QEvent::isSinglePointEvent() const
+ \since 6.0
+
+ Returns \c true if the event object is a subclass of QSinglePointEvent.
+*/
+
namespace {
template <size_t N>
struct QBasicAtomicBitField {
@@ -452,13 +433,16 @@ struct QBasicAtomicBitField {
QBasicAtomicInteger<uint> next;
QBasicAtomicInteger<uint> data[NumInts];
+ constexpr QBasicAtomicBitField() = default;
+
bool allocateSpecific(int which) noexcept
{
QBasicAtomicInteger<uint> &entry = data[which / BitsPerInt];
const uint old = entry.loadRelaxed();
const uint bit = 1U << (which % BitsPerInt);
- return !(old & bit) // wasn't taken
- && entry.testAndSetRelaxed(old, old | bit); // still wasn't taken
+ if (old & bit)
+ return false; // already taken
+ return (entry.fetchAndOrRelaxed(bit) & bit) == 0;
// don't update 'next' here - it's unlikely that it will need
// to be updated, in the general case, and having 'next'
@@ -492,7 +476,7 @@ struct QBasicAtomicBitField {
typedef QBasicAtomicBitField<QEvent::MaxUser - QEvent::User + 1> UserEventTypeRegistry;
-static UserEventTypeRegistry userEventTypeRegistry;
+Q_CONSTINIT static UserEventTypeRegistry userEventTypeRegistry {};
static inline int registerEventTypeZeroBased(int id) noexcept
{
@@ -535,12 +519,12 @@ int QEvent::registerEventType(int hint) noexcept
started one or more timers. Each timer has a unique identifier. A
timer is started with QObject::startTimer().
- The QTimer class provides a high-level programming interface that
+ The QChronoTimer class provides a high-level programming interface that
uses signals instead of events. It also provides single-shot timers.
The event handler QObject::timerEvent() receives timer events.
- \sa QTimer, QObject::timerEvent(), QObject::startTimer(),
+ \sa QChronoTimer, QObject::timerEvent(), QObject::startTimer(),
QObject::killTimer()
*/
@@ -552,12 +536,7 @@ QTimerEvent::QTimerEvent(int timerId)
: QEvent(Timer), id(timerId)
{}
-/*!
- \internal
-*/
-QTimerEvent::~QTimerEvent()
-{
-}
+Q_IMPL_EVENT_COMMON(QTimerEvent)
/*!
\fn int QTimerEvent::timerId() const
@@ -599,12 +578,7 @@ QChildEvent::QChildEvent(Type type, QObject *child)
: QEvent(type), c(child)
{}
-/*!
- \internal
-*/
-QChildEvent::~QChildEvent()
-{
-}
+Q_IMPL_EVENT_COMMON(QChildEvent)
/*!
\fn QObject *QChildEvent::child() const
@@ -656,12 +630,7 @@ QDynamicPropertyChangeEvent::QDynamicPropertyChangeEvent(const QByteArray &name)
{
}
-/*!
- \internal
-*/
-QDynamicPropertyChangeEvent::~QDynamicPropertyChangeEvent()
-{
-}
+Q_IMPL_EVENT_COMMON(QDynamicPropertyChangeEvent)
/*!
\fn QByteArray QDynamicPropertyChangeEvent::propertyName() const
@@ -673,26 +642,13 @@ QDynamicPropertyChangeEvent::~QDynamicPropertyChangeEvent()
*/
/*!
- Constructs a deferred delete event with an initial loopLevel() of zero.
-*/
-QDeferredDeleteEvent::QDeferredDeleteEvent()
- : QEvent(QEvent::DeferredDelete)
- , level(0)
-{ }
-
-/*!
- \internal
+ Constructs a deferred delete event with the given loop and scope level.
*/
-QDeferredDeleteEvent::~QDeferredDeleteEvent()
+QDeferredDeleteEvent::QDeferredDeleteEvent(int loopLevel, int scopeLevel)
+ : QEvent(QEvent::DeferredDelete), m_loopLevel(loopLevel), m_scopeLevel(scopeLevel)
{ }
-/*! \fn int QDeferredDeleteEvent::loopLevel() const
-
- Returns the loop-level in which the event was posted. The
- loop-level is set by QCoreApplication::postEvent().
-
- \sa QObject::deleteLater()
-*/
+Q_IMPL_EVENT_COMMON(QDeferredDeleteEvent)
QT_END_NAMESPACE