1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3#ifndef QTIMER_P_H
4#define QTIMER_P_H
5//
6// W A R N I N G
7// -------------
8//
9// This file is not part of the Qt API. It exists for the convenience
10// of the Qt translation tools. This header file may change from version
11// to version without notice, or even be removed.
12//
13// We mean it.
14//
15#include "qtimer.h"
16#include "qchronotimer.h"
17
18#include "qobject_p.h"
19#include "qproperty_p.h"
20#include "qttypetraits.h"
21
22QT_BEGIN_NAMESPACE
23
24class QTimerPrivate : public QObjectPrivate
25{
26public:
27 QTimerPrivate(QTimer *qq)
28 : q(qq),
29 isQTimer(true)
30 {}
31
32 QTimerPrivate(std::chrono::nanoseconds nsec, QChronoTimer *qq)
33 : intervalDuration(nsec),
34 q(qq)
35 {
36 intervalDuration.notify();
37 }
38 ~QTimerPrivate() override;
39
40 static constexpr int INV_TIMER = -1; // invalid timer id
41
42 void setIntervalDuration(std::chrono::nanoseconds nsec)
43 {
44 if (isQTimer) {
45 const auto msec = std::chrono::ceil<std::chrono::milliseconds>(d: nsec);
46 static_cast<QTimer *>(q)->setInterval(msec);
47 } else {
48 static_cast<QChronoTimer *>(q)->setInterval(nsec);
49 }
50 }
51
52 void setInterval(int msec)
53 {
54 Q_ASSERT(isQTimer);
55 static_cast<QTimer *>(q)->setInterval(msec);
56 }
57
58 bool isActive() const { return id > Qt::TimerId::Invalid; }
59
60 Qt::TimerId id = Qt::TimerId::Invalid;
61 Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QTimerPrivate, int, inter, &QTimerPrivate::setInterval, 0)
62 Q_OBJECT_COMPAT_PROPERTY_WITH_ARGS(QTimerPrivate, std::chrono::nanoseconds, intervalDuration,
63 &QTimerPrivate::setIntervalDuration,
64 std::chrono::nanoseconds{0})
65 Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(QTimerPrivate, bool, single, false)
66 Q_OBJECT_BINDABLE_PROPERTY_WITH_ARGS(QTimerPrivate, Qt::TimerType, type, Qt::CoarseTimer)
67 Q_OBJECT_COMPUTED_PROPERTY(QTimerPrivate, bool, isActiveData, &QTimerPrivate::isActive)
68
69 QObject *q;
70 const bool isQTimer = false; // true if q is a QTimer*
71};
72
73QT_END_NAMESPACE
74#endif // QTIMER_P_H
75

Provided by KDAB

Privacy Policy
Start learning QML with our Intro Training
Find out more

source code of qtbase/src/corelib/kernel/qtimer_p.h