Skip to content

Commit

Permalink
Q*Application: move the compressEvent() virtual to the Private class
Browse files Browse the repository at this point in the history
One of the parameters is the QPostEventList, which is declared in
qthread_p.h:
   class QPostEventList : public QList<QPostEvent>
and is thus private API anyway. This also requires the ELFVERSION: token
in qthread_p.h to avoid marking every class derived from Q*Application
as needing private Qt ABI.

We can't remove the virtual in Qt 6, so we keep the fallback
implementations to just forward to the Private::compressEvent() call.

I've elected to mark the QApplication's override as final.

Change-Id: I49a46f42e62bcaf7db69fffd12a664d8720bbe46
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
  • Loading branch information
thiagomacieira committed Dec 13, 2024
1 parent 902058e commit 438b2f2
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/corelib/kernel/qcoreapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1686,7 +1686,14 @@ void QCoreApplication::postEvent(QObject *receiver, QEvent *event, int priority)
\internal
Returns \c true if \a event was compressed away (possibly deleted) and should not be added to the list.
*/
#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
bool QCoreApplication::compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents)
{
return d_func()->compressEvent(event, receiver, postedEvents);
}
#endif

bool QCoreApplicationPrivate::compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents)
{
Q_ASSERT(event);
Q_ASSERT(receiver);
Expand Down
4 changes: 4 additions & 0 deletions src/corelib/kernel/qcoreapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ QT_BEGIN_NAMESPACE

class QCoreApplicationPrivate;
class QTranslator;
#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
class QPostEventList;
#endif
class QAbstractEventDispatcher;
class QAbstractNativeEventFilter;
class QEventLoopLocker;
Expand Down Expand Up @@ -211,7 +213,9 @@ public Q_SLOTS:
protected:
bool event(QEvent *) override;

# if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
virtual bool compressEvent(QEvent *, QObject *receiver, QPostEventList *);
# endif
#endif // QT_NO_QOBJECT

protected:
Expand Down
1 change: 1 addition & 0 deletions src/corelib/kernel/qcoreapplication_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class Q_CORE_EXPORT QCoreApplicationPrivate

virtual void createEventDispatcher();
virtual void eventDispatcherReady();
virtual bool compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents);
static void removePostedEvent(QEvent *);
#ifdef Q_OS_WIN
static void removePostedTimerEvent(QObject *object, int timerId);
Expand Down
1 change: 1 addition & 0 deletions src/corelib/thread/qthread_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ inline bool operator<(const QPostEvent &first, const QPostEvent &second)

// This class holds the list of posted events.
// The list has to be kept sorted by priority
// ### Qt7 remove the next line
// It's used in a virtual in QCoreApplication, so ELFVERSION:ignore-next
class QPostEventList : public QList<QPostEvent>
{
Expand Down
2 changes: 2 additions & 0 deletions src/gui/kernel/qevent.h
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ class Q_GUI_EXPORT QMoveEvent : public QEvent
protected:
QPoint m_pos, m_oldPos;
friend class QApplication;
friend class QApplicationPrivate;
};

class Q_GUI_EXPORT QExposeEvent : public QEvent
Expand Down Expand Up @@ -556,6 +557,7 @@ class Q_GUI_EXPORT QResizeEvent : public QEvent
protected:
QSize m_size, m_oldSize;
friend class QApplication;
friend class QApplicationPrivate;
};


Expand Down
2 changes: 2 additions & 0 deletions src/gui/kernel/qguiapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2120,13 +2120,15 @@ bool QGuiApplication::event(QEvent *e)
return QCoreApplication::event(e);
}

#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
/*!
\internal
*/
bool QGuiApplication::compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents)
{
return QCoreApplication::compressEvent(event, receiver, postedEvents);
}
#endif

bool QGuiApplicationPrivate::sendQWindowEventToQPlatformWindow(QWindow *window, QEvent *event)
{
Expand Down
2 changes: 2 additions & 0 deletions src/gui/kernel/qguiapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,9 @@ class Q_GUI_EXPORT QGuiApplication : public QCoreApplication
#endif
protected:
bool event(QEvent *) override;
# if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
bool compressEvent(QEvent *, QObject *receiver, QPostEventList *) override;
# endif

QGuiApplication(QGuiApplicationPrivate &p);

Expand Down
9 changes: 8 additions & 1 deletion src/widgets/kernel/qapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,14 @@ QWidget *QApplication::widgetAt(const QPoint &p)
/*!
\internal
*/
#if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
bool QApplication::compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents)
{
return d_func()->compressEvent(event, receiver, postedEvents);
}
#endif

bool QApplicationPrivate::compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents)
{
// Only compress the following events:
const QEvent::Type type = event->type();
Expand All @@ -795,7 +802,7 @@ bool QApplication::compressEvent(QEvent *event, QObject *receiver, QPostEventLis
case QEvent::LanguageChange:
break;
default:
return QGuiApplication::compressEvent(event, receiver, postedEvents);
return QGuiApplicationPrivate::compressEvent(event, receiver, postedEvents);
}

for (const auto &postedEvent : std::as_const(*postedEvents)) {
Expand Down
2 changes: 2 additions & 0 deletions src/widgets/kernel/qapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ public Q_SLOTS:

protected:
bool event(QEvent *) override;
# if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
bool compressEvent(QEvent *, QObject *receiver, QPostEventList *) override;
# endif

private:
Q_DISABLE_COPY(QApplication)
Expand Down
1 change: 1 addition & 0 deletions src/widgets/kernel/qapplication_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ class Q_WIDGETS_EXPORT QApplicationPrivate : public QGuiApplicationPrivate
static void dispatchEnterLeave(QWidget *enter, QWidget *leave, const QPointF &globalPosF);
static QWidget *desktop();
void notifyWindowIconChanged() override;
bool compressEvent(QEvent *event, QObject *receiver, QPostEventList *postedEvents) final;

#ifndef QT_NO_ACTION
QActionPrivate *createActionPrivate() const override;
Expand Down
1 change: 1 addition & 0 deletions src/widgets/kernel/qwidget_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ class QUpdateLaterEvent : public QEvent

protected:
friend class QApplication;
friend class QApplicationPrivate;
QRegion m_region;
};

Expand Down

0 comments on commit 438b2f2

Please sign in to comment.