1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Copyright (C) 2016 Intel Corporation.
5** Contact: https://www.qt.io/licensing/
6**
7** This file is part of the QtCore module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial License Usage
11** Licensees holding valid commercial Qt licenses may use this file in
12** accordance with the commercial license agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and The Qt Company. For licensing terms
15** and conditions see https://www.qt.io/terms-conditions. For further
16** information use the contact form at https://www.qt.io/contact-us.
17**
18** GNU Lesser General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU Lesser
20** General Public License version 3 as published by the Free Software
21** Foundation and appearing in the file LICENSE.LGPL3 included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU Lesser General Public License version 3 requirements
24** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
25**
26** GNU General Public License Usage
27** Alternatively, this file may be used under the terms of the GNU
28** General Public License version 2.0 or (at your option) the GNU General
29** Public license version 3 or any later version approved by the KDE Free
30** Qt Foundation. The licenses are as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
32** included in the packaging of this file. Please review the following
33** information to ensure the GNU General Public License requirements will
34** be met: https://www.gnu.org/licenses/gpl-2.0.html and
35** https://www.gnu.org/licenses/gpl-3.0.html.
36**
37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41#include "qcoreevent.h"
42#include "qcoreapplication.h"
43#include "qcoreapplication_p.h"
44
45#include "qbasicatomic.h"
46
47#include <qtcore_tracepoints_p.h>
48
49#include <limits>
50
51QT_BEGIN_NAMESPACE
52
53/*!
54 \class QEvent
55 \inmodule QtCore
56 \brief The QEvent class is the base class of all
57 event classes. Event objects contain event parameters.
58
59 \ingroup events
60
61 Qt's main event loop (QCoreApplication::exec()) fetches native
62 window system events from the event queue, translates them into
63 QEvents, and sends the translated events to \l{QObject}s.
64
65 In general, events come from the underlying window system
66 (spontaneous() returns \c true), but it is also possible to manually
67 send events using QCoreApplication::sendEvent() and
68 QCoreApplication::postEvent() (spontaneous() returns \c false).
69
70 \l {QObject}{QObjects} receive events by having their QObject::event() function
71 called. The function can be reimplemented in subclasses to
72 customize event handling and add additional event types;
73 QWidget::event() is a notable example. By default, events are
74 dispatched to event handlers like QObject::timerEvent() and
75 QWidget::mouseMoveEvent(). QObject::installEventFilter() allows an
76 object to intercept events destined for another object.
77
78 The basic QEvent contains only an event type parameter and an
79 "accept" flag. The accept flag set with accept(), and cleared
80 with ignore(). It is set by default, but don't rely on this as
81 subclasses may choose to clear it in their constructor.
82
83 Subclasses of QEvent contain additional parameters that describe
84 the particular event.
85
86 \sa QObject::event(), QObject::installEventFilter(),
87 QCoreApplication::sendEvent(),
88 QCoreApplication::postEvent(), QCoreApplication::processEvents()
89*/
90
91
92/*!
93 \enum QEvent::Type
94
95 This enum type defines the valid event types in Qt. The event
96 types and the specialized classes for each type are as follows:
97
98 \value None Not an event.
99 \value ActionAdded A new action has been added (QActionEvent).
100 \value ActionChanged An action has been changed (QActionEvent).
101 \value ActionRemoved An action has been removed (QActionEvent).
102 \value ActivationChange A widget's top-level window activation state has changed.
103 \value ApplicationActivate This enum has been deprecated. Use ApplicationStateChange instead.
104 \value ApplicationActivated This enum has been deprecated. Use ApplicationStateChange instead.
105 \value ApplicationDeactivate This enum has been deprecated. Use ApplicationStateChange instead.
106 \value ApplicationFontChange The default application font has changed.
107 \value ApplicationLayoutDirectionChange The default application layout direction has changed.
108 \value ApplicationPaletteChange The default application palette has changed.
109 \value ApplicationStateChange The state of the application has changed.
110 \value ApplicationWindowIconChange The application's icon has changed.
111 \value ChildAdded An object gets a child (QChildEvent).
112 \value ChildPolished A widget child gets polished (QChildEvent).
113 \value ChildRemoved An object loses a child (QChildEvent).
114 \value Clipboard The clipboard contents have changed.
115 \value Close Widget was closed (QCloseEvent).
116 \value CloseSoftwareInputPanel A widget wants to close the software input panel (SIP).
117 \value ContentsRectChange The margins of the widget's content rect changed.
118 \value ContextMenu Context popup menu (QContextMenuEvent).
119 \value CursorChange The widget's cursor has changed.
120 \value DeferredDelete The object will be deleted after it has cleaned up (QDeferredDeleteEvent)
121 \value DragEnter The cursor enters a widget during a drag and drop operation (QDragEnterEvent).
122 \value DragLeave The cursor leaves a widget during a drag and drop operation (QDragLeaveEvent).
123 \value DragMove A drag and drop operation is in progress (QDragMoveEvent).
124 \value Drop A drag and drop operation is completed (QDropEvent).
125 \value DynamicPropertyChange A dynamic property was added, changed, or removed from the object.
126 \value EnabledChange Widget's enabled state has changed.
127 \value Enter Mouse enters widget's boundaries (QEnterEvent).
128 \value EnterEditFocus An editor widget gains focus for editing. \c QT_KEYPAD_NAVIGATION must be defined.
129 \value EnterWhatsThisMode Send to toplevel widgets when the application enters "What's This?" mode.
130 \value Expose Sent to a window when its on-screen contents are invalidated and need to be flushed from the backing store.
131 \value FileOpen File open request (QFileOpenEvent).
132 \value FocusIn Widget or Window gains keyboard focus (QFocusEvent).
133 \value FocusOut Widget or Window loses keyboard focus (QFocusEvent).
134 \value FocusAboutToChange Widget or Window focus is about to change (QFocusEvent)
135 \value FontChange Widget's font has changed.
136 \value Gesture A gesture was triggered (QGestureEvent).
137 \value GestureOverride A gesture override was triggered (QGestureEvent).
138 \value GrabKeyboard Item gains keyboard grab (QGraphicsItem only).
139 \value GrabMouse Item gains mouse grab (QGraphicsItem only).
140 \value GraphicsSceneContextMenu Context popup menu over a graphics scene (QGraphicsSceneContextMenuEvent).
141 \value GraphicsSceneDragEnter The cursor enters a graphics scene during a drag and drop operation (QGraphicsSceneDragDropEvent).
142 \value GraphicsSceneDragLeave The cursor leaves a graphics scene during a drag and drop operation (QGraphicsSceneDragDropEvent).
143 \value GraphicsSceneDragMove A drag and drop operation is in progress over a scene (QGraphicsSceneDragDropEvent).
144 \value GraphicsSceneDrop A drag and drop operation is completed over a scene (QGraphicsSceneDragDropEvent).
145 \value GraphicsSceneHelp The user requests help for a graphics scene (QHelpEvent).
146 \value GraphicsSceneHoverEnter The mouse cursor enters a hover item in a graphics scene (QGraphicsSceneHoverEvent).
147 \value GraphicsSceneHoverLeave The mouse cursor leaves a hover item in a graphics scene (QGraphicsSceneHoverEvent).
148 \value GraphicsSceneHoverMove The mouse cursor moves inside a hover item in a graphics scene (QGraphicsSceneHoverEvent).
149 \value GraphicsSceneMouseDoubleClick Mouse press again (double click) in a graphics scene (QGraphicsSceneMouseEvent).
150 \value GraphicsSceneMouseMove Move mouse in a graphics scene (QGraphicsSceneMouseEvent).
151 \value GraphicsSceneMousePress Mouse press in a graphics scene (QGraphicsSceneMouseEvent).
152 \value GraphicsSceneMouseRelease Mouse release in a graphics scene (QGraphicsSceneMouseEvent).
153 \value GraphicsSceneMove Widget was moved (QGraphicsSceneMoveEvent).
154 \value GraphicsSceneResize Widget was resized (QGraphicsSceneResizeEvent).
155 \value GraphicsSceneWheel Mouse wheel rolled in a graphics scene (QGraphicsSceneWheelEvent).
156 \value Hide Widget was hidden (QHideEvent).
157 \value HideToParent A child widget has been hidden.
158 \value HoverEnter The mouse cursor enters a hover widget (QHoverEvent).
159 \value HoverLeave The mouse cursor leaves a hover widget (QHoverEvent).
160 \value HoverMove The mouse cursor moves inside a hover widget (QHoverEvent).
161 \value IconDrag The main icon of a window has been dragged away (QIconDragEvent).
162 \value IconTextChange Widget's icon text has been changed. (Deprecated)
163 \value InputMethod An input method is being used (QInputMethodEvent).
164 \value InputMethodQuery A input method query event (QInputMethodQueryEvent)
165 \value KeyboardLayoutChange The keyboard layout has changed.
166 \value KeyPress Key press (QKeyEvent).
167 \value KeyRelease Key release (QKeyEvent).
168 \value LanguageChange The application translation changed.
169 \value LayoutDirectionChange The direction of layouts changed.
170 \value LayoutRequest Widget layout needs to be redone.
171 \value Leave Mouse leaves widget's boundaries.
172 \value LeaveEditFocus An editor widget loses focus for editing. QT_KEYPAD_NAVIGATION must be defined.
173 \value LeaveWhatsThisMode Send to toplevel widgets when the application leaves "What's This?" mode.
174 \value LocaleChange The system locale has changed.
175 \value NonClientAreaMouseButtonDblClick A mouse double click occurred outside the client area (QMouseEvent).
176 \value NonClientAreaMouseButtonPress A mouse button press occurred outside the client area (QMouseEvent).
177 \value NonClientAreaMouseButtonRelease A mouse button release occurred outside the client area (QMouseEvent).
178 \value NonClientAreaMouseMove A mouse move occurred outside the client area (QMouseEvent).
179 \value MacSizeChange The user changed his widget sizes (\macos only).
180 \value MetaCall An asynchronous method invocation via QMetaObject::invokeMethod().
181 \value ModifiedChange Widgets modification state has been changed.
182 \value MouseButtonDblClick Mouse press again (QMouseEvent).
183 \value MouseButtonPress Mouse press (QMouseEvent).
184 \value MouseButtonRelease Mouse release (QMouseEvent).
185 \value MouseMove Mouse move (QMouseEvent).
186 \value MouseTrackingChange The mouse tracking state has changed.
187 \value Move Widget's position changed (QMoveEvent).
188 \value NativeGesture The system has detected a gesture (QNativeGestureEvent).
189 \value OrientationChange The screens orientation has changes (QScreenOrientationChangeEvent).
190 \value Paint Screen update necessary (QPaintEvent).
191 \value PaletteChange Palette of the widget changed.
192 \value ParentAboutToChange The widget parent is about to change.
193 \value ParentChange The widget parent has changed.
194 \value PlatformPanel A platform specific panel has been requested.
195 \value PlatformSurface A native platform surface has been created or is about to be destroyed (QPlatformSurfaceEvent).
196 \omitvalue Pointer
197 \value Polish The widget is polished.
198 \value PolishRequest The widget should be polished.
199 \value QueryWhatsThis The widget should accept the event if it has "What's This?" help (QHelpEvent).
200 \value ReadOnlyChange Widget's read-only state has changed (since Qt 5.4).
201 \value RequestSoftwareInputPanel A widget wants to open a software input panel (SIP).
202 \value Resize Widget's size changed (QResizeEvent).
203 \value ScrollPrepare The object needs to fill in its geometry information (QScrollPrepareEvent).
204 \value Scroll The object needs to scroll to the supplied position (QScrollEvent).
205 \value Shortcut Key press in child for shortcut key handling (QShortcutEvent).
206 \value ShortcutOverride Key press in child, for overriding shortcut key handling (QKeyEvent).
207 When a shortcut is about to trigger, \c ShortcutOverride
208 is sent to the active window. This allows clients (e.g. widgets)
209 to signal that they will handle the shortcut themselves, by
210 accepting the event. If the shortcut override is accepted, the
211 event is delivered as a normal key press to the focus widget.
212 Otherwise, it triggers the shortcut action, if one exists.
213 \value Show Widget was shown on screen (QShowEvent).
214 \value ShowToParent A child widget has been shown.
215 \value SockAct Socket activated, used to implement QSocketNotifier.
216 \omitvalue SockClose
217 \value StateMachineSignal A signal delivered to a state machine (QStateMachine::SignalEvent).
218 \value StateMachineWrapped The event is a wrapper for, i.e., contains, another event (QStateMachine::WrappedEvent).
219 \value StatusTip A status tip is requested (QStatusTipEvent).
220 \value StyleChange Widget's style has been changed.
221 \value TabletMove Wacom tablet move (QTabletEvent).
222 \value TabletPress Wacom tablet press (QTabletEvent).
223 \value TabletRelease Wacom tablet release (QTabletEvent).
224 \omitvalue OkRequest
225 \value TabletEnterProximity Wacom tablet enter proximity event (QTabletEvent), sent to QApplication.
226 \value TabletLeaveProximity Wacom tablet leave proximity event (QTabletEvent), sent to QApplication.
227 \value TabletTrackingChange The Wacom tablet tracking state has changed (since Qt 5.9).
228 \omitvalue ThemeChange
229 \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().
230 \value Timer Regular timer events (QTimerEvent).
231 \value ToolBarChange The toolbar button is toggled on \macos.
232 \value ToolTip A tooltip was requested (QHelpEvent).
233 \value ToolTipChange The widget's tooltip has changed.
234 \value TouchBegin Beginning of a sequence of touch-screen or track-pad events (QTouchEvent).
235 \value TouchCancel Cancellation of touch-event sequence (QTouchEvent).
236 \value TouchEnd End of touch-event sequence (QTouchEvent).
237 \value TouchUpdate Touch-screen event (QTouchEvent).
238 \value UngrabKeyboard Item loses keyboard grab (QGraphicsItem only).
239 \value UngrabMouse Item loses mouse grab (QGraphicsItem, QQuickItem).
240 \value UpdateLater The widget should be queued to be repainted at a later time.
241 \value UpdateRequest The widget should be repainted.
242 \value WhatsThis The widget should reveal "What's This?" help (QHelpEvent).
243 \value WhatsThisClicked A link in a widget's "What's This?" help was clicked.
244 \value Wheel Mouse wheel rolled (QWheelEvent).
245 \value WinEventAct A Windows-specific activation event has occurred.
246 \value WindowActivate Window was activated.
247 \value WindowBlocked The window is blocked by a modal dialog.
248 \value WindowDeactivate Window was deactivated.
249 \value WindowIconChange The window's icon has changed.
250 \value WindowStateChange The \l{QWindow::windowState()}{window's state} (minimized, maximized or full-screen) has changed (QWindowStateChangeEvent).
251 \value WindowTitleChange The window title has changed.
252 \value WindowUnblocked The window is unblocked after a modal dialog exited.
253 \value WinIdChange The window system identifer for this native widget has changed.
254 \value ZOrderChange The widget's z-order has changed. This event is never sent to top level windows.
255
256 User events should have values between \c User and \c{MaxUser}:
257
258 \value User User-defined event.
259 \value MaxUser Last user event ID.
260
261 For convenience, you can use the registerEventType() function to
262 register and reserve a custom event type for your
263 application. Doing so will allow you to avoid accidentally
264 re-using a custom event type already in use elsewhere in your
265 application.
266
267 \omitvalue AcceptDropsChange
268 \omitvalue ActivateControl
269 \omitvalue Create
270 \omitvalue DeactivateControl
271 \omitvalue Destroy
272 \omitvalue DragResponse
273 \omitvalue EmbeddingControl
274 \omitvalue HelpRequest
275 \omitvalue Quit
276 \omitvalue ShowWindowRequest
277 \omitvalue Speech
278 \omitvalue Style
279 \omitvalue StyleAnimationUpdate
280 \omitvalue ZeroTimerEvent
281 \omitvalue ApplicationActivate
282 \omitvalue ApplicationActivated
283 \omitvalue ApplicationDeactivate
284 \omitvalue ApplicationDeactivated
285 \omitvalue MacGLWindowChange
286 \omitvalue MacGLClearDrawable
287 \omitvalue NetworkReplyUpdated
288 \omitvalue FutureCallOut
289 \omitvalue NativeGesture
290 \omitvalue WindowChangeInternal
291 \omitvalue ScreenChangeInternal
292*/
293
294/*!
295 Contructs an event object of type \a type.
296*/
297QEvent::QEvent(Type type)
298 : d(nullptr), t(type), posted(false), spont(false), m_accept(true)
299{
300 Q_TRACE(QEvent_ctor, this, t);
301}
302
303/*!
304 \internal
305 Attempts to copy the \a other event.
306
307 Copying events is a bad idea, yet some Qt 4 code does it (notably,
308 QApplication and the state machine).
309 */
310QEvent::QEvent(const QEvent &other)
311 : d(other.d), t(other.t), posted(other.posted), spont(other.spont),
312 m_accept(other.m_accept)
313{
314 Q_TRACE(QEvent_ctor, this, t);
315 // if QEventPrivate becomes available, make sure to implement a
316 // virtual QEventPrivate *clone() const; function so we can copy here
317 Q_ASSERT_X(!d, "QEvent", "Impossible, this can't happen: QEventPrivate isn't defined anywhere");
318}
319
320/*!
321 \internal
322 Attempts to copy the \a other event.
323
324 Copying events is a bad idea, yet some Qt 4 code does it (notably,
325 QApplication and the state machine).
326 */
327QEvent &QEvent::operator=(const QEvent &other)
328{
329 // if QEventPrivate becomes available, make sure to implement a
330 // virtual QEventPrivate *clone() const; function so we can copy here
331 Q_ASSERT_X(!other.d, "QEvent", "Impossible, this can't happen: QEventPrivate isn't defined anywhere");
332
333 t = other.t;
334 posted = other.posted;
335 spont = other.spont;
336 m_accept = other.m_accept;
337 return *this;
338}
339
340/*!
341 Destroys the event. If it was \l{QCoreApplication::postEvent()}{posted},
342 it will be removed from the list of events to be posted.
343*/
344
345QEvent::~QEvent()
346{
347 Q_TRACE(QEvent_dtor, this, t);
348 if (posted && QCoreApplication::instance())
349 QCoreApplicationPrivate::removePostedEvent(this);
350 Q_ASSERT_X(!d, "QEvent", "Impossible, this can't happen: QEventPrivate isn't defined anywhere");
351}
352
353
354/*!
355 \property QEvent::accepted
356 the accept flag of the event object
357
358 Setting the accept parameter indicates that the event receiver
359 wants the event. Unwanted events might be propagated to the parent
360 widget. By default, isAccepted() is set to true, but don't rely on
361 this as subclasses may choose to clear it in their constructor.
362
363 For convenience, the accept flag can also be set with accept(),
364 and cleared with ignore().
365*/
366
367/*!
368 \fn void QEvent::accept()
369
370 Sets the accept flag of the event object, the equivalent of
371 calling setAccepted(true).
372
373 Setting the accept parameter indicates that the event receiver
374 wants the event. Unwanted events might be propagated to the parent
375 widget.
376
377 \sa ignore()
378*/
379
380
381/*!
382 \fn void QEvent::ignore()
383
384 Clears the accept flag parameter of the event object, the
385 equivalent of calling setAccepted(false).
386
387 Clearing the accept parameter indicates that the event receiver
388 does not want the event. Unwanted events might be propagated to the
389 parent widget.
390
391 \sa accept()
392*/
393
394
395/*!
396 \fn QEvent::Type QEvent::type() const
397
398 Returns the event type.
399*/
400
401/*!
402 \fn bool QEvent::spontaneous() const
403
404 Returns \c true if the event originated outside the application (a
405 system event); otherwise returns \c false.
406
407 The return value of this function is not defined for paint events.
408*/
409
410namespace {
411template <size_t N>
412struct QBasicAtomicBitField {
413 enum {
414 BitsPerInt = std::numeric_limits<uint>::digits,
415 NumInts = (N + BitsPerInt - 1) / BitsPerInt,
416 NumBits = N
417 };
418
419 // This atomic int points to the next (possibly) free ID saving
420 // the otherwise necessary scan through 'data':
421 QBasicAtomicInteger<uint> next;
422 QBasicAtomicInteger<uint> data[NumInts];
423
424 constexpr QBasicAtomicBitField() = default;
425
426 bool allocateSpecific(int which) noexcept
427 {
428 QBasicAtomicInteger<uint> &entry = data[which / BitsPerInt];
429 const uint old = entry.loadRelaxed();
430 const uint bit = 1U << (which % BitsPerInt);
431 return !(old & bit) // wasn't taken
432 && entry.testAndSetRelaxed(expectedValue: old, newValue: old | bit); // still wasn't taken
433
434 // don't update 'next' here - it's unlikely that it will need
435 // to be updated, in the general case, and having 'next'
436 // trailing a bit is not a problem, as it is just a starting
437 // hint for allocateNext(), which, when wrong, will just
438 // result in a few more rounds through the allocateNext()
439 // loop.
440 }
441
442 int allocateNext() noexcept
443 {
444 // Unroll loop to iterate over ints, then bits? Would save
445 // potentially a lot of cmpxchgs, because we can scan the
446 // whole int before having to load it again.
447
448 // Then again, this should never execute many iterations, so
449 // leave like this for now:
450 for (uint i = next.loadRelaxed(); i < NumBits; ++i) {
451 if (allocateSpecific(which: i)) {
452 // remember next (possibly) free id:
453 const uint oldNext = next.loadRelaxed();
454 next.testAndSetRelaxed(expectedValue: oldNext, newValue: qMax(a: i + 1, b: oldNext));
455 return i;
456 }
457 }
458 return -1;
459 }
460};
461
462} // unnamed namespace
463
464typedef QBasicAtomicBitField<QEvent::MaxUser - QEvent::User + 1> UserEventTypeRegistry;
465
466static UserEventTypeRegistry userEventTypeRegistry {};
467
468static inline int registerEventTypeZeroBased(int id) noexcept
469{
470 // if the type hint hasn't been registered yet, take it:
471 if (id < UserEventTypeRegistry::NumBits && id >= 0 && userEventTypeRegistry.allocateSpecific(which: id))
472 return id;
473
474 // otherwise, ignore hint:
475 return userEventTypeRegistry.allocateNext();
476}
477
478/*!
479 \since 4.4
480 \threadsafe
481
482 Registers and returns a custom event type. The \a hint provided
483 will be used if it is available, otherwise it will return a value
484 between QEvent::User and QEvent::MaxUser that has not yet been
485 registered. The \a hint is ignored if its value is not between
486 QEvent::User and QEvent::MaxUser.
487
488 Returns -1 if all available values are already taken or the
489 program is shutting down.
490*/
491int QEvent::registerEventType(int hint) noexcept
492{
493 const int result = registerEventTypeZeroBased(id: QEvent::MaxUser - hint);
494 return result < 0 ? -1 : QEvent::MaxUser - result ;
495}
496
497/*!
498 \class QTimerEvent
499 \inmodule QtCore
500 \brief The QTimerEvent class contains parameters that describe a
501 timer event.
502
503 \ingroup events
504
505 Timer events are sent at regular intervals to objects that have
506 started one or more timers. Each timer has a unique identifier. A
507 timer is started with QObject::startTimer().
508
509 The QTimer class provides a high-level programming interface that
510 uses signals instead of events. It also provides single-shot timers.
511
512 The event handler QObject::timerEvent() receives timer events.
513
514 \sa QTimer, QObject::timerEvent(), QObject::startTimer(),
515 QObject::killTimer()
516*/
517
518/*!
519 Constructs a timer event object with the timer identifier set to
520 \a timerId.
521*/
522QTimerEvent::QTimerEvent(int timerId)
523 : QEvent(Timer), id(timerId)
524{}
525
526/*!
527 \internal
528*/
529QTimerEvent::~QTimerEvent()
530{
531}
532
533/*!
534 \fn int QTimerEvent::timerId() const
535
536 Returns the unique timer identifier, which is the same identifier
537 as returned from QObject::startTimer().
538*/
539
540/*!
541 \class QChildEvent
542 \inmodule QtCore
543 \brief The QChildEvent class contains event parameters for child object
544 events.
545
546 \ingroup events
547
548 Child events are sent immediately to objects when children are
549 added or removed.
550
551 In both cases you can only rely on the child being a QObject (or,
552 if QObject::isWidgetType() returns \c true, a QWidget). This is
553 because in the QEvent::ChildAdded case the child is not yet fully
554 constructed; in the QEvent::ChildRemoved case it might have
555 already been destructed.
556
557 The handler for these events is QObject::childEvent().
558*/
559
560/*!
561 Constructs a child event object of a particular \a type for the
562 \a child.
563
564 \a type can be QEvent::ChildAdded, QEvent::ChildRemoved,
565 or QEvent::ChildPolished.
566
567 \sa child()
568*/
569QChildEvent::QChildEvent(Type type, QObject *child)
570 : QEvent(type), c(child)
571{}
572
573/*!
574 \internal
575*/
576QChildEvent::~QChildEvent()
577{
578}
579
580/*!
581 \fn QObject *QChildEvent::child() const
582
583 Returns the child object that was added or removed.
584*/
585
586/*!
587 \fn bool QChildEvent::added() const
588
589 Returns \c true if type() is QEvent::ChildAdded; otherwise returns
590 false.
591*/
592
593/*!
594 \fn bool QChildEvent::removed() const
595
596 Returns \c true if type() is QEvent::ChildRemoved; otherwise returns
597 false.
598*/
599
600/*!
601 \fn bool QChildEvent::polished() const
602
603 Returns \c true if type() is QEvent::ChildPolished; otherwise returns
604 false.
605*/
606
607
608/*!
609 \class QDynamicPropertyChangeEvent
610 \inmodule QtCore
611 \since 4.2
612 \brief The QDynamicPropertyChangeEvent class contains event parameters for dynamic
613 property change events.
614
615 \ingroup events
616
617 Dynamic property change events are sent to objects when properties are
618 dynamically added, changed or removed using QObject::setProperty().
619*/
620
621/*!
622 Constructs a dynamic property change event object with the property name set to
623 \a name.
624*/
625QDynamicPropertyChangeEvent::QDynamicPropertyChangeEvent(const QByteArray &name)
626 : QEvent(QEvent::DynamicPropertyChange), n(name)
627{
628}
629
630/*!
631 \internal
632*/
633QDynamicPropertyChangeEvent::~QDynamicPropertyChangeEvent()
634{
635}
636
637/*!
638 \fn QByteArray QDynamicPropertyChangeEvent::propertyName() const
639
640 Returns the name of the dynamic property that was added, changed or
641 removed.
642
643 \sa QObject::setProperty(), QObject::dynamicPropertyNames()
644*/
645
646/*!
647 Constructs a deferred delete event with an initial loopLevel() of zero.
648*/
649QDeferredDeleteEvent::QDeferredDeleteEvent()
650 : QEvent(QEvent::DeferredDelete)
651 , level(0)
652{ }
653
654/*!
655 \internal
656*/
657QDeferredDeleteEvent::~QDeferredDeleteEvent()
658{ }
659
660/*! \fn int QDeferredDeleteEvent::loopLevel() const
661
662 Returns the loop-level in which the event was posted. The
663 loop-level is set by QCoreApplication::postEvent().
664
665 \sa QObject::deleteLater()
666*/
667
668QT_END_NAMESPACE
669
670#include "moc_qcoreevent.cpp"
671

source code of qtbase/src/corelib/kernel/qcoreevent.cpp