Make the event delivery go through some more static functions
This commit makes QCoreApplicationPrivate::checkReceiverThread, notify_helper, and sendThroughObjectEventFilters be static functions, since they only deal with global data or the parameters only. Making notifyInternal would have been binary incompatible (it's called from inline functions QCoreApplication::sendSpontaneousEvent and QCoreApplication::sendEvent), so instead add a new static notifyInternal2 and mark the older function deprecated and to be removed in Qt 6. Change-Id: I27eaacb532114dd188c4ffff13d59fe3b0661489 Reviewed-by: Albert Astals Cid <albert.astals@canonical.com> Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>bb10
parent
01f800ae6f
commit
9d98584a83
|
|
@ -1,6 +1,7 @@
|
|||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2015 The Qt Company Ltd.
|
||||
** Copyright (C) 2015 Intel Corporation.
|
||||
** Contact: http://www.qt.io/licensing/
|
||||
**
|
||||
** This file is part of the QtCore module of the Qt Toolkit.
|
||||
|
|
@ -940,12 +941,28 @@ void QCoreApplication::setQuitLockEnabled(bool enabled)
|
|||
|
||||
/*!
|
||||
\internal
|
||||
\deprecated
|
||||
|
||||
This function is here to make it possible for Qt extensions to
|
||||
hook into event notification without subclassing QApplication
|
||||
*/
|
||||
bool QCoreApplication::notifyInternal(QObject *receiver, QEvent *event)
|
||||
{
|
||||
return notifyInternal2(receiver, event);
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
\since 5.6
|
||||
|
||||
This function is here to make it possible for Qt extensions to
|
||||
hook into event notification without subclassing QApplication.
|
||||
*/
|
||||
bool QCoreApplication::notifyInternal2(QObject *receiver, QEvent *event)
|
||||
{
|
||||
if (!self)
|
||||
return false;
|
||||
|
||||
// Make it possible for Qt Script to hook into events even
|
||||
// though QApplication is subclassed...
|
||||
bool result = false;
|
||||
|
|
@ -961,10 +978,9 @@ bool QCoreApplication::notifyInternal(QObject *receiver, QEvent *event)
|
|||
QObjectPrivate *d = receiver->d_func();
|
||||
QThreadData *threadData = d->threadData;
|
||||
QScopedLoopLevelCounter loopLevelCounter(threadData);
|
||||
return notify(receiver, event);
|
||||
return self->notify(receiver, event);
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
Sends \a event to \a receiver: \a {receiver}->event(\a event).
|
||||
Returns the value that is returned from the receiver's event
|
||||
|
|
@ -1020,7 +1036,6 @@ bool QCoreApplication::notifyInternal(QObject *receiver, QEvent *event)
|
|||
|
||||
bool QCoreApplication::notify(QObject *receiver, QEvent *event)
|
||||
{
|
||||
Q_D(QCoreApplication);
|
||||
// no events are delivered after ~QCoreApplication() has started
|
||||
if (QCoreApplicationPrivate::is_app_closing)
|
||||
return true;
|
||||
|
|
@ -1031,10 +1046,10 @@ bool QCoreApplication::notify(QObject *receiver, QEvent *event)
|
|||
}
|
||||
|
||||
#ifndef QT_NO_DEBUG
|
||||
d->checkReceiverThread(receiver);
|
||||
QCoreApplicationPrivate::checkReceiverThread(receiver);
|
||||
#endif
|
||||
|
||||
return receiver->isWidgetType() ? false : d->notify_helper(receiver, event);
|
||||
return receiver->isWidgetType() ? false : QCoreApplicationPrivate::notify_helper(receiver, event);
|
||||
}
|
||||
|
||||
bool QCoreApplicationPrivate::sendThroughApplicationEventFilters(QObject *receiver, QEvent *event)
|
||||
|
|
@ -1058,8 +1073,7 @@ bool QCoreApplicationPrivate::sendThroughApplicationEventFilters(QObject *receiv
|
|||
|
||||
bool QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject *receiver, QEvent *event)
|
||||
{
|
||||
Q_Q(QCoreApplication);
|
||||
if (receiver != q && receiver->d_func()->extraData) {
|
||||
if (receiver != QCoreApplication::instance() && receiver->d_func()->extraData) {
|
||||
for (int i = 0; i < receiver->d_func()->extraData->eventFilters.size(); ++i) {
|
||||
QObject *obj = receiver->d_func()->extraData->eventFilters.at(i);
|
||||
if (!obj)
|
||||
|
|
@ -1078,12 +1092,12 @@ bool QCoreApplicationPrivate::sendThroughObjectEventFilters(QObject *receiver, Q
|
|||
/*!
|
||||
\internal
|
||||
|
||||
Helper function called by notify()
|
||||
Helper function called by QCoreApplicationPrivate::notify() and qapplication.cpp
|
||||
*/
|
||||
bool QCoreApplicationPrivate::notify_helper(QObject *receiver, QEvent * event)
|
||||
{
|
||||
// send to all application event filters
|
||||
if (sendThroughApplicationEventFilters(receiver, event))
|
||||
// send to all application event filters (only does anything in the main thread)
|
||||
if (QCoreApplication::self->d_func()->sendThroughApplicationEventFilters(receiver, event))
|
||||
return true;
|
||||
// send to all receiver event filters
|
||||
if (sendThroughObjectEventFilters(receiver, event))
|
||||
|
|
|
|||
|
|
@ -194,7 +194,10 @@ protected:
|
|||
private:
|
||||
#ifndef QT_NO_QOBJECT
|
||||
static bool sendSpontaneousEvent(QObject *receiver, QEvent *event);
|
||||
bool notifyInternal(QObject *receiver, QEvent *event);
|
||||
# if QT_DEPRECATED_SINCE(5,6)
|
||||
QT_DEPRECATED bool notifyInternal(QObject *receiver, QEvent *event); // ### Qt6 BIC: remove me
|
||||
# endif
|
||||
static bool notifyInternal2(QObject *receiver, QEvent *);
|
||||
#endif
|
||||
|
||||
void init();
|
||||
|
|
@ -221,10 +224,10 @@ private:
|
|||
|
||||
#ifndef QT_NO_QOBJECT
|
||||
inline bool QCoreApplication::sendEvent(QObject *receiver, QEvent *event)
|
||||
{ if (event) event->spont = false; return self ? self->notifyInternal(receiver, event) : false; }
|
||||
{ if (event) event->spont = false; return notifyInternal2(receiver, event); }
|
||||
|
||||
inline bool QCoreApplication::sendSpontaneousEvent(QObject *receiver, QEvent *event)
|
||||
{ if (event) event->spont = true; return self ? self->notifyInternal(receiver, event) : false; }
|
||||
{ if (event) event->spont = true; return notifyInternal2(receiver, event); }
|
||||
#endif
|
||||
|
||||
#ifdef QT_NO_DEPRECATED
|
||||
|
|
|
|||
|
|
@ -86,8 +86,8 @@ public:
|
|||
|
||||
#ifndef QT_NO_QOBJECT
|
||||
bool sendThroughApplicationEventFilters(QObject *, QEvent *);
|
||||
bool sendThroughObjectEventFilters(QObject *, QEvent *);
|
||||
bool notify_helper(QObject *, QEvent *);
|
||||
static bool sendThroughObjectEventFilters(QObject *, QEvent *);
|
||||
static bool notify_helper(QObject *, QEvent *);
|
||||
static inline void setEventSpontaneous(QEvent *e, bool spontaneous) { e->spont = spontaneous; }
|
||||
|
||||
virtual void createEventDispatcher();
|
||||
|
|
@ -109,7 +109,7 @@ public:
|
|||
static QThread *mainThread();
|
||||
static void sendPostedEvents(QObject *receiver, int event_type, QThreadData *data);
|
||||
|
||||
void checkReceiverThread(QObject *receiver);
|
||||
static void checkReceiverThread(QObject *receiver);
|
||||
void cleanupThreadData();
|
||||
#endif // QT_NO_QOBJECT
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue