Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-07-17 08:38:16

0001 // Copyright (C) 2020 The Qt Company Ltd.
0002 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
0003 // Qt-Security score:significant reason:default
0004 
0005 #ifndef QBASICTIMER_H
0006 #define QBASICTIMER_H
0007 
0008 #include <QtCore/qglobal.h>
0009 #include <QtCore/qabstracteventdispatcher.h>
0010 #include <QtCore/qnamespace.h>
0011 
0012 #include <chrono>
0013 
0014 QT_BEGIN_NAMESPACE
0015 
0016 
0017 class QObject;
0018 
0019 class Q_CORE_EXPORT QBasicTimer
0020 {
0021     Qt::TimerId m_id;
0022     Q_DISABLE_COPY(QBasicTimer)
0023 
0024 public:
0025     // use the same duration type
0026     using Duration = QAbstractEventDispatcher::Duration;
0027 
0028     constexpr QBasicTimer() noexcept : m_id{Qt::TimerId::Invalid} {}
0029     ~QBasicTimer() { if (isActive()) stop(); }
0030 
0031     QBasicTimer(QBasicTimer &&other) noexcept
0032         : m_id{std::exchange(other.m_id, Qt::TimerId::Invalid)}
0033     {}
0034 
0035     QT_MOVE_ASSIGNMENT_OPERATOR_IMPL_VIA_MOVE_AND_SWAP(QBasicTimer)
0036 
0037     void swap(QBasicTimer &other) noexcept { std::swap(m_id, other.m_id); }
0038 
0039     bool isActive() const noexcept { return m_id != Qt::TimerId::Invalid; }
0040     int timerId() const noexcept { return qToUnderlying(id()); }
0041     Qt::TimerId id() const noexcept { return m_id; }
0042     QT_CORE_INLINE_SINCE(6, 5)
0043     void start(int msec, QObject *obj);
0044     QT_CORE_INLINE_SINCE(6, 5)
0045     void start(int msec, Qt::TimerType timerType, QObject *obj);
0046 
0047 #if QT_CORE_REMOVED_SINCE(6, 9)
0048     void start(std::chrono::milliseconds duration, QObject *obj);
0049     void start(std::chrono::milliseconds duration, Qt::TimerType timerType, QObject *obj);
0050 #endif
0051     void start(Duration duration, QObject *obj)
0052     { start(duration, Qt::CoarseTimer, obj); }
0053     void start(Duration duration, Qt::TimerType timerType, QObject *obj);
0054     void stop();
0055 };
0056 Q_DECLARE_TYPEINFO(QBasicTimer, Q_RELOCATABLE_TYPE);
0057 
0058 #if QT_CORE_INLINE_IMPL_SINCE(6, 5)
0059 void QBasicTimer::start(int msec, QObject *obj)
0060 {
0061     start(std::chrono::milliseconds{msec}, obj);
0062 }
0063 
0064 void QBasicTimer::start(int msec, Qt::TimerType t, QObject *obj)
0065 {
0066     start(std::chrono::milliseconds{msec}, t, obj);
0067 }
0068 #endif
0069 
0070 inline void swap(QBasicTimer &lhs, QBasicTimer &rhs) noexcept { lhs.swap(rhs); }
0071 
0072 QT_END_NAMESPACE
0073 
0074 #endif // QBASICTIMER_H