From 5573e2d6ac09ff8b8f23edca93f601ff7679fa3c Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 1 Mar 2023 08:23:55 +0100 Subject: [PATCH] QBasicTimer: replace new qint64 overloads with chrono ones Found in API review. As per "chrono first" initiative[1], implement the int overload via the chrono one, not vice versa [1] https://lists.qt-project.org/pipermail/development/2023-January/043563.html Pick-to: 6.5 Change-Id: I65fe7039ad8ae5f9eb21d9c59a46b9c5c152fac3 Reviewed-by: Anton Kudryavtsev Reviewed-by: Thiago Macieira Reviewed-by: Qt CI Bot --- src/corelib/compat/removed_api.cpp | 12 +--------- src/corelib/kernel/qbasictimer.cpp | 36 ++++++++++++++++++------------ src/corelib/kernel/qbasictimer.h | 22 ++++++++++++++---- 3 files changed, 41 insertions(+), 29 deletions(-) diff --git a/src/corelib/compat/removed_api.cpp b/src/corelib/compat/removed_api.cpp index 4a9cef2d41..d99ca42122 100644 --- a/src/corelib/compat/removed_api.cpp +++ b/src/corelib/compat/removed_api.cpp @@ -270,17 +270,7 @@ QT_WARNING_POP #if QT_CORE_REMOVED_SINCE(6, 5) -#include "qbasictimer.h" - -void QBasicTimer::start(int msec, QObject *obj) -{ - start(qint64(msec), obj); -} - -void QBasicTimer::start(int msec, Qt::TimerType timerType, QObject *obj) -{ - start(qint64(msec), timerType, obj); -} +#include "qbasictimer.h" // inlined API #include "qbuffer.h" // inline removed API diff --git a/src/corelib/kernel/qbasictimer.cpp b/src/corelib/kernel/qbasictimer.cpp index 7d762047c1..b843ec1ecf 100644 --- a/src/corelib/kernel/qbasictimer.cpp +++ b/src/corelib/kernel/qbasictimer.cpp @@ -102,42 +102,50 @@ QT_BEGIN_NAMESPACE */ /*! - \fn void QBasicTimer::start(qint64 msec, QObject *object) + \fn void QBasicTimer::start(int msec, QObject *object) - Starts (or restarts) the timer with a \a msec milliseconds timeout. The + \obsolete Use chrono overload instead. +*/ + +/*! + \since 6.5 + + Starts (or restarts) the timer with a \a duration timeout. The timer will be a Qt::CoarseTimer. See Qt::TimerType for information on the different timer types. The given \a object will receive timer events. - \note In Qt versions prior to 6.5, \a msec was \c{int}, not - \c{qint64}. - \sa stop(), isActive(), QObject::timerEvent(), Qt::CoarseTimer */ -void QBasicTimer::start(qint64 msec, QObject *obj) +void QBasicTimer::start(std::chrono::milliseconds duration, QObject *object) { - start(msec, Qt::CoarseTimer, obj); + start(duration, Qt::CoarseTimer, object); } /*! + \fn QBasicTimer::start(int msec, Qt::TimerType timerType, QObject *obj) \overload + \obsolete - Starts (or restarts) the timer with a \a msec milliseconds timeout and the + Use chrono overload instead. +*/ + +/*! + \since 6.5 + + Starts (or restarts) the timer with a \a duration timeout and the given \a timerType. See Qt::TimerType for information on the different timer types. \a obj will receive timer events. - \note In Qt versions prior to 6.5, \a msec was \c{int}, not - \c{qint64}. - \sa stop(), isActive(), QObject::timerEvent(), Qt::TimerType */ -void QBasicTimer::start(qint64 msec, Qt::TimerType timerType, QObject *obj) +void QBasicTimer::start(std::chrono::milliseconds duration, Qt::TimerType timerType, QObject *obj) { QAbstractEventDispatcher *eventDispatcher = QAbstractEventDispatcher::instance(); - if (Q_UNLIKELY(msec < 0)) { + if (Q_UNLIKELY(duration.count() < 0)) { qWarning("QBasicTimer::start: Timers cannot have negative timeouts"); return; } @@ -151,7 +159,7 @@ void QBasicTimer::start(qint64 msec, Qt::TimerType timerType, QObject *obj) } stop(); if (obj) - id = eventDispatcher->registerTimer(msec, timerType, obj); + id = eventDispatcher->registerTimer(duration.count(), timerType, obj); } /*! diff --git a/src/corelib/kernel/qbasictimer.h b/src/corelib/kernel/qbasictimer.h index b39a78d293..ccc93f6e9b 100644 --- a/src/corelib/kernel/qbasictimer.h +++ b/src/corelib/kernel/qbasictimer.h @@ -7,6 +7,8 @@ #include #include +#include + QT_BEGIN_NAMESPACE @@ -31,16 +33,28 @@ public: bool isActive() const noexcept { return id != 0; } int timerId() const noexcept { return id; } -#if QT_CORE_REMOVED_SINCE(6, 5) + QT_CORE_INLINE_SINCE(6, 5) void start(int msec, QObject *obj); + QT_CORE_INLINE_SINCE(6, 5) void start(int msec, Qt::TimerType timerType, QObject *obj); -#endif - void start(qint64 msec, QObject *obj); - void start(qint64 msec, Qt::TimerType timerType, QObject *obj); + void start(std::chrono::milliseconds duration, QObject *obj); + void start(std::chrono::milliseconds duration, Qt::TimerType timerType, QObject *obj); void stop(); }; Q_DECLARE_TYPEINFO(QBasicTimer, Q_RELOCATABLE_TYPE); +#if QT_CORE_INLINE_IMPL_SINCE(6, 5) +void QBasicTimer::start(int msec, QObject *obj) +{ + start(std::chrono::milliseconds{msec}, obj); +} + +void QBasicTimer::start(int msec, Qt::TimerType t, QObject *obj) +{ + start(std::chrono::milliseconds{msec}, t, obj); +} +#endif + inline void swap(QBasicTimer &lhs, QBasicTimer &rhs) noexcept { lhs.swap(rhs); } QT_END_NAMESPACE