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;