From 7ce75b1a2bd9f22a7b2b83d48df875c68a47b390 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Sun, 18 Feb 2024 20:50:35 -0800 Subject: [PATCH] QAbstractEventDispatcher: add an adaptation layer to use V2 methods This way, we can begin using the V2 methods now, regardless of whether the concrete dispatcher class has been ported or not. Change-Id: I83dda2d36c904517b3c0fffd17b52a6256b083af Reviewed-by: Ahmad Samir --- .../kernel/qabstracteventdispatcher.cpp | 44 +++++++++++++++++++ src/corelib/kernel/qabstracteventdispatcher.h | 5 +++ 2 files changed, 49 insertions(+) diff --git a/src/corelib/kernel/qabstracteventdispatcher.cpp b/src/corelib/kernel/qabstracteventdispatcher.cpp index c7cf7fe1e2..f3056a399c 100644 --- a/src/corelib/kernel/qabstracteventdispatcher.cpp +++ b/src/corelib/kernel/qabstracteventdispatcher.cpp @@ -69,6 +69,13 @@ static inline QAbstractEventDispatcherV2 *v2(QAbstractEventDispatcher *self) return static_cast(self); return nullptr; } + +static inline const QAbstractEventDispatcherV2 *v2(const QAbstractEventDispatcher *self) +{ + if (QAbstractEventDispatcherPrivate::get(self)->isV2) + return static_cast(self); + return nullptr; +} #endif // Qt 7 QAbstractEventDispatcherPrivate::QAbstractEventDispatcherPrivate() @@ -578,6 +585,43 @@ bool QAbstractEventDispatcher::filterNativeEvent(const QByteArray &eventType, vo */ #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0) +void QAbstractEventDispatcher::registerTimer(Qt::TimerId timerId, Duration interval, + Qt::TimerType timerType, QObject *object) +{ + if (QAbstractEventDispatcherV2 *self = v2(this)) + self->registerTimer(timerId, interval, timerType, object); + else + registerTimer(int(timerId), fromDuration(interval), timerType, object); +} + +bool QAbstractEventDispatcher::unregisterTimer(Qt::TimerId timerId) +{ + if (QAbstractEventDispatcherV2 *self = v2(this)) + return self->unregisterTimer(timerId); + return unregisterTimer(int(timerId)); +} + +QList +QAbstractEventDispatcher::timersForObject(QObject *object) const +{ + if (const QAbstractEventDispatcherV2 *self = v2(this)) + return self->timersForObject(object); + QList timers = registeredTimers(object); + QList result; + result.reserve(timers.size()); + for (const TimerInfo &t : timers) + result.emplaceBack(TimerInfoV2{ t.interval * 1ms, Qt::TimerId(t.timerId), t.timerType }); + return result; +} + +QAbstractEventDispatcher::Duration +QAbstractEventDispatcher::remainingTime(Qt::TimerId timerId) const +{ + if (const QAbstractEventDispatcherV2 *self = v2(this)) + return self->remainingTime(timerId); + return const_cast(this)->remainingTime(int(timerId)) * 1ms; +} + /*! \class QAbstractEventDispatcherV2 \inmodule QtCore diff --git a/src/corelib/kernel/qabstracteventdispatcher.h b/src/corelib/kernel/qabstracteventdispatcher.h index 2332292d09..ad97a93ba2 100644 --- a/src/corelib/kernel/qabstracteventdispatcher.h +++ b/src/corelib/kernel/qabstracteventdispatcher.h @@ -56,6 +56,11 @@ public: virtual bool unregisterTimer(int timerId) = 0; virtual QList registeredTimers(QObject *object) const = 0; virtual int remainingTime(int timerId) = 0; + + void registerTimer(Qt::TimerId timerId, Duration interval, Qt::TimerType timerType, QObject *object); + bool unregisterTimer(Qt::TimerId timerId); + QList timersForObject(QObject *object) const; + Duration remainingTime(Qt::TimerId timerId) const; #else virtual void registerTimer(Qt::TimerId timerId, Duration interval, Qt::TimerType timerType, QObject *object) = 0; virtual bool unregisterTimer(Qt::TimerId timerId) = 0;