File indexing completed on 2025-12-15 10:24:10
0001
0002
0003
0004 #ifndef QCHRONOTIMER_H
0005 #define QCHRONOTIMER_H
0006
0007 #ifndef QT_NO_QOBJECT
0008
0009 #include <QtCore/qcoreevent.h>
0010 #include <QtCore/qnamespace.h>
0011 #include <QtCore/qobject.h>
0012 #include <QtCore/qproperty.h>
0013 #include <QtCore/qtimer.h>
0014
0015 #include <chrono>
0016
0017 QT_BEGIN_NAMESPACE
0018
0019 class QTimerPrivate;
0020 class Q_CORE_EXPORT QChronoTimer : public QObject
0021 {
0022 Q_OBJECT
0023 Q_PROPERTY(bool singleShot READ isSingleShot WRITE setSingleShot
0024 BINDABLE bindableSingleShot FINAL)
0025 Q_PROPERTY(std::chrono::nanoseconds interval READ interval WRITE setInterval
0026 BINDABLE bindableInterval FINAL)
0027 Q_PROPERTY(std::chrono::nanoseconds remainingTime READ remainingTime FINAL)
0028 Q_PROPERTY(Qt::TimerType timerType READ timerType WRITE setTimerType
0029 BINDABLE bindableTimerType FINAL)
0030 Q_PROPERTY(bool active READ isActive STORED false BINDABLE bindableActive FINAL)
0031
0032 template <typename Functor>
0033 using FunctorContext = typename QtPrivate::ContextTypeForFunctor<Functor>::ContextType;
0034
0035 public:
0036 explicit QChronoTimer(std::chrono::nanoseconds nsec, QObject *parent = nullptr);
0037 explicit QChronoTimer(QObject *parent = nullptr);
0038 ~QChronoTimer() override;
0039
0040 bool isActive() const;
0041 QBindable<bool> bindableActive();
0042 Qt::TimerId id() const;
0043
0044 void setInterval(std::chrono::nanoseconds nsec);
0045 std::chrono::nanoseconds interval() const;
0046 QBindable<std::chrono::nanoseconds> bindableInterval();
0047
0048 std::chrono::nanoseconds remainingTime() const;
0049
0050 void setTimerType(Qt::TimerType atype);
0051 Qt::TimerType timerType() const;
0052 QBindable<Qt::TimerType> bindableTimerType();
0053
0054 void setSingleShot(bool singleShot);
0055 bool isSingleShot() const;
0056 QBindable<bool> bindableSingleShot();
0057
0058 #ifdef Q_QDOC
0059 template <typename Functor>
0060 QMetaObject::Connection callOnTimeout(const QObject *context, Functor &&slot,
0061 Qt::ConnectionType connectionType = Qt::AutoConnection);
0062 #else
0063 template <typename ... Args>
0064 QMetaObject::Connection callOnTimeout(Args && ...args)
0065 {
0066 return QObject::connect(this, &QChronoTimer::timeout, std::forward<Args>(args)... );
0067 }
0068 #endif
0069
0070 public Q_SLOTS:
0071 void start();
0072 void stop();
0073
0074 Q_SIGNALS:
0075 void timeout(QPrivateSignal);
0076
0077 protected:
0078 void timerEvent(QTimerEvent *) override;
0079
0080 private:
0081 Q_DISABLE_COPY(QChronoTimer)
0082
0083
0084 inline QTimerPrivate *d_func() noexcept
0085 { Q_CAST_IGNORE_ALIGN(return reinterpret_cast<QTimerPrivate *>(qGetPtrHelper(d_ptr));) }
0086 inline const QTimerPrivate *d_func() const noexcept
0087 { Q_CAST_IGNORE_ALIGN(return reinterpret_cast<const QTimerPrivate *>(qGetPtrHelper(d_ptr));) }
0088
0089
0090 int startTimer(std::chrono::nanoseconds) = delete;
0091 void killTimer(int) = delete;
0092 };
0093
0094 QT_END_NAMESPACE
0095
0096 #endif
0097
0098 #endif