summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAhmad Samir <a.samirh78@gmail.com>2024-08-18 23:32:35 +0300
committerAhmad Samir <a.samirh78@gmail.com>2024-08-31 00:39:26 +0300
commit751cbbd6b13d9899e31c19d9db80d1c64a72a8bd (patch)
treea4d47430499e31ca63db0c63eb5e3a3c24bd848c
parent540451141f24a0ce5256a4066c63763ad03cecc4 (diff)
QBasicTimer: port to Qt::TimerId
[ChangeLog][QtCore][QBasicTimer] Added id() method returning Qt::TimerId. Fixes: QTBUG-128144 Pick-to: 6.8 Change-Id: Idbe29311cca3befb771dbf1ef976a42e65e59ce9 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
-rw-r--r--src/corelib/kernel/qbasictimer.cpp22
-rw-r--r--src/corelib/kernel/qbasictimer.h15
2 files changed, 25 insertions, 12 deletions
diff --git a/src/corelib/kernel/qbasictimer.cpp b/src/corelib/kernel/qbasictimer.cpp
index 17711a355e6..613c0e696d6 100644
--- a/src/corelib/kernel/qbasictimer.cpp
+++ b/src/corelib/kernel/qbasictimer.cpp
@@ -101,13 +101,25 @@ QT_BEGIN_NAMESPACE
/*!
\fn int QBasicTimer::timerId() const
+ \obsolete
Returns the timer's ID.
+ In new code use id() instead.
+
\sa QTimerEvent::timerId()
*/
/*!
+ \fn Qt::TimerId QBasicTimer::id() const
+ \since 6.8
+
+ Returns the timer's ID.
+
+ \sa QTimerEvent::id()
+*/
+
+/*!
\fn void QBasicTimer::start(int msec, QObject *object)
\obsolete Use chrono overload instead.
@@ -165,7 +177,7 @@ void QBasicTimer::start(std::chrono::milliseconds duration, Qt::TimerType timerT
}
stop();
if (obj)
- id = int(eventDispatcher->registerTimer(duration, timerType, obj));
+ m_id = eventDispatcher->registerTimer(duration, timerType, obj);
}
/*!
@@ -175,15 +187,15 @@ void QBasicTimer::start(std::chrono::milliseconds duration, Qt::TimerType timerT
*/
void QBasicTimer::stop()
{
- if (id) {
+ if (isActive()) {
QAbstractEventDispatcher *eventDispatcher = QAbstractEventDispatcher::instance();
- if (eventDispatcher && !eventDispatcher->unregisterTimer(Qt::TimerId(id))) {
+ if (eventDispatcher && !eventDispatcher->unregisterTimer(m_id)) {
qWarning("QBasicTimer::stop: Failed. Possibly trying to stop from a different thread");
return;
}
- QAbstractEventDispatcherPrivate::releaseTimerId(id);
+ QAbstractEventDispatcherPrivate::releaseTimerId(m_id);
}
- id = 0;
+ m_id = Qt::TimerId::Invalid;
}
QT_END_NAMESPACE
diff --git a/src/corelib/kernel/qbasictimer.h b/src/corelib/kernel/qbasictimer.h
index ccc93f6e9be..38fb24bf6fd 100644
--- a/src/corelib/kernel/qbasictimer.h
+++ b/src/corelib/kernel/qbasictimer.h
@@ -16,23 +16,24 @@ class QObject;
class Q_CORE_EXPORT QBasicTimer
{
- int id;
+ Qt::TimerId m_id;
Q_DISABLE_COPY(QBasicTimer)
public:
- constexpr QBasicTimer() noexcept : id{0} {}
- inline ~QBasicTimer() { if (id) stop(); }
+ constexpr QBasicTimer() noexcept : m_id{Qt::TimerId::Invalid} {}
+ ~QBasicTimer() { if (isActive()) stop(); }
QBasicTimer(QBasicTimer &&other) noexcept
- : id{std::exchange(other.id, 0)}
+ : m_id{std::exchange(other.m_id, Qt::TimerId::Invalid)}
{}
QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QBasicTimer)
- void swap(QBasicTimer &other) noexcept { std::swap(id, other.id); }
+ void swap(QBasicTimer &other) noexcept { std::swap(m_id, other.m_id); }
- bool isActive() const noexcept { return id != 0; }
- int timerId() const noexcept { return id; }
+ bool isActive() const noexcept { return m_id != Qt::TimerId::Invalid; }
+ int timerId() const noexcept { return qToUnderlying(id()); }
+ Qt::TimerId id() const noexcept { return m_id; }
QT_CORE_INLINE_SINCE(6, 5)
void start(int msec, QObject *obj);
QT_CORE_INLINE_SINCE(6, 5)